8 my ($dsn, $dbuser, $dbpass) = @ENV{map { "DBICTEST_PG_${_}" } qw/DSN USER PASS/};
10 plan skip_all => 'Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test'
11 unless ($dsn && $dbuser);
13 my $schema = DBICTest::Schema->connection($dsn, $dbuser, $dbpass, { AutoCommit => 1 });
15 my $dbh = $schema->storage->dbh;
18 local $SIG{__WARN__} = sub {};
19 $dbh->do('DROP TABLE IF EXISTS bindtype_test');
21 # the blob/clob are for reference only, will be useful when we switch to SQLT and can test Oracle along the way
23 CREATE TABLE bindtype_test
25 id serial NOT NULL PRIMARY KEY,
31 ],{ RaiseError => 1, PrintError => 1 });
34 $schema->storage->debug(0); # these tests spew up way too much stuff, disable trace
36 my $big_long_string = "\x00\x01\x02 abcd" x 125000;
39 # test inserting a row
41 $new = $schema->resultset('BindType')->create({ bytea => $big_long_string });
43 ok($new->id, "Created a bytea row");
44 ok($new->bytea eq $big_long_string, "Set the blob correctly.");
47 # test retrieval of the bytea column
49 my $row = $schema->resultset('BindType')->find({ id => $new->id });
50 ok($row->get_column('bytea') eq $big_long_string, "Created the blob correctly.");
54 my $rs = $schema->resultset('BindType')->search({ bytea => $big_long_string });
56 # search on the bytea column (select)
59 is($row ? $row->id : undef, $new->id, "Found the row searching on the bytea column.");
62 # search on the bytea column (update)
64 my $new_big_long_string = $big_long_string . "2";
66 $rs->update({ bytea => $new_big_long_string });
67 my $row = $schema->resultset('BindType')->find({ id => $new->id });
68 ok( ($row ? $row->get_column('bytea') : '') eq $new_big_long_string,
69 "Updated the row correctly (searching on the bytea column)."
71 $schema->txn_rollback;
75 # search on the bytea column (delete)
79 my $row = $schema->resultset('BindType')->find({ id => $new->id });
80 is($row, undef, "Deleted the row correctly (searching on the bytea column).");
81 $schema->txn_rollback;
85 # create with blob from $rs
86 $new = $rs->create({});
87 ok($new->bytea eq $big_long_string, 'Object has bytea value from $rs');
88 $new->discard_changes;
89 ok($new->bytea eq $big_long_string, 'bytea value made it to db');
94 eval { $dbh->do("DROP TABLE bindtype_test") };