From fd87169eb11fc4cfd9082dabe0a85f3bfa385c29 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Mon, 5 Dec 2016 14:07:39 -0500 Subject: 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. --- .../connection_adapters/abstract/schema_statements.rb | 14 +++++++++----- 1 file 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 -- cgit v1.2.3