On Jan 1, 2008, at 11:38 AM, Alexandre da Silva wrote:
>
> http://www.sqlalchemy.org/docs/04/sqlexpression.html
>
> yes, I've already been read that, but I am using TurboGears and
> using session
>
> if you mean that youd like to execute using the "Session" itself, use
> the execute() method on Session and you probably want to bind your
> Session to the engine directly:
>
> http://www.sqlalchemy.org/docs/04/session.html#unitofwork_sql
>
> I see at documentation that Session.execute() is deprecated and now
> we need to use
> Session.query(Class/Mapper).from_statement(stmt) instead so it
> requires a mapper or a
> Class as parameter, and I don“t have sucess trying to do it witout a
> class.
session.execute is not deprecated at all, its been expanded in version
0.4. not sure where you're seeing that. its used to execute literal
SQL and return a result set. Query is used to return a list of object
instances, so its for a different purpose.
>
> like a flat SQL file ? just read the file and execute each
> line....for line in file('myfile.txt'): engine.execute(line)
>
> Yes like a flat SQL file, and for simple inserts and/or updates I do
> exactly this,
> but it is not so usefull if I need to execure multiline statements,
> like:
>
> CREATE OR REPLACE FUNCTION.....
> $
> function body
> ..
> ..
> $...
>
> to do it properly I think I need to write all in one line.
> otherwise I already no tried to create any database function using
> this method.
use semicolons in the file and then split on the semicolon instead of
the newline.
>
>
> for now, to perform default data inserts I will import my model and
> use session.query(Class).from_statement(stmt).all(), it is working
> properly
that is absolutely the wrong way to execute an insert statement.
Query is used for selecting rows and returning object instances. use
engine.execute() or session.execute() for insert statements.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---