Commit | Line | Data |
6e399b4f |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use lib qw(t/lib); |
6 | use DBICTest; |
7 | |
9fdf90df |
8 | my ($dsn, $dbuser, $dbpass) = @ENV{map { "DBICTEST_PG_${_}" } qw/DSN USER PASS/}; |
6e399b4f |
9 | |
9fdf90df |
10 | plan skip_all => 'Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test' |
11 | unless ($dsn && $dbuser); |
12 | |
b1e86b3e |
13 | plan tests => 6; |
9fdf90df |
14 | |
77d76d0f |
15 | my $schema = DBICTest::Schema->connection($dsn, $dbuser, $dbpass, { AutoCommit => 1 }); |
9fdf90df |
16 | |
eda28767 |
17 | my $dbh = $schema->storage->dbh; |
9fdf90df |
18 | |
bb452615 |
19 | { |
20 | local $SIG{__WARN__} = sub {}; |
a65c1894 |
21 | $dbh->do('DROP TABLE IF EXISTS bindtype_test'); |
6ec7d1bb |
22 | |
23 | # the blob/clob are for reference only, will be useful when we switch to SQLT and can test Oracle along the way |
bb452615 |
24 | $dbh->do(qq[ |
6ec7d1bb |
25 | CREATE TABLE bindtype_test |
bb452615 |
26 | ( |
6ec7d1bb |
27 | id serial NOT NULL PRIMARY KEY, |
28 | bytea bytea NULL, |
29 | blob bytea NULL, |
30 | clob text NULL |
bb452615 |
31 | ); |
32 | ],{ RaiseError => 1, PrintError => 1 }); |
33 | } |
9fdf90df |
34 | |
6ffb5be5 |
35 | my $big_long_string = "\x00\x01\x02 abcd" x 125000; |
36 | |
37 | my $new; |
38 | # test inserting a row |
39 | { |
40 | $new = $schema->resultset('BindType')->create({ bytea => $big_long_string }); |
41 | |
42 | ok($new->id, "Created a bytea row"); |
43 | is($new->bytea, $big_long_string, "Set the blob correctly."); |
44 | } |
45 | |
b1e86b3e |
46 | # test retrieval of the bytea column |
47 | { |
48 | my $row = $schema->resultset('BindType')->find({ id => $new->id }); |
49 | is($row->get_column('bytea'), $big_long_string, "Created the blob correctly."); |
50 | } |
9fdf90df |
51 | |
ba61fa2a |
52 | { |
6ffb5be5 |
53 | my $rs = $schema->resultset('BindType')->search({ bytea => $big_long_string }); |
b1e86b3e |
54 | |
6ffb5be5 |
55 | # search on the bytea column (select) |
56 | { |
57 | my $row = $rs->first; |
58 | is($row ? $row->id : undef, $new->id, "Found the row searching on the bytea column."); |
59 | } |
b1e86b3e |
60 | |
6ffb5be5 |
61 | # search on the bytea column (update) |
62 | { |
63 | my $new_big_long_string = $big_long_string . "2"; |
64 | $schema->txn_do(sub { |
65 | $rs->update({ bytea => $new_big_long_string }); |
66 | my $row = $schema->resultset('BindType')->find({ id => $new->id }); |
67 | is($row ? $row->get_column('bytea') : undef, $new_big_long_string, |
68 | "Updated the row correctly (searching on the bytea column)." |
69 | ); |
70 | $schema->txn_rollback; |
71 | }); |
72 | } |
b1e86b3e |
73 | |
6ffb5be5 |
74 | # search on the bytea column (delete) |
75 | { |
76 | $schema->txn_do(sub { |
77 | $rs->delete; |
78 | my $row = $schema->resultset('BindType')->find({ id => $new->id }); |
79 | is($row, undef, "Deleted the row correctly (searching on the bytea column)."); |
80 | $schema->txn_rollback; |
81 | }); |
82 | } |
83 | } |
9fdf90df |
84 | |
6ec7d1bb |
85 | $dbh->do("DROP TABLE bindtype_test"); |