8 use DBIx::Class::Optional::Dependencies ();
12 use DBIC::SqlMakerTest;
14 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_ORA_${_}" } qw/DSN USER PASS/};
16 plan skip_all => 'Set $ENV{DBICTEST_ORA_DSN}, _USER and _PASS to run this test.'
17 unless ($dsn && $user && $pass);
19 plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_rdbms_oracle')
20 unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_rdbms_oracle');
22 $ENV{NLS_SORT} = "BINARY";
23 $ENV{NLS_COMP} = "BINARY";
24 $ENV{NLS_LANG} = "AMERICAN";
27 my $si = DBICTest::Schema->connect($dsn, $user, $pass)->storage->_server_info;
28 $si->{normalized_dbms_version}
29 or die "Unparseable Oracle server version: $si->{dbms_version}\n";
33 # the recyclebin (new for 10g) sometimes comes in the way
34 my $on_connect_sql = $v >= 10 ? ["ALTER SESSION SET recyclebin = OFF"] : [];
36 # iterate all tests on following options
38 { on_connect_do => $on_connect_sql },
39 { quote_char => '"', on_connect_do => $on_connect_sql },
42 # keep a database handle open for cleanup
46 for my $opt (@tryopt) {
47 my $schema = DBICTest::Schema->connect($dsn, $user, $pass, $opt);
49 $dbh = $schema->storage->dbh;
50 my $q = $schema->storage->sql_maker->quote_char || '';
54 _run_blob_tests($schema, $opt);
60 my ($schema, $opt) = @_;
61 my %binstr = ( 'small' => join('', map { chr($_) } ( 1 .. 127 )) );
62 $binstr{'large'} = $binstr{'small'} x 1024;
64 my $maxloblen = (length $binstr{'large'}) + 5;
65 note "Localizing LongReadLen to $maxloblen to avoid truncation of test data";
66 local $dbh->{'LongReadLen'} = $maxloblen;
68 my $rs = $schema->resultset('BindType');
70 if ($DBD::Oracle::VERSION eq '1.23') {
71 throws_ok { $rs->create({ id => 1, blob => $binstr{large} }) }
73 'throws on blob insert with DBD::Oracle == 1.23';
74 skip 'buggy BLOB support in DBD::Oracle 1.23', 1;
77 my $q = $schema->storage->sql_maker->quote_char || '';
78 local $TODO = 'Something is confusing column bindtype assignment when quotes are active'
79 . ': https://rt.cpan.org/Ticket/Display.html?id=64206'
82 # so we can disable BLOB mega-output
83 my $orig_debug = $schema->storage->debug;
86 foreach my $size (qw( small large )) {
89 local $schema->storage->{debug} = $size eq 'large'
94 my $str = $binstr{$size};
96 $rs->create( { 'id' => $id, blob => "blob:$str", clob => "clob:$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';
107 ok (try { $objs[0]->blob }||'' eq "blob:$str", 'blob inserted/retrieved correctly');
108 ok (try { $objs[0]->clob }||'' eq "clob:$str", 'clob inserted/retrieved correctly');
111 local $TODO = '-like comparison on blobs not tested before ora 10 (fails on 8i)'
112 if $schema->storage->_server_info->{normalized_dbms_version} < 10;
115 @objs = $rs->search({ clob => { -like => 'clob:%' } })->all;
116 ok (@objs, 'rows found matching CLOB with a LIKE query');
117 } 'Query with like on blob succeeds';
120 ok(my $subq = $rs->search(
121 { blob => "blob:$str", clob => "clob:$str" },
123 from => \ "(SELECT * FROM ${q}bindtype_test${q} WHERE ${q}id${q} != ?) ${q}me${q}",
124 bind => [ [ undef => 12345678 ] ],
126 )->get_column('id')->as_query);
128 @objs = $rs->search({ id => { -in => $subq } })->all;
129 is (@objs, 1, 'One row found matching on both LOBs as a subquery');
132 $rs->search({ id => $id, blob => "blob:$str", clob => "clob:$str" })
133 ->update({ blob => 'updated blob', clob => 'updated clob' });
134 } 'blob UPDATE with blobs in WHERE clause survived';
136 @objs = $rs->search({ blob => "updated blob", clob => 'updated clob' })->all;
137 is @objs, 1, 'found updated row';
138 ok (try { $objs[0]->blob }||'' eq "updated blob", 'blob updated/retrieved correctly');
139 ok (try { $objs[0]->clob }||'' eq "updated clob", 'clob updated/retrieved correctly');
142 $rs->search({ id => $id })
143 ->update({ blob => 're-updated blob', clob => 're-updated clob' });
144 } 'blob UPDATE without blobs in WHERE clause survived';
146 @objs = $rs->search({ blob => 're-updated blob', clob => 're-updated clob' })->all;
147 is @objs, 1, 'found updated row';
148 ok (try { $objs[0]->blob }||'' eq 're-updated blob', 'blob updated/retrieved correctly');
149 ok (try { $objs[0]->clob }||'' eq 're-updated clob', 'clob updated/retrieved correctly');
152 $rs->search({ blob => "re-updated blob", clob => "re-updated clob" })
154 } 'blob DELETE with WHERE clause survived';
155 @objs = $rs->search({ blob => "re-updated blob", clob => 're-updated clob' })->all;
156 is @objs, 0, 'row deleted successfully';
159 $schema->storage->debug ($orig_debug);
172 $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}blob2${q} blob NULL, ${q}clob${q} clob NULL, ${q}clob2${q} clob NULL, ${q}a_memo${q} integer NULL)");
178 my $dbh = shift || return;
180 for my $q ('', '"') {
182 "DROP TABLE ${q}bindtype_test${q}",
184 eval { $dbh -> do ($_) } for @clean;
190 local $SIG{__WARN__} = sub {};