Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 6: Support lazy transactions #780

Merged
merged 5 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def execute(sql, name = nil)
raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}"
end

materialize_transactions

if id_insert_table_name = query_requires_identity_insert?(sql)
with_identity_insert_enabled(id_insert_table_name) { do_execute(sql, name) }
else
Expand All @@ -26,6 +28,8 @@ def exec_query(sql, name = 'SQL', binds = [], prepare: false)
raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}"
end

materialize_transactions

sp_executesql(sql, name, binds, prepare: prepare)
end

Expand Down Expand Up @@ -136,6 +140,8 @@ def default_insert_value(column)
# === SQLServer Specific ======================================== #

def execute_procedure(proc_name, *variables)
materialize_transactions

vars = if variables.any? && variables.first.is_a?(Hash)
variables.first.map { |k, v| "@#{k} = #{quote(v)}" }
else
Expand Down Expand Up @@ -268,6 +274,8 @@ def set_identity_insert(table_name, enable = true)
# === SQLServer Specific (Executing) ============================ #

def do_execute(sql, name = 'SQL')
materialize_transactions

log(sql, name) { raw_connection_do(sql) }
end

Expand Down
4 changes: 4 additions & 0 deletions lib/active_record/connection_adapters/sqlserver_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ def supports_savepoints?
true
end

def supports_lazy_transactions?
true
end

def supports_in_memory_oltp?
@version_year >= 2014
end
Expand Down
2 changes: 1 addition & 1 deletion test/cases/migration_test_sqlserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class MigrationTestSQLServer < ActiveRecord::TestCase
Person.reset_column_information
end

it 'not drop the default contraint if just renaming' do
it 'not drop the default constraint if just renaming' do
find_default = lambda do
connection.execute_procedure(:sp_helpconstraint, 'sst_string_defaults', 'nomsg').select do |row|
row['constraint_type'] == "DEFAULT on column string_with_pretend_paren_three"
Expand Down