Class: ActiveRecord::ConnectionAdapters::SQLServerAdapter
Overview
Constant Summary
collapse
- ADAPTER_NAME =
'SQLServer'.freeze
- VERSION =
'3.0.15'.freeze
- DATABASE_VERSION_REGEXP =
/Microsoft SQL Server\s+"?(\d{4}|\w+)"?/
- SUPPORTED_VERSIONS =
[2000,2005,2008,2010,2011].freeze
ActiveRecord::ConnectionAdapters::Sqlserver::Errors::LOST_CONNECTION_EXCEPTIONS, ActiveRecord::ConnectionAdapters::Sqlserver::Errors::LOST_CONNECTION_MESSAGES
Instance Attribute Summary collapse
Instance Method Summary
collapse
#lost_connection_exceptions, #lost_connection_messages
#select_one
#column_name_length, #columns_per_multicolumn_index, #columns_per_table, #in_clause_length, #index_name_length, #indexes_per_table, #joins_per_query, #sql_query_length, #table_alias_length, #table_name_length
#add_column, #change_column, #change_column_default, #change_column_null, #columns, #create_table, #drop_table, #indexes, #native_database_types, #remove_column, #remove_index!, #rename_column, #rename_table, #table_exists?, #tables, #type_to_sql, #views
#add_limit_offset!, #begin_db_transaction, #case_sensitive_equality_operator, #charset, #commit_db_transaction, #create_database, #create_savepoint, #current_database, #drop_database, #empty_insert_statement_value, #execute, #execute_procedure, #limited_update_conditions, #newid_function, #newsequentialid_function, #outside_transaction?, #recreate_database, #recreate_database!, #release_savepoint, #rollback_db_transaction, #rollback_to_savepoint, #run_with_isolation_level, #select_one, #select_rows, #use_database, #user_options
#quote, #quote_column_name, #quote_string, #quote_table_name, #quoted_date, #quoted_false, #quoted_true
Constructor Details
Returns a new instance of SQLServerAdapter.
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 178
def initialize(logger,config)
@connection_options = config
connect
super(@connection, logger)
@database_version = info_schema_query { select_value('SELECT @@version') }
@database_year = begin
if @database_version =~ /Microsoft SQL Azure/i
@sqlserver_azure = true
@database_version.match(/\s(\d{4})\s/)[1].to_i
else
year = DATABASE_VERSION_REGEXP.match(@database_version)[1]
year == "Denali" ? 2011 : year.to_i
end
rescue
0
end
initialize_sqlserver_caches
use_database
unless SUPPORTED_VERSIONS.include?(@database_year)
raise NotImplementedError, "Currently, only #{SUPPORTED_VERSIONS.to_sentence} are supported. We got back #{@database_version}."
end
end
|
Instance Attribute Details
#connection_supports_native_types ⇒ Object
Returns the value of attribute connection_supports_native_types.
171
172
173
|
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 171
def connection_supports_native_types
@connection_supports_native_types
end
|
#database_version ⇒ Object
Returns the value of attribute database_version.
171
172
173
|
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 171
def database_version
@database_version
end
|
#database_year ⇒ Object
Returns the value of attribute database_year.
171
172
173
|
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 171
def database_year
@database_year
end
|
Instance Method Details
#active? ⇒ Boolean
Abstract Adapter (Connection Management) ================== #
236
237
238
239
240
241
242
243
244
245
|
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 236
def active?
case @connection_options[:mode]
when :dblib
return @connection.active?
end
raw_connection_do("SELECT 1")
true
rescue *lost_connection_exceptions
false
end
|
#adapter_name ⇒ Object
Abstract Adapter ========================================== #
203
204
205
|
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 203
def adapter_name
ADAPTER_NAME
end
|
#auto_connect ⇒ Object
309
310
311
|
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 309
def auto_connect
@@auto_connect.is_a?(FalseClass) ? false : true
end
|
#cs_equality_operator ⇒ Object
333
334
335
|
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 333
def cs_equality_operator
@@cs_equality_operator || 'COLLATE Latin1_General_CS_AS_WS ='
end
|
#disable_referential_integrity ⇒ Object
227
228
229
230
231
232
|
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 227
def disable_referential_integrity
do_execute "EXEC sp_MSforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'"
yield
ensure
do_execute "EXEC sp_MSforeachtable 'ALTER TABLE ? CHECK CONSTRAINT ALL'"
end
|
#disconnect! ⇒ Object
253
254
255
256
257
258
259
260
261
262
|
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 253
def disconnect!
case @connection_options[:mode]
when :dblib
@connection.close rescue nil
when :odbc
@connection.disconnect rescue nil
else :adonet
@connection.close rescue nil
end
end
|
#inspect ⇒ Object
305
306
307
|
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 305
def inspect
"#<#{self.class} version: #{version}, year: #{@database_year}, connection_options: #{@connection_options.inspect}>"
end
|
#native_binary_database_type ⇒ Object
329
330
331
|
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 329
def native_binary_database_type
@@native_binary_database_type || 'varbinary(max)'
end
|
#native_date_database_type ⇒ Object
325
326
327
|
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 325
def native_date_database_type
sqlserver_2005? ? 'datetime' : 'date'
end
|
#native_string_database_type ⇒ Object
313
314
315
|
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 313
def native_string_database_type
@@native_string_database_type || (enable_default_unicode_types ? 'nvarchar' : 'varchar')
end
|
#native_text_database_type ⇒ Object
317
318
319
|
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 317
def native_text_database_type
@@native_text_database_type || enable_default_unicode_types ? 'nvarchar(max)' : 'varchar(max)'
end
|
#native_time_database_type ⇒ Object
321
322
323
|
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 321
def native_time_database_type
sqlserver_2005? ? 'datetime' : 'time'
end
|
#pk_and_sequence_for(table_name) ⇒ Object
Abstract Adapter (Misc Support) =========================== #
270
271
272
273
|
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 270
def pk_and_sequence_for(table_name)
idcol = identity_column(table_name)
idcol ? [idcol.name,nil] : nil
end
|
#primary_key(table_name) ⇒ Object
275
276
277
|
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 275
def primary_key(table_name)
identity_column(table_name).try(:name)
end
|
#reconnect! ⇒ Object
247
248
249
250
251
|
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 247
def reconnect!
disconnect!
connect
active?
end
|
#reset! ⇒ Object
264
265
266
|
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 264
def reset!
remove_database_connections_and_rollback { }
end
|
#sqlserver? ⇒ Boolean
SQLServer Specific (DB Reflection) ======================== #
281
282
283
|
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 281
def sqlserver?
true
end
|
#sqlserver_2005? ⇒ Boolean
285
286
287
|
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 285
def sqlserver_2005?
@database_year == 2005
end
|
#sqlserver_2008? ⇒ Boolean
289
290
291
|
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 289
def sqlserver_2008?
@database_year == 2008
end
|
#sqlserver_2011? ⇒ Boolean
293
294
295
|
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 293
def sqlserver_2011?
@database_year == 2011
end
|
#sqlserver_azure? ⇒ Boolean
297
298
299
|
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 297
def sqlserver_azure?
@sqlserver_azure
end
|
#supports_count_distinct? ⇒ Boolean
215
216
217
|
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 215
def supports_count_distinct?
true
end
|
#supports_ddl_transactions? ⇒ Boolean
219
220
221
|
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 219
def supports_ddl_transactions?
true
end
|
#supports_migrations? ⇒ Boolean
207
208
209
|
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 207
def supports_migrations?
true
end
|
#supports_primary_key? ⇒ Boolean
211
212
213
|
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 211
def supports_primary_key?
true
end
|
#supports_savepoints? ⇒ Boolean
223
224
225
|
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 223
def supports_savepoints?
true
end
|
#version ⇒ Object
301
302
303
|
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 301
def version
self.class::VERSION
end
|