Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Handling Null or Undef values in DBI (and things of those nature)...

by gav^ (Curate)
on Jan 08, 2002 at 09:05 UTC ( #137050=note: print w/replies, xml ) Need Help??


in reply to Handling Null or Undef values in DBI (and things of those nature)...

Or a slightly different syntax:
my ($field1, $field2, $field3) = (undef, undef, undef); my $sth = $dbh->prepare('select * from table'); $sth->execute; if ($sth->rows > 0) { $sth->bind_columns(\($field1, $field2, $field3)); $sth->fetch; } $sth->finish; for ($field1, $field2, $field3) { $_ ||= '' }
When dealing with failures caused by duplicate values (due to a constraint) I just check like this:
$dbh->do('insert into blah (?, ?, ?)', undef, $x, $y, $z); if ($dbh->err) { if ($dbh->err == 1062) { # duplicate } else { # some other problem } }
1062 happens to be the error code for MySQL.

Look at $DBI::lasth->{Statement} which has the last SQL statement you tried to execute which is quite handy in a debug subroutine.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2022-08-11 02:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?