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->connect_schema($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,
49 ],{ RaiseError => 1, PrintError => 1 });
52 $schema->storage->debug(0); # these tests spew up way too much stuff, disable trace
54 my $big_long_string = "\x00\x01\x02 abcd" x 125000;
57 # test inserting a row
59 $new = $schema->resultset('BindType')->create({ bytea => $big_long_string });
61 ok($new->id, "Created a bytea row");
62 ok($new->bytea eq $big_long_string, "Set the blob correctly.");
65 # test retrieval of the bytea column
67 my $row = $schema->resultset('BindType')->find({ id => $new->id });
68 ok($row->get_column('bytea') eq $big_long_string, "Created the blob correctly.");
72 my $rs = $schema->resultset('BindType')->search({ bytea => $big_long_string });
74 # search on the bytea column (select)
77 is($row ? $row->id : undef, $new->id, "Found the row searching on the bytea column.");
80 # search on the bytea column (update)
82 my $new_big_long_string = $big_long_string . "2";
84 $rs->update({ bytea => $new_big_long_string });
85 my $row = $schema->resultset('BindType')->find({ id => $new->id });
86 ok( ($row ? $row->get_column('bytea') : '') eq $new_big_long_string,
87 "Updated the row correctly (searching on the bytea column)."
89 $schema->txn_rollback;
93 # search on the bytea column (delete)
97 my $row = $schema->resultset('BindType')->find({ id => $new->id });
98 is($row, undef, "Deleted the row correctly (searching on the bytea column).");
99 $schema->txn_rollback;
103 # create with blob from $rs
104 $new = $rs->create({});
105 ok($new->bytea eq $big_long_string, 'Object has bytea value from $rs');
106 $new->discard_changes;
107 ok($new->bytea eq $big_long_string, 'bytea value made it to db');
110 # test inserting a row via populate() (bindtype propagation through execute_for_fetch)
111 # use a new $dbh to ensure no leakage due to prepare_cached
115 $schema->storage->_dbh(undef);
116 my $rs = $schema->resultset('BindType');
122 \[ '?', [ {} => $_ ] ],
123 "pop_${_}_" . $big_long_string,
127 is($rs->count, $cnt, 'All rows were correctly inserted');
129 my $r = $rs->find({ bytea => "pop_${_}_" . $big_long_string });
130 is ($r->id, $_, "Row $_ found after find() on the blob");
137 eval { $schema->storage->dbh_do(sub { $_[1]->do("DROP TABLE bindtype_test") } ) };