| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
# This is a test for statement attributes being present appropriately. |
| 4 |
|
| 5 |
use strict; |
| 6 |
use warnings; |
| 7 |
use Test::More; |
| 8 |
|
| 9 |
BEGIN { use_ok ("DBI") } |
| 10 |
do "./t/lib.pl"; |
| 11 |
|
| 12 |
my $nano = $ENV{DBI_SQL_NANO}; |
| 13 |
my @tbl_def = ( |
| 14 |
[ "id", "INTEGER", 4, &COL_KEY ], |
| 15 |
[ "name", "CHAR", 64, &COL_NULLABLE ], |
| 16 |
); |
| 17 |
|
| 18 |
ok (my $dbh = Connect (), "connect"); |
| 19 |
|
| 20 |
ok (my $tbl = FindNewTable ($dbh), "find new test table"); |
| 21 |
|
| 22 |
like (my $def = TableDefinition ($tbl, @tbl_def), |
| 23 |
qr{^create table $tbl}i, "table definition"); |
| 24 |
ok ($dbh->do ($def), "create table"); |
| 25 |
|
| 26 |
ok (my $sth = $dbh->prepare ("select * from $tbl"), "prepare"); |
| 27 |
ok ($sth->execute, "execute"); |
| 28 |
|
| 29 |
is ($sth->{NUM_OF_FIELDS}, scalar @tbl_def, "NUM_OF_FIELDS"); |
| 30 |
is ($sth->{NUM_OF_PARAMS}, 0, "NUM_OF_PARAMS"); |
| 31 |
is ($sth->{NAME_lc}[0], lc $tbl_def[0][0], "NAME_lc"); |
| 32 |
is ($sth->{NAME_uc}[1], uc $tbl_def[1][0], "NAME_uc"); |
| 33 |
is_deeply ($sth->{NAME_lc_hash}, |
| 34 |
{ map { ( lc $tbl_def[$_][0] => $_ ) } 0 .. $#tbl_def }, "NAME_lc_hash"); |
| 35 |
if ($DBD::File::VERSION gt "0.43") { |
| 36 |
is ($sth->{TYPE}[0], $nano ? &SQL_VARCHAR : &SQL_INTEGER, "TYPE 1"); |
| 37 |
is ($sth->{TYPE}[1], $nano ? &SQL_VARCHAR : &SQL_CHAR, "TYPE 2"); |
| 38 |
is ($sth->{PRECISION}[0], 0, "PRECISION 1"); |
| 39 |
is ($sth->{PRECISION}[1], $nano ? 0 : 64, "PRECISION 2"); |
| 40 |
is ($sth->{NULLABLE}[0], $nano ? 1 : 0, "NULLABLE 1"); |
| 41 |
is ($sth->{NULLABLE}[1], 1, "NULLABLE 2"); |
| 42 |
} |
| 43 |
|
| 44 |
ok ($sth->finish, "finish"); |
| 45 |
#s ($sth->{NUM_OF_FIELDS}, 0, "NUM_OF_FIELDS"); |
| 46 |
undef $sth; |
| 47 |
|
| 48 |
ok ($dbh->do ("drop table $tbl"), "drop table"); |
| 49 |
ok ($dbh->disconnect, "disconnect"); |
| 50 |
|
| 51 |
done_testing (); |