src-db/database/model/functions/AD_TABLE_IMPORT.xml
changeset 799 fef2c5e2feb7
parent 785 8dba91261590
child 1027 2e9052d7de0e
equal deleted inserted replaced
798:4994e5a604bb 799:fef2c5e2feb7
    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;
       
    67     v_Client_ID NUMBER;
    66   BEGIN
    68   BEGIN
    67     IF(p_PInstance_ID IS NOT NULL) THEN
    69     IF(p_PInstance_ID IS NOT NULL) THEN
    68       --  Update AD_PInstance
    70       --  Update AD_PInstance
    69       DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || p_PInstance_ID) ;
    71       DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || p_PInstance_ID) ;
    70       v_ResultStr:='PInstanceNotFound';
    72       v_ResultStr:='PInstanceNotFound';
    71       AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'Y', NULL, NULL) ;
    73       AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'Y', NULL, NULL) ;
    72       -- Get Parameters
    74       -- Get Parameters
    73       v_ResultStr:='ReadingParameters';
    75       v_ResultStr:='ReadingParameters';
    74       FOR Cur_Parameter IN
    76       FOR Cur_Parameter IN
    75         (SELECT i.Record_ID, i.AD_User_ID, p.ParameterName, p.P_String, p.P_Number, p.P_Date
    77         (SELECT i.Record_ID, i.AD_User_ID, p.ParameterName, p.P_String, p.P_Number, p.P_Date, p.AD_CLIENT_ID
    76         FROM AD_PInstance i
    78         FROM AD_PInstance i
    77         LEFT JOIN AD_PInstance_Para p
    79         LEFT JOIN AD_PInstance_Para p
    78           ON i.AD_PInstance_ID=p.AD_PInstance_ID
    80           ON i.AD_PInstance_ID=p.AD_PInstance_ID
    79         WHERE i.AD_PInstance_ID=p_PInstance_ID
    81         WHERE i.AD_PInstance_ID=p_PInstance_ID
    80         ORDER BY p.SeqNo
    82         ORDER BY p.SeqNo
    81         )
    83         )
    82       LOOP
    84       LOOP
    83         v_Record_ID:=Cur_Parameter.Record_ID;
    85         v_Record_ID:=Cur_Parameter.Record_ID;
    84         v_AD_User_ID:=Cur_Parameter.AD_User_ID;
    86         v_AD_User_ID:=Cur_Parameter.AD_User_ID;
       
    87         v_Client_ID:=Cur_Parameter.AD_CLIENT_ID;
    85       END LOOP; -- Get Parameter
    88       END LOOP; -- Get Parameter
    86     ELSE
    89     ELSE
    87       v_Record_ID:=p_AD_Table_ID;
    90       v_Record_ID:=p_AD_Table_ID;
    88     END IF;
    91     END IF;
    89     DBMS_OUTPUT.PUT_LINE('  Record_ID=' || v_Record_ID) ;
    92     DBMS_OUTPUT.PUT_LINE('  Record_ID=' || v_Record_ID) ;
    96     ELSE
    99     ELSE
    97       v_SeqNo:=0;
   100       v_SeqNo:=0;
    98     END IF;
   101     END IF;
    99     FOR Cur_Column IN
   102     FOR Cur_Column IN
   100       (SELECT Column_Name, Data_Type, Data_Length, Nullable, AD_Table_ID, -- added by Ismael Ciordia
   103       (SELECT Column_Name, Data_Type, Data_Length, Nullable, AD_Table_ID, -- added by Ismael Ciordia
   101         uc.DATA_PRECISION, uc.DATA_SCALE, DATA_DEFAULT, Table_Name, t.EntityType
   104         uc.DATA_PRECISION, uc.DATA_SCALE, DATA_DEFAULT, Table_Name
   102       FROM User_Tab_Columns uc, AD_Table t
   105       FROM User_Tab_Columns uc, AD_Table t
   103       WHERE uc.Table_Name=UPPER(t.TableName) AND NOT EXISTS
   106       WHERE uc.Table_Name=UPPER(t.TableName) AND NOT EXISTS
   104         (SELECT *
   107         (SELECT *
   105         FROM AD_Table t, AD_Column c
   108         FROM AD_Table t, AD_Column c
   106         WHERE t.AD_Table_ID=c.AD_Table_ID  AND uc.Table_Name=UPPER(t.TableName) AND uc.Column_Name=UPPER(c.ColumnName)
   109         WHERE t.AD_Table_ID=c.AD_Table_ID  AND uc.Table_Name=UPPER(t.TableName) AND uc.Column_Name=UPPER(c.ColumnName)
   214       INSERT
   217       INSERT
   215       INTO AD_COLUMN
   218       INTO AD_COLUMN
   216         (
   219         (
   217           AD_COLUMN_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE,
   220           AD_COLUMN_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE,
   218           CREATED, CREATEDBY, UPDATED, UPDATEDBY,
   221           CREATED, CREATEDBY, UPDATED, UPDATEDBY,
   219           NAME, VERSION, COLUMNNAME, AD_TABLE_ID,
   222           NAME, COLUMNNAME, AD_TABLE_ID,
   220           AD_REFERENCE_ID, FIELDLENGTH, ISKEY, ISPARENT,
   223           AD_REFERENCE_ID, FIELDLENGTH, ISKEY, ISPARENT,
   221           ISMANDATORY, ISIDENTIFIER, SEQNO, ISTRANSLATED,
   224           ISMANDATORY, ISIDENTIFIER, SEQNO, ISTRANSLATED,
   222           ISENCRYPTED, EntityType, ISUPDATEABLE, AD_REFERENCE_VALUE_ID,
   225           ISENCRYPTED, ISUPDATEABLE, AD_REFERENCE_VALUE_ID,
   223           AD_VAL_RULE_ID, DEFAULTVALUE, ISSESSIONATTR
   226           AD_VAL_RULE_ID, DEFAULTVALUE, ISSESSIONATTR
   224         )
   227         )
   225         VALUES
   228         VALUES
   226         (v_NextNo, 0, 0, 'Y',
   229         (v_NextNo, 0, 0, 'Y',
   227         now(), 0, now(), 0,
   230         now(), 0, now(), 0,
   228         v_columnName, 1, v_columnName, Cur_Column.AD_Table_ID,
   231         v_columnName, v_columnName, Cur_Column.AD_Table_ID,
   229         v_AD_Reference_ID, v_FieldLength, v_IsKey, v_IsParent,
   232         v_AD_Reference_ID, v_FieldLength, v_IsKey, v_IsParent,
   230        (CASE Cur_Column.Nullable WHEN 'Y' THEN 'N' ELSE 'Y' END),
   233        (CASE Cur_Column.Nullable WHEN 'Y' THEN 'N' ELSE 'Y' END),
   231         v_IsIdentifier, v_SeqNo, 'N', 'N', Cur_Column.EntityType, 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) ;
   232       --
   235       --
   233       v_count:=v_count + 1;
   236       v_count:=v_count + 1;
   234       -- Added by Ismael Ciordia
   237       -- Added by Ismael Ciordia
   235       v_SeqNo:=v_SeqNo + 10;
   238       v_SeqNo:=v_SeqNo + 10;
   236       v_LastColumnName:=Cur_Column.Column_Name;
   239       v_LastColumnName:=Cur_Column.Column_Name;
   237       -- Falta: insert de AD_Element
   240       -- Falta: insert de AD_Element
   238       IF(p_PInstance_ID IS NOT NULL) THEN
   241       IF(p_PInstance_ID IS NOT NULL) THEN
       
   242         AD_SEQUENCE_NEXT('AD_PInstance_Log', v_Client_ID, v_PInstance_Log_ID);
   239         INSERT
   243         INSERT
   240         INTO AD_PInstance_Log
   244         INTO AD_PInstance_Log
   241           (
   245           (
   242             AD_PInstance_ID, Log_ID, P_Msg
   246             AD_PInstance_ID, Log_ID, P_Msg
   243           )
   247           )
   244           VALUES
   248           VALUES
   245           (p_PInstance_ID, AD_PInstance_Seq.NextVal, '@Created@ @AD_Column_ID@ ' || InitCap(Cur_Column.Table_Name) || '.' || InitCap(Cur_Column.Column_Name)) ;
   249           (p_PInstance_ID, v_PInstance_Log_ID, '@Created@ @AD_Column_ID@ ' || InitCap(Cur_Column.Table_Name) || '.' || InitCap(Cur_Column.Column_Name)) ;
   246       ELSE
   250       ELSE
   247         DBMS_OUTPUT.PUT_LINE('adding Table ' || InitCap(Cur_Column.Table_Name) || ' Column ' || InitCap(Cur_Column.Column_Name)) ;
   251         DBMS_OUTPUT.PUT_LINE('adding Table ' || InitCap(Cur_Column.Table_Name) || ' Column ' || InitCap(Cur_Column.Column_Name)) ;
   248       END IF;
   252       END IF;
   249     END LOOP; --  All new columns
   253     END LOOP; --  All new columns
   250     -- Summary info
   254     -- Summary info