summaryrefslogtreecommitdiff
path: root/t/48_bind_param_is_sticky.t
blob: 504dd74c95d26377bda708e0df32b6abbcd2e651 (plain)
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
#!/usr/bin/perl

# Check data type assignment in bind_param is sticky

use strict;
BEGIN {
	$|  = 1;
	$^W = 1;
}

use t::lib::Test qw/connect_ok/;
use DBI qw(:sql_types);
use Test::More;
use Test::NoWarnings;

plan tests => 10 + 1;

my $dbh = connect_ok(
    RaiseError => 1,
    PrintError => 0,
    AutoCommit => 0,
);
$dbh->do("CREATE TABLE Blah ( id INTEGER, val BLOB )");
$dbh->commit;
my $sth;
ok($sth = $dbh->prepare("INSERT INTO Blah VALUES (?, ?)"), "prepare");
$sth->bind_param(1, 1);
$sth->bind_param(2, 'foo', SQL_BLOB);
$sth->execute;
$sth->execute(2, 'bar');
sub verify_types() {
    my $rows = $dbh->selectall_arrayref("SELECT typeof(val) FROM Blah ORDER BY id");
    ok($rows, "selectall_arrayref returned data");
    ok(@{$rows} == 2, "... with expected number of rows");
    ok($rows->[0]->[0] eq 'blob', "$rows->[0]->[0] eq blob");
    ok($rows->[1]->[0] eq 'blob', "$rows->[1]->[0] eq blob");
}
verify_types();
$dbh->commit;
$dbh->do("DELETE FROM Blah");
$sth->bind_param_array(1, [1, 2]);
$sth->bind_param_array(2, [qw/FOO BAR/], SQL_BLOB);
$sth->execute_array({});
verify_types();
$dbh->commit;

$dbh->disconnect;
undef($dbh);