# HG changeset patch # User Aurelien Campeas # Date 1385661324 -3600 # Node ID ea12401c0a68aeb6ce356c76e39a90ea6bc996b6 # Parent 22423634d06dad3cd2db8059d146fdb3e1eb88e9 [sqlutils] avoid a crash with sqlite when using group_concat (closes #3331906) diff -r 22423634d06d -r ea12401c0a68 server/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'): diff -r 22423634d06d -r ea12401c0a68 server/test/unittest_sqlutils.py --- 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()