提交 82e767f3 编写于 作者: E Edouard CHIN

Don't assume all database in SQLite are files:

- SQlite allow database to be specified as URL (given that URI filename
  interpretation was turned on on the connection.)

  This commit is necessary for the read_uncommitted transaction
  feature because SQLite doesn't allow to enable the shared-cache mode
  if the database name is `:memory:`. It has to be a URI (`file::memory`)

  Ref https://www.sqlite.org/sharedcache.html#shared_cache_and_in_memory_databases
上级 cf5b6199
......@@ -26,7 +26,7 @@ def sqlite3_connection(config)
# Allow database path relative to Rails.root, but only if the database
# path is not the special path that tells sqlite to build a database only
# in memory.
if ":memory:" != config[:database]
if ":memory:" != config[:database] && !config[:database].to_s.starts_with?("file:")
config[:database] = File.expand_path(config[:database], Rails.root) if defined?(Rails.root)
dirname = File.dirname(config[:database])
Dir.mkdir(dirname) unless File.directory?(dirname)
......@@ -116,6 +116,10 @@ def supports_savepoints?
true
end
def supports_transaction_isolation?
true
end
def supports_partial_index?
true
end
......
......@@ -107,7 +107,7 @@ def shared_cache_flags
def with_connection(options = {})
conn_options = options.reverse_merge(
database: in_memory_db? ? 'file::memory:' : ActiveRecord::Base.configurations["arunit"][:database]
database: in_memory_db? ? "file::memory:" : ActiveRecord::Base.configurations["arunit"][:database]
)
conn = ActiveRecord::Base.sqlite3_connection(conn_options)
......
......@@ -2,7 +2,7 @@
require "cases/helper"
unless ActiveRecord::Base.connection.supports_transaction_isolation?
unless ActiveRecord::Base.connection.supports_transaction_isolation? && !current_adapter?(:SQLite3Adapter)
class TransactionIsolationUnsupportedTest < ActiveRecord::TestCase
self.use_transactional_tests = false
......@@ -10,6 +10,8 @@ class Tag < ActiveRecord::Base
end
test "setting the isolation level raises an error" do
skip if current_adapter?(:SQLite3Adapter)
assert_raises(ActiveRecord::TransactionIsolationError) do
Tag.transaction(isolation: :serializable) { Tag.connection.materialize_transactions }
end
......
......@@ -1127,7 +1127,7 @@ def test_no_automatic_savepoint_for_inner_transaction
end
end if Topic.connection.supports_savepoints?
if ActiveRecord::Base.connection.supports_transaction_isolation?
if ActiveRecord::Base.connection.supports_transaction_isolation? && !in_memory_db?
class ConcurrentTransactionTest < TransactionTest
# This will cause transactions to overlap and fail unless they are performed on
# separate database connections.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册