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());