Skip to content

Commit 26caacb

Browse files
authored
Merge pull request rails#44530 from matthewd/rename-raw-connection-ivar
Rename the raw connection ivar to `@raw_connection`
2 parents a96c5d4 + d86fd64 commit 26caacb

File tree

12 files changed

+73
-73
lines changed

12 files changed

+73
-73
lines changed

activerecord/lib/active_record/connection_adapters/abstract_adapter.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def self.quoted_table_names # :nodoc:
9292
def initialize(connection, logger = nil, config = {}) # :nodoc:
9393
super()
9494

95-
@connection = connection
95+
@raw_connection = connection
9696
@owner = nil
9797
@instrumenter = ActiveSupport::Notifications.instrumenter
9898
@logger = logger
@@ -569,7 +569,7 @@ def disconnect!
569569
def discard!
570570
# This should be overridden by concrete adapters.
571571
#
572-
# Prevent @connection's finalizer from touching the socket, or
572+
# Prevent @raw_connection's finalizer from touching the socket, or
573573
# otherwise communicating with its server, when it is collected.
574574
if schema_cache.connection == self
575575
schema_cache.connection = nil
@@ -625,7 +625,7 @@ def verify!
625625
# PostgreSQL's lo_* methods.
626626
def raw_connection
627627
disable_lazy_transactions!
628-
@connection
628+
@raw_connection
629629
end
630630

631631
def default_uniqueness_comparison(attribute, value) # :nodoc:

activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ def raw_execute(sql, name, async: false)
639639

640640
log(sql, name, async: async) do
641641
ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
642-
@connection.query(sql)
642+
@raw_connection.query(sql)
643643
end
644644
end
645645
end

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def select_all(*, **) # :nodoc:
1111
else
1212
super
1313
end
14-
@connection.abandon_results!
14+
@raw_connection.abandon_results!
1515
result
1616
end
1717

@@ -70,7 +70,7 @@ def exec_query(sql, name = "SQL", binds = [], prepare: false, async: false) # :n
7070
def exec_delete(sql, name = nil, binds = []) # :nodoc:
7171
if without_prepared_statement?(binds)
7272
@lock.synchronize do
73-
execute_and_free(sql, name) { @connection.affected_rows }
73+
execute_and_free(sql, name) { @raw_connection.affected_rows }
7474
end
7575
else
7676
exec_stmt_and_free(sql, name, binds) { |stmt| stmt.affected_rows }
@@ -91,7 +91,7 @@ def high_precision_current_timestamp
9191
def raw_execute(sql, name, async: false)
9292
# make sure we carry over any changes to ActiveRecord.default_timezone that have been
9393
# made since we established the connection
94-
@connection.query_options[:database_timezone] = default_timezone
94+
@raw_connection.query_options[:database_timezone] = default_timezone
9595

9696
super
9797
end
@@ -100,7 +100,7 @@ def execute_batch(statements, name = nil)
100100
statements = statements.map { |sql| transform_query(sql) }
101101
combine_multi_statements(statements).each do |statement|
102102
raw_execute(statement, name)
103-
@connection.abandon_results!
103+
@raw_connection.abandon_results!
104104
end
105105
end
106106

@@ -109,7 +109,7 @@ def default_insert_value(column)
109109
end
110110

111111
def last_inserted_id(result)
112-
@connection.last_id
112+
@raw_connection.last_id
113113
end
114114

115115
def multi_statements_enabled?
@@ -126,13 +126,13 @@ def with_multi_statements
126126
multi_statements_was = multi_statements_enabled?
127127

128128
unless multi_statements_was
129-
@connection.set_server_option(Mysql2::Client::OPTION_MULTI_STATEMENTS_ON)
129+
@raw_connection.set_server_option(Mysql2::Client::OPTION_MULTI_STATEMENTS_ON)
130130
end
131131

