5 use DBIx::Class::Optional::Dependencies ();
10 plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('rdbms_pg')
11 unless DBIx::Class::Optional::Dependencies->req_ok_for ('rdbms_pg');
13 my ($dsn, $dbuser, $dbpass) = @ENV{map { "DBICTEST_PG_${_}" } qw/DSN USER PASS/};
15 plan skip_all => 'Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test'
16 unless ($dsn && $dbuser);
18 my $schema = DBICTest::Schema->connect($dsn, $dbuser, $dbpass, { AutoCommit => 1 });
20 if ($schema->storage->_server_info->{normalized_dbms_version} >= 9.0) {
21 if (not try { DBD::Pg->VERSION('2.17.2') }) {
23 'DBD::Pg < 2.17.2 does not work with Pg >= 9.0 BYTEA columns';
26 elsif (not try { DBD::Pg->VERSION('2.9.2') }) {
28 'DBD::Pg < 2.9.2 does not work with BYTEA columns';
31 my $dbh = $schema->storage->dbh;
34 local $SIG{__WARN__} = sub {};
35 $dbh->do('DROP TABLE IF EXISTS bindtype_test');
37 # the blob/clob are for reference only, will be useful when we switch to SQLT and can test Oracle along the way
39 CREATE TABLE bindtype_test
41 id serial NOT NULL PRIMARY KEY,
47 ],{ RaiseError => 1, PrintError => 1 });
50 $schema->storage->debug(0); # these tests spew up way too much stuff, disable trace
52 my $big_long_string = "\x00\x01\x02 abcd" x 125000;
55 # test inserting a row
57 $new = $schema->resultset('BindType')->create({ bytea => $big_long_string });
59 ok($new->id, "Created a bytea row");
60 ok($new->bytea eq $big_long_string, "Set the blob correctly.");
63 # test retrieval of the bytea column
65 my $row = $schema->resultset('BindType')->find({ id => $new->id });
66 ok($row->get_column('bytea') eq $big_long_string, "Created the blob correctly.");
70 my $rs = $schema->resultset('BindType')->search({ bytea => $big_long_string });
72 # search on the bytea column (select)
75 is($row ? $row->id : undef, $new->id, "Found the row searching on the bytea column.");
78 # search on the bytea column (update)
80 my $new_big_long_string = $big_long_string . "2";
82 $rs->update({ bytea => $new_big_long_string });
83 my $row = $schema->resultset('BindType')->find({ id => $new->id });
84 ok( ($row ? $row->get_column('bytea') : '') eq $new_big_long_string,
85 "Updated the row correctly (searching on the bytea column)."
87 $schema->txn_rollback;
91 # search on the bytea column (delete)
95 my $row = $schema->resultset('BindType')->find({ id => $new->id });
96 is($row, undef, "Deleted the row correctly (searching on the bytea column).");
97 $schema->txn_rollback;
101 # create with blob from $rs
102 $new = $rs->create({});
103 ok($new->bytea eq $big_long_string, 'Object has bytea value from $rs');
104 $new->discard_changes;
105 ok($new->bytea eq $big_long_string, 'bytea value made it to db');
108 # test inserting a row via populate() (bindtype propagation through execute_for_fetch)
109 # use a new $dbh to ensure no leakage due to prepare_cached
113 $schema->storage->_dbh(undef);
114 my $rs = $schema->resultset('BindType');
120 \[ '?', [ {} => $_ ] ],
121 "pop_${_}_" . $big_long_string,
125 is($rs->count, $cnt, 'All rows were correctly inserted');
127 my $r = $rs->find({ bytea => "pop_${_}_" . $big_long_string });
128 is ($r->id, $_, "Row $_ found after find() on the blob");
135 eval { $schema->storage->dbh_do(sub { $_[1]->do("DROP TABLE bindtype_test") } ) };