1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2 use DBIx::Class::Optional::Dependencies -skip_all_without => 'test_rdbms_oracle';
10 use DBICTest::Schema::BindType;
12 DBICTest::Schema::BindType->add_columns(
26 $ENV{NLS_SORT} = "BINARY";
27 $ENV{NLS_COMP} = "BINARY";
28 $ENV{NLS_LANG} = "AMERICAN";
30 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_ORA_${_}" } qw/DSN USER PASS/};
33 my $si = DBICTest::Schema->connect($dsn, $user, $pass)->storage->_server_info;
34 $si->{normalized_dbms_version}
35 or die "Unparseable Oracle server version: $si->{dbms_version}\n";
39 # the recyclebin (new for 10g) sometimes comes in the way
40 my $on_connect_sql = $v >= 10 ? ["ALTER SESSION SET recyclebin = OFF"] : [];
42 # iterate all tests on following options
44 { on_connect_do => $on_connect_sql },
45 { quote_char => '"', on_connect_do => $on_connect_sql },
48 # keep a database handle open for cleanup
52 for my $opt (@tryopt) {
53 my $schema = DBICTest::Schema->connect($dsn, $user, $pass, $opt);
55 $dbh = $schema->storage->dbh;
56 my $q = $schema->storage->sql_maker->quote_char || '';
60 _run_blob_tests($schema, $opt);
65 my ($schema, $opt) = @_;
66 my %binstr = ( 'small' => join('', map { chr($_) } ( 1 .. 127 )) );
67 $binstr{'large'} = $binstr{'small'} x 1024;
69 my $maxloblen = (length $binstr{'large'}) + 5;
70 note "Localizing LongReadLen to $maxloblen to avoid truncation of test data";
71 local $dbh->{'LongReadLen'} = $maxloblen;
73 my $rs = $schema->resultset('BindType');
75 if ($DBD::Oracle::VERSION eq '1.23') {
76 throws_ok { $rs->create({ id => 1, blob => $binstr{large} }) }
78 'throws on blob insert with DBD::Oracle == 1.23';
79 skip 'buggy BLOB support in DBD::Oracle 1.23', 1;
82 my $q = $schema->storage->sql_maker->quote_char || '';
83 local $TODO = 'Something is confusing column bindtype assignment when quotes are active'
84 . ': https://rt.cpan.org/Ticket/Display.html?id=64206'
88 foreach my $size (qw( small large )) {
91 local $schema->storage->{debug} = 0
94 my $str = $binstr{$size};
96 $rs->create( { 'id' => $id, blob => "blob:$str", clob => "clob:$str", blb2 => "blb2:$str", clb2 => "clb2:$str" } )
97 } "inserted $size without dying";
99 my %kids = %{$schema->storage->_dbh->{CachedKids}};
100 my @objs = $rs->search({ blob => "blob:$str", clob => "clob:$str" })->all;
102 $schema->storage->_dbh->{CachedKids},
104 'multi-part LOB equality query was not cached',
105 ) if $size eq 'large';
106 is @objs, 1, 'One row found matching on both LOBs';
108 for my $type (qw( blob clob clb2 blb2 )) {
110 eval { $objs[0]->$type },
112 "$type inserted/retrieved correctly"
117 local $TODO = '-like comparison on blobs not tested before ora 10 (fails on 8i)'
118 if $schema->storage->_server_info->{normalized_dbms_version} < 10;
121 @objs = $rs->search({ clob => { -like => 'clob:%' } })->all;
122 ok (@objs, 'rows found matching CLOB with a LIKE query');
123 } 'Query with like on blob succeeds';
126 ok(my $subq = $rs->search(
127 { blob => "blob:$str", clob => "clob:$str" },
129 from => \ "(SELECT * FROM ${q}bindtype_test${q} WHERE ${q}id${q} != ?) ${q}me${q}",
130 bind => [ [ {} => 12345678 ] ],
132 )->get_column('id')->as_query);
134 @objs = $rs->search({ id => { -in => $subq } })->all;
135 is (@objs, 1, 'One row found matching on both LOBs as a subquery');
138 $rs->search({ id => $id, blob => "blob:$str", clob => "clob:$str" })
139 ->update({ blob => 'updated blob', clob => 'updated clob', clb2 => 'updated clb2', blb2 => 'updated blb2' });
140 } 'blob UPDATE with blobs in WHERE clause survived';
142 @objs = $rs->search({ blob => "updated blob", clob => 'updated clob' })->all;
143 is @objs, 1, 'found updated row';
145 for my $type (qw( blob clob clb2 blb2 )) {
147 eval { $objs[0]->$type },
149 "$type updated/retrieved 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';
161 for my $type (qw( blob clob )) {
163 eval { $objs[0]->$type },
165 "$type updated/retrieved correctly"
170 $rs->search({ blob => "re-updated blob", clob => "re-updated clob" })
172 } 'blob DELETE with WHERE clause survived';
173 @objs = $rs->search({ blob => "re-updated blob", clob => 're-updated clob' })->all;
174 is @objs, 0, 'row deleted successfully';
188 $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)");
194 my $dbh = shift || return;
196 for my $q ('', '"') {
198 "DROP TABLE ${q}bindtype_test${q}",
200 eval { $dbh -> do ($_) } for @clean;
206 local $SIG{__WARN__} = sub {};