Skip to content

Commit 8078ebc

Browse files
committed
Simplify some perform_query implementation
Inline simple operations like reseting the timezone.
1 parent b57dcec commit 8078ebc

File tree

4 files changed

+13
-23
lines changed

4 files changed

+13
-23
lines changed

activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -770,12 +770,6 @@ def warning_ignored?(warning)
770770
warning.level == "Note" || super
771771
end
772772

773-
# Make sure we carry over any changes to ActiveRecord.default_timezone that have been
774-
# made since we established the connection
775-
def sync_timezone_changes(raw_connection)
776-
raise NotImplementedError
777-
end
778-
779773
# See https://dev.mysql.com/doc/mysql-errors/en/server-error-reference.html
780774
ER_DB_CREATE_EXISTS = 1007
781775
ER_FILSORT_ABORT = 1028

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ def select_all(*, **) # :nodoc:
1414
end
1515

1616
private
17-
def sync_timezone_changes(raw_connection)
18-
raw_connection.query_options[:database_timezone] = default_timezone
19-
end
20-
2117
def execute_batch(statements, name = nil)
2218
combine_multi_statements(statements).each do |statement|
2319
with_raw_connection do |conn|
@@ -59,7 +55,9 @@ def with_multi_statements
5955
end
6056

6157
def perform_query(raw_connection, sql, binds, type_casted_binds, prepare:, notification_payload:)
62-
sync_timezone_changes(raw_connection)
58+
# Make sure we carry over any changes to ActiveRecord.default_timezone that have been
59+
# made since we established the connection
60+
raw_connection.query_options[:database_timezone] = default_timezone
6361

6462
result = if prepare
6563
stmt = @statements[sql] ||= raw_connection.prepare(sql)

activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -981,9 +981,9 @@ def reconfigure_connection_timezone
981981
# If using Active Record's time zone support configure the connection
982982
# to return TIMESTAMP WITH ZONE types in UTC.
983983
if default_timezone == :utc
984-
internal_execute("SET SESSION timezone TO 'UTC'", "SCHEMA")
984+
raw_execute("SET SESSION timezone TO 'UTC'", "SCHEMA")
985985
else
986-
internal_execute("SET SESSION timezone TO DEFAULT", "SCHEMA")
986+
raw_execute("SET SESSION timezone TO DEFAULT", "SCHEMA")
987987
end
988988
end
989989

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ def exec_insert(sql, name, binds, pk = nil, sequence_name = nil, returning: nil)
1111

1212
private
1313
def perform_query(raw_connection, sql, binds, type_casted_binds, prepare:, notification_payload:)
14-
sync_timezone_changes(raw_connection)
14+
# Make sure we carry over any changes to ActiveRecord.default_timezone that have been
15+
# made since we established the connection
16+
if default_timezone == :local
17+
raw_connection.query_flags |= ::Trilogy::QUERY_FLAGS_LOCAL_TIMEZONE
18+
else
19+
raw_connection.query_flags &= ~::Trilogy::QUERY_FLAGS_LOCAL_TIMEZONE
20+
end
21+
1522
result = raw_connection.query(sql)
1623
while raw_connection.more_results_exist?
1724
raw_connection.next_result
@@ -42,15 +49,6 @@ def last_inserted_id(result)
4249
end
4350
end
4451

45-
def sync_timezone_changes(conn)
46-
# Sync any changes since connection last established.
47-
if default_timezone == :local
48-
conn.query_flags |= ::Trilogy::QUERY_FLAGS_LOCAL_TIMEZONE
49-
else
50-
conn.query_flags &= ~::Trilogy::QUERY_FLAGS_LOCAL_TIMEZONE
51-
end
52-
end
53-
5452
def execute_batch(statements, name = nil)
5553
combine_multi_statements(statements).each do |statement|
5654
with_raw_connection do |conn|

0 commit comments

Comments
 (0)