src-db/database/model/functions/AD_UPDATE_TABLE_IDENTIFIER.xml
author Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
Wed, 03 Sep 2008 17:55:37 +0000
changeset 1605 8a0fe0193bef
parent 756 ae11e4610537
child 2836 118257a6be77
permissions -rw-r--r--
Merge r2.5x intro trunk
<?xml version="1.0"?>
  <database name="FUNCTION AD_UPDATE_TABLE_IDENTIFIER">
    <function name="AD_UPDATE_TABLE_IDENTIFIER" type="NULL">
      <parameter name="p_pinstance_id" type="VARCHAR" mode="in">
        <default/>
      </parameter>
      <body><![CDATA[/*************************************************************************
* The contents of this file are subject to the Openbravo  Public  License
* Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
* Version 1.1  with a permitted attribution clause; you may not  use this
* file except in compliance with the License. You  may  obtain  a copy of
* the License at http://www.openbravo.com/legal/license.html
* Software distributed under the License  is  distributed  on  an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific  language  governing  rights  and  limitations
* under the License.
* The Original Code is Openbravo ERP.
* The Initial Developer of the Original Code is Openbravo SL
* All portions are Copyright (C) 2001-2006 Openbravo SL
* All Rights Reserved.
* Contributor(s):  ______________________________________.
************************************************************************/
  v_ResultStr VARCHAR2(2000):='';
  v_Message VARCHAR2(2000):='';
  v_Result NUMBER:=1; -- 0=failure
  v_Record_ID VARCHAR2(32);
  v_AD_User_ID VARCHAR2(32);
  v_count NUMBER:=0;
  -- Parameter
  TYPE RECORD IS REF CURSOR;
    Cur_Parameter RECORD;
    v_sql VARCHAR2(4000):='';
    Cur_Tables RECORD;
  BEGIN
    --  Update AD_PInstance
    IF(p_PInstance_ID IS NOT NULL) THEN
      DBMS_OUTPUT.PUT_LINE('AD_Update_Table_Identifier - Processing ' || p_PInstance_ID) ;
      v_ResultStr:='PInstanceNotFound';
      AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'Y', NULL, NULL) ;
      -- Get Parameters
      v_ResultStr:='ReadingParameters';
      FOR Cur_Parameter IN
        (SELECT i.Record_ID, i.AD_User_ID, p.ParameterName, p.P_String, p.P_Number, p.P_Date
        FROM AD_PINSTANCE i
        LEFT JOIN AD_PINSTANCE_PARA p
          ON i.AD_PInstance_ID=p.AD_PInstance_ID
        WHERE i.AD_PInstance_ID=p_PInstance_ID
        ORDER BY p.SeqNo
        )
      LOOP
        v_Record_ID:=Cur_Parameter.Record_ID;
        v_AD_User_ID:=Cur_Parameter.AD_User_ID;
        -- IF (Cur_Parameter.ParameterName = 'xx') THEN
        --  p_xx := Cur_Parameter.P_String;
        --  DBMS_OUTPUT.PUT_LINE('  xx=' || p_xx);
        -- ELSE
        --  DBMS_OUTPUT.PUT_LINE('*** Unknown Parameter=' || Cur_Parameter.ParameterName);
        --  END IF;
      END LOOP; -- Get Parameter
    END IF;
  BEGIN --BODY
    v_ResultStr:='ExecutingUpdates';
    FOR Cur_Tables IN
      (SELECT TABLENAME FROM AD_TABLE)
    LOOP
      v_sql:=Ad_Column_Identifier_Sql(Cur_Tables.TABLENAME) ;
      UPDATE AD_TABLE
        SET SQL_RECORD_IDENTIFIER=v_sql
      WHERE TABLENAME=Cur_Tables.TABLENAME;
      v_count:=v_count + 1;
    END LOOP;
    v_Message:='@Updated@: ' || v_count;
    --<<FINISH_PROCESS>>
    DBMS_OUTPUT.PUT_LINE('AD_Update_Table_Identifier - Finished ' || v_Message) ;
    --  Update AD_PInstance
    IF(p_PInstance_ID IS NOT NULL) THEN
      AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', v_Result, v_Message) ;
    END IF;
    RETURN;
  END; --BODY
EXCEPTION
WHEN OTHERS THEN
  v_ResultStr:= '@ERROR=' || SQLERRM;
  DBMS_OUTPUT.PUT_LINE(v_ResultStr) ;
  ROLLBACK;
  IF(p_PInstance_ID IS NOT NULL) THEN
    AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', 0, v_ResultStr) ;
  END IF;
  RETURN;
END AD_UPDATE_TABLE_IDENTIFIER
]]></body>
    </function>
  </database>