MySqlDb any way to see the query string

Tim Roberts timr at probo.com
Sat Jul 10 19:29:07 EDT 2010


News123 <news1234 at free.fr> wrote:
>
>I'm using MYSQLdb
>
>and have following code
>
>db = MySQLdb.connect(**cfg)
>c = db.cursor()
>qrystr = "insert mytable set id = %s ,  other_field = %s"
>c.execute(qrystr, (id_val,other_field_val) )
>
>What I wondered is whether there is any way to print the 'filled in'
>query string for debuggin.
>
>The reason I'm askng is, that I'd like to copy paste the 'filled in'
>query string and try it from the command line.

You have the source code in front of you.  After you do the execute, the
actual query string that was transmitted is available in "c._executed".

If you need to know the result before you submit it, you can scan the
source for the "execute" method and see how they do the quoting.  It's not
that complicated.
-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the Python-list mailing list