File: 40bindparam.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 (123 lines) | stat: -rw-r--r-- 2,943 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
use strict;
use warnings;

use DBI;
use Test::More;
use lib 't', '.';
require 'lib.pl';
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 => 1 });};
if ($@) {
    plan skip_all => "no database connection";
}

if (!MinimumVersion($dbh, '4.1')) {
    plan skip_all =>
        "SKIP TEST: You must have MySQL version 4.1 and greater for this test to run";
}

plan tests => 41;

ok ($dbh->do("DROP TABLE IF EXISTS dbd_mysql_t40bindparam"));

my $create = <<EOT;
CREATE TABLE dbd_mysql_t40bindparam (
        id int(4) NOT NULL default 0,
        name varchar(64) default ''
        )
EOT

ok ($dbh->do($create));

ok (my $sth = $dbh->prepare("INSERT INTO dbd_mysql_t40bindparam VALUES (?, ?)"));

# Automatic type detection
my $numericVal = 1;
my $charVal = "Alligator Descartes";
ok ($sth->execute($numericVal, $charVal));

# Does the driver remember the automatically detected type?
ok ($sth->execute("3", "Jochen Wiedmann"));

$numericVal = 2;
$charVal = "Tim Bunce";
ok ($sth->execute($numericVal, $charVal));

# Now try the explicit type settings
ok ($sth->bind_param(1, " 4", SQL_INTEGER()));

# umlaut equivalent is vowel followed by 'e'
ok ($sth->bind_param(2, 'Andreas Koenig'));
ok ($sth->execute);

# Works undef -> NULL?
ok ($sth->bind_param(1, 5, SQL_INTEGER()));

ok ($sth->bind_param(2, undef));

ok ($sth->execute);

ok ($sth->bind_param(1, undef, SQL_INTEGER()));

ok ($sth->bind_param(2, undef));

ok ($sth->execute(-1, "abc"));

ok ($dbh->do("INSERT INTO dbd_mysql_t40bindparam VALUES (6, '?')"));

ok ($dbh->do('SET @old_sql_mode = @@sql_mode, @@sql_mode = \'\''));

ok ($dbh->do("INSERT INTO dbd_mysql_t40bindparam VALUES (7, \"?\")"));

ok ($dbh->do('SET @@sql_mode = @old_sql_mode'));

ok ($sth = $dbh->prepare("SELECT * FROM dbd_mysql_t40bindparam ORDER BY id"));

ok($sth->execute);

my ($id, $name);

ok ($sth->bind_columns(undef, \$id, \$name));

my $ref = $sth->fetch ;

is $id,  -1, 'id set to -1';

cmp_ok $name, 'eq', 'abc', 'name eq abc';

$ref = $sth->fetch;
is $id, 1, 'id set to 1';
cmp_ok $name, 'eq', 'Alligator Descartes', '$name set to Alligator Descartes';

$ref = $sth->fetch;
is $id, 2, 'id set to 2';
cmp_ok $name, 'eq', 'Tim Bunce', '$name set to Tim Bunce';

$ref = $sth->fetch;
is $id, 3, 'id set to 3';
cmp_ok $name, 'eq', 'Jochen Wiedmann', '$name set to Jochen Wiedmann';

$ref = $sth->fetch;
is $id, 4, 'id set to 4';
cmp_ok $name, 'eq', 'Andreas Koenig', '$name set to Andreas Koenig';

$ref = $sth->fetch;
is $id, 5, 'id set to 5';
ok !defined($name), 'name not defined';

$ref = $sth->fetch;
is $id, 6, 'id set to 6';
cmp_ok $name, 'eq', '?', "\$name set to '?'";

$ref = $sth->fetch;
is $id, 7, '$id set to 7';
cmp_ok $name, 'eq', '?', "\$name set to '?'";

ok ($dbh->do("DROP TABLE dbd_mysql_t40bindparam"));

ok $sth->finish;

ok $dbh->disconnect;