Reviewers: ,

Description:
trytond: SUBSTR doesn't allow negative length

Please review this at http://codereview.tryton.org/793002/

Affected files:
  trytond/ir/translation.py


Index: trytond/ir/translation.py
===================================================================
--- a/trytond/ir/translation.py
+++ b/trytond/ir/translation.py
@@ -144,7 +144,10 @@
     def search_model(cls, name, clause):
         cursor = Transaction().cursor
         cursor.execute('SELECT id FROM "%s" '
-            'WHERE SUBSTR(name, 1, POSITION(\',\' IN name) - 1) %s %%s' %
+            'WHERE SUBSTR(name, 1, '
+            'CASE WHEN POSITION(\',\' IN name) > 0 '
+                'THEN POSITION(\',\' IN name) - 1 '
+                'ELSE 0 END) %s %%s' %
             (cls._table, clause[1]), (clause[2],))
         return [('id', 'in', [x[0] for x in cursor.fetchall()])]



Reply via email to