1 use DBIx::Class::Optional::Dependencies -skip_all_without => 'test_rdbms_oracle';
13 use DBICTest::Schema::BindType;
15 DBICTest::Schema::BindType->add_columns(
29 $ENV{NLS_SORT} = "BINARY";
30 $ENV{NLS_COMP} = "BINARY";
31 $ENV{NLS_LANG} = "AMERICAN";
33 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_ORA_${_}" } qw/DSN USER PASS/};
36 my $si = DBICTest::Schema->connect($dsn, $user, $pass)->storage->_server_info;
37 $si->{normalized_dbms_version}
38 or die "Unparseable Oracle server version: $si->{dbms_version}\n";
42 # the recyclebin (new for 10g) sometimes comes in the way
43 my $on_connect_sql = $v >= 10 ? ["ALTER SESSION SET recyclebin = OFF"] : [];
45 # iterate all tests on following options
47 { on_connect_do => $on_connect_sql },
48 { quote_char => '"', on_connect_do => $on_connect_sql },
51 # keep a database handle open for cleanup
55 for my $opt (@tryopt) {
56 my $schema = DBICTest::Schema->connect($dsn, $user, $pass, $opt);
58 $dbh = $schema->storage->dbh;
59 my $q = $schema->storage->sql_maker->quote_char || '';
63 _run_blob_tests($schema, $opt);
68 my ($schema, $opt) = @_;
69 my %binstr = ( 'small' => join('', map { chr($_) } ( 1 .. 127 )) );
70 $binstr{'large'} = $binstr{'small'} x 1024;
72 my $maxloblen = (length $binstr{'large'}) + 5;
73 note "Localizing LongReadLen to $maxloblen to avoid truncation of test data";
74 local $dbh->{'LongReadLen'} = $maxloblen;
76 my $rs = $schema->resultset('BindType');
78 if ($DBD::Oracle::VERSION eq '1.23') {
79 throws_ok { $rs->create({ id => 1, blob => $binstr{large} }) }
81 'throws on blob insert with DBD::Oracle == 1.23';
82 skip 'buggy BLOB support in DBD::Oracle 1.23', 1;
85 my $q = $schema->storage->sql_maker->quote_char || '';
86 local $TODO = 'Something is confusing column bindtype assignment when quotes are active'
87 . ': https://rt.cpan.org/Ticket/Display.html?id=64206'
91 foreach my $size (qw( small large )) {
94 local $schema->storage->{debug} = 0
97 my $str = $binstr{$size};
99 $rs->create( { 'id' => $id, blob => "blob:$str", clob => "clob:$str", blb2 => "blb2:$str", clb2 => "clb2:$str" } )
100 } "inserted $size without dying";
102 my %kids = %{$schema->storage->_dbh->{CachedKids}};
103 my @objs = $rs->search({ blob => "blob:$str", clob => "clob:$str" })->all;
105 $schema->storage->_dbh->{CachedKids},
107 'multi-part LOB equality query was not cached',
108 ) if $size eq 'large';
109 is @objs, 1, 'One row found matching on both LOBs';
110 ok (try { $objs[0]->blob }||'' eq "blob:$str", 'blob inserted/retrieved correctly');
111 ok (try { $objs[0]->clob }||'' eq "clob:$str", 'clob inserted/retrieved correctly');
112 ok (try { $objs[0]->clb2 }||'' eq "clb2:$str", "clb2 inserted correctly");
113 ok (try { $objs[0]->blb2 }||'' eq "blb2:$str", "blb2 inserted correctly");
116 local $TODO = '-like comparison on blobs not tested before ora 10 (fails on 8i)'
117 if $schema->storage->_server_info->{normalized_dbms_version} < 10;
120 @objs = $rs->search({ clob => { -like => 'clob:%' } })->all;
121 ok (@objs, 'rows found matching CLOB with a LIKE query');
122 } 'Query with like on blob succeeds';
125 ok(my $subq = $rs->search(
126 { blob => "blob:$str", clob => "clob:$str" },
128 from => \ "(SELECT * FROM ${q}bindtype_test${q} WHERE ${q}id${q} != ?) ${q}me${q}",
129 bind => [ [ {} => 12345678 ] ],
131 )->get_column('id')->as_query);
133 @objs = $rs->search({ id => { -in => $subq } })->all;
134 is (@objs, 1, 'One row found matching on both LOBs as a subquery');
137 $rs->search({ id => $id, blob => "blob:$str", clob => "clob:$str" })
138 ->update({ blob => 'updated blob', clob => 'updated clob', clb2 => 'updated clb2', blb2 => 'updated blb2' });
139 } 'blob UPDATE with blobs in WHERE clause survived';
141 @objs = $rs->search({ blob => "updated blob", clob => 'updated clob' })->all;
142 is @objs, 1, 'found updated row';
143 ok (try { $objs[0]->blob }||'' eq "updated blob", 'blob updated/retrieved correctly');
144 ok (try { $objs[0]->clob }||'' eq "updated clob", 'clob updated/retrieved correctly');
145 ok (try { $objs[0]->clb2 }||'' eq "updated clb2", "clb2 updated correctly");
146 ok (try { $objs[0]->blb2 }||'' eq "updated blb2", "blb2 updated correctly");
149 $rs->search({ id => $id })
150 ->update({ blob => 're-updated blob', clob => 're-updated clob' });
151 } 'blob UPDATE without blobs in WHERE clause survived';
153 @objs = $rs->search({ blob => 're-updated blob', clob => 're-updated clob' })->all;
154 is @objs, 1, 'found updated row';
155 ok (try { $objs[0]->blob }||'' eq 're-updated blob', 'blob updated/retrieved correctly');
156 ok (try { $objs[0]->clob }||'' eq 're-updated clob', 'clob updated/retrieved correctly');
159 $rs->search({ blob => "re-updated blob", clob => "re-updated clob" })
161 } 'blob DELETE with WHERE clause survived';
162 @objs = $rs->search({ blob => "re-updated blob", clob => 're-updated clob' })->all;
163 is @objs, 0, 'row deleted successfully';
177 $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)");
183 my $dbh = shift || return;
185 for my $q ('', '"') {
187 "DROP TABLE ${q}bindtype_test${q}",
189 eval { $dbh -> do ($_) } for @clean;
195 local $SIG{__WARN__} = sub {};