[sqlutils] avoid a crash with sqlite when using group_concat (closes #3331906) stable
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Thu, 28 Nov 2013 18:55:24 +0100
branchstable
changeset 9334 ea12401c0a68
parent 9333 22423634d06d
child 9335 7da91456be2c
[sqlutils] avoid a crash with sqlite when using group_concat (closes #3331906)
server/sqlutils.py
server/test/unittest_sqlutils.py
--- a/server/sqlutils.py	Thu Oct 24 18:28:18 2013 +0200
+++ b/server/sqlutils.py	Thu Nov 28 18:55:24 2013 +0100
@@ -337,7 +337,8 @@
             if value is not None:
                 self.values.append(value)
         def finalize(self):
-            return ', '.join(self.values)
+            return ', '.join(str(v) for v in self.values)
+
     cnx.create_aggregate("GROUP_CONCAT", 1, group_concat)
 
     def _limit_size(text, maxsize, format='text/plain'):
--- a/server/test/unittest_sqlutils.py	Thu Oct 24 18:28:18 2013 +0200
+++ b/server/test/unittest_sqlutils.py	Thu Nov 28 18:55:24 2013 +0100
@@ -24,6 +24,8 @@
 
 from cubicweb.server.sqlutils import *
 
+from cubicweb.devtools.testlib import CubicWebTC
+
 BASE_CONFIG = {
     'db-driver' : 'Postgres',
     'db-host'   : 'crater',
@@ -44,5 +46,17 @@
         o = SQLAdapterMixIn(config)
         self.assertEqual(o.dbhelper.dbencoding, 'ISO-8859-1')
 
+
+class SQLUtilsTC(CubicWebTC):
+
+    def test_group_concat(self):
+        req = self.request()
+        u = req.create_entity('CWUser', login=u'toto', upassword=u'',
+                              in_group=req.execute('CWGroup G WHERE G name "managers"').rows[0][0])
+        rset = self.execute('Any L,GROUP_CONCAT(G) GROUPBY L WHERE X login L,'
+                            'X in_group G, G name GN, NOT G name "users"')
+        self.assertEqual([[u'admin', u'3'], [u'anon', u'2'], [u'toto', u'3']],
+                         rset.rows)
+
 if __name__ == '__main__':
     unittest_main()