From 7a51983efc50c8f9092785b1b586f8884dedc01a Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Sun, 17 May 2009 16:02:10 -0400 Subject: initial implementation of cross-engine join Conflicts: lib/arel/engines/memory/relations/array.rb lib/arel/engines/sql/primitives.rb --- lib/arel/engines/memory/relations/array.rb | 4 ++++ lib/arel/engines/memory/relations/compound.rb | 2 +- lib/arel/engines/memory/relations/operations.rb | 4 ++-- lib/arel/engines/sql/engine.rb | 4 +++- lib/arel/engines/sql/primitives.rb | 4 ++++ lib/arel/engines/sql/relations/table.rb | 4 ++++ 6 files changed, 18 insertions(+), 4 deletions(-) (limited to 'lib/arel/engines') 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 -- cgit v1.2.3