Skip to content

Commit

Permalink
Fixes for use clause
Browse files Browse the repository at this point in the history
  • Loading branch information
aidanharan committed Sep 20, 2023
1 parent b0dbf8f commit 5c4675b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module ActiveRecord
module ConnectionAdapters
module SQLServer
module DatabaseStatements
READ_QUERY = ActiveRecord::ConnectionAdapters::AbstractAdapter.build_read_query_regexp(:begin, :commit, :dbcc, :explain, :save, :select, :set, :rollback, :waitfor) # :nodoc:
READ_QUERY = ActiveRecord::ConnectionAdapters::AbstractAdapter.build_read_query_regexp(:begin, :commit, :dbcc, :explain, :save, :select, :set, :rollback, :waitfor, :use) # :nodoc:
private_constant :READ_QUERY

def write_query?(sql) # :nodoc:
Expand Down Expand Up @@ -217,7 +217,7 @@ def use_database(database = nil)
return if sqlserver_azure?

name = SQLServer::Utils.extract_identifiers(database || @connection_parameters[:database]).quoted
execute "USE #{name}" unless name.blank?
execute("USE #{name}", "SCHEMA") unless name.blank?
end

def user_options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,12 @@ def primary_keys_select(table_name)
AND TC.CONSTRAINT_TYPE = N'PRIMARY KEY'
ORDER BY KCU.ORDINAL_POSITION ASC
}.gsub(/[[:space:]]/, " ")

binds = []
nv128 = SQLServer::Type::UnicodeVarchar.new limit: 128
binds << Relation::QueryAttribute.new("TABLE_NAME", identifier.object, nv128)
binds << Relation::QueryAttribute.new("TABLE_SCHEMA", identifier.schema, nv128) unless identifier.schema.blank?

sp_executesql(sql, "SCHEMA", binds).map { |r| r["name"] }
end

Expand Down

0 comments on commit 5c4675b

Please sign in to comment.