Skip to content

Commit 3be5045

Browse files
authored
Merge pull request #2424 from andynu/rails-7-2-support
Rails 7.2 support!
2 parents fd4161e + c3a9198 commit 3be5045

File tree

17 files changed

+97
-105
lines changed

17 files changed

+97
-105
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,16 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
# Rails 7.0 requires Ruby 2.7 or higeher.
16+
# Rails 7.2 requires Ruby 3.1 or higeher.
1717
# CI pending the following matrix until JRuby 9.4 that supports Ruby 2.7 will be released.
1818
# https://github.com/jruby/jruby/issues/6464
1919
# - jruby,
2020
# - jruby-head
2121
ruby: [
22+
'3.4',
2223
'3.3',
2324
'3.2',
2425
'3.1',
25-
'3.0',
26-
'2.7'
2726
]
2827
env:
2928
ORACLE_HOME: /opt/oracle/instantclient_23_6

.github/workflows/test_11g.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,16 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
# Rails 7.0 requires Ruby 2.7 or higeher.
16+
# Rails 7.2 requires Ruby 3.1 or higeher.
1717
# CI pending the following matrix until JRuby 9.4 that supports Ruby 2.7 will be released.
1818
# https://github.com/jruby/jruby/issues/6464
1919
# - jruby,
2020
# - jruby-head
2121
ruby: [
22+
'3.4',
2223
'3.3',
2324
'3.2',
2425
'3.1',
25-
'3.0',
26-
'2.7'
2726
]
2827
env:
2928
ORACLE_HOME: /opt/oracle/instantclient_21_15

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ group :development do
1313
gem "rubocop-rails", require: false
1414
gem "rubocop-rspec", require: false
1515

16-
gem "activerecord", github: "rails/rails", branch: "7-1-stable"
16+
gem "activerecord", github: "rails/rails", branch: "7-2-stable"
1717
gem "ruby-plsql", github: "rsim/ruby-plsql", branch: "master"
1818

1919
platforms :ruby do

activerecord-oracle_enhanced-adapter.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ This adapter is superset of original ActiveRecord Oracle adapter.
2626
"rubygems_mfa_required" => "true"
2727
}
2828

29-
s.add_runtime_dependency("activerecord", ["~> 7.1.0"])
29+
s.add_runtime_dependency("activerecord", ["~> 7.2.0"])
3030
s.add_runtime_dependency("ruby-plsql", [">= 0.6.0"])
3131
if /java/.match?(RUBY_PLATFORM)
3232
s.platform = Gem::Platform.new("java")

lib/active_record/connection_adapters/oracle_enhanced/quoting.rb

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,60 @@ module ActiveRecord
44
module ConnectionAdapters
55
module OracleEnhanced
66
module Quoting
7+
extend ActiveSupport::Concern
78
# QUOTING ==================================================
89
#
910
# see: abstract/quoting.rb
1011
QUOTED_COLUMN_NAMES = Concurrent::Map.new # :nodoc:
1112
QUOTED_TABLE_NAMES = Concurrent::Map.new # :nodoc:
1213

