develooper Front page | perl.dbi.users | Postings from July 2009

Re: Retrieving warnings after executing a MySQL INSERT statement

Thread Previous | Thread Next
From:
David Goodman
Date:
July 28, 2009 09:19
Subject:
Re: Retrieving warnings after executing a MySQL INSERT statement
Message ID:
650651.97489.qm@web36102.mail.mud.yahoo.com

Hello Scott:

I suggest that you check to see if the string $DBI::errstr is empty rather than just whether the 'do' function executed correctly. 

It seems that the SQL is correctly submitted from the DBI side but the database server actually produces an error message. So this is a server side error message rather than a client side error message.

regards,

David

--- On Tue, 7/28/09, Saccone, Scott <ssaccone@wustl.edu> wrote:

> From: Saccone, Scott <ssaccone@wustl.edu>
> Subject: Retrieving warnings after executing a MySQL INSERT statement
> To: "dbi-users@perl.org" <dbi-users@perl.org>
> Date: Tuesday, July 28, 2009, 11:19 AM
> 
> Hello, I was wondering if the DBI can determine if there
> are warnings after an INSERT statement.  For example,
> here's some MySQL code:
> 
> mysql> INSERT INTO test(id,name,age) VALUES
> ("1","Bob","abc");
> Query OK, 1 row affected, 1 warning (0.00 sec)
> 
> mysql> show warnings;
> +---------+------+----------------------------------------------------------+
> | Level   | Code | Message   
>                
>                
>               |
> +---------+------+----------------------------------------------------------+
> | Warning | 1366 | Incorrect integer value: 'sdc' for
> column 'age' at row 1 |
> +---------+------+----------------------------------------------------------+
> 1 row in set (0.00 sec)
> 
> If I do the same thing in the DBI, I don't seem to see any
> errors or warnings raised:
> 
> $code=<<EOF;
> INSERT INTO test(id,name,age)
> VALUES("1","Bob","abc");
> EOF
> 
> $dbh->do($code) or die "Error loading data:
> $DBI::errstr";
> 
> Thanks,
> 
> Scott
> 
> Scott Saccone, Ph.D.
> Department of Psychiatry, Box 8134
> Washington University School of Medicine
> 660 South Euclid Avenue
> Saint Louis, Missouri 63110-1093
> Voice: (314) 286-2581
> FAX: (314) 286-2577
> Email: ssaccone@wustl.edu<mailto:ssaccone@wustl.edu>
> 
> 
> ________________________________
> The materials in this message are private and may contain
> Protected Healthcare Information or other information of a
> sensitive nature. If you are not the intended recipient, be
> advised that any unauthorized use, disclosure, copying or
> the taking of any action in reliance on the contents of this
> information is strictly prohibited. If you have received
> this email in error, please immediately notify the sender
> via telephone or return mail.
>

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About