aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/engines/sql
diff options
context:
space:
mode:
authorErnie Miller <ernie@metautonomo.us>2010-04-09 19:52:43 -0400
committerErnie Miller <ernie@metautonomo.us>2010-05-07 13:07:43 -0400
commitbd473344000bd538d353e4bc6d20ca8fff2e4704 (patch)
treec2586b9dc543aa828dcbefd2769e7a1d7485280a /lib/arel/engines/sql
parent0433b054eebd5a53ff6c5f35383a6c0aed0015b2 (diff)
downloadrails-bd473344000bd538d353e4bc6d20ca8fff2e4704.tar.gz
rails-bd473344000bd538d353e4bc6d20ca8fff2e4704.tar.bz2
rails-bd473344000bd538d353e4bc6d20ca8fff2e4704.zip
Support predicate complements and alternate not syntax (overload BasicObject#!)
Diffstat (limited to 'lib/arel/engines/sql')
-rw-r--r--lib/arel/engines/sql/core_extensions/nil_class.rb4
-rw-r--r--lib/arel/engines/sql/core_extensions/object.rb4
-rw-r--r--lib/arel/engines/sql/predicates.rb14
-rw-r--r--lib/arel/engines/sql/primitives.rb8
4 files changed, 23 insertions, 7 deletions
diff --git a/lib/arel/engines/sql/core_extensions/nil_class.rb b/lib/arel/engines/sql/core_extensions/nil_class.rb
index 3f70677ba6..d4bb0e4c33 100644
--- a/lib/arel/engines/sql/core_extensions/nil_class.rb
+++ b/lib/arel/engines/sql/core_extensions/nil_class.rb
@@ -4,6 +4,10 @@ module Arel
def equality_predicate_sql
'IS'
end
+
+ def inequality_predicate_sql
+ 'IS NOT'
+ end
def not_predicate_sql
'IS NOT'
diff --git a/lib/arel/engines/sql/core_extensions/object.rb b/lib/arel/engines/sql/core_extensions/object.rb
index b71ef29fd5..5415c84706 100644
--- a/lib/arel/engines/sql/core_extensions/object.rb
+++ b/lib/arel/engines/sql/core_extensions/object.rb
@@ -8,6 +8,10 @@ module Arel
def equality_predicate_sql
'='
end
+
+ def inequality_predicate_sql
+ '!='
+ end
def not_predicate_sql
'!='
diff --git a/lib/arel/engines/sql/predicates.rb b/lib/arel/engines/sql/predicates.rb
index b459168620..df8700a500 100644
--- a/lib/arel/engines/sql/predicates.rb
+++ b/lib/arel/engines/sql/predicates.rb
@@ -30,21 +30,19 @@ module Arel
def predicate_sql; "AND" end
end
- class GroupedPredicate < Polyadic
+ class Polyadic < Predicate
def to_sql(formatter = nil)
"(" +
- additional_operands.inject([]) { |predicates, operand|
- predicates << operator.new(operand1, operand).to_sql(formatter)
- }.join(" #{predicate_sql} ") +
+ predicates.map {|p| p.to_sql(formatter)}.join(" #{predicate_sql} ") +
")"
end
end
- class Any < GroupedPredicate
+ class Any < Polyadic
def predicate_sql; "OR" end
end
- class All < GroupedPredicate
+ class All < Polyadic
def predicate_sql; "AND" end
end
@@ -55,7 +53,9 @@ module Arel
end
class Inequality < Equality
- def predicate_sql; '!=' end
+ def predicate_sql
+ operand2.inequality_predicate_sql
+ end
end
class GreaterThanOrEqualTo < Binary
diff --git a/lib/arel/engines/sql/primitives.rb b/lib/arel/engines/sql/primitives.rb
index 78e1ed7f0b..41769fa510 100644
--- a/lib/arel/engines/sql/primitives.rb
+++ b/lib/arel/engines/sql/primitives.rb
@@ -29,10 +29,18 @@ module Arel
def inclusion_predicate_sql
value.inclusion_predicate_sql
end
+
+ def exclusion_predicate_sql
+ value.exclusion_predicate_sql
+ end
def equality_predicate_sql
value.equality_predicate_sql
end
+
+ def inequality_predicate_sql
+ value.inequality_predicate_sql
+ end
def not_predicate_sql
value.not_predicate_sql