Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: DBI trace has limited output

by kcott (Bishop)
on Oct 23, 2021 at 18:34 UTC ( #11137922=note: print w/replies, xml ) Need Help??

in reply to DBI trace has limited output

This is vague, contradictory, and missing information. You'll need to supply a lot more information before we can effectively help you.

"I've enabled DBI trace with level 15 so it shows the full trace but it has no effect."

On the surface, this is contradictory: "so it shows the full trace" is the expected effect. Did you perhaps mean the opposite: "but it doesn't show the full trace"? Suggests a coding problem but, as you've shown no code, that's just guesswork.

"the output remains the same whether level 1 or 99"

There is no trace level 99. The valid range is 0-15.

"In particular I'd like to capture the SQL queries with the values interpolated."

See "DBI: Trace Flags"; in particular,

SQL - trace SQL statements executed (not yet implemented in DBI but implemented in some DBDs)

You haven't told us which DBD you're using, so I'm unable to comment on that part. There's also the possibility of a coding error; again, no code so only guesses.

"In other machines I do."

Please tell what machine you're currently using and the machines on which the same code is capturing the SQL queries.

"It's a bit of an old system with DBI version 1.64."

There is no "DBI version 1.64". See DBI: there are versions like 1.64x, where x is 0-3 and dates are 2018-2020 (so none are particularly old); BackPAN has a v0.64 from 1995.

In an attempt to provide some basic help, I created this dummy test database:

$ sqlite3 pm_11137916_anon SQLite version 3.34.0 2020-12-01 16:14:00 Enter ".help" for usage hints. sqlite> create table Planet (id, name, type); sqlite> insert into Planet values (3, 'Earth', 'rock'); sqlite> insert into Planet values (5, 'Jupiter', 'gas'); sqlite> insert into Planet values (9, 'Pluto', 'dwarf'); sqlite> select * from Planet; 3|Earth|rock 5|Jupiter|gas 9|Pluto|dwarf sqlite>

I then wrote this very simple Perl script ( as a basic test:

#!/usr/bin/env perl use strict; use warnings; use DBI; DBI->trace(0); my $dbh = DBI->connect('dbi:SQLite:dbname=pm_11137916_anon'); print join('|', @$_), "\n" for $dbh->selectall_array('select * from Pl +anet');

The output from that is the same as from the raw SQL statement:

$ ./ 3|Earth|rock 5|Jupiter|gas 9|Pluto|dwarf

Then I made multiple copies of that which changed the trace level to 1, 4, 5 and 15 (e.g. DBI->trace(4);). I then made equivalent copies that included the SQL trace flag (e.g. DBI->trace("4|SQL");). At each increased trace level, more information was produced. The SQL trace flag made no noticeable difference (so it doesn't look like DBD::SQLite is one of the DBDs that support that flag).

The output from all of those is far too great to post here; you can, of course, try them for yourself. However, I did capture the output from all of those; you can see how they increase with each trace level:

$ ls -al *.out -rw-r--r-- 1 ken None 1839 Oct 24 03:50 trace_dbi_1.out -rw-r--r-- 1 ken None 1853 Oct 24 03:51 trace_dbi_1_sql.out -rw-r--r-- 1 ken None 16771 Oct 24 04:14 trace_dbi_15.out -rw-r--r-- 1 ken None 16893 Oct 24 04:15 trace_dbi_15_sql.out -rw-r--r-- 1 ken None 6512 Oct 24 03:45 trace_dbi_4.out -rw-r--r-- 1 ken None 6570 Oct 24 03:45 trace_dbi_4_sql.out -rw-r--r-- 1 ken None 10574 Oct 24 04:02 trace_dbi_5.out -rw-r--r-- 1 ken None 10632 Oct 24 04:03 trace_dbi_5_sql.out

The first thing for you to do would be to read "How do I post a question effectively?" so that you understand the type of information we need and how to format it. Then create one or more SSCCE's to allow us to investigate: keep these as simple as possible, much like I've shown above.

All of my examples use Perl 5.34 and DBI 1.643.

— Ken

Replies are listed 'Best First'.
Re^2: DBI trace has limited output
by Tux (Canon) on Oct 24, 2021 at 08:19 UTC

    Just some side notes:

    • Trace levels 1 and 2 are reserved for the DBI itself
    • The DBI itself only features levels 1..15, but the underlying DBD might support up to whatever they like. I think I saw one that took all over 100 to be special, but my recollection might be troubled.
    • Some DBD's support additional trace flags
      (all that from the documentation, they might have undocumented debugging flags)
    • Not all of the trace messages come from DBI itself, so check the DBD you use if they have additional documentation

    Enjoy, Have FUN! H.Merijn

      G'day Tux,

      ++ Thanks for supplying all of that extra info. It looks like you went to a fair amount of effort.

      — Ken

Re^2: DBI trace has limited output
by Anonymous Monk on Oct 25, 2021 at 10:51 UTC
    Thanks a lot for your effort.I found what happens.I had to wrap the following in a BEGIN block at the top of the CGI script:

    BEGIN { $ENV{DBI_TRACE}='15=/var/www/xx/dbitrace.log';use DBI; }

    The output now shows everything including the sql statements and the data retrieved.
    What does BEGIN do and why has it made such a big difference? I think it has something to do with the environment that Apache/CGI runs,like that Apache initializes something before the perl script runs? What do you think?

      This is equivalent to DBI_TRACE=15 perl Your solution looks to me to be the nuclear option. I would investigate further. With Apache, since Re: DBI trace has limited output (this has already done it for you without Apache.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11137922]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2022-05-29 08:10 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (101 votes). Check out past polls.