8 use DBIx::Class::Optional::Dependencies ();
12 use DBICTest::Schema::BindType;
14 DBICTest::Schema::BindType->add_columns(
28 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_ORA_${_}" } qw/DSN USER PASS/};
30 plan skip_all => 'Set $ENV{DBICTEST_ORA_DSN}, _USER and _PASS to run this test.'
31 unless ($dsn && $user && $pass);
33 plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_rdbms_oracle')
34 unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_rdbms_oracle');
36 $ENV{NLS_SORT} = "BINARY";
37 $ENV{NLS_COMP} = "BINARY";
38 $ENV{NLS_LANG} = "AMERICAN";
41 my $si = DBICTest::Schema->connect($dsn, $user, $pass)->storage->_server_info;
42 $si->{normalized_dbms_version}
43 or die "Unparseable Oracle server version: $si->{dbms_version}\n";
47 # the recyclebin (new for 10g) sometimes comes in the way
48 my $on_connect_sql = $v >= 10 ? ["ALTER SESSION SET recyclebin = OFF"] : [];
50 # iterate all tests on following options
52 { on_connect_do => $on_connect_sql },
53 { quote_char => '"', on_connect_do => $on_connect_sql },
56 # keep a database handle open for cleanup
60 for my $opt (@tryopt) {
61 my $schema = DBICTest::Schema->connect($dsn, $user, $pass, $opt);
63 $dbh = $schema->storage->dbh;
64 my $q = $schema->storage->sql_maker->quote_char || '';
68 _run_blob_tests($schema, $opt);
73 my ($schema, $opt) = @_;
74 my %binstr = ( 'small' => join('', map { chr($_) } ( 1 .. 127 )) );
75 $binstr{'large'} = $binstr{'small'} x 1024;
77 my $maxloblen = (length $binstr{'large'}) + 5;
78 note "Localizing LongReadLen to $maxloblen to avoid truncation of test data";
79 local $dbh->{'LongReadLen'} = $maxloblen;
81 my $rs = $schema->resultset('BindType');
83 if ($DBD::Oracle::VERSION eq '1.23') {
84 throws_ok { $rs->create({ id => 1, blob => $binstr{large} }) }
86 'throws on blob insert with DBD::Oracle == 1.23';
87 skip 'buggy BLOB support in DBD::Oracle 1.23', 1;
90 my $q = $schema->storage->sql_maker->quote_char || '';
91 local $TODO = 'Something is confusing column bindtype assignment when quotes are active'
92 . ': https://rt.cpan.org/Ticket/Display.html?id=64206'
96 foreach my $size (qw( small large )) {
99 local $schema->storage->{debug} = 0
102 my $str = $binstr{$size};
104 $rs->create( { 'id' => $id, blob => "blob:$str", clob => "clob:$str", blb2 => "blb2:$str", clb2 => "clb2:$str" } )
105 } "inserted $size without dying";
107 my %kids = %{$schema->storage->_dbh->{CachedKids}};
108 my @objs = $rs->search({ blob => "blob:$str", clob => "clob:$str" })->all;
110 $schema->storage->_dbh->{CachedKids},
112 'multi-part LOB equality query was not cached',
113 ) if $size eq 'large';
114 is @objs, 1, 'One row found matching on both LOBs';
115 ok (try { $objs[0]->blob }||'' eq "blob:$str", 'blob inserted/retrieved correctly');
116 ok (try { $objs[0]->clob }||'' eq "clob:$str", 'clob inserted/retrieved correctly');
117 ok (try { $objs[0]->clb2 }||'' eq "clb2:$str", "clb2 inserted correctly");
118 ok (try { $objs[0]->blb2 }||'' eq "blb2:$str", "blb2 inserted correctly");
121 local $TODO = '-like comparison on blobs not tested before ora 10 (fails on 8i)'
122 if $schema->storage->_server_info->{normalized_dbms_version} < 10;
125 @objs = $rs->search({ clob => { -like => 'clob:%' } })->all;
126 ok (@objs, 'rows found matching CLOB with a LIKE query');
127 } 'Query with like on blob succeeds';
130 ok(my $subq = $rs->search(
131 { blob => "blob:$str", clob => "clob:$str" },
133 from => \ "(SELECT * FROM ${q}bindtype_test${q} WHERE ${q}id${q} != ?) ${q}me${q}",
134 bind => [ [ undef => 12345678 ] ],
136 )->get_column('id')->as_query);
138 @objs = $rs->search({ id => { -in => $subq } })->all;
139 is (@objs, 1, 'One row found matching on both LOBs as a subquery');
142 $rs->search({ id => $id, blob => "blob:$str", clob => "clob:$str" })
143 ->update({ blob => 'updated blob', clob => 'updated clob', clb2 => 'updated clb2', blb2 => 'updated blb2' });
144 } 'blob UPDATE with blobs in WHERE clause survived';
146 @objs = $rs->search({ blob => "updated blob", clob => 'updated clob' })->all;
147 is @objs, 1, 'found updated row';
148 ok (try { $objs[0]->blob }||'' eq "updated blob", 'blob updated/retrieved correctly');
149 ok (try { $objs[0]->clob }||'' eq "updated clob", 'clob updated/retrieved correctly');
150 ok (try { $objs[0]->clb2 }||'' eq "updated clb2", "clb2 updated correctly");
151 ok (try { $objs[0]->blb2 }||'' eq "updated blb2", "blb2 updated correctly");
154 $rs->search({ id => $id })
155 ->update({ blob => 're-updated blob', clob => 're-updated clob' });
156 } 'blob UPDATE without blobs in WHERE clause survived';
158 @objs = $rs->search({ blob => 're-updated blob', clob => 're-updated clob' })->all;
159 is @objs, 1, 'found updated row';
160 ok (try { $objs[0]->blob }||'' eq 're-updated blob', 'blob updated/retrieved correctly');
161 ok (try { $objs[0]->clob }||'' eq 're-updated clob', 'clob updated/retrieved correctly');
164 $rs->search({ blob => "re-updated blob", clob => "re-updated clob" })
166 } 'blob DELETE with WHERE clause survived';
167 @objs = $rs->search({ blob => "re-updated blob", clob => 're-updated clob' })->all;
168 is @objs, 0, 'row deleted successfully';
182 $dbh->do("CREATE TABLE ${q}bindtype_test${q} (${q}id${q} integer NOT NULL PRIMARY KEY, ${q}bytea${q} integer NULL, ${q}blob${q} blob NULL, ${q}blb2${q} blob NULL, ${q}clob${q} clob NULL, ${q}clb2${q} clob NULL, ${q}a_memo${q} integer NULL)");
188 my $dbh = shift || return;
190 for my $q ('', '"') {
192 "DROP TABLE ${q}bindtype_test${q}",
194 eval { $dbh -> do ($_) } for @clean;
200 local $SIG{__WARN__} = sub {};