1 use DBIx::Class::Optional::Dependencies -skip_all_without => qw(test_rdbms_pg binary_data);
7 use DBIx::Class::_Util 'modver_gt_or_eq';
12 my ($dsn, $dbuser, $dbpass) = @ENV{map { "DBICTEST_PG_${_}" } qw/DSN USER PASS/};
14 my $schema = DBICTest::Schema->connect($dsn, $dbuser, $dbpass, { AutoCommit => 1 });
16 plan skip_all => 'DBD::Pg < 2.17.2 does not work with Pg >= 9.0 BYTEA columns' if (
17 ! modver_gt_or_eq('DBD::Pg', '2.17.2')
19 $schema->storage->_server_info->{normalized_dbms_version} >= 9.0
22 my $dbh = $schema->storage->dbh;
25 local $SIG{__WARN__} = sub {};
26 $dbh->do('DROP TABLE IF EXISTS bindtype_test');
28 # the blob/clob are for reference only, will be useful when we switch to SQLT and can test Oracle along the way
30 CREATE TABLE bindtype_test
32 id serial NOT NULL PRIMARY KEY,
38 ],{ RaiseError => 1, PrintError => 1 });
41 $schema->storage->debug(0); # these tests spew up way too much stuff, disable trace
43 my $big_long_string = "\x00\x01\x02 abcd" x 125000;
46 # test inserting a row
48 $new = $schema->resultset('BindType')->create({ bytea => $big_long_string });
50 ok($new->id, "Created a bytea row");
51 ok($new->bytea eq $big_long_string, "Set the blob correctly.");
54 # test retrieval of the bytea column
56 my $row = $schema->resultset('BindType')->find({ id => $new->id });
57 ok($row->get_column('bytea') eq $big_long_string, "Created the blob correctly.");
61 my $rs = $schema->resultset('BindType')->search({ bytea => $big_long_string });
63 # search on the bytea column (select)
66 is($row ? $row->id : undef, $new->id, "Found the row searching on the bytea column.");
69 # search on the bytea column (update)
71 my $new_big_long_string = $big_long_string . "2";
73 $rs->update({ bytea => $new_big_long_string });
74 my $row = $schema->resultset('BindType')->find({ id => $new->id });
75 ok( ($row ? $row->get_column('bytea') : '') eq $new_big_long_string,
76 "Updated the row correctly (searching on the bytea column)."
78 $schema->txn_rollback;
82 # search on the bytea column (delete)
86 my $row = $schema->resultset('BindType')->find({ id => $new->id });
87 is($row, undef, "Deleted the row correctly (searching on the bytea column).");
88 $schema->txn_rollback;
92 # create with blob from $rs
93 $new = $rs->create({});
94 ok($new->bytea eq $big_long_string, 'Object has bytea value from $rs');
95 $new->discard_changes;
96 ok($new->bytea eq $big_long_string, 'bytea value made it to db');
99 # test inserting a row via populate() (bindtype propagation through execute_for_fetch)
100 # use a new $dbh to ensure no leakage due to prepare_cached
104 $schema->storage->_dbh(undef);
105 my $rs = $schema->resultset('BindType');
111 \[ '?', [ {} => $_ ] ],
112 "pop_${_}_" . $big_long_string,
116 is($rs->count, $cnt, 'All rows were correctly inserted');
118 my $r = $rs->find({ bytea => "pop_${_}_" . $big_long_string });
119 is ($r->id, $_, "Row $_ found after find() on the blob");
126 eval { $schema->storage->dbh_do(sub { $_[1]->do("DROP TABLE bindtype_test") } ) };