diff options
author | Emilio Tagua <miloops@gmail.com> | 2009-04-23 18:53:03 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2009-04-23 18:53:03 -0300 |
commit | a454d45403cd0b8a24b05b7ff37021e307905825 (patch) | |
tree | 1d5b989e1bd32f47f00f7e72d3bfe97cf085ac0e /lib/arel/sql | |
parent | 318cf575eb2b7cf42cb133b3f24cd1aa5fa5e155 (diff) | |
download | rails-a454d45403cd0b8a24b05b7ff37021e307905825.tar.gz rails-a454d45403cd0b8a24b05b7ff37021e307905825.tar.bz2 rails-a454d45403cd0b8a24b05b7ff37021e307905825.zip |
Fix insertion to work on SQLite3
Diffstat (limited to 'lib/arel/sql')
-rw-r--r-- | lib/arel/sql/formatters.rb | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/lib/arel/sql/formatters.rb b/lib/arel/sql/formatters.rb index 068fb8d22d..22a116117e 100644 --- a/lib/arel/sql/formatters.rb +++ b/lib/arel/sql/formatters.rb @@ -5,104 +5,104 @@ module Arel delegate :christener, :engine, :to => :environment delegate :name_for, :to => :christener delegate :quote_table_name, :quote_column_name, :quote, :to => :engine - + def initialize(environment) @environment = environment end end - + class SelectClause < Formatter def attribute(attribute) "#{quote_table_name(name_for(attribute.original_relation))}.#{quote_column_name(attribute.name)}" + (attribute.alias ? " AS #{quote(attribute.alias.to_s)}" : "") end - + def expression(expression) "#{expression.function_sql}(#{expression.attribute.to_sql(self)})" + (expression.alias ? " AS #{quote_column_name(expression.alias)}" : '') end - + def select(select_sql, table) "(#{select_sql}) AS #{quote_table_name(name_for(table))}" end - + def value(value) value end end - + class PassThrough < Formatter def value(value) value end end - + class WhereClause < PassThrough end - - class OrderClause < PassThrough + + class OrderClause < PassThrough def attribute(attribute) "#{quote_table_name(name_for(attribute.original_relation))}.#{quote_column_name(attribute.name)}" end end - + class GroupClause < PassThrough def attribute(attribute) "#{quote_table_name(name_for(attribute.original_relation))}.#{quote_column_name(attribute.name)}" end end - + class WhereCondition < Formatter def attribute(attribute) "#{quote_table_name(name_for(attribute.original_relation))}.#{quote_column_name(attribute.name)}" end - + def expression(expression) "#{expression.function_sql}(#{expression.attribute.to_sql(self)})" end - + def value(value) value.to_sql(self) end - + def scalar(value, column = nil) quote(value, column) end - + def select(select_sql, table) "(#{select_sql})" end end - + class SelectStatement < Formatter def select(select_sql, table) select_sql end end - + class TableReference < Formatter def select(select_sql, table) "(#{select_sql}) AS #{quote_table_name(name_for(table))}" end - + def table(table) quote_table_name(table.name) + (table.name != name_for(table) ? " AS " + quote_table_name(name_for(table)) : '') end end - + class Attribute < WhereCondition def scalar(scalar) quote(scalar, environment.column) end - + def array(array) "(" + array.collect { |e| e.to_sql(self) }.join(', ') + ")" end - + def range(left, right) "#{left} AND #{right}" end end - + class Value < WhereCondition end end -end
\ No newline at end of file +end |