From: Andre-Littoz <ajl...@us...> - 2013-11-17 11:12:11
|
Update of /cvsroot/lxr/lxr/templates/initdb In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv23311/templates/initdb Modified Files: initdb-o-template.sql initdb-p-template.sql initdb-s-template.sql Log Message: templates/initdb/initdb-o-template.sql, initdb-p-template.sql, initdb-s-template.sql: manage "relation" reference count directly from SQL trigger instead of from Perl programming Index: initdb-o-template.sql =================================================================== RCS file: /cvsroot/lxr/lxr/templates/initdb/initdb-o-template.sql,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- initdb-o-template.sql 11 Jan 2013 12:08:48 -0000 1.3 +++ initdb-o-template.sql 17 Nov 2013 11:12:07 -0000 1.4 @@ -1,7 +1,7 @@ /*- -*- tab-width: 4 -*- -*/ /*- * SQL template for creating Oracle tables - * (C) 2012 A. Littoz + * (C) 2012-2013 A. Littoz * $Id$ * * This template is intended to be customised by Perl script @@ -222,10 +222,33 @@ unique (symnane) ); +create index %DB_tbl_prefix%symlookup + on %DB_tbl_prefix%files(symname); + /* The following function decrements the symbol reference count + * for a definition * (to be used in triggers). */ -create or replace procedure %DB_tbl_prefix%decsym() +create or replace procedure %DB_tbl_prefix%decdecl() +as +begin + update %DB_tbl_prefix%symbols + set symcount = symcount - 1 + where symid = old.symid + and symcount > 0; + if old.relid is not null + then update %DB_tbl_prefix%symbols + set symcount = symcount - 1 + where symid = old.relid + and symcount > 0; + end if; +end; + +/* The following function decrements the symbol reference count + * for a usage + * (to be used in triggers). + */ +create or replace procedure %DB_tbl_prefix%decusage() as begin update %DB_tbl_prefix%symbols @@ -233,7 +256,6 @@ where symid = old.symid and symcount > 0; end; -/ commit; @@ -275,7 +297,7 @@ create or replace trigger %DB_tbl_prefix%remove_definition after delete on %DB_tbl_prefix%definitions for each row - execute procedure %DB_tbl_prefix%decsym(); + execute procedure %DB_tbl_prefix%decdecl(); commit; @@ -301,7 +323,7 @@ create or replace trigger %DB_tbl_prefix%remove_usage after delete on %DB_tbl_prefix%usages for each row - execute procedure %DB_tbl_prefix%decsym(); + execute procedure %DB_tbl_prefix%decusage(); commit; Index: initdb-p-template.sql =================================================================== RCS file: /cvsroot/lxr/lxr/templates/initdb/initdb-p-template.sql,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- initdb-p-template.sql 11 Jan 2013 12:08:48 -0000 1.3 +++ initdb-p-template.sql 17 Nov 2013 11:12:07 -0000 1.4 @@ -1,7 +1,7 @@ /*- -*- tab-width: 4 -*- -*/ /*- * SQL template for creating PostgreSQL tables - * (C) 2012 A. Littoz + * (C) 2012-2013 A. Littoz * $Id$ * * This template is intended to be customised by Perl script @@ -321,12 +321,16 @@ , constraint %DB_tbl_prefix%uk_symbols unique (symname) ); +-- create index %DB_tbl_prefix%symlookup +-- on %DB_tbl_prefix%symbols +-- using btree (symname); /* The following function decrements the symbol reference count + * for a definition * (to be used in triggers). */ -drop function if exists %DB_tbl_prefix%decsym(); -create function %DB_tbl_prefix%decsym() +drop function if exists %DB_tbl_prefix%decdecl(); +create function %DB_tbl_prefix%decdecl() returns trigger language PLpgSQL /*@IF %_shell% */ @@ -339,7 +343,39 @@ set symcount = symcount - 1 where symid = old.symid and symcount > 0; - return old; + if old.relid is not null + then update %DB_tbl_prefix%symbols + set symcount = symcount - 1 + where symid = old.relid + and symcount > 0; + end if; + return new; + end; +/*@IF %_shell% */ + \$\$; +/*@ELSE*/ + $$; +/*@ENDIF %_shell% */ + +/* The following function decrements the symbol reference count + * for a usage + * (to be used in triggers). + */ +drop function if exists %DB_tbl_prefix%decusage(); +create function %DB_tbl_prefix%decusage() + returns trigger + language PLpgSQL +/*@IF %_shell% */ + as \$\$ +/*@ELSE*/ + as $$ +/*@ENDIF %_shell% */ + begin + update %DB_tbl_prefix%symbols + set symcount = symcount - 1 + where symid = old.symid + and symcount > 0; + return new; end; /*@IF %_shell% */ \$\$; @@ -383,12 +419,32 @@ /* The following trigger maintains correct symbol reference count * after definition deletion. */ +-- drop function if exists %DB_tbl_prefix%proxy_rem_def(); +-- create function %DB_tbl_prefix%proxy_rem_def() +-- returns trigger +-- language PLpgSQL +-- /*@IF %_shell% */ +-- as \$\$ +-- /*@ELSE*/ +-- as $$ +-- /*@ENDIF %_shell% */ +-- begin +-- perform %DB_tbl_prefix%decsym(old.symid); +-- if old.relid is not null +-- then perform %DB_tbl_prefix%decsym(old.relid); +-- end if; +-- end; +-- /*@IF %_shell% */ +-- \$\$; +-- /*@ELSE*/ +-- $$; +-- /*@ENDIF %_shell% */ drop trigger if exists %DB_tbl_prefix%remove_definition on %DB_tbl_prefix%definitions; create trigger %DB_tbl_prefix%remove_definition after delete on %DB_tbl_prefix%definitions for each row - execute procedure %DB_tbl_prefix%decsym(); + execute procedure %DB_tbl_prefix%decdecl(); /* Usages */ create table %DB_tbl_prefix%usages @@ -409,12 +465,29 @@ /* The following trigger maintains correct symbol reference count * after usage deletion. */ +-- drop function if exists %DB_tbl_prefix%proxy_rem_usg(); +-- create function %DB_tbl_prefix%proxy_rem_usg() +-- returns trigger +-- language PLpgSQL +-- /*@IF %_shell% */ +-- as \$\$ +-- /*@ELSE*/ +-- as $$ +-- /*@ENDIF %_shell% */ +-- begin +-- perform %DB_tbl_prefix%decsym(old.symid); +-- end; +-- /*@IF %_shell% */ +-- \$\$; +-- /*@ELSE*/ +-- $$; +-- /*@ENDIF %_shell% */ drop trigger if exists %DB_tbl_prefix%remove_usage on %DB_tbl_prefix%usages; create trigger %DB_tbl_prefix%remove_usage after delete on %DB_tbl_prefix%usages for each row - execute procedure %DB_tbl_prefix%decsym(); + execute procedure %DB_tbl_prefix%decusage(); grant select on %DB_tbl_prefix%files to public; grant select on %DB_tbl_prefix%symbols to public; Index: initdb-s-template.sql =================================================================== RCS file: /cvsroot/lxr/lxr/templates/initdb/initdb-s-template.sql,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- initdb-s-template.sql 11 Jan 2013 12:08:48 -0000 1.3 +++ initdb-s-template.sql 17 Nov 2013 11:12:07 -0000 1.4 @@ -1,7 +1,7 @@ /*- -*- tab-width: 4 -*- */ /* * SQL template for creating MySQL tables - * (C) 2012 A. Littoz + * (C) 2012-2013 A. Littoz * $Id$ * * This template is intended to be customised by Perl script @@ -181,6 +181,8 @@ , symcount int , symname varchar(255) not null unique ); +create index %DB_tbl_prefix%symlookup + on %DB_tbl_prefix%symbols(symname); /* Definitions */ /* symid, fileid and line define the location of the declaration @@ -226,6 +228,11 @@ set symcount = symcount - 1 where symid = old.symid and symcount > 0; + update %DB_tbl_prefix%symbols + set symcount = symcount - 1 + where symid = old.relid + and symcount > 0 + and old.relid is not null; end; /* Usages */ |