13-
def quote_column_name(name) # :nodoc:
14-
name = name.to_s
15-
QUOTED_COLUMN_NAMES[name] ||= if /\A[a-z][a-z_0-9$#]*\Z/.match?(name)
16-
"\"#{name.upcase}\""
17-
else
18-
# remove double quotes which cannot be used inside quoted identifier
19-
"\"#{name.delete('"')}\""
14+
module ClassMethods # :nodoc:
15+
def column_name_matcher
16+
/
17+
\A
18+
(
19+
(?:
20+
# "table_name"."column_name" | function(one or no argument)
21+
((?:\w+\.|"\w+"\.)?(?:\w+|"\w+") | \w+\((?:|\g<2>)\))
22+
)
23+
(?:(?:\s+AS)?\s+(?:\w+|"\w+"))?
24+
)
25+
(?:\s*,\s*\g<1>)*
26+
\z
27+
/ix
28+
end
29+
30+
def column_name_with_order_matcher
31+
/
32+
\A
33+
(
34+
(?:
35+
# "table_name"."column_name" | function(one or no argument)
36+
((?:\w+\.|"\w+"\.)?(?:\w+|"\w+") | \w+\((?:|\g<2>)\))
37+
)
38+
(?:\s+ASC|\s+DESC)?
39+
(?:\s+NULLS\s+(?:FIRST|LAST))?
40+
)
41+
(?:\s*,\s*\g<1>)*
42+
\z
43+
/ix
44+
end
45+
46+
def quote_column_name(name) # :nodoc:
47+
name = name.to_s
48+
QUOTED_COLUMN_NAMES[name] ||= if /\A[a-z][a-z_0-9$#]*\Z/.match?(name)
49+
"\"#{name.upcase}\""
50+
else
51+
# remove double quotes which cannot be used inside quoted identifier
52+
"\"#{name.delete('"')}\""
53+
end
54+
end
55+
56+
def quote_table_name(name) # :nodoc:
57+
name, _link = name.to_s.split("@")
58+
QUOTED_TABLE_NAMES[name] ||= [name.split(".").map { |n| quote_column_name(n) }].join(".")
2059
end
60+
2161
end
2262

2363
# This method is used in add_index to identify either column name (which is quoted)
@@ -67,10 +107,6 @@ def self.mixed_case?(name)
67107
!!(object_name =~ /[A-Z]/ && object_name =~ /[a-z]/)
68108
end
69109

70-
def quote_table_name(name) # :nodoc:
71-
name, _link = name.to_s.split("@")
72-
QUOTED_TABLE_NAMES[name] ||= [name.split(".").map { |n| quote_column_name(n) }].join(".")
73-
end
74110

75111
def quote_string(s) # :nodoc:
76112
s.gsub(/'/, "''")
@@ -131,42 +167,6 @@ def type_cast(value)
131167
end
132168
end
133169

134-
def column_name_matcher
135-
COLUMN_NAME
136-
end
137-
138-
def column_name_with_order_matcher
139-
COLUMN_NAME_WITH_ORDER
140-
end
141-
142-
COLUMN_NAME = /
143-
\A
144-
(
145-
(?:
146-
# "table_name"."column_name" | function(one or no argument)
147-
((?:\w+\.|"\w+"\.)?(?:\w+|"\w+") | \w+\((?:|\g<2>)\))
148-
)
149-
(?:(?:\s+AS)?\s+(?:\w+|"\w+"))?
150-
)
151-
(?:\s*,\s*\g<1>)*
152-
\z
153-
/ix
154-
155-
COLUMN_NAME_WITH_ORDER = /
156-
\A
157-
(
158-
(?:
159-
# "table_name"."column_name" | function(one or no argument)
160-
((?:\w+\.|"\w+"\.)?(?:\w+|"\w+") | \w+\((?:|\g<2>)\))
161-
)
162-
(?:\s+ASC|\s+DESC)?
163-
(?:\s+NULLS\s+(?:FIRST|LAST))?
164-
)
165-
(?:\s*,\s*\g<1>)*
166-
\z
167-
/ix
168-
private_constant :COLUMN_NAME, :COLUMN_NAME_WITH_ORDER
169-
170170
private
171171
def oracle_downcase(column_name)
172172
return nil if column_name.nil?

lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def drop_table(table_name, **options) # :nodoc:
276276
end
277277

278278
def insert_versions_sql(versions) # :nodoc:
279-
sm_table = quote_table_name(ActiveRecord::Base.connection.schema_migration.table_name)
279+
sm_table = quote_table_name(ActiveRecord::Tasks::DatabaseTasks.migration_connection_pool.schema_migration.table_name)
280280

281281
if supports_multi_insert?
282282
versions.inject(+"INSERT ALL\n") { |sql, version|

lib/active_record/connection_adapters/oracle_enhanced_adapter.rb

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,6 @@
6363
require "active_record/type/oracle_enhanced/character_string"
6464

6565
module ActiveRecord
66-
module ConnectionHandling # :nodoc:
67-
# Establishes a connection to the database that's used by all Active Record objects.
68-
def oracle_enhanced_connection(config) # :nodoc:
69-
if config[:emulate_oracle_adapter] == true
70-
# allows the enhanced adapter to look like the OracleAdapter. Useful to pick up
71-
# conditionals in the rails activerecord test suite
72-
require "active_record/connection_adapters/emulation/oracle_adapter"
73-
ConnectionAdapters::OracleAdapter.new(
74-
ConnectionAdapters::OracleEnhanced::Connection.create(config), logger, config)
75-
else
76-
ConnectionAdapters::OracleEnhancedAdapter.new(
77-
ConnectionAdapters::OracleEnhanced::Connection.create(config), logger, config)
78-
end
79-
end
80-
end
8166

8267
module ConnectionAdapters # :nodoc:
8368
# Oracle enhanced adapter will work with both
@@ -837,6 +822,26 @@ def select_value_forcing_binds(arel, name, binds)
837822
end
838823
end
839824

825+
## Register OracleEnhancedAdapter as the adapter to use for "oracle_enhanced" connection string
826+
if ActiveRecord::ConnectionAdapters.respond_to?(:register)
827+
ActiveRecord::ConnectionAdapters.register(
828+
"oracle_enhanced",
829+
"ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter",
830+
"active_record/connection_adapters/oracle_enhanced_adapter"
831+
)
832+
833+
# This is similar to the notion of emulating the original OracleAdapter but
834+
# using the OracleEnhancedAdapter instead, but without using the emulate flag.
835+
# Instead this will get picked up if you set the adapter to 'oracle' in the database config.
836+
#
837+
# Register OracleAdapter as the adapter to use for "oracle" connection string
838+
ActiveRecord::ConnectionAdapters.register(
839+
"oracle",
840+
"ActiveRecord::ConnectionAdapters::OracleAdapter",
841+
"active_record/connection_adapters/emulation/oracle_adapter"
842+
)
843+
end
844+
840845
require "active_record/connection_adapters/oracle_enhanced/version"
841846

842847
module ActiveRecord

lib/arel/visitors/oracle.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,6 @@ def split_order_string(string)
195195
array
196196
end
197197

198-
def visit_ActiveModel_Attribute(o, collector)
199-
collector.add_bind(o) { |i| ":a#{i}" }
200-
end
201-
202-
def visit_Arel_Nodes_BindParam(o, collector)
203-
collector.add_bind(o.value) { |i| ":a#{i}" }
204-
end
205-
206198
def is_distinct_from(o, collector)
207199
collector << "DECODE("
208200
collector = visit [o.left, o.right, 0, 1], collector

lib/arel/visitors/oracle12.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,6 @@ def visit_Arel_Nodes_UpdateStatement(o, collector)
100100
super
101101
end
102102

103-
def visit_ActiveModel_Attribute(o, collector)
104-
collector.add_bind(o) { |i| ":a#{i}" }
105-
end
106-
107-
def visit_Arel_Nodes_BindParam(o, collector)
108-
collector.add_bind(o.value) { |i| ":a#{i}" }
109-
end
110-
111103
def is_distinct_from(o, collector)
112104
collector << "DECODE("
113105
collector = visit [o.left, o.right, 0, 1], collector

lib/arel/visitors/oracle_common.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
module Arel # :nodoc: all
44
module Visitors
55
module OracleCommon
6+
7+
BIND_BLOCK = proc { |i| ":a#{i}" }
8+
private_constant :BIND_BLOCK
9+
10+
def bind_block; BIND_BLOCK; end
11+
612
private
713
# Oracle can't compare CLOB columns with standard SQL operators for comparison.
814
# We need to replace standard equality for text/binary columns to use DBMS_LOB.COMPARE function.

0 commit comments

Comments
 (0)