Debian Codegraph @

t/50_chopblanks.t

raw
1 #!/usr/bin/perl
2
3 # This driver should check if 'ChopBlanks' works.
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 @tbl_def = (
13 [ "id", "INTEGER", 4, &COL_NULLABLE ],
14 [ "name", "CHAR", 64, &COL_NULLABLE ],
15 );
16
17 ok (my $dbh = Connect (), "connect");
18
19 ok (my $tbl = FindNewTable ($dbh), "find new test table");
20
21 like (my $def = TableDefinition ($tbl, @tbl_def),
22 qr{^create table $tbl}i, "table definition");
23 ok ($dbh->do ($def), "create table");
24
25 my @rows = (
26 [ 1, "NULL", ],
27 [ 2, " ", ],
28 [ 3, " a b c ", ],
29 [ 4, " a \r ", ],
30 [ 5, " a \t ", ],
31 [ 6, " a \n ", ],
32 );
33 ok (my $sti = $dbh->prepare ("insert into $tbl (id, name) values (?, ?)"), "prepare ins");
34 ok (my $sth = $dbh->prepare ("select id, name from $tbl where id = ?"), "prepare sel");
35 foreach my $row (@rows) {
36 ok ($sti->execute (@$row), "insert $row->[0]");
37
38 $sth->{ChopBlanks} = 0;
39 ok (1, "ChopBlanks 0");
40 ok ($sth->execute ($row->[0]), "execute");
41 ok (my $r = $sth->fetch, "fetch ($row->[0]:1)");
42 is_deeply ($r, $row, "content ($row->[0]:1)");
43
44 $sth->{ChopBlanks} = 1;
45 ok (1, "ChopBlanks 1");
46 ok ($sth->execute ($row->[0]), "execute");
47 s/ +$// for @$row;
48 if ($DBD::File::VERSION <= 0.38) {
49 s/\s+$// for @$row; # Bug fixed in new DBI
50 }
51 ok ($r = $sth->fetch, "fetch ($row->[0]:2)");
52 is_deeply ($r, $row, "content ($row->[0]:2)");
53 }
54
55 ok ($sti->finish, "finish sti");
56 undef $sti;
57 ok ($sth->finish, "finish sth");
58 undef $sth;
59
60 ok ($dbh->do ("drop table $tbl"), "drop table");
61 ok ($dbh->disconnect, "disconnect");
62
63 done_testing ();