You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
164 lines
4.9 KiB
164 lines
4.9 KiB
-- Funktionen um Laender zu verwalten --
|
|
-- [
|
|
create function "chk_land" (text,varchar(3),varchar(4))
|
|
returns int4 as '
|
|
/*
|
|
* chk_land(land, lnd_kz, vorwahl_l)
|
|
*
|
|
* ueberpruefen ob das Land schon in der DB gespeichert ist.
|
|
*
|
|
* returns: -1: falsche Parameter
|
|
* -2: Inkonsistenz endeckt. Es existiert bereits ein
|
|
* Land mit dem einer, aber nicht alle der Parameter
|
|
* uebereinstimmen
|
|
* 0: Land existiert noch nicht in der DB
|
|
* >0: Land existiert bereits, gibt id_land zurueck.
|
|
*/
|
|
|
|
DECLARE
|
|
idl adresse.land%ROWTYPE;
|
|
BEGIN
|
|
IF $1 IS NULL OR $1 = '''' OR
|
|
$2 IS NULL OR $2 = '''' OR
|
|
$3 IS NULL OR $3 = '''' THEN
|
|
RETURN -1;
|
|
END IF;
|
|
|
|
/*
|
|
* Jeder der Teile is unique, existiert also einer der Teile
|
|
* schon aber mit anderen Partnern dann is ein Fehler aufgetreten.
|
|
*/
|
|
select INTO idl * from adresse.land where
|
|
land = $1 or
|
|
lnd_kz = $2 or
|
|
vorwahl_l = $3;
|
|
|
|
IF NOT FOUND THEN
|
|
RETURN 0;
|
|
ELSE
|
|
IF idl.land <> $1 OR idl.lnd_kz <> $2 OR
|
|
idl.vorwahl_l <> $3 THEN
|
|
RETURN -2;
|
|
END IF;
|
|
END IF;
|
|
|
|
RETURN idl._id_;
|
|
END;
|
|
' language 'plpgsql';
|
|
|
|
create function "ins_land" (text,varchar(3),varchar(4))
|
|
returns int4 as '
|
|
/*
|
|
* ins_land(land, lnd_kz, vorwahl_l)
|
|
*
|
|
* fuegt ein Land in die DB ein sofern es nicht schon existiert,
|
|
* inkonsistenzen erzeugt wuerden, oder die Eingabedaten fehlerhast
|
|
* sind.
|
|
*
|
|
* returns: 0: wenn das Land nicht eingefuegt werden kann
|
|
* >0: wenn das Land eingefuegt werden konnte oder bereits
|
|
* existierte, gibt id_land zurueck.
|
|
*/
|
|
|
|
DECLARE
|
|
id_land adresse.land._id_%TYPE;
|
|
BEGIN
|
|
/*
|
|
* Daten ueberpruefen (siehe chk_land)
|
|
*/
|
|
select INTO id_land adresse.chk_land($1, $2, $3);
|
|
|
|
IF id_land < 0 THEN
|
|
RETURN 0;
|
|
ELSE
|
|
IF id_land = 0 THEN
|
|
insert into adresse.land (land, lnd_kz, vorwahl_l)
|
|
values ($1, $2, $3);
|
|
|
|
select INTO id_land adresse.chk_land($1, $2, $3);
|
|
END IF;
|
|
END IF;
|
|
|
|
RETURN id_land;
|
|
END;
|
|
' language 'plpgsql';
|
|
|
|
create function "id_land_by_land" (text)
|
|
returns int4 as '
|
|
/*
|
|
* get_id_land_by_land(land)
|
|
*
|
|
* Ermittelt die id (id_land) eines in der DB enthaltenen Landes
|
|
* anhand seiner Bezeuchnung (land.land)
|
|
*
|
|
* returns: 0: wenn das Land nicht eingefuegt werden kann
|
|
* >0: wenn das Land gefunden wurde, gibt id_land zurueck.
|
|
*/
|
|
|
|
DECLARE
|
|
idl adresse.land._id_%TYPE;
|
|
BEGIN
|
|
select INTO idl _id_ from adresse.land where
|
|
land = $1;
|
|
|
|
IF NOT FOUND THEN
|
|
RETURN 0;
|
|
ELSE
|
|
RETURN idl;
|
|
END IF;
|
|
END;
|
|
' language 'plpgsql';
|
|
|
|
create function "id_land_by_lnd_kz" (varchar(3))
|
|
returns int4 as '
|
|
/*
|
|
* get_id_land_by_lnd_kz(lnd_kz)
|
|
*
|
|
* Ermittelt die id (id_land) eines in der DB enthaltenen Landes
|
|
* anhand des internationalen Kennzeichens (land.lnd_kz)
|
|
*
|
|
* returns: 0: wenn das Land nicht eingefuegt werden kann
|
|
* >0: wenn das Land gefunden wurde, gibt id_land zurueck.
|
|
*/
|
|
|
|
DECLARE
|
|
idl adresse.land._id_%TYPE;
|
|
BEGIN
|
|
select INTO idl _id_ from adresse.land where
|
|
lnd_kz = $1;
|
|
|
|
IF NOT FOUND THEN
|
|
RETURN 0;
|
|
ELSE
|
|
RETURN idl;
|
|
END IF;
|
|
END;
|
|
' language 'plpgsql';
|
|
|
|
create function "id_land_by_vorwahl_l" (varchar(4))
|
|
returns int4 as '
|
|
/*
|
|
* get_id_land_by_vorwahl_l(vorwahl_l)
|
|
*
|
|
* Ermittelt die id (id_land) eines in der DB enthaltenen Landes
|
|
* anhand die internationalen Laendervorwahl (land.land_kz)
|
|
*
|
|
* returns: 0: wenn das Land nicht eingefuegt werden kann
|
|
* >0: wenn das Land gefunden wurde, gibt id_land zurueck.
|
|
*/
|
|
|
|
DECLARE
|
|
idl adresse.land._id_%TYPE;
|
|
BEGIN
|
|
select INTO idl _id_ from adresse.land where
|
|
vorwahl_l = $1;
|
|
|
|
IF NOT FOUND THEN
|
|
RETURN 0;
|
|
ELSE
|
|
RETURN idl;
|
|
END IF;
|
|
END;
|
|
' language 'plpgsql';
|
|
-- ]
|
|
-- Ende Laender --
|