src-db/database/model/functions/AD_TABLE_IMPORT.xml
changeset 1605 8a0fe0193bef
parent 1027 2e9052d7de0e
child 1653 628e629d96db
equal deleted inserted replaced
1604:a1c518e6ed93 1605:8a0fe0193bef
     1 <?xml version="1.0"?>
     1 <?xml version="1.0"?>
     2   <database name="FUNCTION AD_TABLE_IMPORT">
     2   <database name="FUNCTION AD_TABLE_IMPORT">
     3     <function name="AD_TABLE_IMPORT" type="NULL">
     3     <function name="AD_TABLE_IMPORT" type="NULL">
     4       <parameter name="p_pinstance_id" type="NUMERIC" mode="in">
     4       <parameter name="p_pinstance_id" type="VARCHAR" mode="in">
     5         <default/>
     5         <default/>
     6       </parameter>
     6       </parameter>
     7       <parameter name="p_ad_table_id" type="NUMERIC" mode="in">
     7       <parameter name="p_ad_table_id" type="VARCHAR" mode="in">
     8         <default/>
     8         <default/>
     9       </parameter>
     9       </parameter>
    10       <body><![CDATA[/*************************************************************************
    10       <body><![CDATA[/*************************************************************************
    11   * The contents of this file are subject to the Compiere Public
    11   * The contents of this file are subject to the Compiere Public
    12   * License 1.1 ("License"); You may not use this file except in
    12   * License 1.1 ("License"); You may not use this file except in
    35   ************************************************************************/
    35   ************************************************************************/
    36   -- Logistice
    36   -- Logistice
    37   v_ResultStr VARCHAR2(2000):='';
    37   v_ResultStr VARCHAR2(2000):='';
    38   v_Message VARCHAR2(2000):='';
    38   v_Message VARCHAR2(2000):='';
    39   v_Result NUMBER:=1; -- 0=failure
    39   v_Result NUMBER:=1; -- 0=failure
    40   v_Record_ID NUMBER;
    40   v_Record_ID VARCHAR2(32);
    41   v_AD_User_ID NUMBER:=0;
    41   v_AD_User_ID VARCHAR2(32):='0';
    42   -- Parameter
    42   -- Parameter
    43   TYPE RECORD IS REF CURSOR;
    43   TYPE RECORD IS REF CURSOR;
    44     Cur_Parameter RECORD;
    44     Cur_Parameter RECORD;
    45     -- Parameter Variables
    45     -- Parameter Variables
    46     --
    46     --
    47     Cur_Column RECORD;
    47     Cur_Column RECORD;
    48     --
    48     --
    49     v_NextNo NUMBER(10) ;
    49     v_NextNo VARCHAR2(32) ;
    50     v_count NUMBER(10):=0;
    50     v_count NUMBER(10):=0;
    51     -- Added by Ismael Ciordia
    51     -- Added by Ismael Ciordia
    52     v_AD_Reference_ID NUMBER;
    52     v_AD_Reference_ID VARCHAR2(32);
    53     v_AD_Reference_Value_ID NUMBER;
    53     v_AD_Reference_Value_ID VARCHAR2(32);
    54     v_AD_Val_Rule_ID NUMBER;
    54     v_AD_Val_Rule_ID VARCHAR2(32);
    55     v_IsParent CHAR(1):='N';
    55     v_IsParent CHAR(1):='N';
    56     v_IsKey CHAR(1):='N';
    56     v_IsKey CHAR(1):='N';
    57     v_IsIdentifier CHAR(1):='N';
    57     v_IsIdentifier CHAR(1):='N';
    58     v_IsSessionAttr CHAR(1):='N';
    58     v_IsSessionAttr CHAR(1):='N';
    59     v_IsUpdateable CHAR(1):='Y';
    59     v_IsUpdateable CHAR(1):='Y';
    61     v_SeqNo NUMBER(10) ;
    61     v_SeqNo NUMBER(10) ;
    62     v_columnName VARCHAR2(40) ;
    62     v_columnName VARCHAR2(40) ;
    63     v_LastColumnName VARCHAR2(40) ;
    63     v_LastColumnName VARCHAR2(40) ;
    64     v_varchar2 VARCHAR2(32767) ;
    64     v_varchar2 VARCHAR2(32767) ;
    65     v_FieldLength NUMBER(10) ;
    65     v_FieldLength NUMBER(10) ;
    66     v_PInstance_Log_ID NUMBER;
    66     v_PInstance_Log_ID VARCHAR2(32);
    67     v_Client_ID NUMBER;
    67     v_Client_ID VARCHAR2(32);
    68   BEGIN
    68   BEGIN
    69     IF(p_PInstance_ID IS NOT NULL) THEN
    69     IF(p_PInstance_ID IS NOT NULL) THEN
    70       --  Update AD_PInstance
    70       --  Update AD_PInstance
    71       DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || p_PInstance_ID) ;
    71       DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || p_PInstance_ID) ;
    72       v_ResultStr:='PInstanceNotFound';
    72       v_ResultStr:='PInstanceNotFound';
   184       ELSE
   184       ELSE
   185         v_FieldLength:=Cur_Column.Data_Length;
   185         v_FieldLength:=Cur_Column.Data_Length;
   186       END IF;
   186       END IF;
   187       IF(v_AD_Reference_ID IS NULL) THEN
   187       IF(v_AD_Reference_ID IS NULL) THEN
   188         IF(Cur_Column.Data_Type IN('CHAR','BPCHAR') AND Cur_Column.Data_Length=1) THEN
   188         IF(Cur_Column.Data_Type IN('CHAR','BPCHAR') AND Cur_Column.Data_Length=1) THEN
   189           v_AD_Reference_ID:=20;
   189           v_AD_Reference_ID:='20';
   190         ELSIF(Cur_Column.Data_Type IN('VARCHAR2', 'NVARCHAR2', 'CHAR', 'NCHAR') AND Cur_Column.Data_Length=4000) THEN
   190         ELSIF(Cur_Column.Data_Type IN('VARCHAR2', 'NVARCHAR2', 'CHAR', 'NCHAR') AND Cur_Column.Data_Length=4000) THEN
   191           v_AD_Reference_ID:=14;
   191           v_AD_Reference_ID:='14';
   192         ELSIF(Cur_Column.Data_Type IN('VARCHAR2', 'NVARCHAR2', 'CHAR', 'NCHAR')) THEN
   192         ELSIF(Cur_Column.Data_Type IN('VARCHAR2', 'NVARCHAR2', 'CHAR', 'NCHAR')) THEN
   193           v_AD_Reference_ID:=10;
   193           v_AD_Reference_ID:='10';
   194         ELSIF(Cur_Column.Data_Type IN('VARCHAR2', 'NVARCHAR2', 'CHAR', 'NCHAR')) THEN
   194         ELSIF(Cur_Column.Data_Type IN('VARCHAR2', 'NVARCHAR2', 'CHAR', 'NCHAR')) THEN
   195           v_AD_Reference_ID:=10;
   195           v_AD_Reference_ID:='10';
   196         ELSIF(Cur_Column.Data_Type='NUMBER' AND Cur_Column.DATA_SCALE=0) THEN
   196         ELSIF(Cur_Column.Data_Type='NUMBER' AND Cur_Column.DATA_SCALE=0) THEN
   197           v_AD_Reference_ID:=11;
   197           v_AD_Reference_ID:='11';
   198         ELSIF(Cur_Column.Data_Type='NUMBER' AND UPPER(Cur_Column.Column_Name) LIKE '%AMT%') THEN
   198         ELSIF(Cur_Column.Data_Type='NUMBER' AND UPPER(Cur_Column.Column_Name) LIKE '%AMT%') THEN
   199           v_AD_Reference_ID:=12;
   199           v_AD_Reference_ID:='12';
   200         ELSIF(Cur_Column.Data_Type='NUMBER' AND UPPER(Cur_Column.Column_Name) LIKE '%QTY%') THEN
   200         ELSIF(Cur_Column.Data_Type='NUMBER' AND UPPER(Cur_Column.Column_Name) LIKE '%QTY%') THEN
   201           v_AD_Reference_ID:=29;
   201           v_AD_Reference_ID:='29';
   202         ELSIF(Cur_Column.Data_Type='NUMBER') THEN
   202         ELSIF(Cur_Column.Data_Type='NUMBER') THEN
   203           v_AD_Reference_ID:=22;
   203           v_AD_Reference_ID:='22';
   204         ELSIF(Cur_Column.Data_Type='DATE') THEN
   204         ELSIF(Cur_Column.Data_Type='DATE') THEN
   205           v_AD_Reference_ID:=15;
   205           v_AD_Reference_ID:='15';
   206         ELSE
   206         ELSE
   207           v_AD_Reference_ID:=10; -- if not found, use String
   207           v_AD_Reference_ID:='10'; -- if not found, use String
   208         END IF;
   208         END IF;
   209       END IF;
   209       END IF;
   210       v_columnName:=InitCap(Cur_Column.Column_Name) ;
   210       v_columnName:=InitCap(Cur_Column.Column_Name) ;
   211       IF(INSTR(v_columnName, '_')<>0 AND INSTR(v_columnName, '_')<5) THEN
   211       IF(INSTR(v_columnName, '_')<>0 AND INSTR(v_columnName, '_')<5) THEN
   212         v_columnName:=UPPER(SUBSTR(v_columnName, 1, INSTR(v_columnName, '_'))) ||SUBSTR(v_columnName, INSTR(v_columnName, '_') +1, 40) ;
   212         v_columnName:=UPPER(SUBSTR(v_columnName, 1, INSTR(v_columnName, '_'))) ||SUBSTR(v_columnName, INSTR(v_columnName, '_') +1, 40) ;
   224           ISMANDATORY, ISIDENTIFIER, SEQNO, ISTRANSLATED,
   224           ISMANDATORY, ISIDENTIFIER, SEQNO, ISTRANSLATED,
   225           ISENCRYPTED, ISUPDATEABLE, AD_REFERENCE_VALUE_ID,
   225           ISENCRYPTED, ISUPDATEABLE, AD_REFERENCE_VALUE_ID,
   226           AD_VAL_RULE_ID, DEFAULTVALUE, ISSESSIONATTR
   226           AD_VAL_RULE_ID, DEFAULTVALUE, ISSESSIONATTR
   227         )
   227         )
   228         VALUES
   228         VALUES
   229         (v_NextNo, 0, 0, 'Y',
   229         (v_NextNo, '0', '0', 'Y',
   230         now(), 0, now(), 0,
   230         now(), '0', now(), '0',
   231         v_columnName, v_columnName, Cur_Column.AD_Table_ID,
   231         v_columnName, v_columnName, Cur_Column.AD_Table_ID,
   232         v_AD_Reference_ID, v_FieldLength, v_IsKey, v_IsParent,
   232         v_AD_Reference_ID, v_FieldLength, v_IsKey, v_IsParent,
   233        (CASE Cur_Column.Nullable WHEN 'Y' THEN 'N' ELSE 'Y' END),
   233        (CASE Cur_Column.Nullable WHEN 'Y' THEN 'N' ELSE 'Y' END),
   234         v_IsIdentifier, v_SeqNo, 'N', 'N', v_IsUpdateable, v_AD_Reference_Value_ID, v_AD_Val_Rule_ID, v_DefaultValue, v_IsSessionAttr) ;
   234         v_IsIdentifier, v_SeqNo, 'N', 'N', v_IsUpdateable, v_AD_Reference_Value_ID, v_AD_Val_Rule_ID, v_DefaultValue, v_IsSessionAttr) ;
   235       --
   235       --