Skip to content

Commit 9bc4bb5

Browse files
committed
Add test for new "named parameters are unsupported" error message.
If a named parameter is passed to bind_param() ensure the expected error message is reported.
1 parent 32b7fed commit 9bc4bb5

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

t/45bindnamedparam_error.t

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
use strict;
2+
use warnings;
3+
4+
use Test::More;
5+
use DBI;
6+
use vars qw($test_dsn $test_user $test_password);
7+
use lib 't', '.';
8+
require 'lib.pl';
9+
10+
my $dbh;
11+
eval {$dbh = DBI->connect($test_dsn, $test_user, $test_password,
12+
{ RaiseError => 1, AutoCommit => 1}) or ServerError();};
13+
14+
if ($@) {
15+
plan skip_all => "no database connection";
16+
}
17+
plan tests => 11;
18+
19+
SKIP: {
20+
skip 'SET @@auto_increment_offset needs MySQL >= 5.0.2', 2 unless $dbh->{mysql_serverversion} >= 50002;
21+
ok $dbh->do('SET @@auto_increment_offset = 1');
22+
ok $dbh->do('SET @@auto_increment_increment = 1');
23+
}
24+
25+
my $create= <<EOT;
26+
CREATE TEMPORARY TABLE dbd_mysql_t45bindnamedparam (
27+
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
28+
num INT(3))
29+
EOT
30+
31+
ok $dbh->do($create), "create table dbd_mysql_t45bindnamedparam";
32+
33+
ok $dbh->do("INSERT INTO dbd_mysql_t45bindnamedparam VALUES(NULL, 1)"), "insert into dbd_mysql_t45bindnamedparam (null, 1)";
34+
35+
my $rows;
36+
ok ($rows= $dbh->selectall_arrayref("SELECT * FROM dbd_mysql_t45bindnamedparam"));
37+
38+
is $rows->[0][1], 1, "\$rows->[0][1] == 1";
39+
40+
ok (my $sth = $dbh->prepare("SELECT * FROM dbd_mysql_t45bindnamedparam WHERE num = :num"));
41+
42+
$dbh->{PrintError} = 0;
43+
$dbh->{PrintWarn} = 0;
44+
eval {($sth->bind_param(":num", 1, SQL_INTEGER()));};
45+
$dbh->{PrintError} = 1;
46+
$dbh->{PrintWarn} = 1;
47+
ok defined($DBI::errstr);
48+
49+
like($DBI::errstr, qr/named parameters are unsupported/, 'bind_param reports exepcted error with named parameter');
50+
51+
ok ($sth->finish());
52+
53+
ok ($dbh->disconnect());

0 commit comments

Comments
 (0)