132132
yield
133133
ensure
134134
unless multi_statements_was
135-
@connection.set_server_option(Mysql2::Client::OPTION_MULTI_STATEMENTS_OFF)
135+
@raw_connection.set_server_option(Mysql2::Client::OPTION_MULTI_STATEMENTS_OFF)
136136
end
137137
end
138138

@@ -171,15 +171,15 @@ def exec_stmt_and_free(sql, name, binds, cache_stmt: false, async: false)
171171

172172
# make sure we carry over any changes to ActiveRecord.default_timezone that have been
173173
# made since we established the connection
174-
@connection.query_options[:database_timezone] = default_timezone
174+
@raw_connection.query_options[:database_timezone] = default_timezone
175175

176176
type_casted_binds = type_casted_binds(binds)
177177

178178
log(sql, name, binds, type_casted_binds, async: async) do
179179
if cache_stmt
180-
stmt = @statements[sql] ||= @connection.prepare(sql)
180+
stmt = @statements[sql] ||= @raw_connection.prepare(sql)
181181
else
182-
stmt = @connection.prepare(sql)
182+
stmt = @raw_connection.prepare(sql)
183183
end
184184

185185
begin

activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def error_number(exception)
111111
#++
112112

113113
def quote_string(string)
114-
@connection.escape(string)
114+
@raw_connection.escape(string)
115115
rescue Mysql2::Error => error
116116
raise translate_exception(error, message: error.message, sql: "<escape>", binds: [])
117117
end
@@ -121,7 +121,7 @@ def quote_string(string)
121121
#++
122122

123123
def active?
124-
@connection.ping
124+
@raw_connection.ping
125125
end
126126

127127
def reconnect!
@@ -135,13 +135,13 @@ def reconnect!
135135
# Otherwise, this method does nothing.
136136
def disconnect!
137137
super
138-
@connection.close
138+
@raw_connection.close
139139
end
140140

141141
def discard! # :nodoc:
142142
super
143-
@connection.automatic_close = false
144-
@connection = nil
143+
@raw_connection.automatic_close = false
144+
@raw_connection = nil
145145
end
146146

147147
private
@@ -154,12 +154,12 @@ def check_prepared_statements_deprecation(config)
154154
end
155155

156156
def connect
157-
@connection = self.class.new_client(@config)
157+
@raw_connection = self.class.new_client(@config)
158158
configure_connection
159159
end
160160

161161
def configure_connection
162-
@connection.query_options[:as] = :array
162+
@raw_connection.query_options[:as] = :array
163163
super
164164
end
165165

@@ -168,7 +168,7 @@ def full_version
168168
end
169169

170170
def get_full_version
171-
@connection.server_info[:version]
171+
@raw_connection.server_info[:version]
172172
end
173173

174174
def translate_exception(exception, message:, sql:, binds:)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def query(sql, name = nil) # :nodoc:
1515

1616
log(sql, name) do
1717
ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
18-
@connection.async_exec(sql).map_types!(@type_map_for_results).values
18+
@raw_connection.async_exec(sql).map_types!(@type_map_for_results).values
1919
end
2020
end
2121
end
@@ -43,7 +43,7 @@ def execute(sql, name = nil)
4343

4444
log(sql, name) do
4545
ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
46-
@connection.async_exec(sql)
46+
@raw_connection.async_exec(sql)
4747
end
4848
end
4949
end
@@ -120,8 +120,8 @@ def commit_db_transaction # :nodoc:
120120

121121
# Aborts a transaction.
122122
def exec_rollback_db_transaction # :nodoc:
123-
@connection.cancel unless @connection.transaction_status == PG::PQTRANS_IDLE
124-
@connection.block
123+
@raw_connection.cancel unless @raw_connection.transaction_status == PG::PQTRANS_IDLE
124+
@raw_connection.block
125125
execute("ROLLBACK", "TRANSACTION")
126126
end
127127

activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ module PostgreSQL
66
module Quoting
77
# Escapes binary strings for bytea input to the database.
88
def escape_bytea(value)
9-
@connection.escape_bytea(value) if value
9+
@raw_connection.escape_bytea(value) if value
1010
end
1111

1212
# Unescapes bytea output from a database to the binary string it represents.
1313
# NOTE: This is NOT an inverse of escape_bytea! This is only to be used
1414
# on escaped binary output from database drive.
1515
def unescape_bytea(value)
16-
@connection.unescape_bytea(value) if value
16+
@raw_connection.unescape_bytea(value) if value
1717
end
1818

1919
def quote(value) # :nodoc:
@@ -43,7 +43,7 @@ def quote(value) # :nodoc:
4343

4444
# Quotes strings for use in SQL input.
4545
def quote_string(s) # :nodoc:
46-
@connection.escape(s)
46+
@raw_connection.escape(s)
4747
end
4848

4949
# Checks the following cases:

activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def index_algorithms
256256
class StatementPool < ConnectionAdapters::StatementPool # :nodoc:
257257
def initialize(connection, max)
258258
super(max)
259-
@connection = connection
259+
@raw_connection = connection
260260
@counter = 0
261261
end
262262

@@ -266,12 +266,12 @@ def next_key
266266

267267
private
268268
def dealloc(key)
269-
@connection.query "DEALLOCATE #{key}" if connection_active?
269+
@raw_connection.query "DEALLOCATE #{key}" if connection_active?
270270
rescue PG::Error
271271
end
272272

273273
def connection_active?
274-
@connection.status == PG::CONNECTION_OK
274+
@raw_connection.status == PG::CONNECTION_OK
275275
rescue PG::Error
276276
false
277277
end
@@ -306,7 +306,7 @@ def self.database_exists?(config)
306306
# Is this connection alive and ready for queries?
307307
def active?
308308
@lock.synchronize do
309-
@connection.query ";"
309+
@raw_connection.query ";"
310310
end
311311
true
312312
rescue PG::Error
@@ -321,7 +321,7 @@ def reload_type_map # :nodoc:
321321
# Close then reopen the connection.
322322
def reconnect!
323323
@lock.synchronize do
324-
@connection.reset
324+
@raw_connection.reset
325325
configure_connection
326326
reload_type_map
327327
super
@@ -333,10 +333,10 @@ def reconnect!
333333
def reset!
334334
@lock.synchronize do
335335
reset_transaction
336-
unless @connection.transaction_status == ::PG::PQTRANS_IDLE
337-
@connection.query "ROLLBACK"
336+
unless @raw_connection.transaction_status == ::PG::PQTRANS_IDLE
337+
@raw_connection.query "ROLLBACK"
338338
end
339-
@connection.query "DISCARD ALL"
339+
@raw_connection.query "DISCARD ALL"
340340
clear_cache!(new_connection: true)
341341
configure_connection
342342
end
@@ -347,14 +347,14 @@ def reset!
347347
def disconnect!
348348
@lock.synchronize do
349349
super
350-
@connection.close rescue nil
350+
@raw_connection.close rescue nil
351351
end
352352
end
353353

354354
def discard! # :nodoc:
355355
super
356-
@connection.socket_io.reopen(IO::NULL) rescue nil
357-
@connection = nil
356+
@raw_connection.socket_io.reopen(IO::NULL) rescue nil
357+
@raw_connection = nil
358358
end
359359

360360
def native_database_types # :nodoc:
@@ -503,7 +503,7 @@ def use_insert_returning?
503503

504504
# Returns the version of the connected PostgreSQL server.
505505
def get_database_version # :nodoc:
506-
@connection.server_version
506+
@raw_connection.server_version
507507
end
508508
alias :postgresql_version :database_version
509509

