@@ -85,6 +85,7 @@ def internal_begin_transaction(mode, isolation)
85
85
86
86
def perform_query ( raw_connection , sql , binds , type_casted_binds , prepare :, notification_payload :, batch : false )
87
87
total_changes_before_query = raw_connection . total_changes
88
+ affected_rows = nil
88
89
89
90
if batch
90
91
raw_connection . execute_batch2 ( sql )
@@ -102,20 +103,20 @@ def perform_query(raw_connection, sql, binds, type_casted_binds, prepare:, notif
102
103
end
103
104
result = if stmt . column_count . zero? # No return
104
105
stmt . step
105
- @ affected_rows = raw_connection . total_changes - total_changes_before_query
106
- ActiveRecord ::Result . empty ( affected_rows : @ affected_rows)
106
+ affected_rows = raw_connection . total_changes - total_changes_before_query
107
+ ActiveRecord ::Result . empty ( affected_rows : affected_rows )
107
108
else
108
109
rows = stmt . to_a
109
- @ affected_rows = raw_connection . total_changes - total_changes_before_query
110
- ActiveRecord ::Result . new ( stmt . columns , rows , stmt . types . map { |t | type_map . lookup ( t ) } , affected_rows : @ affected_rows)
110
+ affected_rows = raw_connection . total_changes - total_changes_before_query
111
+ ActiveRecord ::Result . new ( stmt . columns , rows , stmt . types . map { |t | type_map . lookup ( t ) } , affected_rows : affected_rows )
111
112
end
112
113
ensure
113
114
stmt . close unless prepare
114
115
end
115
116
end
116
117
verified!
117
118
118
- notification_payload [ :affected_rows ] = @ affected_rows
119
+ notification_payload [ :affected_rows ] = affected_rows
119
120
notification_payload [ :row_count ] = result &.length || 0
120
121
result
121
122
end
@@ -127,7 +128,7 @@ def cast_result(result)
127
128
end
128
129
129
130
def affected_rows ( result )
130
- @ affected_rows
131
+ result . affected_rows
131
132
end
132
133
133
134
def execute_batch ( statements , name = nil , **kwargs )
0 commit comments