From e532181e97ad2542ca7621820acc1902fb07f44b Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Fri, 26 Jan 2007 10:06:05 +0000 Subject: [PATCH] * Replace some sqlj function with pl/pgsql version. --- db/ddlutils/postgresql/build.xml | 22 +++++++++- db/ddlutils/postgresql/init.sql | 66 ---------------------------- db/ddlutils/postgresql/operators.sql | 9 ++++ 3 files changed, 29 insertions(+), 68 deletions(-) delete mode 100644 db/ddlutils/postgresql/init.sql create mode 100644 db/ddlutils/postgresql/operators.sql diff --git a/db/ddlutils/postgresql/build.xml b/db/ddlutils/postgresql/build.xml index 7896cd9b55..886c37e527 100644 --- a/db/ddlutils/postgresql/build.xml +++ b/db/ddlutils/postgresql/build.xml @@ -49,7 +49,7 @@ - @@ -74,7 +74,25 @@ - + + + + + + + + + + + + + + + + + + + diff --git a/db/ddlutils/postgresql/init.sql b/db/ddlutils/postgresql/init.sql deleted file mode 100644 index bd34912945..0000000000 --- a/db/ddlutils/postgresql/init.sql +++ /dev/null @@ -1,66 +0,0 @@ -/** Change Numeric for Integer */ -CREATE OR REPLACE FUNCTION adempiere.ID (record NUMERIC) -RETURNS INTEGER AS $$ -DECLARE -ID integer := 0; -BEGIN - ID := CAST(record AS INTEGER); - --RAISE NOTICE 'Quantity here is %', ID; - RETURN ID; -END; -$$ LANGUAGE plpgsql VOLATILE; - -CREATE OR REPLACE FUNCTION adempiere.getdate() -RETURNS TIMESTAMP WITH TIME ZONE AS $$ -BEGIN - RETURN now(); -END; -$$ LANGUAGE plpgsql VOLATILE; - -/**TIMESTAMP WITH TIME ZONE **/ -CREATE OR REPLACE FUNCTION adempiere.addDays (day TIMESTAMP WITH TIME ZONE, days DECIMAL) -RETURNS TIMESTAMP WITH TIME ZONE AS $$ -BEGIN - RETURN adempiere.addDays(day,adempiere.ID(days)); -END; -$$ LANGUAGE plpgsql VOLATILE; - - -CREATE OR REPLACE FUNCTION adempiere.subtractdays (day TIMESTAMP WITH TIME ZONE, days DECIMAL) -RETURNS TIMESTAMP WITH TIME ZONE AS $$ -BEGIN - RETURN adempiere.addDays(day,adempiere.ID(days * -1)); -END; -$$ LANGUAGE plpgsql VOLATILE; - -CREATE OR REPLACE FUNCTION adddays("day" timestamp with time zone, days integer) RETURNS timestamp with time zone - AS $$org.compiere.sqlj.Adempiere.addDays(java.sql.Timestamp,int)$$ - LANGUAGE java; - - -CREATE OR REPLACE FUNCTION adempiere.subtractdays (day TIMESTAMP WITH TIME ZONE, days INTEGER) -RETURNS TIMESTAMP WITH TIME ZONE AS $$ -BEGIN - RETURN adempiere.addDays(day,days * -1); -END; -$$ LANGUAGE plpgsql VOLATILE; - -DROP OPERATOR adempiere.+ (timestamptz, INTEGER); -CREATE OPERATOR adempiere.+ ( PROCEDURE = adempiere.adddays, -LEFTARG = TIMESTAMPTZ, RIGHTARG = INTEGER, -COMMUTATOR = +); - -DROP OPERATOR adempiere.- (timestamptz, INTEGER); -CREATE OPERATOR adempiere.- ( PROCEDURE = adempiere.subtractdays, -LEFTARG = TIMESTAMPTZ, RIGHTARG = INTEGER, -COMMUTATOR = -); - -DROP OPERATOR adempiere.+ (timestamptz, NUMERIC); -CREATE OPERATOR adempiere.+ ( PROCEDURE = adempiere.adddays, -LEFTARG = TIMESTAMPTZ, RIGHTARG = NUMERIC, -COMMUTATOR = +); - -DROP OPERATOR adempiere.- (timestamptz, NUMERIC); -CREATE OPERATOR adempiere.- ( PROCEDURE = adempiere.subtractdays, -LEFTARG = TIMESTAMPTZ, RIGHTARG = NUMERIC, -COMMUTATOR = -); diff --git a/db/ddlutils/postgresql/operators.sql b/db/ddlutils/postgresql/operators.sql new file mode 100644 index 0000000000..333762b29a --- /dev/null +++ b/db/ddlutils/postgresql/operators.sql @@ -0,0 +1,9 @@ +DROP OPERATOR + (timestamptz, NUMERIC); +CREATE OPERATOR + ( PROCEDURE = adddays, +LEFTARG = TIMESTAMPTZ, RIGHTARG = NUMERIC, +COMMUTATOR = +); + +DROP OPERATOR - (timestamptz, NUMERIC); +CREATE OPERATOR - ( PROCEDURE = subtractdays, +LEFTARG = TIMESTAMPTZ, RIGHTARG = NUMERIC, +COMMUTATOR = -);