-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy path29warnings.t
66 lines (47 loc) · 1.73 KB
/
29warnings.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use strict;
use warnings;
use Test::More;
use DBI;
use lib '.', 't';
require 'lib.pl';
$|= 1;
use vars qw($test_dsn $test_user $test_password);
my $dbh;
eval {$dbh= DBI->connect($test_dsn, $test_user, $test_password,
{ RaiseError => 1, PrintError => 1, AutoCommit => 0});};
if ($@) {
plan skip_all => "no database connection";
}
if ($dbh->{mysql_serverversion} < 40101) {
plan skip_all => "Servers < 4.1.1 do not report warnings";
}
my $expected_warnings = 2;
if ($dbh->{mysql_serverversion} >= 50000 && $dbh->{mysql_serverversion} < 50500) {
$expected_warnings = 1;
}
plan tests => 14;
ok(defined $dbh, "Connected to database");
ok(my $sth= $dbh->prepare("DROP TABLE IF EXISTS no_such_table"));
ok($sth->execute());
is($sth->{mysql_warning_count}, 1, 'warnings from sth');
ok($dbh->do("SET sql_mode=''"));
ok($dbh->do("CREATE TEMPORARY TABLE dbd_drv_sth_warnings (c CHAR(1))"));
ok($dbh->do("INSERT INTO dbd_drv_sth_warnings (c) VALUES ('perl'), ('dbd'), ('mysql')"));
is($dbh->{mysql_warning_count}, 3, 'warnings from dbh');
# tests to make sure mysql_warning_count is the same as reported by mysql_info();
# see https://rt.cpan.org/Ticket/Display.html?id=29363
ok($dbh->do("CREATE TEMPORARY TABLE dbd_drv_count_warnings (i TINYINT NOT NULL)") );
my $q = "INSERT INTO dbd_drv_count_warnings VALUES (333),('as'),(3)";
ok($sth = $dbh->prepare($q));
ok($sth->execute());
is($sth->{'mysql_warning_count'}, 2 );
# $dbh->{info} actually uses mysql_info()
my $str = $dbh->{info};
my $numwarn;
if ( $str =~ /Warnings:\s(\d+)$/ ) {
$numwarn = $1;
}
# this test passes on mysql 5.5.x and fails on 5.1.x
# but I'm not sure which versions, so I'll just disable it for now
is($numwarn, $expected_warnings);
ok($dbh->disconnect);