1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2 use DBIx::Class::Optional::Dependencies -skip_all_without => qw(test_rdbms_pg binary_data);
8 use DBIx::Class::_Util 'modver_gt_or_eq';
13 my ($dsn, $dbuser, $dbpass) = @ENV{map { "DBICTEST_PG_${_}" } qw/DSN USER PASS/};
15 my $schema = DBICTest::Schema->connect($dsn, $dbuser, $dbpass, { AutoCommit => 1 });
17 plan skip_all => 'DBD::Pg < 2.17.2 does not work with Pg >= 9.0 BYTEA columns' if (
18 ! modver_gt_or_eq('DBD::Pg', '2.17.2')
20 $schema->storage->_server_info->{normalized_dbms_version} >= 9.0
23 my $dbh = $schema->storage->dbh;
26 local $SIG{__WARN__} = sub {};
27 $dbh->do('DROP TABLE IF EXISTS bindtype_test');
29 # the blob/clob are for reference only, will be useful when we switch to SQLT and can test Oracle along the way
31 CREATE TABLE bindtype_test
33 id serial NOT NULL PRIMARY KEY,
39 ],{ RaiseError => 1, PrintError => 1 });
42 $schema->storage->debug(0); # these tests spew up way too much stuff, disable trace
44 my $big_long_string = "\x00\x01\x02 abcd" x 125000;
47 # test inserting a row
49 $new = $schema->resultset('BindType')->create({ bytea => $big_long_string });
51 ok($new->id, "Created a bytea row");
52 ok($new->bytea eq $big_long_string, "Set the blob correctly.");
55 # test retrieval of the bytea column
57 my $row = $schema->resultset('BindType')->find({ id => $new->id });
58 ok($row->get_column('bytea') eq $big_long_string, "Created the blob correctly.");
62 my $rs = $schema->resultset('BindType')->search({ bytea => $big_long_string });
64 # search on the bytea column (select)
67 is($row ? $row->id : undef, $new->id, "Found the row searching on the bytea column.");
70 # search on the bytea column (update)
72 my $new_big_long_string = $big_long_string . "2";
74 $rs->update({ bytea => $new_big_long_string });
75 my $row = $schema->resultset('BindType')->find({ id => $new->id });
76 ok( ($row ? $row->get_column('bytea') : '') eq $new_big_long_string,
77 "Updated the row correctly (searching on the bytea column)."
79 $schema->txn_rollback;
83 # search on the bytea column (delete)
87 my $row = $schema->resultset('BindType')->find({ id => $new->id });
88 is($row, undef, "Deleted the row correctly (searching on the bytea column).");
89 $schema->txn_rollback;
93 # create with blob from $rs
94 $new = $rs->create({});
95 ok($new->bytea eq $big_long_string, 'Object has bytea value from $rs');
96 $new->discard_changes;
97 ok($new->bytea eq $big_long_string, 'bytea value made it to db');
100 # test inserting a row via populate() (bindtype propagation through execute_for_fetch)
101 # use a new $dbh to ensure no leakage due to prepare_cached
105 $schema->storage->_dbh(undef);
106 my $rs = $schema->resultset('BindType');
112 \[ '?', [ {} => $_ ] ],
113 "pop_${_}_" . $big_long_string,
117 is($rs->count, $cnt, 'All rows were correctly inserted');
119 my $r = $rs->find({ bytea => "pop_${_}_" . $big_long_string });
120 is ($r->id, $_, "Row $_ found after find() on the blob");
127 eval { $schema->storage->dbh_do(sub { $_[1]->do("DROP TABLE bindtype_test") } ) };