[Print PDF] Replaced trigger with a unique partial index
authorAaron Calero <aaron.calero@openbravo.com>
Thu, 14 Mar 2019 13:20:12 +0100
changeset 32495 c191a834ff54
parent 32494 672664220013
child 32496 b5f399f8e0b1
[Print PDF] Replaced trigger with a unique partial index
src-db/database/model/tables/C_FILE.xml
src-db/database/model/triggers/C_FILE_TRG2.xml
--- a/src-db/database/model/tables/C_FILE.xml	Wed Mar 13 15:45:10 2019 +0100
+++ b/src-db/database/model/tables/C_FILE.xml	Thu Mar 14 13:20:12 2019 +0100
@@ -81,6 +81,9 @@
       <foreign-key foreignTable="AD_TABLE" name="C_FILE_AD_TABLE" onDelete="cascade">
         <reference local="AD_TABLE_ID" foreign="AD_TABLE_ID"/>
       </foreign-key>
+      <index name="C_FILE_ATTACHMENT_UNQ" unique="true">
+        <index-column name="functionBasedColumn" functionExpression="CASE WHEN KEEPANDATTACHPRINTFILE=&apos;Y&apos; THEN ad_table_id || ad_record_id ELSE NULL END"/>
+      </index>
       <index name="C_FILE_KEEPANDATTACH_IDX" unique="false">
         <index-column name="KEEPANDATTACHPRINTFILE"/>
       </index>
--- a/src-db/database/model/triggers/C_FILE_TRG2.xml	Wed Mar 13 15:45:10 2019 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-<?xml version="1.0"?>
-  <database name="TRIGGER C_FILE_TRG2">
-    <trigger name="C_FILE_TRG2" table="C_FILE" fires="before" insert="true" update="true" delete="false" foreach="row">
-      <body><![CDATA[
-    /*************************************************************************
-    * The contents of this file are subject to the Openbravo  Public  License
-    * Version  1.1  (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 SLU
-    * All portions are Copyright (C) 2016-2017 Openbravo SLU
-    * All Rights Reserved.
-    * Contributor(s):  ______________________________________.
-    ************************************************************************/
-
-v_count NUMBER;
-BEGIN
-  IF AD_isTriggerEnabled()='N' THEN RETURN;
-  END IF;
-
-  -- Get number of attachments with multiple prints stored
-  SELECT count(1) INTO v_count
-    FROM c_file
-    WHERE keepandattachprintfile = 'Y'
-    AND :new.ad_table_id = ad_table_id
-    AND :new.ad_record_id = ad_record_id;
-
-  IF (v_count > 0) THEN
-    RAISE_APPLICATION_ERROR(-20000, '@DuplicatedStoredPrinting@');
-  END IF;
-
-END C_FILE_TRG2
-]]></body>
-    </trigger>
-  </database>