Skip to content

Commit 80cbfd4

Browse files
committed
Cleanup
1 parent bcb11c5 commit 80cbfd4

File tree

2 files changed

+7
-45
lines changed

2 files changed

+7
-45
lines changed

lib/active_record/connection_adapters/sqlserver/schema_statements.rb

+1-8
Original file line numberDiff line numberDiff line change
@@ -631,13 +631,6 @@ def column_type(ci:)
631631
end
632632

633633
def column_definitions_sql(database, identifier)
634-
# puts "column_definitions_sql: identifier=#{identifier}"
635-
# puts "column_definitions_sql: database=#{database}"
636-
637-
638-
639-
640-
641634
schema_name = "schema_name()"
642635

643636
if prepared_statements
@@ -730,7 +723,7 @@ def remove_check_constraints(table_name, column_name)
730723
end
731724

732725
def remove_default_constraint(table_name, column_name)
733-
# If their are foreign keys in this table, we could still get back a 2D array, so flatten just in case.
726+
# If there are foreign keys in this table, we could still get back a 2D array, so flatten just in case.
734727
execute_procedure(:sp_helpconstraint, table_name, "nomsg").flatten.select do |row|
735728
row["constraint_type"] == "DEFAULT on column #{column_name}"
736729
end.each do |row|

test/cases/temporary_table_test_sqlserver.rb

+6-37
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,17 @@
33
require "cases/helper_sqlserver"
44

55
class TemporaryTableSQLServer < ActiveRecord::TestCase
6-
# setup do
7-
# @connection = ActiveRecord::Base.lease_connection
8-
# @connection.create_table(:barcodes, primary_key: "code", id: :uuid, force: true)
9-
# end
10-
#
11-
# # teardown do
12-
# # @connection.drop_table(:barcodes, if_exists: true)
13-
# # end
14-
#
156
def test_insert_into_temporary_table
16-
ActiveSupport::Notifications.subscribe('sql.active_record') do |_name, _start, _finish, _id, payload|
17-
puts payload[:sql]
18-
end
19-
20-
217
ActiveRecord::Base.with_connection do |conn|
22-
temp_table = "#temp_users"
23-
# connection.exec_query("IF OBJECT_ID('tempdb..#{temp_table}') IS NOT NULL DROP TABLE #{temp_table}")
24-
25-
puts "Creating table"
26-
conn.exec_query("CREATE TABLE #{temp_table} (id INT IDENTITY(1,1), name NVARCHAR(100))")
27-
28-
puts "Selecting table"
29-
result = conn.exec_query("SELECT * FROM #{temp_table}")
30-
puts "Result: #{result.to_a}"
31-
32-
puts "Inserting into table"
33-
34-
# ❌ This raises "Table doesn’t exist" error
35-
conn.exec_query("INSERT INTO #{temp_table} (name) VALUES ('John')")
36-
37-
8+
conn.exec_query("CREATE TABLE #temp_users (id INT IDENTITY(1,1), name NVARCHAR(100))")
389

39-
# ✅ Workaround: Only runs if the table still exists in this session
40-
# conn.exec_query("IF OBJECT_ID('tempdb..#{temp_table}') IS NOT NULL INSERT INTO #{temp_table} (name) VALUES ('John')")
10+
result = conn.exec_query("SELECT * FROM #temp_users")
11+
assert_equal 0, result.count
4112

42-
# ✅ Workaround: raw_connection works without issue
43-
# conn.raw_connection.execute("IF OBJECT_ID('tempdb..#{temp_table}') IS NOT NULL INSERT INTO #{temp_table} (name) VALUES ('John')")
13+
conn.exec_query("INSERT INTO #temp_users (name) VALUES ('John'), ('Doe')")
4414

45-
puts "Selecting table again"
46-
result = conn.exec_query("SELECT * FROM #{temp_table}")
47-
puts "Result: #{result.to_a}"
15+
result = conn.exec_query("SELECT * FROM #temp_users")
16+
assert_equal 2, result.count
4817
end
4918
end
5019
end

0 commit comments

Comments
 (0)