@@ -765,7 +765,7 @@ def exec_no_cache(sql, name, binds, async: false)
765765
type_casted_binds = type_casted_binds(binds)
766766
log(sql, name, binds, type_casted_binds, async: async) do
767767
ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
768-
@connection.exec_params(sql, type_casted_binds)
768+
@raw_connection.exec_params(sql, type_casted_binds)
769769
end
770770
end
771771
end
@@ -779,7 +779,7 @@ def exec_cache(sql, name, binds, async: false)
779779

780780
log(sql, name, binds, type_casted_binds, stmt_key, async: async) do
781781
ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
782-
@connection.exec_prepared(stmt_key, type_casted_binds)
782+
@raw_connection.exec_prepared(stmt_key, type_casted_binds)
783783
end
784784
end
785785
rescue ActiveRecord::StatementInvalid => e
@@ -833,12 +833,12 @@ def prepare_statement(sql, binds)
833833
unless @statements.key? sql_key
834834
nextkey = @statements.next_key
835835
begin
836-
@connection.prepare nextkey, sql
836+
@raw_connection.prepare nextkey, sql
837837
rescue => e
838838
raise translate_exception_class(e, sql, binds)
839839
end
840840
# Clear the queue
841-
@connection.get_last_result
841+
@raw_connection.get_last_result
842842
@statements[sql_key] = nextkey
843843
end
844844
@statements[sql_key]
@@ -848,7 +848,7 @@ def prepare_statement(sql, binds)
848848
# Connects to a PostgreSQL server and sets up the adapter depending on the
849849
# connected server's characteristics.
850850
def connect
851-
@connection = self.class.new_client(@connection_parameters)
851+
@raw_connection = self.class.new_client(@connection_parameters)
852852
configure_connection
853853
add_pg_encoders
854854
add_pg_decoders
@@ -858,7 +858,7 @@ def connect
858858
# This is called by #connect and should not be called manually.
859859
def configure_connection
860860
if @config[:encoding]
861-
@connection.set_client_encoding(@config[:encoding])
861+
@raw_connection.set_client_encoding(@config[:encoding])
862862
end
863863
self.client_min_messages = @config[:min_messages] || "warning"
864864
self.schema_search_path = @config[:schema_search_path] || @config[:schema_order]
@@ -937,7 +937,7 @@ def arel_visitor
937937
end
938938

939939
def build_statement_pool
940-
StatementPool.new(@connection, self.class.type_cast_config_to_integer(@config[:statement_limit]))
940+
StatementPool.new(@raw_connection, self.class.type_cast_config_to_integer(@config[:statement_limit]))
941941
end
942942

943943
def can_perform_case_insensitive_comparison_for?(column)
@@ -967,7 +967,7 @@ def add_pg_encoders
967967
map[Integer] = PG::TextEncoder::Integer.new
968968
map[TrueClass] = PG::TextEncoder::Boolean.new
969969
map[FalseClass] = PG::TextEncoder::Boolean.new
970-
@connection.type_map_for_queries = map
970+
@raw_connection.type_map_for_queries = map
971971
end
972972

973973
def update_typemap_for_default_timezone
@@ -977,7 +977,7 @@ def update_typemap_for_default_timezone
977977
PG::TextDecoder::TimestampWithoutTimeZone
978978

979979
@timestamp_decoder = decoder_class.new(@timestamp_decoder.to_h)
980-
@connection.type_map_for_results.add_coder(@timestamp_decoder)
980+
@raw_connection.type_map_for_results.add_coder(@timestamp_decoder)
981981

982982
@mapped_default_timezone = default_timezone
983983

@@ -1016,7 +1016,7 @@ def add_pg_decoders
10161016

10171017
map = PG::TypeMapByOid.new
10181018
coders.each { |coder| map.add_coder(coder) }
1019-
@connection.type_map_for_results = map
1019+
@raw_connection.type_map_for_results = map
10201020

10211021
@type_map_for_results = PG::TypeMapByOid.new
10221022
@type_map_for_results.default_type_map = map

0 commit comments

Comments
 (0)