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 124 125 126 127 128
|
#!/usr/bin/perl
#
#
# 2011-01-24 stefansbv
# New version based on t/testlib.pl and Firebird.dbtest
use strict;
use warnings;
use Test::More;
use DBI qw(:sql_types);
use lib 't','.';
use TestFirebird;
my $T = TestFirebird->new;
my ($dbh, $error_str) = $T->connect_to_database( { ChopBlanks => 1 } );
if ($error_str) {
BAIL_OUT("Unknown: $error_str!");
}
unless ( $dbh->isa('DBI::db') ) {
plan skip_all => 'Connection to database failed, cannot continue testing';
}
else {
plan tests => 37;
}
ok($dbh, 'Connected to the database');
# ------- TESTS ------------------------------------------------------------- #
#DBI->trace(4, "trace.txt");
#
# Find a possible new table name
#
my $table = find_new_table($dbh);
ok($table, qq{Table is '$table'});
#
# Create the new table
#
my $def = qq{
CREATE TABLE $table (
id INTEGER NOT NULL,
name CHAR(64) CHARACTER SET ISO8859_1
)
};
ok($dbh->do($def), "CREATE TABLE '$table'");
ok(my $cursor = $dbh->prepare("INSERT INTO $table VALUES (?, ?)"));
#
# Insert some rows
#
# Automatic type detection
my $numericVal = 1;
my $charVal = 'Alligator Descartes';
ok($cursor->execute($numericVal, $charVal));
# Does the driver remember the automatically detected type?
ok($cursor->execute("3", "Jochen Wiedmann"));
$numericVal = 2;
$charVal = "Tim Bunce";
ok($cursor->execute($numericVal, $charVal));
# Now try the explicit type settings
ok($cursor->bind_param(1, ' 4', SQL_INTEGER()));
ok($cursor->bind_param(2, 'Andreas Knig'));
ok($cursor->execute);
# Works undef -> NULL?
ok($cursor->bind_param(1, 5, SQL_INTEGER()));
ok($cursor->bind_param(2, undef));
ok($cursor->execute);
#
# Try various mixes of question marks, single and double quotes
#
ok($dbh->do("INSERT INTO $table VALUES (6, '?')"));
#
# And now retreive the rows using bind_columns
#
ok($cursor = $dbh->prepare("SELECT * FROM $table ORDER BY id"));
ok($cursor->execute);
my ($id, $name);
ok($cursor->bind_columns(undef, \$id, \$name), 'Bind columns');
ok($cursor->fetch);
is($id, 1, 'Check id 1');
is($name, 'Alligator Descartes', 'Check name');
ok($cursor->fetch);
is($id, 2, 'Check id 2');
is($name, 'Tim Bunce', 'Check name');
ok($cursor->fetch);
is($id, 3, 'Check id 3');
is($name, 'Jochen Wiedmann', 'Check name');
ok($cursor->fetch);
is($id, 4, 'Check id 4');
is($name, 'Andreas Knig', 'Check name');
ok($cursor->fetch);
is($id, 5, 'Check id 5');
is($name, undef, 'Check name');
ok($cursor->fetch);
is($id, 6, 'Check id 6');
is($name, '?', 'Check name');
# Have to call finish
ok($cursor->finish);
#
# Finally drop the test table.
#
ok($dbh->do("DROP TABLE $table"), "DROP TABLE '$table'");
# -- end test
|