From 4a078705b35d540d50dd2b1b3ee97d76137c3855 Mon Sep 17 00:00:00 2001 From: mdipierro Date: Sat, 6 Apr 2013 09:38:16 -0500 Subject: [PATCH] fixed issue 1246 with a nested select --- VERSION | 2 +- gluon/sqlhtml.py | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/VERSION b/VERSION index 10e32df1..d033d854 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.4.5-stable+timestamp.2013.04.05.15.59.29 +Version 2.4.5-stable+timestamp.2013.04.06.09.37.36 diff --git a/gluon/sqlhtml.py b/gluon/sqlhtml.py index fac59c5a..01f3a83a 100644 --- a/gluon/sqlhtml.py +++ b/gluon/sqlhtml.py @@ -2121,13 +2121,15 @@ class SQLFORM(FORM): if subquery: dbset = dbset(subquery) try: - if left or groupby: - if groupby: - c = 'count(distinct %s)' % str(groupby) - else: - c = 'count(*)' - nrows = dbset.select(c, left=left, cacheable=True, - groupby=groupby).first()[c] + if groupby: + c = 'count(*)' + nrows = db.executesql( + 'select count(*) from (%s);' % + dbset._select(c, left=left, cacheable=True, + groupby=groupby)[:-1])[0][0] + elif left: + c = 'count(*)' + nrows = dbset.select(c, left=left, cacheable=True).first()[c] elif dbset._db._adapter.dbengine=='google:datastore': #if we don't set a limit, this can timeout for a large table nrows = dbset.db._adapter.count(dbset.query, limit=1000)