Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Subquery WIP.

  • Loading branch information...
commit 18981161f83c76508f7433a198b641fd5f295445 1 parent 1d199e7
@greensnark authored
Showing with 24 additions and 4 deletions.
  1. +24 −4 commands/sql_builder.rb
View
28 commands/sql_builder.rb
@@ -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])
@@ -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
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.