>
> Is there a way to print out the query as it would execute on the
> server? I'd like to copy/paste it into the server to get the 'explain'
> output, and the '%s' variables are very unhelpful here.
the string output of str(statement) is what's actually sent to the
client lib. In some cases, that is the actual string that goes to
the server, such as cx_oracle, which receives the bind parameters
separately within the network conversation. The fact that MySQLDB and
psycopg2 do an in-client "substitution" of the string before passing
on is an implementation artifact of those libraries.
Feel free to construct the string yourself (this is specific to
MySQL's bind param style):
stmt = str(statement)
compiled = statement.compile()
params = compiled.params
stmt = stmt % [params[k] for k in compiled.positiontup]
> I'd also like to turn off the 'alias and backtick-escape every column'
> default behavior if I can.
we don't "backtick every column". We quote case sensitive idenfitier
names, if that's what you mean, where "case sensitive" is any
identifier that is spelled out in MixedCase - this is required for the
column to be properly recognized by the database. Use all lower case
letters to indicate a "case insensitive" identifier.
>
> Thanks.
>
> Trying to do this in 0.5, it seems someone deleted the Query.compile()
> method without updating the rest of the code:
> Traceback (most recent call last):
> File "./test1.py", line 139, in ?
> try: exit(main(*argv))
> File "./test1.py", line 121, in main
> print_query(q)
> File "./test1.py", line 20, in print_query
> print str(q)
> File "/python-2.4.1/lib/python2.4/site-packages/
> SQLAlchemy-0.5.0beta1-py2.4.egg/sqlalchemy/orm/query.py", line 1448,
> in __str__
> return str(self.compile())
> AttributeError: 'Query' object has no attribute 'compile'
its been fixed in trunk. Keep an eye on http://www.sqlalchemy.org/trac/browser/sqlalchemy/trunk/CHANGES
. beta2 is out very soon (like, this week).
> Reverting to 0.4, there are other problems. Statement.params is a
> function, so I added some ()'s, but it just returns the same query
> again. Statement.positiontup doesn't exist, and the string stmt
> doesn't have formatting to make use of python's % operator.
my code example used the 0.5 APIs, but in all cases you have to get
the "compiled" object first. This is described in the tutorials for
both 0.4 and 0.5, such as at http://www.sqlalchemy.org/docs/05/sqlexpression.html#sql_insert
.
>
> Why is this so hard?? In SQLObject, this "problem" consists entirely
> of:
>
> print queryobj
in SQLAlchemy it is also:
print queryobj
how is that harder ?