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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
#!/usr/bin/perl
use strict;
BEGIN {
$| = 1;
$^W = 1;
}
use t::lib::Test;
use Test::More tests => 39;
use Test::NoWarnings;
use DBI ':sql_types';
# Create a database
my $dbh = connect_ok( dbfile => 'foo', RaiseError => 1, PrintError => 1, PrintWarn => 1 );
# Create the table
ok( $dbh->do(<<'END_SQL'), 'CREATE TABLE' );
CREATE TABLE one (
id INTEGER NOT NULL,
name CHAR (64) NULL
)
END_SQL
my $konig = "Andreas K\xf6nig";
SCOPE: {
my $sth = $dbh->prepare("INSERT INTO one VALUES ( ?, ? )");
isa_ok( $sth, 'DBI::st' );
# Automatic type detection
my $number = 1;
my $char = "A";
ok( $sth->execute($number, $char), 'EXECUTE 1' );
# Does the driver remember the automatically detected type?
ok( $sth->execute("3", "Jochen Wiedmann"), 'EXECUTE 2' );
$number = 2;
$char = "Tim Bunce";
ok( $sth->execute($number, $char), 'EXECUTE 3');
# Now try the explicit type settings
ok( $sth->bind_param(1, " 4", SQL_INTEGER), 'bind 1' );
ok( $sth->bind_param(2, $konig), 'bind 2' );
ok( $sth->execute, '->execute' );
# Works undef -> NULL?
ok( $sth->bind_param(1, 5, SQL_INTEGER), 'bind 3' );
ok( $sth->bind_param(2, undef), 'bind 4' );
ok( $sth->execute, '->execute' );
# Works with PADTMPs?
my @values = (6, "Larry");
for (my $i=0; $i<2; $i++) {
ok( $sth->bind_param($i+1, "$values[$i]"), 'bind '.($i+5) );
}
ok( $sth->execute, '->execute' );
}
# Reconnect
ok( $dbh->disconnect, '->disconnect' );
$dbh = connect_ok( dbfile => 'foo' );
SCOPE: {
my $sth = $dbh->prepare("SELECT * FROM one ORDER BY id");
isa_ok( $sth, 'DBI::st' );
ok( $sth->execute, '->execute' );
my $id = undef;
my $name = undef;
ok( $sth->bind_columns(undef, \$id, \$name), '->bind_columns' );
ok( $sth->fetch, '->fetch' );
is( $id, 1, 'id = 1' );
is( $name, 'A', 'name = A' );
ok( $sth->fetch, '->fetch' );
is( $id, 2, 'id = 2' );
is( $name, 'Tim Bunce', 'name = Tim Bunce' );
ok( $sth->fetch, '->fetch' );
is( $id, 3, 'id = 3' );
is( $name, 'Jochen Wiedmann', 'name = Jochen Wiedmann' );
ok( $sth->fetch, '->fetch' );
is( $id, 4, 'id = 4' );
is( $name, $konig, 'name = $konig' );
ok( $sth->fetch, '->fetch' );
is( $id, 5, 'id = 5' );
is( $name, undef, 'name = undef' );
ok( $sth->fetch, '->fetch' );
is( $id, 6, 'id = 6' );
is( $name, 'Larry', 'name = Larry' );
}
|