mirror of
https://github.com/postgres/postgres.git
synced 2025-06-10 00:01:28 -04:00
Change some of the existing plpgsql regression test cases so that they
exercise dollar quoting and named function parameters. AFAICS we had no tests of either feature before.
This commit is contained in:
parent
2f48836b1f
commit
6da0c439ee
@ -119,14 +119,14 @@ create trigger tg_room_ad after delete
|
|||||||
-- * BEFORE INSERT or UPDATE on WSlot
|
-- * BEFORE INSERT or UPDATE on WSlot
|
||||||
-- * - Check that room exists
|
-- * - Check that room exists
|
||||||
-- ************************************************************
|
-- ************************************************************
|
||||||
create function tg_wslot_biu() returns trigger as '
|
create function tg_wslot_biu() returns trigger as $$
|
||||||
begin
|
begin
|
||||||
if count(*) = 0 from Room where roomno = new.roomno then
|
if count(*) = 0 from Room where roomno = new.roomno then
|
||||||
raise exception ''Room % does not exist'', new.roomno;
|
raise exception 'Room % does not exist', new.roomno;
|
||||||
end if;
|
end if;
|
||||||
return new;
|
return new;
|
||||||
end;
|
end;
|
||||||
' language 'plpgsql';
|
$$ language plpgsql;
|
||||||
create trigger tg_wslot_biu before insert or update
|
create trigger tg_wslot_biu before insert or update
|
||||||
on WSlot for each row execute procedure tg_wslot_biu();
|
on WSlot for each row execute procedure tg_wslot_biu();
|
||||||
-- ************************************************************
|
-- ************************************************************
|
||||||
@ -159,18 +159,18 @@ create trigger tg_pfield_ad after delete
|
|||||||
-- * BEFORE INSERT or UPDATE on PSlot
|
-- * BEFORE INSERT or UPDATE on PSlot
|
||||||
-- * - Ensure that our patchfield does exist
|
-- * - Ensure that our patchfield does exist
|
||||||
-- ************************************************************
|
-- ************************************************************
|
||||||
create function tg_pslot_biu() returns trigger as '
|
create function tg_pslot_biu() returns trigger as $proc$
|
||||||
declare
|
declare
|
||||||
pfrec record;
|
pfrec record;
|
||||||
rename new to ps;
|
rename new to ps;
|
||||||
begin
|
begin
|
||||||
select into pfrec * from PField where name = ps.pfname;
|
select into pfrec * from PField where name = ps.pfname;
|
||||||
if not found then
|
if not found then
|
||||||
raise exception ''Patchfield "%" does not exist'', ps.pfname;
|
raise exception $$Patchfield "%" does not exist$$, ps.pfname;
|
||||||
end if;
|
end if;
|
||||||
return ps;
|
return ps;
|
||||||
end;
|
end;
|
||||||
' language 'plpgsql';
|
$proc$ language plpgsql;
|
||||||
create trigger tg_pslot_biu before insert or update
|
create trigger tg_pslot_biu before insert or update
|
||||||
on PSlot for each row execute procedure tg_pslot_biu();
|
on PSlot for each row execute procedure tg_pslot_biu();
|
||||||
-- ************************************************************
|
-- ************************************************************
|
||||||
@ -191,25 +191,25 @@ create trigger tg_system_au after update
|
|||||||
-- * BEFORE INSERT or UPDATE on IFace
|
-- * BEFORE INSERT or UPDATE on IFace
|
||||||
-- * - set the slotname to IF.sysname.ifname
|
-- * - set the slotname to IF.sysname.ifname
|
||||||
-- ************************************************************
|
-- ************************************************************
|
||||||
create function tg_iface_biu() returns trigger as '
|
create function tg_iface_biu() returns trigger as $$
|
||||||
declare
|
declare
|
||||||
sname text;
|
sname text;
|
||||||
sysrec record;
|
sysrec record;
|
||||||
begin
|
begin
|
||||||
select into sysrec * from system where name = new.sysname;
|
select into sysrec * from system where name = new.sysname;
|
||||||
if not found then
|
if not found then
|
||||||
raise exception ''system "%" does not exist'', new.sysname;
|
raise exception $q$system "%" does not exist$q$, new.sysname;
|
||||||
end if;
|
end if;
|
||||||
sname := ''IF.'' || new.sysname;
|
sname := 'IF.' || new.sysname;
|
||||||
sname := sname || ''.'';
|
sname := sname || '.';
|
||||||
sname := sname || new.ifname;
|
sname := sname || new.ifname;
|
||||||
if length(sname) > 20 then
|
if length(sname) > 20 then
|
||||||
raise exception ''IFace slotname "%" too long (20 char max)'', sname;
|
raise exception 'IFace slotname "%" too long (20 char max)', sname;
|
||||||
end if;
|
end if;
|
||||||
new.slotname := sname;
|
new.slotname := sname;
|
||||||
return new;
|
return new;
|
||||||
end;
|
end;
|
||||||
' language 'plpgsql';
|
$$ language plpgsql;
|
||||||
create trigger tg_iface_biu before insert or update
|
create trigger tg_iface_biu before insert or update
|
||||||
on IFace for each row execute procedure tg_iface_biu();
|
on IFace for each row execute procedure tg_iface_biu();
|
||||||
-- ************************************************************
|
-- ************************************************************
|
||||||
@ -243,12 +243,10 @@ create trigger tg_hub_a after insert or update or delete
|
|||||||
-- ************************************************************
|
-- ************************************************************
|
||||||
-- * Support function to add/remove slots of Hub
|
-- * Support function to add/remove slots of Hub
|
||||||
-- ************************************************************
|
-- ************************************************************
|
||||||
create function tg_hub_adjustslots(bpchar, integer, integer)
|
create function tg_hub_adjustslots(hname bpchar,
|
||||||
|
oldnslots integer,
|
||||||
|
newnslots integer)
|
||||||
returns integer as '
|
returns integer as '
|
||||||
declare
|
|
||||||
hname alias for $1;
|
|
||||||
oldnslots alias for $2;
|
|
||||||
newnslots alias for $3;
|
|
||||||
begin
|
begin
|
||||||
if newnslots = oldnslots then
|
if newnslots = oldnslots then
|
||||||
return 0;
|
return 0;
|
||||||
@ -262,7 +260,7 @@ begin
|
|||||||
values (''HS.dummy'', hname, i, '''');
|
values (''HS.dummy'', hname, i, '''');
|
||||||
end loop;
|
end loop;
|
||||||
return 0;
|
return 0;
|
||||||
end;
|
end
|
||||||
' language 'plpgsql';
|
' language 'plpgsql';
|
||||||
-- Test comments
|
-- Test comments
|
||||||
COMMENT ON FUNCTION tg_hub_adjustslots_wrong(bpchar, integer, integer) IS 'function with args';
|
COMMENT ON FUNCTION tg_hub_adjustslots_wrong(bpchar, integer, integer) IS 'function with args';
|
||||||
@ -589,11 +587,9 @@ create trigger tg_backlink_a after insert or update or delete
|
|||||||
-- * Support function to set the opponents backlink field
|
-- * Support function to set the opponents backlink field
|
||||||
-- * if it does not already point to the requested slot
|
-- * if it does not already point to the requested slot
|
||||||
-- ************************************************************
|
-- ************************************************************
|
||||||
create function tg_backlink_set(bpchar, bpchar)
|
create function tg_backlink_set(myname bpchar, blname bpchar)
|
||||||
returns integer as '
|
returns integer as '
|
||||||
declare
|
declare
|
||||||
myname alias for $1;
|
|
||||||
blname alias for $2;
|
|
||||||
mytype char(2);
|
mytype char(2);
|
||||||
link char(4);
|
link char(4);
|
||||||
rec record;
|
rec record;
|
||||||
@ -684,8 +680,8 @@ begin
|
|||||||
end if;
|
end if;
|
||||||
return 0;
|
return 0;
|
||||||
end if;
|
end if;
|
||||||
end;
|
end
|
||||||
' language 'plpgsql';
|
' language plpgsql;
|
||||||
-- ************************************************************
|
-- ************************************************************
|
||||||
-- * AFTER INSERT or UPDATE or DELETE on slot with slotlink
|
-- * AFTER INSERT or UPDATE or DELETE on slot with slotlink
|
||||||
-- * - Ensure that the opponent correctly points back to us
|
-- * - Ensure that the opponent correctly points back to us
|
||||||
|
@ -159,14 +159,14 @@ create trigger tg_room_ad after delete
|
|||||||
-- * BEFORE INSERT or UPDATE on WSlot
|
-- * BEFORE INSERT or UPDATE on WSlot
|
||||||
-- * - Check that room exists
|
-- * - Check that room exists
|
||||||
-- ************************************************************
|
-- ************************************************************
|
||||||
create function tg_wslot_biu() returns trigger as '
|
create function tg_wslot_biu() returns trigger as $$
|
||||||
begin
|
begin
|
||||||
if count(*) = 0 from Room where roomno = new.roomno then
|
if count(*) = 0 from Room where roomno = new.roomno then
|
||||||
raise exception ''Room % does not exist'', new.roomno;
|
raise exception 'Room % does not exist', new.roomno;
|
||||||
end if;
|
end if;
|
||||||
return new;
|
return new;
|
||||||
end;
|
end;
|
||||||
' language 'plpgsql';
|
$$ language plpgsql;
|
||||||
|
|
||||||
create trigger tg_wslot_biu before insert or update
|
create trigger tg_wslot_biu before insert or update
|
||||||
on WSlot for each row execute procedure tg_wslot_biu();
|
on WSlot for each row execute procedure tg_wslot_biu();
|
||||||
@ -208,18 +208,18 @@ create trigger tg_pfield_ad after delete
|
|||||||
-- * BEFORE INSERT or UPDATE on PSlot
|
-- * BEFORE INSERT or UPDATE on PSlot
|
||||||
-- * - Ensure that our patchfield does exist
|
-- * - Ensure that our patchfield does exist
|
||||||
-- ************************************************************
|
-- ************************************************************
|
||||||
create function tg_pslot_biu() returns trigger as '
|
create function tg_pslot_biu() returns trigger as $proc$
|
||||||
declare
|
declare
|
||||||
pfrec record;
|
pfrec record;
|
||||||
rename new to ps;
|
rename new to ps;
|
||||||
begin
|
begin
|
||||||
select into pfrec * from PField where name = ps.pfname;
|
select into pfrec * from PField where name = ps.pfname;
|
||||||
if not found then
|
if not found then
|
||||||
raise exception ''Patchfield "%" does not exist'', ps.pfname;
|
raise exception $$Patchfield "%" does not exist$$, ps.pfname;
|
||||||
end if;
|
end if;
|
||||||
return ps;
|
return ps;
|
||||||
end;
|
end;
|
||||||
' language 'plpgsql';
|
$proc$ language plpgsql;
|
||||||
|
|
||||||
create trigger tg_pslot_biu before insert or update
|
create trigger tg_pslot_biu before insert or update
|
||||||
on PSlot for each row execute procedure tg_pslot_biu();
|
on PSlot for each row execute procedure tg_pslot_biu();
|
||||||
@ -246,25 +246,25 @@ create trigger tg_system_au after update
|
|||||||
-- * BEFORE INSERT or UPDATE on IFace
|
-- * BEFORE INSERT or UPDATE on IFace
|
||||||
-- * - set the slotname to IF.sysname.ifname
|
-- * - set the slotname to IF.sysname.ifname
|
||||||
-- ************************************************************
|
-- ************************************************************
|
||||||
create function tg_iface_biu() returns trigger as '
|
create function tg_iface_biu() returns trigger as $$
|
||||||
declare
|
declare
|
||||||
sname text;
|
sname text;
|
||||||
sysrec record;
|
sysrec record;
|
||||||
begin
|
begin
|
||||||
select into sysrec * from system where name = new.sysname;
|
select into sysrec * from system where name = new.sysname;
|
||||||
if not found then
|
if not found then
|
||||||
raise exception ''system "%" does not exist'', new.sysname;
|
raise exception $q$system "%" does not exist$q$, new.sysname;
|
||||||
end if;
|
end if;
|
||||||
sname := ''IF.'' || new.sysname;
|
sname := 'IF.' || new.sysname;
|
||||||
sname := sname || ''.'';
|
sname := sname || '.';
|
||||||
sname := sname || new.ifname;
|
sname := sname || new.ifname;
|
||||||
if length(sname) > 20 then
|
if length(sname) > 20 then
|
||||||
raise exception ''IFace slotname "%" too long (20 char max)'', sname;
|
raise exception 'IFace slotname "%" too long (20 char max)', sname;
|
||||||
end if;
|
end if;
|
||||||
new.slotname := sname;
|
new.slotname := sname;
|
||||||
return new;
|
return new;
|
||||||
end;
|
end;
|
||||||
' language 'plpgsql';
|
$$ language plpgsql;
|
||||||
|
|
||||||
create trigger tg_iface_biu before insert or update
|
create trigger tg_iface_biu before insert or update
|
||||||
on IFace for each row execute procedure tg_iface_biu();
|
on IFace for each row execute procedure tg_iface_biu();
|
||||||
@ -304,12 +304,10 @@ create trigger tg_hub_a after insert or update or delete
|
|||||||
-- ************************************************************
|
-- ************************************************************
|
||||||
-- * Support function to add/remove slots of Hub
|
-- * Support function to add/remove slots of Hub
|
||||||
-- ************************************************************
|
-- ************************************************************
|
||||||
create function tg_hub_adjustslots(bpchar, integer, integer)
|
create function tg_hub_adjustslots(hname bpchar,
|
||||||
|
oldnslots integer,
|
||||||
|
newnslots integer)
|
||||||
returns integer as '
|
returns integer as '
|
||||||
declare
|
|
||||||
hname alias for $1;
|
|
||||||
oldnslots alias for $2;
|
|
||||||
newnslots alias for $3;
|
|
||||||
begin
|
begin
|
||||||
if newnslots = oldnslots then
|
if newnslots = oldnslots then
|
||||||
return 0;
|
return 0;
|
||||||
@ -323,7 +321,7 @@ begin
|
|||||||
values (''HS.dummy'', hname, i, '''');
|
values (''HS.dummy'', hname, i, '''');
|
||||||
end loop;
|
end loop;
|
||||||
return 0;
|
return 0;
|
||||||
end;
|
end
|
||||||
' language 'plpgsql';
|
' language 'plpgsql';
|
||||||
|
|
||||||
-- Test comments
|
-- Test comments
|
||||||
@ -700,11 +698,9 @@ create trigger tg_backlink_a after insert or update or delete
|
|||||||
-- * Support function to set the opponents backlink field
|
-- * Support function to set the opponents backlink field
|
||||||
-- * if it does not already point to the requested slot
|
-- * if it does not already point to the requested slot
|
||||||
-- ************************************************************
|
-- ************************************************************
|
||||||
create function tg_backlink_set(bpchar, bpchar)
|
create function tg_backlink_set(myname bpchar, blname bpchar)
|
||||||
returns integer as '
|
returns integer as '
|
||||||
declare
|
declare
|
||||||
myname alias for $1;
|
|
||||||
blname alias for $2;
|
|
||||||
mytype char(2);
|
mytype char(2);
|
||||||
link char(4);
|
link char(4);
|
||||||
rec record;
|
rec record;
|
||||||
@ -797,8 +793,8 @@ begin
|
|||||||
end if;
|
end if;
|
||||||
return 0;
|
return 0;
|
||||||
end if;
|
end if;
|
||||||
end;
|
end
|
||||||
' language 'plpgsql';
|
' language plpgsql;
|
||||||
|
|
||||||
|
|
||||||
-- ************************************************************
|
-- ************************************************************
|
||||||
|
Loading…
x
Reference in New Issue
Block a user