@@ -25,7 +25,7 @@ def execute(sql, name = nil)
25
25
end
26
26
end
27
27
28
- def exec_query ( sql , name = ' SQL' , binds = [ ] , prepare : false )
28
+ def exec_query ( sql , name = " SQL" , binds = [ ] , prepare : false )
29
29
if preventing_writes? && write_query? ( sql )
30
30
raise ActiveRecord ::ReadOnlyError , "Write query attempted while in readonly mode: #{ sql } "
31
31
end
@@ -44,17 +44,17 @@ def exec_insert(sql, name = nil, binds = [], pk = nil, _sequence_name = nil)
44
44
end
45
45
46
46
def exec_delete ( sql , name , binds )
47
- sql = sql . dup << ' ; SELECT @@ROWCOUNT AS AffectedRows'
47
+ sql = sql . dup << " ; SELECT @@ROWCOUNT AS AffectedRows"
48
48
super ( sql , name , binds ) . rows . first . first
49
49
end
50
50
51
51
def exec_update ( sql , name , binds )
52
- sql = sql . dup << ' ; SELECT @@ROWCOUNT AS AffectedRows'
52
+ sql = sql . dup << " ; SELECT @@ROWCOUNT AS AffectedRows"
53
53
super ( sql , name , binds ) . rows . first . first
54
54
end
55
55
56
56
def begin_db_transaction
57
- do_execute ' BEGIN TRANSACTION'
57
+ do_execute " BEGIN TRANSACTION"
58
58
end
59
59
60
60
def transaction_isolation_levels
@@ -71,11 +71,11 @@ def set_transaction_isolation_level(isolation_level)
71
71
end
72
72
73
73
def commit_db_transaction
74
- do_execute ' COMMIT TRANSACTION'
74
+ do_execute " COMMIT TRANSACTION"
75
75
end
76
76
77
77
def exec_rollback_db_transaction
78
- do_execute ' IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION'
78
+ do_execute " IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION"
79
79
end
80
80
81
81
include Savepoints
@@ -159,9 +159,9 @@ def execute_procedure(proc_name, *variables)
159
159
variables . first . map { |k , v | "@#{ k } = #{ quote ( v ) } " }
160
160
else
161
161
variables . map { |v | quote ( v ) }
162
- end . join ( ', ' )
162
+ end . join ( ", " )
163
163
sql = "EXEC #{ proc_name } #{ vars } " . strip
164
- name = ' Execute Procedure'
164
+ name = " Execute Procedure"
165
165
log ( sql , name ) do
166
166
case @connection_options [ :mode ]
167
167
when :dblib
@@ -192,14 +192,14 @@ def use_database(database = nil)
192
192
193
193
def user_options
194
194
return { } if sqlserver_azure?
195
- rows = select_rows ( ' DBCC USEROPTIONS WITH NO_INFOMSGS' , ' SCHEMA' )
195
+ rows = select_rows ( " DBCC USEROPTIONS WITH NO_INFOMSGS" , " SCHEMA" )
196
196
rows = rows . first if rows . size == 2 && rows . last . empty?
197
197
rows . reduce ( HashWithIndifferentAccess . new ) do |values , row |
198
198
if row . instance_of? Hash
199
- set_option = row . values [ 0 ] . gsub ( /\s +/ , '_' )
199
+ set_option = row . values [ 0 ] . gsub ( /\s +/ , "_" )
200
200
user_value = row . values [ 1 ]
201
201
elsif row . instance_of? Array
202
- set_option = row [ 0 ] . gsub ( /\s +/ , '_' )
202
+ set_option = row [ 0 ] . gsub ( /\s +/ , "_" )
203
203
user_value = row [ 1 ]
204
204
end
205
205
values [ set_option ] = user_value
@@ -209,9 +209,9 @@ def user_options
209
209
210
210
def user_options_dateformat
211
211
if sqlserver_azure?
212
- select_value ' SELECT [dateformat] FROM [sys].[syslanguages] WHERE [langid] = @@LANGID' , ' SCHEMA'
212
+ select_value " SELECT [dateformat] FROM [sys].[syslanguages] WHERE [langid] = @@LANGID" , " SCHEMA"
213
213
else
214
- user_options [ ' dateformat' ]
214
+ user_options [ " dateformat" ]
215
215
end
216
216
end
217
217
@@ -226,26 +226,26 @@ def user_options_isolation_level
226
226
WHEN 5 THEN 'SNAPSHOT' END AS [isolation_level]
227
227
FROM [sys].[dm_exec_sessions]
228
228
WHERE [session_id] = @@SPID) . squish
229
- select_value sql , ' SCHEMA'
229
+ select_value sql , " SCHEMA"
230
230
else
231
- user_options [ ' isolation_level' ]
231
+ user_options [ " isolation_level" ]
232
232
end
233
233
end
234
234
235
235
def user_options_language
236
236
if sqlserver_azure?
237
- select_value ' SELECT @@LANGUAGE AS [language]' , ' SCHEMA'
237
+ select_value " SELECT @@LANGUAGE AS [language]" , " SCHEMA"
238
238
else
239
- user_options [ ' language' ]
239
+ user_options [ " language" ]
240
240
end
241
241
end
242
242
243
243
def newid_function
244
- select_value ' SELECT NEWID()'
244
+ select_value " SELECT NEWID()"
245
245
end
246
246
247
247
def newsequentialid_function
248
- select_value ' SELECT NEWSEQUENTIALID()'
248
+ select_value " SELECT NEWSEQUENTIALID()"
249
249
end
250
250
251
251
@@ -263,7 +263,7 @@ def sql_for_insert(sql, pk, binds)
263
263
exclude_output_inserted = exclude_output_inserted_table_name? ( table_name , sql )
264
264
265
265
if exclude_output_inserted
266
- id_sql_type = exclude_output_inserted . is_a? ( TrueClass ) ? ' bigint' : exclude_output_inserted
266
+ id_sql_type = exclude_output_inserted . is_a? ( TrueClass ) ? " bigint" : exclude_output_inserted
267
267
<<~SQL . squish
268
268
DECLARE @ssaIdInsertTable table (#{ quoted_pk } #{ id_sql_type } );
269
269
#{ sql . dup . insert sql . index ( / (DEFAULT )?VALUES/ ) , " OUTPUT INSERTED.#{ quoted_pk } INTO @ssaIdInsertTable" }
@@ -288,7 +288,7 @@ def set_identity_insert(table_name, enable = true)
288
288
289
289
# === SQLServer Specific (Executing) ============================ #
290
290
291
- def do_execute ( sql , name = ' SQL' )
291
+ def do_execute ( sql , name = " SQL" )
292
292
materialize_transactions
293
293
294
294
log ( sql , name ) { raw_connection_do ( sql ) }
@@ -318,9 +318,9 @@ def sp_executesql_sql_type(attr)
318
318
return attr . type . sqlserver_type if attr . type . respond_to? ( :sqlserver_type )
319
319
case value = attr . value_for_database
320
320
when Numeric
321
- value > 2_147_483_647 ? ' bigint' . freeze : ' int' . freeze
321
+ value > 2_147_483_647 ? " bigint" . freeze : " int" . freeze
322
322
else
323
- ' nvarchar(max)' . freeze
323
+ " nvarchar(max)" . freeze
324
324
end
325
325
end
326
326
@@ -335,14 +335,14 @@ def sp_executesql_sql_param(attr)
335
335
end
336
336
337
337
def sp_executesql_sql ( sql , types , params , name )
338
- if name == ' EXPLAIN'
338
+ if name == " EXPLAIN"
339
339
params . each . with_index do |param , index |
340
340
substitute_at_finder = /(@#{ index } )(?=(?:[^']|'[^']*')*$)/ # Finds unquoted @n values.
341
341
sql = sql . sub substitute_at_finder , param . to_s
342
342
end
343
343
else
344
- types = quote ( types . join ( ', ' ) )
345
- params = params . map . with_index { |p , i | "@#{ i } = #{ p } " } . join ( ', ' ) # Only p is needed, but with @i helps explain regexp.
344
+ types = quote ( types . join ( ", " ) )
345
+ params = params . map . with_index { |p , i | "@#{ i } = #{ p } " } . join ( ", " ) # Only p is needed, but with @i helps explain regexp.
346
346
sql = "EXEC sp_executesql #{ quote ( sql ) } "
347
347
sql += ", #{ types } , #{ params } " unless params . empty?
348
348
end
@@ -357,7 +357,7 @@ def raw_connection_do(sql)
357
357
# TinyTDS returns false instead of raising an exception if connection fails.
358
358
# Getting around this by raising an exception ourselves while this PR
359
359
# https://github.com/rails-sqlserver/tiny_tds/pull/469 is not released.
360
- raise TinyTds ::Error , ' failed to execute statement' if result . is_a? ( FalseClass )
360
+ raise TinyTds ::Error , " failed to execute statement" if result . is_a? ( FalseClass )
361
361
362
362
result . do
363
363
end
@@ -407,7 +407,7 @@ def identity_columns(table_name)
407
407
408
408
# === SQLServer Specific (Selecting) ============================ #
409
409
410
- def raw_select ( sql , name = ' SQL' , binds = [ ] , options = { } )
410
+ def raw_select ( sql , name = " SQL" , binds = [ ] , options = { } )
411
411
log ( sql , name , binds ) { _raw_select ( sql , options ) }
412
412
end
413
413
0 commit comments