[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb: [125] trunk/utils
- Subject: SF.net SVN: ledger-smb: [125] trunk/utils
- From: ..hidden..
- Date: Wed, 20 Sep 2006 20:49:30 -0700
Revision: 125
http://svn.sourceforge.net/ledger-smb/?rev=125&view=rev
Author: einhverfr
Date: 2006-09-20 20:49:28 -0700 (Wed, 20 Sep 2006)
Log Message:
-----------
Custom fields database support is now an add-on.
Added Paths:
-----------
trunk/utils/custom_fields/
trunk/utils/custom_fields/custom_fields.sql
Added: trunk/utils/custom_fields/custom_fields.sql
===================================================================
--- trunk/utils/custom_fields/custom_fields.sql (rev 0)
+++ trunk/utils/custom_fields/custom_fields.sql 2006-09-21 03:49:28 UTC (rev 125)
@@ -0,0 +1,47 @@
+
+CREATE OR REPLACE FUNCTION add_custom_field (VARCHAR, VARCHAR, VARCHAR)
+RETURNS BOOL AS
+'
+DECLARE
+table_name ALIAS FOR $1;
+new_field_name ALIAS FOR $2;
+field_datatype ALIAS FOR $3;
+
+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)'';
+ 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;
+END;
+' LANGUAGE PLPGSQL;
+
+CREATE OR REPLACE FUNCTION drop_custom_field (VARCHAR, VARCHAR)
+RETURNS BOOL AS
+'
+DECLARE
+table_name ALIAS FOR $1;
+custom_field_name ALIAS FOR $2;
+BEGIN
+ DELETE FROM custom_field_catalog
+ WHERE field_name = custom_field_name AND
+ table_id = (SELECT table_id FROM custom_table_catalog
+ WHERE extends = table_name);
+ EXECUTE ''ALTER TABLE custom_'' || table_name ||
+ '' DROP COLUMN '' || custom_field_name;
+ RETURN TRUE;
+END;
+' LANGUAGE PLPGSQL;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.