Skip to content

Commit

Permalink
Subquery WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
greensnark committed Mar 22, 2011
1 parent 1d199e7 commit 1898116
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions commands/sql_builder.rb
Expand Up @@ -70,6 +70,18 @@ def self.sanity_check_merge(query)
end

class SQLQuery
@@current_query = nil

def self.with_query(query)
old_query = @@current_query
begin
@@current_query = query
yield
ensure
@@current_query = old_query
end
end

def initialize(config)
@config = config
context_name = config[:context] || command_line_context(config[:cmdline])
Expand All @@ -90,6 +102,12 @@ def initialize(config)
validate_query
end

def with
SQLQuery.with_query(self) do
yield
end
end

def strip_command_identifier(command_line)
command_line.sub(/^\W\w+\s+/, '')
end
Expand Down Expand Up @@ -216,11 +234,13 @@ def where_clauses

def where_node
@where_node ||= @context.with do
base_where_node = SQLExprs.operator('AND')
each_condition_node do |condition|
base_where_node << SQLExprs.create(condition)
self.with do
base_where_node = SQLExprs.operator('AND')
each_condition_node do |condition|
base_where_node << SQLExprs.create(condition)
end
base_where_node.empty? ? nil : base_where_node
end
base_where_node.empty? ? nil : base_where_node
end
@where_node
end
Expand Down

0 comments on commit 1898116

Please sign in to comment.