[IMP] models: when checking for data in a table, do not use column 'id'
authorRaphael Collet <rco@openerp.com>
Wed, 24 Sep 2014 13:41:09 +0000 (15:41 +0200)
committerRaphael Collet <rco@openerp.com>
Thu, 25 Sep 2014 08:37:28 +0000 (10:37 +0200)
Replace the query "SELECT min(id) FROM xxx" by "SELECT 1 FROM xxx LIMIT 1".
Both requests are as efficient, and the second one does not crash if column
'id' is missing.

openerp/models.py

index 360c220..4f9fc28 100644 (file)
@@ -2502,8 +2502,8 @@ class BaseModel(object):
                 self._create_table(cr)
                 has_rows = False
             else:
-                cr.execute('SELECT min(id) FROM "%s"' % (self._table,))
-                has_rows = cr.fetchone()[0] is not None
+                cr.execute('SELECT 1 FROM "%s" LIMIT 1' % self._table)
+                has_rows = cr.rowcount
 
             cr.commit()
             if self._parent_store: