# HG changeset patch
# User Asier Lostalé <asier.lostale@openbravo.com>
# Date 1330601667 -3600
# Node ID 532a18059f15cc1fa5a7bcd45164cc5d45bbc004
# Parent  6eca00939cc8409d6d1c33e4e0b4072b35976059
fixed bug 17821: Improved performance in ad_parent_tree function

Proper exit recursivity instead of waiting for an exception to be thrown

diff -r 6eca00939cc8 -r 532a18059f15 src-db/database/model/functions/AD_PARENT_TREE.xml
--- a/src-db/database/model/functions/AD_PARENT_TREE.xml	Wed Feb 29 23:29:42 2012 +0100
+++ b/src-db/database/model/functions/AD_PARENT_TREE.xml	Thu Mar 01 12:34:27 2012 +0100
@@ -19,7 +19,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) 2001-2008 Openbravo SLU
+* All portions are Copyright (C) 2001-2012 Openbravo SLU
 * All Rights Reserved.
 * Contributor(s):  ______________________________________.
 ************************************************************************/
@@ -33,8 +33,12 @@
    WHERE node_id = p_node_id
      AND ad_tree_id = p_tree_id;
 
+    IF vp IS NULL THEN
+      RETURN ' ';
+    ELSE
+      p := ad_parent_tree(p_tree_id, vp);
+    END IF;
 
-    p := ad_parent_tree(p_tree_id, vp);
     IF p != ' ' THEN
       RETURN '|'||vp||'|'||p;
     END IF;
