1 use DBIx::Class::Optional::Dependencies -skip_all_without => 'test_rdbms_pg';
11 my ($dsn, $dbuser, $dbpass) = @ENV{map { "DBICTEST_PG_${_}" } qw/DSN USER PASS/};
13 my $schema = DBICTest::Schema->connect($dsn, $dbuser, $dbpass, { AutoCommit => 1 });
15 if ($schema->storage->_server_info->{normalized_dbms_version} >= 9.0) {
16 if (not try { DBD::Pg->VERSION('2.17.2') }) {
18 'DBD::Pg < 2.17.2 does not work with Pg >= 9.0 BYTEA columns';
21 elsif (not try { DBD::Pg->VERSION('2.9.2') }) {
23 'DBD::Pg < 2.9.2 does not work with BYTEA columns';
26 my $dbh = $schema->storage->dbh;
29 local $SIG{__WARN__} = sub {};
30 $dbh->do('DROP TABLE IF EXISTS bindtype_test');
32 # the blob/clob are for reference only, will be useful when we switch to SQLT and can test Oracle along the way
34 CREATE TABLE bindtype_test
36 id serial NOT NULL PRIMARY KEY,
42 ],{ RaiseError => 1, PrintError => 1 });
45 $schema->storage->debug(0); # these tests spew up way too much stuff, disable trace
47 my $big_long_string = "\x00\x01\x02 abcd" x 125000;
50 # test inserting a row
52 $new = $schema->resultset('BindType')->create({ bytea => $big_long_string });
54 ok($new->id, "Created a bytea row");
55 ok($new->bytea eq $big_long_string, "Set the blob correctly.");
58 # test retrieval of the bytea column
60 my $row = $schema->resultset('BindType')->find({ id => $new->id });
61 ok($row->get_column('bytea') eq $big_long_string, "Created the blob correctly.");
65 my $rs = $schema->resultset('BindType')->search({ bytea => $big_long_string });
67 # search on the bytea column (select)
70 is($row ? $row->id : undef, $new->id, "Found the row searching on the bytea column.");
73 # search on the bytea column (update)
75 my $new_big_long_string = $big_long_string . "2";
77 $rs->update({ bytea => $new_big_long_string });
78 my $row = $schema->resultset('BindType')->find({ id => $new->id });
79 ok( ($row ? $row->get_column('bytea') : '') eq $new_big_long_string,
80 "Updated the row correctly (searching on the bytea column)."
82 $schema->txn_rollback;
86 # search on the bytea column (delete)
90 my $row = $schema->resultset('BindType')->find({ id => $new->id });
91 is($row, undef, "Deleted the row correctly (searching on the bytea column).");
92 $schema->txn_rollback;
96 # create with blob from $rs
97 $new = $rs->create({});
98 ok($new->bytea eq $big_long_string, 'Object has bytea value from $rs');
99 $new->discard_changes;
100 ok($new->bytea eq $big_long_string, 'bytea value made it to db');
103 # test inserting a row via populate() (bindtype propagation through execute_for_fetch)
104 # use a new $dbh to ensure no leakage due to prepare_cached
108 $schema->storage->_dbh(undef);
109 my $rs = $schema->resultset('BindType');
115 \[ '?', [ {} => $_ ] ],
116 "pop_${_}_" . $big_long_string,
120 is($rs->count, $cnt, 'All rows were correctly inserted');
122 my $r = $rs->find({ bytea => "pop_${_}_" . $big_long_string });
123 is ($r->id, $_, "Row $_ found after find() on the blob");
130 eval { $schema->storage->dbh_do(sub { $_[1]->do("DROP TABLE bindtype_test") } ) };