Add supports_common_table_expressions?
for CTE testing
This commit is contained in:
parent
6e53de27f1
commit
d775176d3a
@ -383,6 +383,10 @@ def supports_optimizer_hints?
|
||||
false
|
||||
end
|
||||
|
||||
def supports_common_table_expressions?
|
||||
false
|
||||
end
|
||||
|
||||
def supports_lazy_transactions?
|
||||
false
|
||||
end
|
||||
|
@ -109,6 +109,14 @@ def supports_optimizer_hints?
|
||||
!mariadb? && database_version >= "5.7.7"
|
||||
end
|
||||
|
||||
def supports_common_table_expressions?
|
||||
if mariadb?
|
||||
database_version >= "10.2.1"
|
||||
else
|
||||
database_version >= "8.0.1"
|
||||
end
|
||||
end
|
||||
|
||||
def supports_advisory_locks?
|
||||
true
|
||||
end
|
||||
|
@ -67,7 +67,9 @@ def query(sql, name = nil) #:nodoc:
|
||||
end
|
||||
end
|
||||
|
||||
READ_QUERY = ActiveRecord::ConnectionAdapters::AbstractAdapter.build_read_query_regexp(:begin, :commit, :explain, :select, :set, :show, :release, :savepoint, :rollback, :with) # :nodoc:
|
||||
READ_QUERY = ActiveRecord::ConnectionAdapters::AbstractAdapter.build_read_query_regexp(
|
||||
:begin, :commit, :explain, :select, :set, :show, :release, :savepoint, :rollback, :with
|
||||
) # :nodoc:
|
||||
private_constant :READ_QUERY
|
||||
|
||||
def write_query?(sql) # :nodoc:
|
||||
|
@ -362,6 +362,10 @@ def supports_optimizer_hints?
|
||||
@has_pg_hint_plan
|
||||
end
|
||||
|
||||
def supports_common_table_expressions?
|
||||
true
|
||||
end
|
||||
|
||||
def supports_lazy_transactions?
|
||||
true
|
||||
end
|
||||
|
@ -4,7 +4,9 @@ module ActiveRecord
|
||||
module ConnectionAdapters
|
||||
module SQLite3
|
||||
module DatabaseStatements
|
||||
READ_QUERY = ActiveRecord::ConnectionAdapters::AbstractAdapter.build_read_query_regexp(:begin, :commit, :explain, :select, :pragma, :release, :savepoint, :rollback, :with) # :nodoc:
|
||||
READ_QUERY = ActiveRecord::ConnectionAdapters::AbstractAdapter.build_read_query_regexp(
|
||||
:begin, :commit, :explain, :select, :pragma, :release, :savepoint, :rollback, :with
|
||||
) # :nodoc:
|
||||
private_constant :READ_QUERY
|
||||
|
||||
def write_query?(sql) # :nodoc:
|
||||
|
@ -144,6 +144,10 @@ def supports_json?
|
||||
true
|
||||
end
|
||||
|
||||
def supports_common_table_expressions?
|
||||
database_version >= "3.8.3"
|
||||
end
|
||||
|
||||
def supports_insert_on_conflict?
|
||||
database_version >= "3.24.0"
|
||||
end
|
||||
|
@ -234,6 +234,20 @@ def test_doesnt_error_when_a_select_query_is_called_while_preventing_writes
|
||||
end
|
||||
end
|
||||
|
||||
if ActiveRecord::Base.connection.supports_common_table_expressions?
|
||||
def test_doesnt_error_when_a_read_query_with_a_cte_is_called_while_preventing_writes
|
||||
@connection.insert("INSERT INTO subscribers(nick) VALUES ('138853948594')")
|
||||
|
||||
@connection_handler.while_preventing_writes do
|
||||
result = @connection.select_all(<<~SQL)
|
||||
WITH matching_subscribers AS (SELECT subscribers.* FROM subscribers WHERE nick = '138853948594')
|
||||
SELECT * FROM matching_subscribers
|
||||
SQL
|
||||
assert_equal 1, result.length
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_uniqueness_violations_are_translated_to_specific_exception
|
||||
@connection.execute "INSERT INTO subscribers(nick) VALUES('me')"
|
||||
error = assert_raises(ActiveRecord::RecordNotUnique) do
|
||||
|
@ -232,15 +232,6 @@ def test_doesnt_error_when_a_read_query_with_leading_chars_is_called_while_preve
|
||||
end
|
||||
end
|
||||
|
||||
def test_doesnt_error_when_a_read_query_with_a_cte_is_called_while_preventing_writes
|
||||
@conn.execute("INSERT INTO `engines` (`car_id`) VALUES ('138853948594')")
|
||||
|
||||
@connection_handler.while_preventing_writes do
|
||||
sql = "WITH matching_cars AS (SELECT `engines`.* FROM `engines` WHERE `engines`.`car_id` = '138853948594') SELECT * FROM matching_cars"
|
||||
assert_equal 1, @conn.execute(sql).entries.count
|
||||
end
|
||||
end
|
||||
|
||||
def test_read_timeout_exception
|
||||
ActiveRecord::Base.establish_connection(
|
||||
ActiveRecord::Base.configurations[:arunit].merge("read_timeout" => 1)
|
||||
|
@ -457,17 +457,6 @@ def test_doesnt_error_when_a_read_query_with_leading_chars_is_called_while_preve
|
||||
end
|
||||
end
|
||||
|
||||
def test_doesnt_error_when_a_read_query_with_a_cte_is_called_while_preventing_writes
|
||||
with_example_table do
|
||||
@connection.execute("INSERT INTO ex (data) VALUES ('138853948594')")
|
||||
|
||||
@connection_handler.while_preventing_writes do
|
||||
sql = "WITH matching_ex_values AS (SELECT * FROM ex WHERE data = '138853948594') SELECT * FROM matching_ex_values"
|
||||
assert_equal 1, @connection.execute(sql).entries.count
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def with_example_table(definition = "id serial primary key, number integer, data character varying(255)", &block)
|
||||
super(@connection, "ex", definition, &block)
|
||||
|
@ -652,17 +652,6 @@ def test_doesnt_error_when_a_read_query_with_leading_chars_is_called_while_preve
|
||||
end
|
||||
end
|
||||
|
||||
def test_doesnt_error_when_a_read_query_with_a_cte_is_called_while_preventing_writes
|
||||
with_example_table "id int, data string" do
|
||||
@conn.execute("INSERT INTO ex (data) VALUES ('138853948594')")
|
||||
|
||||
@connection_handler.while_preventing_writes do
|
||||
sql = "WITH matching_ex_values AS (SELECT * FROM ex WHERE data = '138853948594') SELECT * FROM matching_ex_values"
|
||||
assert_equal 1, @conn.execute(sql).entries.count
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def assert_logged(logs)
|
||||
subscriber = SQLSubscriber.new
|
||||
|
Loading…
Reference in New Issue
Block a user