473,396 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

MySQLdb - parameterised SQL - how to see resulting SQL ?

Hi - I've got SQL that looks like this ...

cursor =
self.MySQLDb_conn.cursor(cursorclass=MySQLdb.curso rs.DictCursor)
sqlQuery = "SELECT * FROM T1 WHERE C1 = %s and C2 = %s"
sql = cursor.execute(sqlQuery,(strURLAlias,strSessionID) )
rows = cursor.fetchall()
cursor.close

.... i would be interested in seeing what the actual SQL used by the
..execute looks like after the replacements have been done. Is there a
way of doing this ?

thanks

richard.

May 18 '06 #1
3 1248
On 17 May 2006 18:41:55 -0700,
sh*********@gmail.com wrote:
Hi - I've got SQL that looks like this ...
cursor =
self.MySQLDb_conn.cursor(cursorclass=MySQLdb.curso rs.DictCursor)
sqlQuery = "SELECT * FROM T1 WHERE C1 = %s and C2 = %s"
sql = cursor.execute(sqlQuery,(strURLAlias,strSessionID) )
rows = cursor.fetchall()
cursor.close
ITYM cursor.close()
... i would be interested in seeing what the actual SQL used by the
.execute looks like after the replacements have been done. Is there a
way of doing this ?


Taking a quick peek at pysqlite and the API spec, I'd say no, not a
standard way.

OTOH, eventually, mysqldb has to create that SQL in order to pass it to
the database for execution, so it's probably as simple as finding the
right place to put a "print" statement and/or to store the finished SQL
in the cursor object.

HTH,
Dan

--
Dan Sommers
<http://www.tombstonezero.net/dan/>
"I wish people would die in alphabetical order." -- My wife, the genealogist
May 18 '06 #2
sh*********@gmail.com writes:
... i would be interested in seeing what the actual SQL used by the
.execute looks like after the replacements have been done. Is there a
way of doing this ?


I also think this would be a very useful feature for enabling logging,
debugging, and other introspection. It surely is possible for the code
to present that information (it must construct the final SQL statement
to pass to the database engine), but I can't see a way to get at it
with the current DB API.

--
\ "Better not take a dog on the space shuttle, because if he |
`\ sticks his head out when you're coming home his face might burn |
_o__) up." -- Jack Handey |
Ben Finney

May 18 '06 #3
> ... i would be interested in seeing what the actual SQL used by the
.execute looks like after the replacements have been done. Is there a
way of doing this ?


On my development machine I'm using the "--log" argument to MySQL so that it
logs all queries and connections. I wouldn't recommend that on a production
machine though.

The logfile is stored in /var/lib/mysql/<hostname>.log
--
damjan
May 18 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dave Harrison | last post by:
Hi all, got a problem combinging mx and MySQLdb, when I build and install both for my Python2.1 install on a Solaris 9 box I can import mx fine, but importing MySQLdb causing python to core dump. ...
1
by: Peter Nikolaidis | last post by:
Greetings, I am attempting to get MySQLdb 0.9.2 installed on Mac OS 10.2 with a Fink distribution of Python 2.2.2. I have seen only a few posts on the subject, some of them relate to...
1
by: Steve | last post by:
Darwin steve.local 8.3.0 Darwin Kernel Version 8.3.0: Mon Oct 3 20:04:04 PDT 2005; root:xnu-792.6.22.obj~2/RELEASE_PPC Power Macintosh powerpc MacOSX 10.4.3 mysql Ver 14.7 Distrib 4.1.14, for...
1
by: shearichard | last post by:
Hi - I have written some python to insert a row into a table using MySQLDB. I have never before written SQL/Python using embedded parameters in the SQL and I'm having some difficulties. Could...
5
by: Bowen | last post by:
import md5 import string import MySQLdb tc = raw_input("Teacher Code: ") p = raw_input("New Password: ") print tc hash = md5.new() hash.update(p)
1
by: Yi Xing | last post by:
Hi, I met the following error when I tried to install MySQLdb. I had no problem installing numarray, Numeric, Rpy, etc. Does anyone know what's the problem? Thanks! running install running...
13
by: Steven Bethard | last post by:
Jean-Paul Calderone <exarkun@divmod.comwrote: Interesting. Could you give a few illustrations of this? (I didn't run into the same problem at all, so I'm curious.) Steve
2
by: Nikhil | last post by:
I am using the MySQLdb python module. I have a table named 'testing' with few columns, under the 'test' database, what is hosted on a remote mysql server. I want to run the following query to...
3
by: AdamGr | last post by:
I am currently trying to convert a program I just wrote to application form, on the Mac. I'm using py2app to accomplish this, and everything works fine up until the last stage; when I try to complete...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.