File: 29warnings.t

package info (click to toggle)
libdbd-mysql-perl 4.053-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,128 kB
  • sloc: ansic: 4,780; perl: 836; makefile: 29; sh: 22
file content (66 lines) | stat: -rw-r--r-- 1,775 bytes parent folder | download | duplicates (4)
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);