aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBryan Helmkamp <bryan@brynary.com>2009-05-17 16:02:10 -0400
committerBryan Helmkamp <bryan@brynary.com>2009-05-17 16:12:06 -0400
commit7a51983efc50c8f9092785b1b586f8884dedc01a (patch)
tree5b915ee48c7aa454207312ba20bb13c4dadfdf70 /lib
parent07833d39c2885a5cddf38eeb860d79353c0f447b (diff)
downloadrails-7a51983efc50c8f9092785b1b586f8884dedc01a.tar.gz
rails-7a51983efc50c8f9092785b1b586f8884dedc01a.tar.bz2
rails-7a51983efc50c8f9092785b1b586f8884dedc01a.zip
initial implementation of cross-engine join
Conflicts: lib/arel/engines/memory/relations/array.rb lib/arel/engines/sql/primitives.rb
Diffstat (limited to 'lib')
-rw-r--r--lib/arel/algebra/relations/row.rb5
-rw-r--r--lib/arel/engines/memory/relations/array.rb4
-rw-r--r--lib/arel/engines/memory/relations/compound.rb2
-rw-r--r--lib/arel/engines/memory/relations/operations.rb4
-rw-r--r--lib/arel/engines/sql/engine.rb4
-rw-r--r--lib/arel/engines/sql/primitives.rb4
-rw-r--r--lib/arel/engines/sql/relations/table.rb4
7 files changed, 21 insertions, 6 deletions
diff --git a/lib/arel/algebra/relations/row.rb b/lib/arel/algebra/relations/row.rb
index 3731dd9696..e8484944bd 100644
--- a/lib/arel/algebra/relations/row.rb
+++ b/lib/arel/algebra/relations/row.rb
@@ -4,12 +4,13 @@ module Arel
deriving :==, :initialize
def [](attribute)
- tuple[relation.position_of(attribute)]
+ attribute.type_cast(tuple[relation.position_of(attribute)])
end
def slice(*attributes)
Row.new(relation, attributes.inject([]) do |cheese, attribute|
- cheese << self[attribute]
+ # FIXME TESTME method chaining
+ cheese << tuple[relation.relation.position_of(attribute)]
cheese
end)
end
diff --git a/lib/arel/engines/memory/relations/array.rb b/lib/arel/engines/memory/relations/array.rb
index 15a3e95e1b..6e2dc29252 100644
--- a/lib/arel/engines/memory/relations/array.rb
+++ b/lib/arel/engines/memory/relations/array.rb
@@ -14,6 +14,10 @@ module Arel
end
end
+ def format(attribute, value)
+ value
+ end
+
def eval
@array.collect { |r| Row.new(self, r) }
end
diff --git a/lib/arel/engines/memory/relations/compound.rb b/lib/arel/engines/memory/relations/compound.rb
index 3791fa4622..9e7827dfb3 100644
--- a/lib/arel/engines/memory/relations/compound.rb
+++ b/lib/arel/engines/memory/relations/compound.rb
@@ -3,7 +3,7 @@ module Arel
delegate :array, :to => :relation
def unoperated_rows
- relation.eval.collect { |row| row.bind(self) }
+ relation.call.collect { |row| row.bind(self) }
end
end
end
diff --git a/lib/arel/engines/memory/relations/operations.rb b/lib/arel/engines/memory/relations/operations.rb
index e35fbe3234..e0fd2824b3 100644
--- a/lib/arel/engines/memory/relations/operations.rb
+++ b/lib/arel/engines/memory/relations/operations.rb
@@ -47,8 +47,8 @@ module Arel
class Join < Relation
def eval
result = []
- relation1.eval.each do |row1|
- relation2.eval.each do |row2|
+ relation1.call.each do |row1|
+ relation2.call.each do |row2|
combined_row = row1.combine(row2, self)
if predicates.all? { |p| p.eval(combined_row) }
result << combined_row
diff --git a/lib/arel/engines/sql/engine.rb b/lib/arel/engines/sql/engine.rb
index 0700ae9733..d27d93a5dc 100644
--- a/lib/arel/engines/sql/engine.rb
+++ b/lib/arel/engines/sql/engine.rb
@@ -20,7 +20,9 @@ module Arel
def read(relation)
# FIXME
- class << rows = connection.execute(relation.to_sql)
+ rows = connection.select_rows(relation.to_sql)
+
+ class << rows
include Enumerable
end
diff --git a/lib/arel/engines/sql/primitives.rb b/lib/arel/engines/sql/primitives.rb
index 9e9143ac0f..22ee19dcf0 100644
--- a/lib/arel/engines/sql/primitives.rb
+++ b/lib/arel/engines/sql/primitives.rb
@@ -4,6 +4,10 @@ module Arel
original_relation.column_for(self)
end
+ def type_cast(value)
+ root.relation.format(self, value)
+ end
+
def format(object)
object.to_sql(Sql::Attribute.new(self))
end
diff --git a/lib/arel/engines/sql/relations/table.rb b/lib/arel/engines/sql/relations/table.rb
index 2653744149..e842f85ed1 100644
--- a/lib/arel/engines/sql/relations/table.rb
+++ b/lib/arel/engines/sql/relations/table.rb
@@ -16,6 +16,10 @@ module Arel
end
end
+ def format(attribute, value)
+ attribute.column.type_cast(value)
+ end
+
def column_for(attribute)
has_attribute?(attribute) and columns.detect { |c| c.name == attribute.name.to_s }
end