Skip Menu |

This queue is for tickets about the DBD-mysql CPAN distribution.

Report information
The Basics
Id: 83352
Status: resolved
Priority: 0/
Queue: DBD-mysql

People
Owner: Nobody in particular
Requestors: sveta.smirnova [...] oracle.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 4.020
Fixed in: (no value)



Subject: Support $dbh->{mysql_warning_count}
This bug was originally reported by Mike Pomraning at http://bugs.mysql.com/bug.php?id=63027 Description: DBD-mysql-4.020 offers the `mysql_warning_count` attribute on statement handles but not on database handles themselves. Thus, the user cannot tell whether a successful `$dbh->do(...)` statement gave rise to any warnings without laboriously issuing a SHOW WARNINGS statement. See http://stackoverflow.com/questions/7946655/dbi-perl-logging-mysql-warnings/7949798#7949798 for a real world example of where this would be useful. How to repeat: #! /usr/bin/perl use strict; use DBI; my $dbh = DBI->connect(@ARGV[0..2], {RaiseError => 1}); # DSN, user, pass $dbh->do(q|set sql_mode=''|); $dbh->do(q|CREATE TABLE t (c CHAR(1))|); $dbh->do(q|INSERT INTO t (c) VALUES ('perl'), ('dbd'), ('mysql')|); print "Expected warnings: 3; actual warnings: ", $dbh->{mysql_warning_count}, "\n"; Suggested fix: Patch forthcoming
Subject: DBD-mysql-4.020-dbh-mysql_warning_count.patch
diff -up DBD-mysql-4.020/dbdimp.c.orig DBD-mysql-4.020/dbdimp.c --- DBD-mysql-4.020/dbdimp.c.orig 2011-08-20 13:35:59.000000000 -0500 +++ DBD-mysql-4.020/dbdimp.c 2011-10-30 22:59:05.000000000 -0500 @@ -2574,6 +2574,11 @@ SV* dbd_db_FETCH_attrib(SV *dbh, imp_dbh if (kl == 9 && strEQ(key, "thread_id")) result= sv_2mortal(newSViv(mysql_thread_id(imp_dbh->pmysql))); break; + + case 'w': + if (kl == 13 && strEQ(key, "warning_count")) + result= sv_2mortal(newSViv(mysql_warning_count(imp_dbh->pmysql))); + break; } if (result== NULL) diff -up DBD-mysql-4.020/lib/DBD/mysql.pm.orig DBD-mysql-4.020/lib/DBD/mysql.pm --- DBD-mysql-4.020/lib/DBD/mysql.pm.orig 2011-08-20 13:39:24.000000000 -0500 +++ DBD-mysql-4.020/lib/DBD/mysql.pm 2011-10-30 23:18:23.000000000 -0500 @@ -1617,6 +1617,7 @@ Whenever possible, the ANSI SQL name is =item mysql_warning_count The number of warnings generated during execution of the SQL statement. +This attribute is available on both statement handles and database handles. =back diff -up DBD-mysql-4.020/t/29warnings.t.orig DBD-mysql-4.020/t/29warnings.t --- DBD-mysql-4.020/t/29warnings.t.orig 2011-08-19 08:27:27.000000000 -0500 +++ DBD-mysql-4.020/t/29warnings.t 2011-10-30 23:00:25.000000000 -0500 @@ -18,7 +18,7 @@ eval {$dbh= DBI->connect($test_dsn, $tes if ($@) { plan skip_all => "ERROR: $@. Can't continue test"; } -plan tests => 4; +plan tests => 8; ok(defined $dbh, "Connected to database"); @@ -26,6 +26,12 @@ SKIP: { skip "Server doesn't report warnings", 3 if $dbh->get_info($GetInfoType{SQL_DBMS_VER}) lt "4.1"; + ok($dbh->do(q|SET sql_mode=''|)); + ok(!$dbh->{mysql_warning_count}, '$dbh->do() no warnings found'); + + ok($dbh->do("DROP TABLE IF EXISTS no_such_table")); + is($dbh->{mysql_warning_count}, 1, '$dbh->do() 1 warning found'); + my $sth; ok($sth= $dbh->prepare("DROP TABLE IF EXISTS no_such_table")); ok($sth->execute());
Thanks for your patch! This will be in upcoming DBD::mysql 4.025 https://github.com/perl5-dbi/DBD-mysql/commit/3f697d00ceadc18a243eb81c28c33dc57f11131f -- Mike