diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2017-06-15 12:18:03 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-15 12:18:03 -0400 |
commit | 67a51c62f4e19390cd8eb408596ca48bb0806362 (patch) | |
tree | 8f8b8fa1edb2db071dc9df360f37418138fd484d /lib/arel/visitors | |
parent | de0a83e11cae11ba0674bd197296326e53354597 (diff) | |
parent | 5e6312e1745dc278ba0a99bf2bc7b78977785d35 (diff) | |
download | rails-67a51c62f4e19390cd8eb408596ca48bb0806362.tar.gz rails-67a51c62f4e19390cd8eb408596ca48bb0806362.tar.bz2 rails-67a51c62f4e19390cd8eb408596ca48bb0806362.zip |
Merge pull request #484 from kirs/multiple-insert-v2
Support INSERT with multiple values (v2)
Diffstat (limited to 'lib/arel/visitors')
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index 486c51a183..3f1e390dcc 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -166,6 +166,28 @@ module Arel collector << "FALSE" end + def visit_Arel_Nodes_ValuesList o, collector + collector << "VALUES " + + len = o.rows.length - 1 + o.rows.each_with_index { |row, i| + collector << '(' + row_len = row.length - 1 + row.each_with_index do |value, k| + case value + when Nodes::SqlLiteral, Nodes::BindParam + collector = visit(value, collector) + else + collector << quote(value) + end + collector << COMMA unless k == row_len + end + collector << ')' + collector << COMMA unless i == len + } + collector + end + def visit_Arel_Nodes_Values o, collector collector << "VALUES (" |