[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb: [498] trunk/sql/legacy/Pg-upgrade-2.6.18-2.6.19.sql
- Subject: SF.net SVN: ledger-smb: [498] trunk/sql/legacy/Pg-upgrade-2.6.18-2.6.19.sql
- From: ..hidden..
- Date: Wed, 08 Nov 2006 10:34:30 -0800
Revision: 498
http://svn.sourceforge.net/ledger-smb/?rev=498&view=rev
Author: einhverfr
Date: 2006-11-08 10:32:17 -0800 (Wed, 08 Nov 2006)
Log Message:
-----------
Fixed bug: custom field tables don't contain declared primary key
Modified Paths:
--------------
trunk/sql/legacy/Pg-upgrade-2.6.18-2.6.19.sql
Modified: trunk/sql/legacy/Pg-upgrade-2.6.18-2.6.19.sql
===================================================================
--- trunk/sql/legacy/Pg-upgrade-2.6.18-2.6.19.sql 2006-11-08 18:28:25 UTC (rev 497)
+++ trunk/sql/legacy/Pg-upgrade-2.6.18-2.6.19.sql 2006-11-08 18:32:17 UTC (rev 498)
@@ -278,4 +278,31 @@
DROP TABLE old_defaults;
+
+CREATE OR REPLACE FUNCTION add_custom_field (VARCHAR, VARCHAR, VARCHAR)
+RETURNS BOOL AS
+'BEGIN
+ EXECUTE ''SELECT TABLE_ID FROM custom_table_catalog
+ WHERE extends = '''''' || table_name || '''''' '';
+ IF NOT FOUND THEN
+ BEGIN
+ INSERT INTO custom_table_catalog (extends)
+ VALUES (table_name);
+ EXECUTE ''CREATE TABLE custom_''||table_name ||
+ '' (row_id INT PRIMARY KEY)'';
+ EXCEPTION WHEN duplicate_table THEN
+ -- do nothing
+ END;
+ END IF;
+ EXECUTE ''INSERT INTO custom_field_catalog (field_name, table_id)
+ VALUES ( '''''' || new_field_name ||'''''', (SELECT table_id FROM custom_table_catalog
+ WHERE extends = ''''''|| table_name || ''''''))'';
+ EXECUTE ''ALTER TABLE custom_''||table_name || '' ADD COLUMN ''
+ || new_field_name || '' '' || field_datatype;
+ RETURN TRUE;
+' LANGUAGE PLPGSQL;
+
+END;
+
+
COMMIT;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.