File: 41_nulls.t

package info (click to toggle)
libdbd-csv-perl 0.4500-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 320 kB
  • ctags: 55
  • sloc: perl: 2,142; makefile: 4
file content (72 lines) | stat: -rw-r--r-- 2,066 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl

# This is a test for correctly handling NULL values.

use strict;
use warnings;
use Test::More;

BEGIN { use_ok ("DBI") }
do "t/lib.pl";

my $nano = $ENV{DBI_SQL_NANO};
my @tbl_def = (
    [ "id",   "INTEGER",  4, &COL_NULLABLE	],
    [ "name", "CHAR",    64, &COL_NULLABLE	],
    [ "str",  "CHAR",    64, &COL_NULLABLE	],
    );

ok (my $dbh = Connect (),			"connect");

ok (my $tbl = FindNewTable ($dbh),		"find new test table");

like (my $def = TableDefinition ($tbl, @tbl_def),
	qr{^create table $tbl}i,		"table definition");
ok ($dbh->do ($def),				"create table");

ok ($dbh->do ("insert into $tbl values (NULL, 'NULL-id', ' ')"), "insert");

my $row;

ok (my $sth = $dbh->prepare ("select * from $tbl where id is NULL"), "prepare");
ok ($sth->execute,				"execute");
TODO: {
    local $TODO = $nano ? "SQL::Nano does not yet support this syntax" : undef;
    ok ($row = $sth->fetch,			"fetch");
    is_deeply ($row, [ "", "NULL-id", " " ],	"default content");
    }
ok ($sth->finish,				"finish");
undef $sth;

ok ($dbh = Connect ({ csv_null => 1 }),		"connect csv_null");

ok ($sth = $dbh->prepare ("select * from $tbl where id is NULL"), "prepare");
ok ($sth->execute,				"execute");
TODO: {
    local $TODO = $nano ? "SQL::Nano does not yet support this syntax" : undef;
    ok ($row = $sth->fetch,				"fetch");
    is_deeply ($row, [ undef, "NULL-id", " " ],	"NULL content");
    }
ok ($sth->finish,				"finish");
undef $sth;

ok ($dbh->do ("drop table $tbl"),		"drop table");
ok ($dbh->disconnect,				"disconnect");

ok ($dbh = Connect ({ csv_null => 1 }),		"connect csv_null");
ok ($dbh->do ($def),				"create table");

ok ($dbh->do ("insert into $tbl (id, str) values (1, ' ')"), "insert just 2");

ok ($sth = $dbh->prepare ("select * from $tbl"), "prepare");
ok ($sth->execute,				"execute");
ok ($row = $sth->fetch,				"fetch");
is_deeply ($row, [ 1, undef, " " ],		"content");

ok ($sth->finish,				"finish");
undef $sth;

ok ($dbh->do ("drop table $tbl"),		"drop table");
ok ($dbh->disconnect,				"disconnect");

done_testing ();