# HG changeset patch
# User Asier Lostalé <asier.lostale@openbravo.com>
# Date 1524577321 -7200
#      Tue Apr 24 15:42:01 2018 +0200
# Node ID 56eda0aecd7ff5ef9a1ca0b4f2f0f2a1708ba19f
# Parent  c5d8fbd7e953259aa3bab391b2931d6a9436939e
fixes 38435: plcheck warn selpref not assigned yet in ad_get_preference_value

  The code was weired because inside a loop it emulated continue statements inside
  with boolean variables because in Oracle <11 continue was not supported [1].

  Starting from 11 it is supported [2], so the code has been simplified making use
  of it.

[1] https://code.openbravo.com/erp/devel/pi/rev/db9f2996856b
[2] https://oracle-base.com/articles/11g/continue-statement-in-11gr1

diff -r c5d8fbd7e953 -r 56eda0aecd7f src-db/database/model/functions/AD_GET_PREFERENCE_VALUE.xml
--- a/src-db/database/model/functions/AD_GET_PREFERENCE_VALUE.xml	Wed Apr 25 10:06:27 2018 +0200
+++ b/src-db/database/model/functions/AD_GET_PREFERENCE_VALUE.xml	Tue Apr 24 15:42:01 2018 +0200
@@ -34,7 +34,7 @@
 * under the License.
 * The Original Code is Openbravo ERP.
 * The Initial Developer of the Original Code is Openbravo SLU
-* All portions are Copyright (C) 2010 Openbravo SLU
+* All portions are Copyright (C) 2010-2018 Openbravo SLU
 * All Rights Reserved.
 * Contributor(s):  ______________________________________.
 ************************************************************************/
@@ -42,14 +42,11 @@
   v_ad_org_id varchar2(32);
   depth1 NUMBER;
   depth2 NUMBER;
-  valueAssigned boolean := false;
-  
+ 
   TYPE RECORD IS REF CURSOR;
-    cur RECORD;
-    
+  cur RECORD;
+  
   selPref ad_preference%ROWTYPE;
-  
-  v_continue boolean;
 BEGIN
 
   if p_ad_client_id is null then
@@ -64,7 +61,7 @@
     v_ad_org_id := p_ad_org_id;
   end if;
   
-  
+  selPref := null;
   for cur in 
        (select *
           from ad_preference 
@@ -81,86 +78,82 @@
            and (ad_window_id = p_ad_window_id
                 or aD_window_id is null)
            ) loop
-     v_continue := false;
-     if (not valueAssigned) then
+     if (selPref.ad_preference_id is null) then
        selPref := cur;
-       valueAssigned := true;
-       v_continue := true;
+       continue;
      end if;
      
      --check org priority
-     if ((not v_continue) and selPref.AD_Org_ID is not null and cur.AD_Org_ID is null) then
-       v_continue :=true;
+     if (selPref.AD_Org_ID is not null and cur.AD_Org_ID is null) then
+       continue;
      end if;
      
-     if ((not v_continue) and selPref.AD_Org_ID is null and cur.AD_Org_ID is not null) then
+     if (selPref.AD_Org_ID is null and cur.AD_Org_ID is not null) then
        selPref := cur;
-        v_continue :=true;
+       continue;
      end if;
      
-     if ((not v_continue) and selPref.AD_Org_ID is not null and cur.AD_Org_ID is not null) then
+     if (selPref.AD_Org_ID is not null and cur.AD_Org_ID is not null) then
        depth1 := ad_isorgincluded(v_ad_org_id, coalesce(selPref.visibleAt_Org_id,'0'), v_ad_client_id);
        depth2 := ad_isorgincluded(v_ad_org_id, coalesce(cur.visibleAt_Org_id,'0'), v_ad_client_id);
        if (depth1<depth2) then
-         v_continue := true;
+         continue;
        elsif (depth1>depth2) then
          selPref := cur;
-         v_continue := true;
+         continue;
        end if;
      end if;
      
      --check user priority
-     if ((not v_continue) and selPref.AD_User_ID is not null and cur.AD_User_ID is null) then
-       v_continue := true;
+     if (selPref.AD_User_ID is not null and cur.AD_User_ID is null) then
+       continue;
      end if;
      
-     if ((not v_continue) and selPref.AD_User_ID is null and cur.AD_User_ID is not null) then
+     if (selPref.AD_User_ID is null and cur.AD_User_ID is not null) then
        selPref := cur;
-       v_continue := true;
+       continue;
      end if;
      
      --check role priority
-     if ((not v_continue) and selPref.visibleAt_Role_ID is not null and cur.visibleAt_Role_ID is null) then
-       v_continue := true;
+     if (selPref.visibleAt_Role_ID is not null and cur.visibleAt_Role_ID is null) then
+       continue;
      end if;
      
-     if ((not v_continue) and selPref.visibleAt_Role_ID is null and cur.visibleAt_Role_ID is not null) then
+     if (selPref.visibleAt_Role_ID is null and cur.visibleAt_Role_ID is not null) then
        selPref := cur;
-       v_continue := true;
+       continue;
      end if;
      
      --check window priority
-      if ((not v_continue) and selPref.AD_Window_ID is not null and cur.AD_Window_ID is null) then
-       v_continue := true;
+     if (selPref.AD_Window_ID is not null and cur.AD_Window_ID is null) then
+       continue;
      end if;
      
-     if ((not v_continue) and selPref.AD_Window_ID is null and cur.AD_Window_ID is not null) then
+     if (selPref.AD_Window_ID is null and cur.AD_Window_ID is not null) then
        selPref := cur;
-       v_continue := true;
+       continue;
      end if;
      
      --Same priority, check selected
-     if ((not v_continue) and selPref.selected ='Y' and cur.selected ='N') then
-       v_continue := true;
+     if (selPref.selected ='Y' and cur.selected ='N') then
+       continue;
      end if;
      
-     if ((not v_continue) and selPref.selected ='N' and cur.selected ='Y') then
+     if (selPref.selected ='N' and cur.selected ='Y') then
        selPref := cur;
-       v_continue := true;
+       continue;
      end if;
      
      --Conflict, check same value
-     if ((not v_continue) and selPref.value = cur.value) then
-       v_continue := true;
+     if (selPref.value = cur.value) then
+       continue;
      end if;
      
-     if (not v_continue) then
-       --Actual conflict, raise error
-       RAISE_APPLICATION_ERROR(-20000, p_PROPERTY_NAME||' @PropertyConflict@');
-     end if;
+     --Actual conflict, raise error
+     RAISE_APPLICATION_ERROR(-20000, p_PROPERTY_NAME||' @PropertyConflict@');
    end loop;
    
-   if (not valueAssigned) then
+   if (selPref.ad_preference_id is null) then
      RAISE_APPLICATION_ERROR(-20000, p_PROPERTY_NAME||' @PropertyNotFound@');
    end if;
    
