Thanks,

I've attached a script (using in-memory sqlite db), that asserts the
unexpected behaviour.

Sincerely yours,
Nadav


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---
from sqlalchemy import *

metadata = BoundMetaData('sqlite://')

users_table = Table('users', metadata,
        Column('user_id', Integer, primary_key=True),
        Column('user_name', String(40)))

orders_table = Table('orders', metadata,
        Column('order_id', Integer, primary_key=True),
        Column('product', String(40)),
        Column('owner', Integer, ForeignKey('users.user_id')))

metadata.create_all()
        
users_table.insert().execute(
        {'user_id': 1, 'user_name': 'me'},
        {'user_id': 2, 'user_name': 'you'})

orders_table.insert().execute(
        {'product': 'coffee', 'owner': 1}, 
        {'product': 'milk', 'owner': 1},
        {'product': 'sugar', 'owner': 2})

# Test 1
sub = select([func.count('*')], 
    (orders_table.c.owner==users_table.c.user_id), scalar=True)
s = select([users_table, sub])
assert 'user_id)' in list(s.execute())[0].keys()

# Test 2
sub = select([func.count('*')], (
    (orders_table.c.owner==users_table.c.user_id) & 
    (orders_table.c.product=='milk')), scalar=True)
s = select([users_table, sub])
assert 'product = ?)' in list(s.execute())[0].keys()

# Test 3
sub = select([func.count('*').label('subcount')], (
    (orders_table.c.owner==users_table.c.user_id) & 
    (orders_table.c.product=='milk')), scalar=True)
s = select([users_table, sub])
assert 'subcount' not in list(s.execute())[0].keys()

Reply via email to