Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I tried to reproduce the problem, but I couldn't get the same result you mentioned.
#!/usr/bin/perl -w use DBI; use strict; my $dbh = DBI->connect("DBI:mysql:test;host=localhost" . ";mysql_read_default_file=$ENV{HOME}/.my.cnf", undef, undef, {RaiseError => 1}) or die "can't connect\n"; my $pairs = { ONE => 'RTEST', TWO => undef, THREE => 'ANOTHER' }; # Creating a dummy table to match the example $dbh->do(qq{CREATE TABLE IF NOT EXISTS web_sessions_aux (wsa_id INT not null, wsa_type char(10), wsa_key char(10), wsa_value char(10))}); my ($id,$type) = (1,'UNKNOWN'); my $sth = $dbh->prepare(" INSERT INTO web_sessions_aux (wsa_id, wsa_type, wsa_key, wsa_value) VALUES (?,?,?,?)"); DBI->trace(2); foreach my $key (keys %$pairs) { my $key_value = defined($pairs->{$key})? $pairs->{$key} : ''; $sth->execute($id,$type,$key,$key_value); } DBI->trace(0); $dbh->disconnect();
This sample script shows what is going on behind the scenes.
DBI 1.21-nothread dispatch trace level set to 2 -> execute for DBD::mysql::st (DBI::st=HASH(0x81342c0)~0x80b1264 1 + 'UNKNOWN' 'TWO' '') -> dbd_st_execute for 081342f0 Binding parameters: INSERT INTO web_sessions_aux (wsa_id, wsa_type, wsa_key, wsa_va +lue) VALUES (1,'UNKNOWN','TWO','') <- dbd_st_execute 1 rows <- execute= 1 at dbi_quoting_problem.pl line 29 -> execute for DBD::mysql::st (DBI::st=HASH(0x81342c0)~0x80b1264 1 + 'UNKNOWN' 'THREE' 'ANOTHER') -> dbd_st_execute for 081342f0 Binding parameters: INSERT INTO web_sessions_aux (wsa_id, wsa_type, wsa_key, wsa_va +lue) VALUES (1,'UNKNOWN','THREE','ANOTH +ER') <- dbd_st_execute 1 rows <- execute= 1 at dbi_quoting_problem.pl line 29 -> execute for DBD::mysql::st (DBI::st=HASH(0x81342c0)~0x80b1264 1 + 'UNKNOWN' 'ONE' 'RTEST') -> dbd_st_execute for 081342f0 Binding parameters: INSERT INTO web_sessions_aux (wsa_id, wsa_type, wsa_key, wsa_va +lue) VALUES (1,'UNKNOWN','ONE','RTEST') <- dbd_st_execute 1 rows <- execute= 1 at dbi_quoting_problem.pl line 29
Since the DBI seems to be doing its honest job correctly, I would investigate some side effects somewhere else. Is the problem replicable? Could you isolate the strange behavior in a stand-alone (possibly short) script? That would be useful to understand where the problem lays.
As an additional thought, this case looks similar to DBI-trace and $hDB-quote() interaction. The problem there was related to some CGI variables behaving differently under trace(0) and trace(2). I was not able to find out what exactly was happening in that case, except that interpolating the variable made the problem disappear.
In this case, with or without trace(2), I get a correct database update.
Maybe, if the two cases are related, we could reach a more enlightening conclusion.

HTH
_ _ _ _ (_|| | |(_|>< _|

In reply to Re: DBD::mysql Unusual Behavior by gmax
in thread DBD::mysql Unusual Behavior by tadman

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (3)
    As of 2019-11-13 08:13 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Strict and warnings: which comes first?



      Results (70 votes). Check out past polls.

      Notices?