Entire test suite passes under DBIC_TRACE=1
[dbsrgits/DBIx-Class.git] / t / bind / bindtype_columns.t
CommitLineData
6e399b4f 1use strict;
68de9438 2use warnings;
6e399b4f 3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
7
9fdf90df 8my ($dsn, $dbuser, $dbpass) = @ENV{map { "DBICTEST_PG_${_}" } qw/DSN USER PASS/};
6e399b4f 9
9fdf90df 10plan skip_all => 'Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test'
11 unless ($dsn && $dbuser);
d7f20fdf 12
b1e86b3e 13plan tests => 6;
9fdf90df 14
77d76d0f 15my $schema = DBICTest::Schema->connection($dsn, $dbuser, $dbpass, { AutoCommit => 1 });
9fdf90df 16
eda28767 17my $dbh = $schema->storage->dbh;
9fdf90df 18
bb452615 19{
20 local $SIG{__WARN__} = sub {};
a65c1894 21 $dbh->do('DROP TABLE IF EXISTS bindtype_test');
6ec7d1bb 22
23 # the blob/clob are for reference only, will be useful when we switch to SQLT and can test Oracle along the way
bb452615 24 $dbh->do(qq[
6ec7d1bb 25 CREATE TABLE bindtype_test
bb452615 26 (
6ec7d1bb 27 id serial NOT NULL PRIMARY KEY,
28 bytea bytea NULL,
29 blob bytea NULL,
30 clob text NULL
bb452615 31 );
32 ],{ RaiseError => 1, PrintError => 1 });
33}
9fdf90df 34
0007aedf 35$schema->storage->debug(0); # these tests spew up way too much stuff, disable trace
36
d7f20fdf 37my $big_long_string = "\x00\x01\x02 abcd" x 125000;
6ffb5be5 38
39my $new;
40# test inserting a row
41{
42 $new = $schema->resultset('BindType')->create({ bytea => $big_long_string });
43
44 ok($new->id, "Created a bytea row");
d7f20fdf 45 is($new->bytea, $big_long_string, "Set the blob correctly.");
6ffb5be5 46}
47
b1e86b3e 48# test retrieval of the bytea column
49{
50 my $row = $schema->resultset('BindType')->find({ id => $new->id });
51 is($row->get_column('bytea'), $big_long_string, "Created the blob correctly.");
52}
9fdf90df 53
ba61fa2a 54{
6ffb5be5 55 my $rs = $schema->resultset('BindType')->search({ bytea => $big_long_string });
b1e86b3e 56
6ffb5be5 57 # search on the bytea column (select)
58 {
59 my $row = $rs->first;
60 is($row ? $row->id : undef, $new->id, "Found the row searching on the bytea column.");
61 }
b1e86b3e 62
6ffb5be5 63 # search on the bytea column (update)
64 {
65 my $new_big_long_string = $big_long_string . "2";
66 $schema->txn_do(sub {
67 $rs->update({ bytea => $new_big_long_string });
68 my $row = $schema->resultset('BindType')->find({ id => $new->id });
69 is($row ? $row->get_column('bytea') : undef, $new_big_long_string,
70 "Updated the row correctly (searching on the bytea column)."
71 );
72 $schema->txn_rollback;
73 });
74 }
b1e86b3e 75
6ffb5be5 76 # search on the bytea column (delete)
77 {
78 $schema->txn_do(sub {
79 $rs->delete;
80 my $row = $schema->resultset('BindType')->find({ id => $new->id });
81 is($row, undef, "Deleted the row correctly (searching on the bytea column).");
82 $schema->txn_rollback;
83 });
84 }
85}
9fdf90df 86
6ec7d1bb 87$dbh->do("DROP TABLE bindtype_test");