aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2016-12-05 14:07:39 -0500
committerSean Griffin <sean@seantheprogrammer.com>2016-12-05 14:07:39 -0500
commitfd87169eb11fc4cfd9082dabe0a85f3bfa385c29 (patch)
tree596be4df7d0d523dc5a1734eaef620dcefe98a17 /activerecord
parentd8533e116e9f951f0dd9c2abcc916627ff49dd64 (diff)
downloadrails-fd87169eb11fc4cfd9082dabe0a85f3bfa385c29.tar.gz
rails-fd87169eb11fc4cfd9082dabe0a85f3bfa385c29.tar.bz2
rails-fd87169eb11fc4cfd9082dabe0a85f3bfa385c29.zip
Don't try to run multiple insert queries at once
SQLite's default query interface ignores anything after the first semicolon in a query. This is actually quite common behavior in database drivers, especially when dealing with code paths for prepared statements (which we are). While this should only affect SQLite, as I'm not aware of any drivers which don't support multi-insert. Even if this does affect other third party drivers though, I'd prefer not to assume that more than one query can be executed per call to `execute`. Fixes #26948. Close #27242.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb14
1 files changed, 9 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
index 151629b02a..25e8c51115 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -996,15 +996,13 @@ module ActiveRecord
def insert_versions_sql(versions) # :nodoc:
sm_table = ActiveRecord::Migrator.schema_migrations_table_name
- if supports_multi_insert?
+ if versions.is_a?(Array)
sql = "INSERT INTO #{sm_table} (version) VALUES\n"
sql << versions.map { |v| "('#{v}')" }.join(",\n")
sql << ";\n\n"
sql
else
- versions.map { |version|
- "INSERT INTO #{sm_table} (version) VALUES ('#{version}');"
- }.join "\n\n"
+ "INSERT INTO #{sm_table} (version) VALUES ('#{versions}');"
end
end
@@ -1042,7 +1040,13 @@ module ActiveRecord
if (duplicate = inserting.detect { |v| inserting.count(v) > 1 })
raise "Duplicate migration #{duplicate}. Please renumber your migrations to resolve the conflict."
end
- execute insert_versions_sql(inserting)
+ if supports_multi_insert?
+ execute insert_versions_sql(inserting)
+ else
+ inserting.each do |v|
+ execute insert_versions_sql(v)
+ end
+ end
end
end