提交 fd87169e 编写于 作者: S Sean Griffin

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.
上级 d8533e11
......@@ -996,15 +996,13 @@ def dump_schema_information #:nodoc:
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 @@ def assume_migrated_upto_version(version, migrations_paths)
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册