Permalink
Browse files

allowing sql literals for values in insert statements

  • Loading branch information...
1 parent 4dade48 commit b707dddd89a61b86570cbe3a5e923bb8e436c38d @tenderlove tenderlove committed Mar 22, 2011
Showing with 15 additions and 1 deletion.
  1. +1 −0 History.txt
  2. +5 −1 lib/arel/visitors/to_sql.rb
  3. +9 −0 test/test_insert_manager.rb
View
@@ -10,6 +10,7 @@
* Add Arel::SelectManager#offset
* Add Arel::SelectManager#offset=
* Added Arel::SelectManager#create_insert for building an insert manager.
+ * SQL Literals are allowed for values in INSERT statements.
* Math operations have been added to attributes, thanks to
Vladimir Meremyanin.
@@ -102,7 +102,11 @@ def column_cache
def visit_Arel_Nodes_Values o
"VALUES (#{o.expressions.zip(o.columns).map { |value, attr|
- quote(value, attr && column_for(attr))
+ if Nodes::SqlLiteral === value
+ visit_Arel_Nodes_SqlLiteral value
+ else
+ quote(value, attr && column_for(attr))
+ end
}.join ', '})"
end
@@ -19,6 +19,15 @@ module Arel
assert_equal %w{ c d }, values.right
end
+ it 'allows sql literals' do
+ table = Table.new(:users)
+ manager = Arel::InsertManager.new Table.engine
+ manager.values = manager.create_values [Arel.sql('*')], %w{ a }
+ manager.to_sql.must_be_like %{
+ INSERT INTO NULL VALUES (*)
+ }
+ end
+
it "inserts false" do
table = Table.new(:users)
manager = Arel::InsertManager.new Table.engine

0 comments on commit b707ddd

Please sign in to comment.