3
# $Id: 40bindparam.t,v 1.1.1.1 1999/06/13 12:59:35 joe Exp $
5
# This is a skeleton test. For writing new tests, take this file
6
# and modify/extend it.
24
use vars qw($COL_NULLABLE);
26
foreach $file ("lib.pl", "t/lib.pl") {
27
do $file; if ($@) { print STDERR "Error while executing lib.pl: $@\n";
34
if ($mdriver eq 'pNET') {
40
my $err = $DBI::errstr; # Hate -w ...
41
print STDERR ("Cannot connect: ", $DBI::errstr, "\n",
42
"\tEither your server is not up and running or you have no\n",
43
"\tpermissions for acessing the DSN $test_dsn.\n",
44
"\tThis test requires a running server and write permissions.\n",
45
"\tPlease make sure your server is running and you have\n",
46
"\tpermissions, then retry.\n");
50
if (!defined(&SQL_VARCHAR)) {
51
eval "sub SQL_VARCHAR { 12 }";
53
if (!defined(&SQL_INTEGER)) {
54
eval "sub SQL_INTEGER { 4 }";
58
# Main loop; leave this untouched, put tests after creating
63
# Connect to the database
64
Test($state or $dbh = DBI->connect($test_dsn, $test_user, $test_password),
69
# Find a possible new table name
71
Test($state or $table = FindNewTable($dbh), 'FindNewTable')
72
or DbiError($dbh->err, $dbh->errstr);
75
# Create a new table; EDIT THIS!
77
Test($state or ($def = TableDefinition($table,
78
["id", "INTEGER", 4, 0],
79
["name", "CHAR", 64, $COL_NULLABLE]) and
80
$dbh->do($def)), 'create', $def)
81
or DbiError($dbh->err, $dbh->errstr);
84
Test($state or $cursor = $dbh->prepare("INSERT INTO $table"
85
. " VALUES (?, ?)"), 'prepare')
86
or DbiError($dbh->err, $dbh->errstr);
92
# Automatic type detection
94
my $charVal = "Alligator Descartes";
95
Test($state or $cursor->execute($numericVal, $charVal), 'execute insert 1')
96
or DbiError($dbh->err, $dbh->errstr);
98
# Does the driver remember the automatically detected type?
99
Test($state or $cursor->execute("3", "Jochen Wiedmann"),
100
'execute insert num as string')
101
or DbiError($dbh->err, $dbh->errstr);
103
$charVal = "Tim Bunce";
104
Test($state or $cursor->execute($numericVal, $charVal), 'execute insert 2')
105
or DbiError($dbh->err, $dbh->errstr);
107
# Now try the explicit type settings
108
Test($state or $cursor->bind_param(1, " 4", SQL_INTEGER()), 'bind 1')
109
or DbiError($dbh->err, $dbh->errstr);
110
Test($state or $cursor->bind_param(2, "Andreas K�nig"), 'bind 2')
111
or DbiError($dbh->err, $dbh->errstr);
112
Test($state or $cursor->execute, 'execute binds')
113
or DbiError($dbh->err, $dbh->errstr);
115
# Works undef -> NULL?
116
Test($state or $cursor->bind_param(1, 5, SQL_INTEGER()))
117
or DbiError($dbh->err, $dbh->errstr);
118
Test($state or $cursor->bind_param(2, undef))
119
or DbiError($dbh->err, $dbh->errstr);
120
Test($state or $cursor->execute)
121
or DbiError($dbh->err, $dbh->errstr);
124
Test($state or $cursor -> finish, 'finish');
126
Test($state or undef $cursor || 1, 'undef cursor');
128
Test($state or $dbh -> disconnect, 'disconnect');
130
Test($state or undef $dbh || 1, 'undef dbh');
133
# And now retreive the rows using bind_columns
136
# Connect to the database
138
Test($state or $dbh = DBI->connect($test_dsn, $test_user, $test_password),
142
Test($state or $cursor = $dbh->prepare("SELECT * FROM $table"
144
or DbiError($dbh->err, $dbh->errstr);
146
Test($state or $cursor->execute)
147
or DbiError($dbh->err, $dbh->errstr);
149
Test($state or $cursor->bind_columns(undef, \$id, \$name))
150
or DbiError($dbh->err, $dbh->errstr);
152
Test($state or ($ref = $cursor->fetch) && $id == 1 &&
153
$name eq 'Alligator Descartes')
154
or printf("Query returned id = %s, name = %s, ref = %s, %d\n",
155
$id, $name, $ref, scalar(@$ref));
157
Test($state or (($ref = $cursor->fetch) && $id == 2 &&
158
$name eq 'Tim Bunce'))
159
or printf("Query returned id = %s, name = %s, ref = %s, %d\n",
160
$id, $name, $ref, scalar(@$ref));
162
Test($state or (($ref = $cursor->fetch) && $id == 3 &&
163
$name eq 'Jochen Wiedmann'))
164
or printf("Query returned id = %s, name = %s, ref = %s, %d\n",
165
$id, $name, $ref, scalar(@$ref));
167
Test($state or (($ref = $cursor->fetch) && $id == 4 &&
168
$name eq 'Andreas K�nig'))
169
or printf("Query returned id = %s, name = %s, ref = %s, %d\n",
170
$id, $name, $ref, scalar(@$ref));
172
Test($state or (($ref = $cursor->fetch) && $id == 5 &&
174
or printf("Query returned id = %s, name = %s, ref = %s, %d\n",
175
$id, $name, $ref, scalar(@$ref));
177
Test($state or undef $cursor or 1);
180
# Finally drop the test table.
182
Test($state or $dbh->do("DROP TABLE $table"))
183
or DbiError($dbh->err, $dbh->errstr);