Module: ActiveRecord::ConnectionAdapters::SQLServer::DatabaseTasks

Included in:
ActiveRecord::ConnectionAdapters::SQLServerAdapter
Defined in:
lib/active_record/connection_adapters/sqlserver/database_tasks.rb

Instance Method Summary collapse

Instance Method Details

#charsetObject



24
25
26
# File 'lib/active_record/connection_adapters/sqlserver/database_tasks.rb', line 24

def charset
  select_value "SELECT DATABASEPROPERTYEX(DB_NAME(), 'SqlCharSetName')"
end

#collationObject



28
29
30
# File 'lib/active_record/connection_adapters/sqlserver/database_tasks.rb', line 28

def collation
  @collation ||= select_value "SELECT DATABASEPROPERTYEX(DB_NAME(), 'Collation')"
end

#create_database(database, options = {}) ⇒ Object



7
8
9
10
11
12
# File 'lib/active_record/connection_adapters/sqlserver/database_tasks.rb', line 7

def create_database(database, options = {})
  name = SQLServer::Utils.extract_identifiers(database)
  db_options = create_database_options(options)
  edition_options = create_database_edition_options(options)
  execute "CREATE DATABASE #{name} #{db_options} #{edition_options}"
end

#current_databaseObject



20
21
22
# File 'lib/active_record/connection_adapters/sqlserver/database_tasks.rb', line 20

def current_database
  select_value "SELECT DB_NAME()"
end

#drop_database(database) ⇒ Object



14
15
16
17
18
# File 'lib/active_record/connection_adapters/sqlserver/database_tasks.rb', line 14

def drop_database(database)
  name = SQLServer::Utils.extract_identifiers(database)
  execute "ALTER DATABASE #{name} SET SINGLE_USER WITH ROLLBACK IMMEDIATE"
  execute "DROP DATABASE #{name}"
end