Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

allowing sql literals for values in insert statements

  • Loading branch information...
commit b707dddd89a61b86570cbe3a5e923bb8e436c38d 1 parent 4dade48
@tenderlove tenderlove authored
View
1  History.txt
@@ -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.
View
6 lib/arel/visitors/to_sql.rb
@@ -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
View
9 test/test_insert_manager.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.