5 use DBIx::Class::Optional::Dependencies ();
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');
12 my ($dsn, $dbuser, $dbpass) = @ENV{map { "DBICTEST_PG_${_}" } qw/DSN USER PASS/};
14 plan skip_all => 'Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test'
15 unless ($dsn && $dbuser);
17 my $schema = DBICTest::Schema->connection($dsn, $dbuser, $dbpass, { AutoCommit => 1 });
19 my $dbh = $schema->storage->dbh;
22 local $SIG{__WARN__} = sub {};
23 $dbh->do('DROP TABLE IF EXISTS bindtype_test');
25 # the blob/clob are for reference only, will be useful when we switch to SQLT and can test Oracle along the way
27 CREATE TABLE bindtype_test
29 id serial NOT NULL PRIMARY KEY,
35 ],{ RaiseError => 1, PrintError => 1 });
38 $schema->storage->debug(0); # these tests spew up way too much stuff, disable trace
40 my $big_long_string = "\x00\x01\x02 abcd" x 125000;
43 # test inserting a row
45 $new = $schema->resultset('BindType')->create({ bytea => $big_long_string });
47 ok($new->id, "Created a bytea row");
48 ok($new->bytea eq $big_long_string, "Set the blob correctly.");
51 # test retrieval of the bytea column
53 my $row = $schema->resultset('BindType')->find({ id => $new->id });
54 ok($row->get_column('bytea') eq $big_long_string, "Created the blob correctly.");
58 my $rs = $schema->resultset('BindType')->search({ bytea => $big_long_string });
60 # search on the bytea column (select)
63 is($row ? $row->id : undef, $new->id, "Found the row searching on the bytea column.");
66 # search on the bytea column (update)
68 my $new_big_long_string = $big_long_string . "2";
70 $rs->update({ bytea => $new_big_long_string });
71 my $row = $schema->resultset('BindType')->find({ id => $new->id });
72 ok( ($row ? $row->get_column('bytea') : '') eq $new_big_long_string,
73 "Updated the row correctly (searching on the bytea column)."
75 $schema->txn_rollback;
79 # search on the bytea column (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;
89 # create with blob from $rs
90 $new = $rs->create({});
91 ok($new->bytea eq $big_long_string, 'Object has bytea value from $rs');
92 $new->discard_changes;
93 ok($new->bytea eq $big_long_string, 'bytea value made it to db');
98 eval { $dbh->do("DROP TABLE bindtype_test") };