/
26-mysql-blob.t
61 lines (54 loc) · 1.53 KB
/
26-mysql-blob.t
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
use v6;
use Test;
use DBIish;
plan 19;
my %con-parms = :database<dbdishtest>, :user<testuser>, :password<testpass>;
my $dbh;
try {
$dbh = DBIish.connect('mysql', |%con-parms);
CATCH {
when X::DBIish::LibraryMissing | X::DBDish::ConnectionFailed {
diag "$_\nCan't continue.";
}
default { .throw; }
}
}
without $dbh {
skip-rest 'prerequisites failed';
exit;
}
ok $dbh, 'Connected';
lives-ok { $dbh.do('DROP TABLE IF EXISTS test') }, 'Clean';
lives-ok {
$dbh.do(q|
CREATE TABLE test (
id INT(3) NOT NULL DEFAULT 0,
name BLOB)|)
}, 'Table created';
my $blob = Buf.new(^256);
my $query = 'INSERT INTO test VALUES(?, ?)';
with $dbh.prepare($query) {
LEAVE { .dispose }
ok $_, "Prepared '$query'";
ok .execute(1, $blob), 'Executed with buf';
ok .execute(2, Buf), 'Executed without buf';
} else { .fail }
with $dbh.prepare('SELECT name FROM test WHERE id = ?') {
LEAVE { .dispose }
ok $_, 'SELECT prepared';
ok .execute(1), 'Executed for 1';
ok (my @res = .row), 'Get a row';
is @res.elems, 1, 'One field';
ok (my $data = @res[0]), 'With data at 0';
ok $data ~~ Buf, 'Data is-a Buf';
is $data, $blob, 'Data in Buf match with original';
ok .execute(2), 'Executed for 2';
ok (@res = .row), 'Get a row';
is @res.elems, 1, 'One field';
$data = @res[0];
ok $data ~~ Buf, 'Data is-a Buf';
ok not $data.defined, 'But is NULL';
} else { .fail }
lives-ok {
$dbh.do('DROP TABLE IF EXISTS test');
}, 'All clean';