Lukasz Szybalski ha scritto:

> bind_meta_data()
> users_table = Table('users', metadata, autoload=True)
>
> class Users(object):
>     pass
>
> usersmapper=mapper(Users,users_table)
>   

assign_mapper() in place of mapper()

> mysession=session.query(Users)
>
> 1. What would be the code from now on to query all Users? Does
> 'mysession'  have a connection to a database already?
>   

Yes, if you used assign_mapper instead, your model's classes will be 
implicitly bound to the session context.

So...

> 2. How do I select a user where User_Sid=100?
>   

What is the schema of the table?

If User_Sid is the primary key:

User.get(100)

If it's not:

User.select_by(User_Sid=100)

> Why doesn't this work?
> jj=[]
> for users in session.query(Users):
>     jj.append(users.Users_Sid)
>   

ehm, weird use of plural for a loop variable.

You are using an explicit session here, you don't need to do that in 
TurboGears since the classes have an implicit session bound to the 
request, that it cleaned after each served page.

Anyway, it should work more or less (I note Users_Sid in place of User_sid)

> What is the simples way to query my database to get user with user_sid=100?
> What is the simples way to query my database to get user
> last_name='Smith' with user_sid=100?
>   

Again, are filtering by both last_name and user_sid? So I suppose 
user_sid is not the primary key after all.

User.select_by(User_sid=100, last_name='Smith')


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to