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