src-db/database/model/functions/AT_TEST_DELETE.xml
author Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
Wed, 03 Sep 2008 17:55:37 +0000
changeset 1605 8a0fe0193bef
parent 756 ae11e4610537
child 6701 690d2af86089
permissions -rw-r--r--
Merge r2.5x intro trunk
carlos@0
     1
<?xml version="1.0"?>
adrian@94
     2
  <database name="FUNCTION AT_TEST_DELETE">
adrian@94
     3
    <function name="AT_TEST_DELETE" type="NULL">
juanpablo@1605
     4
      <parameter name="p_pinstance_id" type="VARCHAR" mode="in">
antonio@735
     5
        <default/>
antonio@735
     6
      </parameter>
gorkaion@239
     7
      <body><![CDATA[/*************************************************************************
carlos@0
     8
* The contents of this file are subject to the Openbravo  Public  License
carlos@0
     9
* Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
carlos@0
    10
* Version 1.1  with a permitted attribution clause; you may not  use this
carlos@0
    11
* file except in compliance with the License. You  may  obtain  a copy of
carlos@0
    12
* the License at http://www.openbravo.com/legal/license.html
carlos@0
    13
* Software distributed under the License  is  distributed  on  an "AS IS"
carlos@0
    14
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
carlos@0
    15
* License for the specific  language  governing  rights  and  limitations
carlos@0
    16
* under the License.
carlos@0
    17
* The Original Code is Openbravo ERP.
carlos@0
    18
* The Initial Developer of the Original Code is Openbravo SL
carlos@0
    19
* All portions are Copyright (C) 2001-2006 Openbravo SL
carlos@0
    20
* All Rights Reserved.
carlos@0
    21
* Contributor(s):  ______________________________________.
carlos@0
    22
************************************************************************/
carlos@0
    23
  -- Logistice
carlos@0
    24
  v_ResultStr VARCHAR2(2000):='';
carlos@0
    25
  v_Message VARCHAR2(2000):='';
juanpablo@1605
    26
  v_Record_ID VARCHAR2(32);
carlos@0
    27
  -- Parameter
carlos@0
    28
  TYPE RECORD IS REF CURSOR;
carlos@0
    29
    Cur_Parameter RECORD;
carlos@0
    30
    -- Parameter Variables
carlos@0
    31
    v_NoOfLines NUMBER:=0;
carlos@0
    32
  BEGIN
carlos@0
    33
    --  Update AD_PInstance
carlos@0
    34
    DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || p_PInstance_ID) ;
carlos@0
    35
    v_ResultStr:='PInstanceNotFound';
carlos@0
    36
    AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'Y', NULL, NULL) ;
carlos@0
    37
  BEGIN --BODY
carlos@0
    38
    -- Get Parameters
carlos@0
    39
    v_ResultStr:='ReadingParameters';
carlos@0
    40
    FOR Cur_Parameter IN
carlos@0
    41
      (SELECT i.Record_ID, p.ParameterName, p.P_String, p.P_Number, p.P_Date
carlos@0
    42
      FROM AD_PInstance i
carlos@0
    43
      LEFT JOIN AD_PInstance_Para p
carlos@0
    44
        ON i.AD_PInstance_ID=p.AD_PInstance_ID
carlos@0
    45
      WHERE i.AD_PInstance_ID=p_PInstance_ID
carlos@0
    46
      ORDER BY p.SeqNo
carlos@0
    47
      )
carlos@0
    48
    LOOP
carlos@0
    49
      v_Record_ID:=Cur_Parameter.Record_ID;
carlos@0
    50
    END LOOP; -- Get Parameter
carlos@0
    51
    DBMS_OUTPUT.PUT_LINE('  Record_ID=' || v_Record_ID) ;
carlos@0
    52
    --Count number of lines
carlos@0
    53
    SELECT count(*)
carlos@0
    54
    INTO v_NoOfLines
carlos@0
    55
    FROM AT_LINE
carlos@0
    56
    WHERE AT_TEST_ID=v_Record_ID
carlos@0
    57
    GROUP BY AT_TEST_ID;
carlos@0
    58
    --Delete lines
carlos@0
    59
    DELETE FROM AT_LINE  WHERE AT_TEST_ID=v_Record_ID;
carlos@0
    60
    v_Message:='@Deleted@=' || v_NoOfLines || ' lines';
gorkaion@239
    61
    --<<FINISH_PROCESS>>
carlos@0
    62
    --  Update AD_PInstance
carlos@0
    63
    DBMS_OUTPUT.PUT_LINE('Updating PInstance - Finished ' || v_Message) ;
carlos@0
    64
    AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', 1, v_Message) ;
carlos@0
    65
    RETURN;
carlos@0
    66
  END; --BODY
carlos@0
    67
EXCEPTION
carlos@0
    68
WHEN OTHERS THEN
carlos@0
    69
  v_ResultStr:= '@ERROR=' || SQLERRM;
carlos@0
    70
  DBMS_OUTPUT.PUT_LINE(v_ResultStr) ;
carlos@0
    71
  AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', 0, v_ResultStr) ;
carlos@0
    72
  RETURN;
antonio@735
    73
END AT_TEST_DELETE
gorkaion@239
    74
]]></body>
adrian@94
    75
    </function>
adrian@94
    76
  </database>