Unstumpped!

Chris Radcliff chris at velocigen.com
Sun Mar 12 09:44:15 CST 2000


~sdpm~

Cash Perkins wrote:
> I found the little bugger!  It was the semi-colon I had at the end of the
> sqlstatement.
> 

Good! It's always what you least expect. Still, there are a few things
in your function that you might want to look at in the future:

> $dbh = DBI->connect(...);
> $sth = $dbh->prepare($sqlstatement);
> $sth->execute || die "Could not execute SQL statement ... maybe invalid?";
> $sth->finish;

Have you considered setting the RaiseError or PrintError flags on
connect? It might have helped in this case assuming mySQL produces
syntax errors on prepare; I know Oracle does. It looks like this:

$dbh = DBI->connect($dsn, $user, $password,
                            { RaiseError => 1, AutoCommit => 0 });

...or you can specify it when setting $dsn:

$dsn = "dbi:Driver(RaiseError=>1,Taint=>1,AutoCommit=>0):dbname";

Also, $sth->execute returns a value; in this case it would return the
number of rows affected or 0E0 if none. You might want to catch that and
test whether it's what you expect. Your die would catch an error (which
returns undef) but not a case where no rows updated.

Last and most picky, $sth->finish isn't recommended unless the statement
is a select. It's not going to throw an error or do anything weird, at
least not at the moment, but it's one less statement to debug. ;)

Cheers,
~chris
~sdpm~

The posting address is: san-diego-pm-list at hfb.pm.org

List requests should be sent to: majordomo at hfb.pm.org

If you ever want to remove yourself from this mailing list,
you can send mail to <majordomo at happyfunball.pm.org> with the following
command in the body of your email message:

    unsubscribe san-diego-pm-list

If you ever need to get in contact with the owner of the list,
(if you have trouble unsubscribing, or have questions about the
list itself) send email to <owner-san-diego-pm-list at happyfunball.pm.org> .
This is the general rule for most mailing lists when you need
to contact a human.




More information about the San-Diego-pm mailing list