aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorMatthew M. Boedicker <matthewm@boedicker.org>2013-03-08 08:22:33 -0800
committerMatthew M. Boedicker <matthewm@boedicker.org>2013-03-11 23:14:46 -0700
commitd3e5118e7d42a9425b843190380d12ed3ce1e5f9 (patch)
tree889736b79604b2cc90664d93dd1fa94d3a458ca1 /activerecord/lib/active_record
parentf278deb712b16c7897d63a6565bea3431ec0d38a (diff)
downloadrails-d3e5118e7d42a9425b843190380d12ed3ce1e5f9.tar.gz
rails-d3e5118e7d42a9425b843190380d12ed3ce1e5f9.tar.bz2
rails-d3e5118e7d42a9425b843190380d12ed3ce1e5f9.zip
Pass column to quote when copying a sqlite table.
To make quote escape binary data correctly it needs the column passed in.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb10
1 files changed, 9 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
index 84fa1c7d5a..d3ffee3a8b 100644
--- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
@@ -583,9 +583,17 @@ module ActiveRecord
quoted_columns = columns.map { |col| quote_column_name(col) } * ','
quoted_to = quote_table_name(to)
+
+ raw_column_mappings = Hash[columns(from).map { |c| [c.name, c] }]
+
exec_query("SELECT * FROM #{quote_table_name(from)}").each do |row|
sql = "INSERT INTO #{quoted_to} (#{quoted_columns}) VALUES ("
- sql << columns.map {|col| quote row[column_mappings[col]]} * ', '
+
+ column_values = columns.map do |col|
+ quote(row[column_mappings[col]], raw_column_mappings[col])
+ end
+
+ sql << column_values * ', '
sql << ')'
exec_query sql
end