@@ -14,8 +14,6 @@ def write_query?(sql) # :nodoc:
14
14
end
15
15
16
16
def raw_execute ( sql , name , async : false , allow_retry : false , materialize_transactions : true )
17
- # puts "raw_execute: #{sql}" if $AIDO
18
-
19
17
log ( sql , name , async : async ) do |notification_payload |
20
18
with_raw_connection ( allow_retry : allow_retry , materialize_transactions : materialize_transactions ) do |conn |
21
19
result = if id_insert_table_name = query_requires_identity_insert? ( sql )
@@ -314,11 +312,8 @@ def sql_for_insert(sql, pk, binds, returning)
314
312
# === SQLServer Specific ======================================== #
315
313
316
314
def set_identity_insert ( table_name , conn , enable )
317
- # puts "set_identity_insert: #{table_name} #{enable}"
318
-
319
315
internal_raw_execute ( "SET IDENTITY_INSERT #{ table_name } #{ enable ? 'ON' : 'OFF' } " , conn , perform_do : true )
320
316
rescue Exception
321
- puts "IDENTITY_INSERT could not be turned #{ enable ? 'ON' : 'OFF' } for table #{ table_name } "
322
317
raise ActiveRecordError , "IDENTITY_INSERT could not be turned #{ enable ? 'ON' : 'OFF' } for table #{ table_name } "
323
318
end
324
319
@@ -409,37 +404,12 @@ def exclude_output_inserted_id_sql_type(pk, exclude_output_inserted)
409
404
end
410
405
411
406
def query_requires_identity_insert? ( sql )
412
- # puts "query_requires_identity_insert?: #{sql}" if $AIDO
413
-
414
407
return false unless insert_sql? ( sql )
415
408
416
409
raw_table_name = get_raw_table_name ( sql )
417
-
418
- # binding.pry
419
- # if $AIDO
420
- #
421
- # puts "xxxx"
422
- # return true
423
- # end
424
-
425
-
426
-
427
-
428
410
id_column = identity_columns ( raw_table_name ) . first
429
411
430
-
431
- if id_column && sql =~ /^\s *(INSERT|EXEC sp_executesql N'INSERT)[^(]+\( [^)]*\b (#{ id_column . name } )\b ,?[^)]*\) /i
432
-
433
- # puts "xxx: raw_table_name=#{raw_table_name}, id_column=#{id_column.name}" if $AIDO
434
- # puts "xxx: quoted=#{SQLServer::Utils.extract_identifiers(raw_table_name).quoted}" if $AIDO
435
-
436
- SQLServer ::Utils . extract_identifiers ( raw_table_name ) . quoted
437
- else
438
- false
439
-
440
- end
441
-
442
- # id_column && sql =~ /^\s*(INSERT|EXEC sp_executesql N'INSERT)[^(]+\([^)]*\b(#{id_column.name})\b,?[^)]*\)/i ? SQLServer::Utils.extract_identifiers(raw_table_name).quoted : false
412
+ id_column && sql =~ /^\s *(INSERT|EXEC sp_executesql N'INSERT)[^(]+\( [^)]*\b (#{ id_column . name } )\b ,?[^)]*\) /i ? SQLServer ::Utils . extract_identifiers ( raw_table_name ) . quoted : false
443
413
end
444
414
445
415
def insert_sql? ( sql )
@@ -483,8 +453,6 @@ def finish_statement_handle(handle)
483
453
# Getting around this by raising an exception ourselves while PR
484
454
# https://github.com/rails-sqlserver/tiny_tds/pull/469 is not released.
485
455
def internal_raw_execute ( sql , conn , perform_do : false )
486
- # puts "internal_raw_execute: #{sql}" if $AIDO
487
-
488
456
result = conn . execute ( sql ) . tap do |_result |
489
457
raise TinyTds ::Error , "failed to execute statement" if _result . is_a? ( FalseClass )
490
458
end
0 commit comments