| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
# This is a test for correctly handling NULL values. |
| 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_NULLABLE ], |
| 15 |
[ "name", "CHAR", 64, &COL_NULLABLE ], |
| 16 |
[ "str", "CHAR", 64, &COL_NULLABLE ], |
| 17 |
); |
| 18 |
|
| 19 |
ok (my $dbh = Connect (), "connect"); |
| 20 |
|
| 21 |
ok (my $tbl = FindNewTable ($dbh), "find new test table"); |
| 22 |
|
| 23 |
like (my $def = TableDefinition ($tbl, @tbl_def), |
| 24 |
qr{^create table $tbl}i, "table definition"); |
| 25 |
ok ($dbh->do ($def), "create table"); |
| 26 |
|
| 27 |
ok ($dbh->do ("insert into $tbl values (NULL, 'NULL-id', ' ')"), "insert"); |
| 28 |
|
| 29 |
my $row; |
| 30 |
|
| 31 |
ok (my $sth = $dbh->prepare ("select * from $tbl where id is NULL"), "prepare"); |
| 32 |
ok ($sth->execute, "execute"); |
| 33 |
TODO: { |
| 34 |
local $TODO = $nano ? "SQL::Nano does not yet support this syntax" : undef; |
| 35 |
ok ($row = $sth->fetch, "fetch"); |
| 36 |
is_deeply ($row, [ "", "NULL-id", " " ], "default content"); |
| 37 |
} |
| 38 |
ok ($sth->finish, "finish"); |
| 39 |
undef $sth; |
| 40 |
|
| 41 |
ok ($dbh = Connect ({ csv_null => 1 }), "connect csv_null"); |
| 42 |
|
| 43 |
ok ($sth = $dbh->prepare ("select * from $tbl where id is NULL"), "prepare"); |
| 44 |
ok ($sth->execute, "execute"); |
| 45 |
TODO: { |
| 46 |
local $TODO = $nano ? "SQL::Nano does not yet support this syntax" : undef; |
| 47 |
ok ($row = $sth->fetch, "fetch"); |
| 48 |
is_deeply ($row, [ undef, "NULL-id", " " ], "NULL content"); |
| 49 |
} |
| 50 |
ok ($sth->finish, "finish"); |
| 51 |
undef $sth; |
| 52 |
|
| 53 |
ok ($dbh->do ("drop table $tbl"), "drop table"); |
| 54 |
ok ($dbh->disconnect, "disconnect"); |
| 55 |
|
| 56 |
ok ($dbh = Connect ({ csv_null => 1 }), "connect csv_null"); |
| 57 |
ok ($dbh->do ($def), "create table"); |
| 58 |
|
| 59 |
ok ($dbh->do ("insert into $tbl (id, str) values (1, ' ')"), "insert just 2"); |
| 60 |
|
| 61 |
ok ($sth = $dbh->prepare ("select * from $tbl"), "prepare"); |
| 62 |
ok ($sth->execute, "execute"); |
| 63 |
ok ($row = $sth->fetch, "fetch"); |
| 64 |
is_deeply ($row, [ 1, undef, " " ], "content"); |
| 65 |
|
| 66 |
ok ($sth->finish, "finish"); |
| 67 |
undef $sth; |
| 68 |
|
| 69 |
ok ($dbh->do ("drop table $tbl"), "drop table"); |
| 70 |
ok ($dbh->disconnect, "disconnect"); |
| 71 |
|
| 72 |
done_testing (); |