Debian Codegraph @

t/43_blobs.t

raw
1 #!/usr/bin/perl
2
3 # This is a test for correct handling of BLOBS and $dbh->quote ()
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 $size = 128;
13 my @tbl_def = (
14 [ "id", "INTEGER", 4, 0 ],
15 [ "name", "BLOB", $size, 0 ],
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 $blob = (pack "C*", 0 .. 255) x $size, "create blob");
27 is (length $blob, $size * 256, "blob size");
28 ok (my $qblob = $dbh->quote ($blob), "quote blob");
29
30 ok ($dbh->do ("insert into $tbl values (1, ?)", undef, $blob), "insert");
31
32 ok (my $sth = $dbh->prepare ("select * from $tbl where id = 1"), "prepare");
33 ok ($sth->execute, "execute");
34
35 ok (my $row = $sth->fetch, "fetch");
36 is_deeply ($row, [ 1, $blob ], "content");
37
38 ok ($sth->finish, "finish");
39 undef $sth;
40
41 ok ($dbh->do ("drop table $tbl"), "drop table");
42 ok ($dbh->disconnect, "disconnect");
43
44 done_testing ();