473,394 Members | 1,800 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,394 software developers and data experts.

DBI trace?

Is there something akin to perl's DBI->trace in python?

I can't find anything documented in DBI modules like pyPgSQL...or is
there some otherway of getting debug-level logging out of database
calls?

sorry for more newbie-ism but can't find anything in the O'Reilly
books or Google Groups either.

Thanks,

-Drew
Jul 18 '05 #1
3 2595
>>>>> "Andrew" == Andrew Fabbro <an******************@fabbro.org> writes:

Andrew> Is there something akin to perl's DBI->trace in python?

I don't know. What is DBI->trace? If you describe what you're looking for,
perhaps someone will have some ideas about whether or not it exists
currently or might be fairly easily implemented.

Skip

Jul 18 '05 #2
Andrew Fabbro wrote:
Is there something akin to perl's DBI->trace in python? [...]


I suppose you mean logging of SQL statements. There is no standard way
in the Python DB-API, I can only speak for the projects I'm involved in:

pyPgSQL: There is a hidden attribute 'toggleShowQuery' in the low-level
connection object, which will log the queries to stderr (stderr is
currently hard-coded):

#v+
gerhard ( at ) gargamel:~$ python
Python 2.2.2 (#1, Nov 30 2002, 23:19:58)
[GCC 2.95.4 20020320 [FreeBSD]] on freebsd4
Type "help", "copyright", "credits" or "license" for more information.
from pyPgSQL import PgSQL
con = PgSQL.connect()
con.conn.toggleShowQuery 'On' cursor = con.cursor() QUERY: BEGIN WORK cursor.execute("select * from test") QUERY: DECLARE "PgSQL_0811F1EC" CURSOR FOR select * from test
QUERY: FETCH 1 FROM "PgSQL_0811F1EC"
QUERY: SELECT typname, -1 , typelem FROM pg_type WHERE oid = 23
QUERY: SELECT typname, -1 , typelem FROM pg_type WHERE oid = 1043 result = cursor.fetchmany(5) QUERY: FETCH 4 FROM "PgSQL_0811F1EC" result [[None, 'A'], [None, 'B'], [None, 'C'], [None, 'F'], [None, 'F']] con.commit()

QUERY: CLOSE PgSQL_0811F1EC
QUERY: COMMIT WORK
#v-

PySQLite:

In the .connect() call, there is an optional parameter command_logfile,
which will accept a file-like object (or anything that implements a
write() method).

HTH,

-- Gerhard
Jul 18 '05 #3
Skip Montanaro <sk**@pobox.com> wrote:
I don't know. What is DBI->trace? If you describe what you're looking for,
perhaps someone will have some ideas about whether or not it exists
currently or might be fairly easily implemented.


I guess that would help, eh? Sorry ;0

DBI->trace allows you dump the entire conversation between perl and
the database to a file. It's sort of like running your database calls
with a "-v" to see everything that the call is doing. There are
various levels of verbosity, depending on how deep you want to get.

It's very helpful for seeing exactly what the parameters passed to
your database are after interpolation, if your program is saying to
the database what you think it is saying, if the database is giving
more error output than you are seeing from perl, etc.

You can do this within the DB - for example, in postgres you can
change the logging levels in the postgresql.conf and bounce the DB.
But obviously, you don't want to have to bounce the DB every time you
want to debug.

Here's an example (specifically, this was done with
DBI->trace(1,'/tmp/dbi.log')
in perl):
-> DBI->connect(dbi:Pg:dbname=SANDBOX, andrew, ****,
HASH(0x834e070))
pg_db_login
<- connect('dbname=SANDBOX' 'andrew' ...)= DBI::db=HASH(0x8136970)
at DBI.pm
line 582
dbd_db_STORE
<- STORE('PrintError' 1)= 1 at DBI.pm line 622
dbd_db_STORE
<- STORE('AutoCommit' 1)= 1 at DBI.pm line 622
dbd_db_STORE
<- STORE('Username' 'andrew')= 1 at DBI.pm line 625
<- connect= DBI::db=HASH(0x8136970)
dbd_db_STORE
<- STORE('dbi_connect_closure' CODE(0x8366194))= 1 at DBI.pm line
639
dbd_st_prepare: statement = >
SELECT *
FROM gl
WHERE transaction_date >= ? AND transaction_date < ?
AND
( account_credit = ? OR account_debit = ? )<
dbd_st_preparse: statement = >
SELECT *
FROM gl
WHERE transaction_date >= ? AND transaction_date < ?
AND
( account_credit = ? OR account_debit = ? )<
<- prepare('
SELECT *
FROM gl
WHERE transaction_date >= ? AND transaction_date < ?
AND
( account_credit = ? OR account_debit = ? )')=
DBI::st=HASH(0x834de48) at Accounting_Utils.pm line 367
dbd_bind_ph
dbd_st_rebind
dbd_bind_ph
dbd_st_rebind
dbd_bind_ph
dbd_st_rebind
dbd_bind_ph
dbd_st_rebind
dbd_st_execute
<- execute('2003-10-01' '2003-09-01' ...)= '0E0' at
Accounting_Utils.pm
line 372
dbd_st_FETCH
1 <- FETCH('NAME')= [ 'glid' 'account_debit' 'amount'
'account_credit'
'transaction_date' 'reconciled' 'ref' 'note' 'last_modified'
'modified_by' ] at
Accounting_Utils.pm line 376
dbd_st_fetch
1 <- fetch= undef row-1 at Accounting_Utils.pm line 376
<- fetchrow_hashref= undef row-1 at Accounting_Utils.pm line 376
<- finish= 1 at Accounting_Utils.pm line 383
dbd_db_disconnect
<- disconnect= 1 at Accounting_Utils.pm line 384
dbd_st_destroy
<- DESTROY= undef at index.cgi line 195
dbd_db_destroy
<- DESTROY= undef at index.cgi line 195
dbd_st_FETCH
1 <- FETCH('NAME')= [ 'monthyear' 'account_number' 'amount' ] at
index.cgi
line 190
dbd_st_fetch
dbd_st_FETCH
1 <- FETCH('NAME')= [ 'monthyear' 'account_number' 'amount' ] at
index.cgi
line 190
dbd_st_fetch
dbd_st_FETCH
1 <- FETCH('NAME')= [ 'monthyear' 'account_number' 'amount' ] at
index.cgi
line 190

dbd_st_fetch
dbd_st_FETCH
1 <- FETCH('NAME')= [ 'monthyear' 'account_number' 'amount' ] at
index.cgi
line 190
dbd_st_fetch
dbd_st_FETCH
1 <- FETCH('NAME')= [ 'monthyear' 'account_number' 'amount' ] at
index.cgi
line 190
dbd_st_fetch
dbd_st_FETCH
1 <- FETCH('NAME')= [ 'monthyear' 'account_number' 'amount' ] at
index.cgi
line 190
dbd_st_fetch
dbd_st_FETCH
1 <- FETCH('NAME')= [ 'monthyear' 'account_number' 'amount' ] at
index.cgi
line 190
dbd_st_fetch
dbd_st_FETCH
1 <- FETCH('NAME')= [ 'monthyear' 'account_number' 'amount' ] at
index.cgi
line 190
dbd_st_fetch
dbd_st_FETCH
1 <- FETCH('NAME')= [ 'monthyear' 'account_number' 'amount' ] at
index.cgi
line 190
dbd_st_fetch
dbd_st_FETCH
1 <- FETCH('NAME')= [ 'monthyear' 'account_number' 'amount' ] at
index.cgi
line 190
dbd_st_fetch
dbd_st_FETCH
1 <- FETCH('NAME')= [ 'monthyear' 'account_number' 'amount' ] at
index.cgi
line 190
dbd_st_fetch

(etc.)
Jul 18 '05 #4

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

Similar topics

2
by: Ken | last post by:
I would like to start using EventLogTraceListener, and am running into a couple of significant limitations: 1) I have found that there is no way to write EventLog entries with different...
9
by: svenn.are | last post by:
Hi, has anybody thought of / already used graphviz to convert the output of trace.py into a graph? I looked at PyUMLGraph, but 1. PyUMLGraph does not successfully create a dot file, and 2. I...
2
by: Wilfried Hoermann | last post by:
Presumably a trivial question... I want to write trace information from a web service to a log file using the Trace Class. Is this possible without closing and opening the Trace in every single...
5
by: martin | last post by:
Hi, The trace class seems to me to be very usefull however there are a few features of it that have to confused. I am using visual studio 2003. the IDE will not let me write ...
3
by: JR | last post by:
I'm experiencing a problem where, for seemingly no reason, trace output stops being logged (and appearing on my pages.) trace.enabled suddenly just turns to false. Any idea why this happens?...
5
by: who be dat? | last post by:
Hello all. I'm writing an application that is writing trace information that can be viewed in trace.axd. I would like to rename this and use a different name specific to my application. I know...
5
by: cameron | last post by:
I have attempted to lock down the trace.axd file with the standard: <location path="trace.axd"> <system.web> <authorization> <allow roles="SOME GROUP"/> <deny users="*"/> </authorization>...
9
by: Joe Rattz | last post by:
I can't seem to get to trace.axd. I have turned tracing on in web.config. Here is how I currently have i configured: <trace enabled="true" requestLimit="10" pageOutput="false"...
1
by: Patrick | last post by:
When Tracing in ASP.NET, the IIS process (on IIs5.1) is locking on the Trace file, and I can't read the trace file without restarting the IIS: Even the following does NOT work (how could I fix...
3
by: Arman Sahakyan | last post by:
Hi, I'm an MFC programmer and know little about .NET programming. Now, for some reasons, I'm developing an ASP .NET application... What I need to know is how to output into VS's Output Window...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.