Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Commit

Permalink
Make sure SQL is generated with proper scoping of operations
Browse files Browse the repository at this point in the history
[#1031 state:resolved]
  • Loading branch information
dkubb committed Oct 7, 2009
1 parent a58701e commit 1d2da71
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions lib/dm-core/adapters/data_objects_adapter.rb
Expand Up @@ -471,21 +471,9 @@ def join_statement(query, qualify)
# @api private
def conditions_statement(conditions, qualify = false)
case conditions
when Query::Conditions::NotOperation
negate_operation(conditions, qualify)

when Query::Conditions::AbstractOperation
# TODO: remove this once conditions can be compressed
if conditions.operands.size == 1
# factor out operations with a single operand
conditions_statement(conditions.operands.first, qualify)
else
operation_statement(conditions, qualify)
end

when Query::Conditions::AbstractComparison
comparison_statement(conditions, qualify)

when Query::Conditions::NotOperation then negate_operation(conditions, qualify)
when Query::Conditions::AbstractOperation then operation_statement(conditions, qualify)
when Query::Conditions::AbstractComparison then comparison_statement(conditions, qualify)
when Array
statement, bind_values = conditions # handle raw conditions
[ "(#{statement})", bind_values ]
Expand Down Expand Up @@ -527,18 +515,17 @@ def operation_statement(operation, qualify)

operation.each do |operand|
statement, values = conditions_statement(operand, qualify)

if operand.respond_to?(:operands) && operand.operands.size > 1
statement = "(#{statement})"
end

statements << statement
bind_values.concat(values)
end

join_with = operation.kind_of?(@negated ? Query::Conditions::OrOperation : Query::Conditions::AndOperation) ? 'AND' : 'OR'
statement = statements.join(" #{join_with} ")

if statements.size > 1
statement = "(#{statement})"
end

return statement, bind_values
end

Expand Down

0 comments on commit 1d2da71

Please sign in to comment.