IDEMPIERE-730 03_update_sequences.sql for native sequence

This commit is contained in:
Carlos Ruiz 2013-04-22 15:56:04 -05:00
parent 4a33f4434e
commit 9388df405b
2 changed files with 25 additions and 6 deletions

View File

@ -3,6 +3,7 @@ DECLARE
cmdsys VARCHAR2 (1000); cmdsys VARCHAR2 (1000);
cmdnosys VARCHAR2 (1000); cmdnosys VARCHAR2 (1000);
cmdseq VARCHAR2 (1000); cmdseq VARCHAR2 (1000);
cmdcrseq VARCHAR2 (1000);
cmdupd VARCHAR2 (1000); cmdupd VARCHAR2 (1000);
currentnextsys NUMBER (10); currentnextsys NUMBER (10);
currentnext NUMBER (10); currentnext NUMBER (10);
@ -10,6 +11,8 @@ DECLARE
Currentseq Number (10); Currentseq Number (10);
Isnativeseqon Varchar2(1); Isnativeseqon Varchar2(1);
sqlcmd VARCHAR2(200); sqlcmd VARCHAR2(200);
seq_doesnot_exist EXCEPTION;
PRAGMA EXCEPTION_INIT(seq_doesnot_exist, -2289);
BEGIN BEGIN
DBMS_OUTPUT.PUT_LINE ('Start'); DBMS_OUTPUT.PUT_LINE ('Start');
@ -20,6 +23,7 @@ BEGIN
FROM AD_COLUMN c FROM AD_COLUMN c
WHERE t.ad_table_id = c.ad_table_id WHERE t.ad_table_id = c.ad_table_id
AND c.columnname = t.tablename || '_ID') AND c.columnname = t.tablename || '_ID')
AND IsView= 'N'
ORDER BY 1) ORDER BY 1)
LOOP LOOP
cmdsys := cmdsys :=
@ -87,17 +91,23 @@ BEGIN
|| 'WHERE Name = ''' || 'WHERE Name = '''
|| r.Tablename || r.Tablename
|| ''' AND istableid = ''Y'''; || ''' AND istableid = ''Y''';
BEGIN
EXECUTE IMMEDIATE cmdseq INTO currentseq, currentseqsys;
EXCEPTION
WHEN seq_doesnot_exist THEN
cmdcrseq:= 'CREATE SEQUENCE '||Trim(R.Tablename)||'_SQ MINVALUE 1000000 MAXVALUE 2147483647 INCREMENT BY 1 START WITH 1000000';
Execute Immediate cmdcrseq;
EXECUTE IMMEDIATE cmdseq INTO currentseq, currentseqsys;
END;
ELSE ELSE
cmdseq := cmdseq :=
'SELECT currentnext, currentnextsys FROM AD_Sequence ' 'SELECT currentnext, currentnextsys FROM AD_Sequence '
|| 'WHERE Name = ''' || 'WHERE Name = '''
|| r.tablename || r.tablename
|| ''' AND istableid = ''Y'''; || ''' AND istableid = ''Y''';
EXECUTE IMMEDIATE cmdseq INTO currentseq, currentseqsys;
END IF; END IF;
EXECUTE IMMEDIATE cmdseq
INTO currentseq, currentseqsys;
IF currentnextsys <> currentseqsys OR (currentnext <> currentseq AND Isnativeseqon ='N') IF currentnextsys <> currentseqsys OR (currentnext <> currentseq AND Isnativeseqon ='N')
THEN THEN
DBMS_OUTPUT.PUT_LINE ( r.tablename DBMS_OUTPUT.PUT_LINE ( r.tablename

View File

@ -1,9 +1,10 @@
CREATE OR REPLACE FUNCTION update_sequences() RETURNS void as $func$
-- TODO: Currently not inserting new sequences -- TODO: Currently not inserting new sequences
CREATE OR REPLACE FUNCTION update_sequences() RETURNS void as $func$
DECLARE DECLARE
cmdsys VARCHAR (1000); cmdsys VARCHAR (1000);
cmdnosys VARCHAR (1000); cmdnosys VARCHAR (1000);
cmdseq VARCHAR (1000); cmdseq VARCHAR (1000);
cmdcrseq VARCHAR (1000);
cmdupd VARCHAR (1000); cmdupd VARCHAR (1000);
currentnextsys NUMERIC (10); currentnextsys NUMERIC (10);
currentnext NUMERIC (10); currentnext NUMERIC (10);
@ -21,6 +22,7 @@ BEGIN
FROM AD_COLUMN c FROM AD_COLUMN c
WHERE t.ad_table_id = c.ad_table_id WHERE t.ad_table_id = c.ad_table_id
AND c.columnname = t.tablename || '_ID') AND c.columnname = t.tablename || '_ID')
AND IsView= 'N'
ORDER BY 1) ORDER BY 1)
LOOP LOOP
cmdsys := cmdsys :=
@ -82,15 +84,22 @@ BEGIN
|| 'WHERE Name = ''' || 'WHERE Name = '''
|| r.tablename || r.tablename
|| ''' AND istableid = ''Y'''; || ''' AND istableid = ''Y''';
BEGIN
EXECUTE cmdseq INTO currentseq, currentseqsys;
EXCEPTION
WHEN undefined_table THEN
cmdcrseq := 'CREATE SEQUENCE '||trim(r.tablename)||'_SQ INCREMENT 1 MINVALUE 1000000 MAXVALUE 2147483647 START '||currentseq;
EXECUTE cmdcrseq;
EXECUTE cmdseq INTO currentseq, currentseqsys;
END;
ELSE ELSE
cmdseq := cmdseq :=
'SELECT currentnext, currentnextsys FROM AD_Sequence ' 'SELECT currentnext, currentnextsys FROM AD_Sequence '
|| 'WHERE Name = ''' || 'WHERE Name = '''
|| r.tablename || r.tablename
|| ''' AND istableid = ''Y'''; || ''' AND istableid = ''Y''';
END IF;
EXECUTE cmdseq INTO currentseq, currentseqsys; EXECUTE cmdseq INTO currentseq, currentseqsys;
END IF;
IF currentnextsys <> currentseqsys OR (currentnext <> currentseq AND isnativeseqon ='N') IF currentnextsys <> currentseqsys OR (currentnext <> currentseq AND isnativeseqon ='N')
THEN THEN