Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Dumper with DBI/DBD?

by kingram (Acolyte)
on Jul 30, 2012 at 08:45 UTC ( #984396=perlquestion: print w/replies, xml ) Need Help??
kingram has asked for the wisdom of the Perl Monks concerning the following question:

When using DBI and the associated Database module, what is the best way to find out the final statement and contents reaching the database?

Particularly when you are passing values? E.G.
$sql="insert into test (one, two, three) VALUES (?,?,?)" @params = ('4','5',"str_to_date(\'$time_value\',\'%Y-%m-%d %h:%i:%s %p +\') $sth->prepare($sql); print Dumper($sth); my $rslt = $sth->execute($params[0],$params[1],$params[2]); print Dumper($rslt);
Dumper just gives me:
$VAR1 = bless( {}, 'DBI::st' );
$VAR1 = 1;
Not sure how to make sense of the first response, or if I need to use a different tool. The 2nd response indicates a successful SQL operation, but the date_to_string function is failing to put the date into the record.

Replies are listed 'Best First'.
Re: Dumper with DBI/DBD?
by marto (Archbishop) on Jul 30, 2012 at 08:47 UTC

    If you're having problems debugging SQL/DBI I'd suggest using Tracing to try and find out where exactly the problem occurs, be it the query, DBI or the database drivers.

      That helped.
      DBI was doing it's job. The str_to_date function was being passed as a string instead of a function.
      I've learned quite a bit since I started building this thing.
      45 hours getting right with my Perl skills with a lot of good help from The Monks...

        I'm glad this helped, IMHO it's wise to familiarise yourself with debugging tools. An editor which supports Syntax_highlighting would also be advantageous.

Re: Dumper with DBI/DBD?
by moritz (Cardinal) on Jul 30, 2012 at 10:04 UTC
Re: Dumper with DBI/DBD?
by mje (Curate) on Jul 30, 2012 at 09:37 UTC

    You may find DBIx::Log4perl useful. It can log just the SQL and and bound parameters at execute time.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://984396]
Front-paged by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2018-06-23 05:12 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.