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,
30 ],{ RaiseError => 1, PrintError => 1 });
33 $schema->storage->debug(0); # these tests spew up way too much stuff, disable trace
35 my $big_long_string = "\x00\x01\x02 abcd" x 125000;
38 # test inserting a row
40 $new = $schema->resultset('BindType')->create({ bytea => $big_long_string });
42 ok($new->id, "Created a bytea row");
43 is($new->bytea, $big_long_string, "Set the blob correctly.");
46 # test retrieval of the bytea column
48 my $row = $schema->resultset('BindType')->find({ id => $new->id });
49 is($row->get_column('bytea'), $big_long_string, "Created the blob correctly.");
53 my $rs = $schema->resultset('BindType')->search({ bytea => $big_long_string });
55 # search on the bytea column (select)
58 is($row ? $row->id : undef, $new->id, "Found the row searching on the bytea column.");
61 # search on the bytea column (update)
63 my $new_big_long_string = $big_long_string . "2";
65 $rs->update({ bytea => $new_big_long_string });
66 my $row = $schema->resultset('BindType')->find({ id => $new->id });
67 is($row ? $row->get_column('bytea') : undef, $new_big_long_string,
68 "Updated the row correctly (searching on the bytea column)."
70 $schema->txn_rollback;
74 # search on the bytea column (delete)
78 my $row = $schema->resultset('BindType')->find({ id => $new->id });
79 is($row, undef, "Deleted the row correctly (searching on the bytea column).");
80 $schema->txn_rollback;
84 # create with blob from $rs
85 $new = $rs->create({});
86 is($new->bytea, $big_long_string, 'Object has bytea value from $rs');
87 $new->discard_changes;
88 is($new->bytea, $big_long_string, 'bytea value made it to db');
93 eval { $dbh->do("DROP TABLE bindtype_test") };