Skip to content

Commit

Permalink
Fix oracle (I am so stupid)
Browse files Browse the repository at this point in the history
  • Loading branch information
ribasushi committed Jul 27, 2011
1 parent 43d10c9 commit e12571a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Changes
@@ -1,5 +1,9 @@
Revision history for DBIx::Class

* Fixes
- Fix horrible oversight in the Oracle sqlmaker when dealing with
queries updating blobs (RT#69829)

0.08194 2011-07-20 16:10 (UTC)
* Fixes
- Fix $rs->populate([]) to be a no-op rather than an exception
Expand Down
7 changes: 6 additions & 1 deletion lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm
Expand Up @@ -515,7 +515,8 @@ sub _prep_for_execute {
$self->throw_exception('Update with complex WHERE clauses currently not supported')
if $sql =~ /\bWHERE\b .+ \bWHERE\b/xs;

($final_sql, $sql) = $sql =~ /^ (.+?) ( \bWHERE\b .+) /xs;
my $where_sql;
($final_sql, $where_sql) = $sql =~ /^ (.+?) ( \bWHERE\b .+) /xs;

if (my $set_bind_count = $final_sql =~ y/?//) {

Expand All @@ -530,6 +531,10 @@ sub _prep_for_execute {
keys %$lob_bind_indices
};
}

# if we got that far - assume the where SQL is all we got
# (the first part is already shoved into $final_sql)
$sql = $where_sql;
}
elsif ($op ne 'select' and $op ne 'delete') {
$self->throw_exception("Unsupported \$op: $op");
Expand Down
16 changes: 13 additions & 3 deletions t/73oracle.t
Expand Up @@ -449,18 +449,28 @@ sub _run_tests {
lives_ok {
$rs->search({ id => $id, blob => "blob:$str", clob => "clob:$str" })
->update({ blob => 'updated blob', clob => 'updated clob' });
} 'blob UPDATE with WHERE clause survived';
} 'blob UPDATE with blobs in WHERE clause survived';

@objs = $rs->search({ blob => "updated blob", clob => 'updated clob' })->all;
is @objs, 1, 'found updated row';
ok (try { $objs[0]->blob }||'' eq "updated blob", 'blob updated/retrieved correctly');
ok (try { $objs[0]->clob }||'' eq "updated clob", 'clob updated/retrieved correctly');

lives_ok {
$rs->search({ blob => "updated blob", clob => "updated clob" })
$rs->search({ id => $id })
->update({ blob => 're-updated blob', clob => 're-updated clob' });
} 'blob UPDATE without blobs in WHERE clause survived';

@objs = $rs->search({ blob => 're-updated blob', clob => 're-updated clob' })->all;
is @objs, 1, 'found updated row';
ok (try { $objs[0]->blob }||'' eq 're-updated blob', 'blob updated/retrieved correctly');
ok (try { $objs[0]->clob }||'' eq 're-updated clob', 'clob updated/retrieved correctly');

lives_ok {
$rs->search({ blob => "re-updated blob", clob => "re-updated clob" })
->delete;
} 'blob DELETE with WHERE clause survived';
@objs = $rs->search({ blob => "updated blob", clob => 'updated clob' })->all;
@objs = $rs->search({ blob => "re-updated blob", clob => 're-updated clob' })->all;
is @objs, 0, 'row deleted successfully';
}

Expand Down

0 comments on commit e12571a

Please sign in to comment.