Skip to content

Commit c25c1c1

Browse files
committed
Prefer result.affected_rows over ivar
1 parent fcf01b8 commit c25c1c1

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

activerecord/lib/active_record/connection_adapters/sqlite3/database_statements.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def internal_begin_transaction(mode, isolation)
8585

8686
def perform_query(raw_connection, sql, binds, type_casted_binds, prepare:, notification_payload:, batch: false)
8787
total_changes_before_query = raw_connection.total_changes
88+
affected_rows = nil
8889

8990
if batch
9091
raw_connection.execute_batch2(sql)
@@ -102,20 +103,20 @@ def perform_query(raw_connection, sql, binds, type_casted_binds, prepare:, notif
102103
end
103104
result = if stmt.column_count.zero? # No return
104105
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)
107108
else
108109
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)
111112
end
112113
ensure
113114
stmt.close unless prepare
114115
end
115116
end
116117
verified!
117118

118-
notification_payload[:affected_rows] = @affected_rows
119+
notification_payload[:affected_rows] = affected_rows
119120
notification_payload[:row_count] = result&.length || 0
120121
result
121122
end
@@ -127,7 +128,7 @@ def cast_result(result)
127128
end
128129

129130
def affected_rows(result)
130-
@affected_rows
131+
result.affected_rows
131132
end
132133

133134
def execute_batch(statements, name = nil, **kwargs)

activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ def initialize(...)
149149
end
150150
end
151151

152-
@last_affected_rows = nil
153152
@previous_read_uncommitted = nil
154153
@config[:strict] = ConnectionAdapters::SQLite3Adapter.strict_strings_by_default unless @config.key?(:strict)
155154

0 commit comments

Comments
 (0)