Hi,
I haven't had a chance to dig through
why this is coming up, but it seems
like count() for selectables is
getting rebound from what FromClause
defines. Test code and output are
below.
--- test code:
# Test count() on selectable
import sqlalchemy as rdb
engine = rdb.create_engine('sqlite://', echo=True)
# Setup the data
t1 = rdb.Table(
't1', engine,
rdb.Column('id', rdb.Integer, primary_key=True),
rdb.Column('name', rdb.String),
)
t1.create()
for i in xrange(5):
t1.insert().execute(id=i, name=str(i))
rdb.objectstore.commit()
# Get a subselect
ss = t1.select(t1.c.id.in_(1, 2)).alias('t1subselect')
# Test
def get_count(selectable):
return rdb.select([rdb.func.count(1)],
from_obj=[selectable])
def get_count2(selectable):
return selectable.count()
def test(selectable, counter):
try:
q = counter(selectable)
except:
print 'XXX: Broken'
return
print 'SQL:', q
r = q.execute().fetchall()[0][0]
print 'Count:', r
return r
for s in (t1, ss):
for c in (get_count, get_count2):
print '---', s.name, c.__name__
test(s, c)
--- output:
[2006-03-07 16:35:27,547] [engine]:
CREATE TABLE t1(
id INTEGER NOT NULL PRIMARY KEY,
name TEXT
)
[2006-03-07 16:35:27,548] [engine]: None
[2006-03-07 16:35:27,551] [engine]: INSERT INTO t1 (id, name) VALUES
(?, ?)
[2006-03-07 16:35:27,551] [engine]: [0, '0']
[2006-03-07 16:35:27,552] [engine]: INSERT INTO t1 (id, name) VALUES
(?, ?)
[2006-03-07 16:35:27,553] [engine]: [1, '1']
[2006-03-07 16:35:27,554] [engine]: INSERT INTO t1 (id, name) VALUES
(?, ?)
[2006-03-07 16:35:27,555] [engine]: [2, '2']
[2006-03-07 16:35:27,557] [engine]: INSERT INTO t1 (id, name) VALUES
(?, ?)
[2006-03-07 16:35:27,557] [engine]: [3, '3']
[2006-03-07 16:35:27,558] [engine]: INSERT INTO t1 (id, name) VALUES
(?, ?)
[2006-03-07 16:35:27,559] [engine]: [4, '4']
--- t1 get_count
SQL: SELECT count(?)
FROM t1
[2006-03-07 16:35:27,562] [engine]: SELECT count(?)
FROM t1
[2006-03-07 16:35:27,562] [engine]: [1]
Count: 5
--- t1 get_count2
SQL: SELECT count(?) AS count
FROM t1
[2006-03-07 16:35:27,564] [engine]: SELECT count(?) AS count
FROM t1
[2006-03-07 16:35:27,564] [engine]: [1]
Count: 5
--- t1subselect get_count
SQL: SELECT count(?)
FROM (SELECT t1.id AS id, t1.name AS name
FROM t1
WHERE t1.id IN (?, ?)) AS t1subselect
[2006-03-07 16:35:27,568] [engine]: SELECT count(?)
FROM (SELECT t1.id AS id, t1.name AS name
FROM t1
WHERE t1.id IN (?, ?)) AS t1subselect
[2006-03-07 16:35:27,568] [engine]: [1, 1, 2]
Count: 2
--- t1subselect get_count2
XXX: Broken
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users