src-db/database/model/functions/AD_TABLE_IMPORT.xml
changeset 13367 0951c9cfecef
parent 11391 af3c2ae60fce
child 13436 7f7af04a2913
equal deleted inserted replaced
13366:d2e5daf7691b 13367:0951c9cfecef
    60     v_IsIdentifier CHAR(1):='N';
    60     v_IsIdentifier CHAR(1):='N';
    61     v_IsSessionAttr CHAR(1):='N';
    61     v_IsSessionAttr CHAR(1):='N';
    62     v_IsUpdateable CHAR(1):='Y';
    62     v_IsUpdateable CHAR(1):='Y';
    63     v_DefaultValue NVARCHAR2(2000):='';
    63     v_DefaultValue NVARCHAR2(2000):='';
    64     v_SeqNo NUMBER(10) ;
    64     v_SeqNo NUMBER(10) ;
       
    65     v_columnNameOrg VARCHAR2(40) ;
    65     v_columnName VARCHAR2(40) ;
    66     v_columnName VARCHAR2(40) ;
    66     v_TableName  VARCHAR2(40) ;
    67     v_TableName  VARCHAR2(40) ;
    67     v_LastColumnName VARCHAR2(40) ;
    68     v_LastColumnName VARCHAR2(40) ;
    68     v_varchar2 VARCHAR2(32767) ;
    69     v_varchar2 VARCHAR2(32767) ;
    69     v_FieldLength NUMBER(10) ;
    70     v_FieldLength NUMBER(10) ;
   227         v_columnName:=UPPER(SUBSTR(v_columnName, 1, INSTR(v_columnName, '_'))) ||SUBSTR(v_columnName, INSTR(v_columnName, '_') +1, 40) ;
   228         v_columnName:=UPPER(SUBSTR(v_columnName, 1, INSTR(v_columnName, '_'))) ||SUBSTR(v_columnName, INSTR(v_columnName, '_') +1, 40) ;
   228       END IF;
   229       END IF;
   229       IF(v_columnName LIKE '%_Id') THEN
   230       IF(v_columnName LIKE '%_Id') THEN
   230         v_columnName:=SUBSTR(v_columnName, 1, LENGTH(v_columnName) -3) ||'_ID';
   231         v_columnName:=SUBSTR(v_columnName, 1, LENGTH(v_columnName) -3) ||'_ID';
   231       END IF;
   232       END IF;
   232       
   233       -- Some columns need to have specific names for DAL to work correctly:
       
   234       v_columnNameOrg:=v_columnName;
       
   235       IF(v_columnName = 'AD_Org_ID') THEN
       
   236         v_columnName:='Organization';
       
   237       END IF;
       
   238       IF(v_columnName = 'AD_Client_ID') THEN
       
   239         v_columnName:='Client';
       
   240       END IF;
       
   241       IF(v_columnName = 'Created') THEN
       
   242         v_columnName:='Creation Date';
       
   243       END IF;
       
   244       IF(v_columnName = 'Createdby') THEN
       
   245         v_columnName:='Created By';
       
   246       END IF;
       
   247       IF(v_columnName = 'Updated') THEN
       
   248         v_columnName:='Updated';
       
   249       END IF;
       
   250       IF(v_columnName = 'Updatedby') THEN
       
   251         v_columnName:='Updated By';
       
   252       END IF;
       
   253       IF(v_columnName = 'Isactive') THEN
       
   254         v_columnName:='Active';
       
   255       END IF;
   233       IF substr(upper(v_columnName),1,3)='EM_' then
   256       IF substr(upper(v_columnName),1,3)='EM_' then
   234         db_prefix := substr(v_columnName,4,instr(v_columnName,'_',1,2)-4);
   257         db_prefix := substr(v_columnName,4,instr(v_columnName,'_',1,2)-4);
   235         DBMS_OUTPUT.PUT_LINE('Prefix:'||db_prefix);
   258         DBMS_OUTPUT.PUT_LINE('Prefix:'||db_prefix);
   236         select max(ad_module_id)
   259         select max(ad_module_id)
   237           into v_module_id
   260           into v_module_id
   282             POSITION, aD_module_id
   305             POSITION, aD_module_id
   283           )
   306           )
   284           VALUES
   307           VALUES
   285           (v_NextNo, '0', '0', 'Y',
   308           (v_NextNo, '0', '0', 'Y',
   286           now(), '0', now(), '0',
   309           now(), '0', now(), '0',
   287           v_columnName, v_columnName, Cur_Column.AD_Table_ID,
   310            v_columnName,v_columnNameOrg, Cur_Column.AD_Table_ID,
   288           v_AD_Reference_ID, v_FieldLength, v_IsKey, v_IsParent,
   311           v_AD_Reference_ID, v_FieldLength, v_IsKey, v_IsParent,
   289          (CASE Cur_Column.Nullable WHEN 'Y' THEN 'N' ELSE 'Y' END),
   312          (CASE Cur_Column.Nullable WHEN 'Y' THEN 'N' ELSE 'Y' END),
   290           v_IsIdentifier, v_SeqNo, 'N', 'N', v_IsUpdateable, v_AD_Reference_Value_ID, 
   313           v_IsIdentifier, v_SeqNo, 'N', 'N', v_IsUpdateable, v_AD_Reference_Value_ID, 
   291           null, v_DefaultValue, v_IsSessionAttr,
   314           null, v_DefaultValue, v_IsSessionAttr,
   292           Cur_Column.COLUMN_ID, v_module_id);
   315           Cur_Column.COLUMN_ID, v_module_id);
   311     IF (v_Record_ID is not null) THEN
   334     IF (v_Record_ID is not null) THEN
   312       v_missingColumns := false;
   335       v_missingColumns := false;
   313       FOR Cur_CommonCols IN (select columnname
   336       FOR Cur_CommonCols IN (select columnname
   314                               from ad_column c
   337                               from ad_column c
   315                              where c.ad_table_id = '100'
   338                              where c.ad_table_id = '100'
   316                                and lower(c.columnname) in ('ad_client_id','ad_org_id','isactive','created','updated','createdby','updatedby')
   339                                and lower(c.columnname) in ('client','organization','active','creation date','updated','created by','updated by')
   317                                and not exists (select 1 
   340                                and not exists (select 1 
   318                                                  from ad_column c1
   341                                                  from ad_column c1
   319                                                 where c1.ad_table_id = v_Record_ID
   342                                                 where c1.ad_table_id = v_Record_ID
   320                                                  and lower(c1.columnname) = lower(c.columnname))) LOOP
   343                                                  and lower(c1.columnname) = lower(c.columnname))) LOOP
   321         v_missingColumns := true;
   344         v_missingColumns := true;