Skip to content

Commit 0553eb5

Browse files
committed
further clean-up and fixes
1 parent 8cfa457 commit 0553eb5

2 files changed

Lines changed: 15 additions & 49 deletions

File tree

config/initializers/oracle.rb

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@ def close_and_clear_statements
4949
end
5050
end
5151

52+
# uncomment the commented our lines for https://github.com/rsim/oracle-enhanced/pull/2485
53+
# if you uncomment them and things don't fail, then they are taking effect
5254
ActiveRecord::Base.skip_callback(:update, :after, :enhanced_write_lobs)
55+
# ActiveRecord::Base.skip_callback(:create, :after, :enhanced_write_lobs)
56+
ActiveRecord::Base.skip_callback(:update, :before, :record_changed_lobs)
57+
# ActiveRecord::Base.skip_callback(:create, :before, :record_lobs_for_create)
5358

5459
# For more information see https://github.com/rsim/oracle-enhanced/pull/2483
5560
module OracleEnhancedSmartQuoting
@@ -195,47 +200,6 @@ def find_one(id)
195200
end
196201
end)
197202

198-
ActiveRecord::ConnectionAdapters::OracleEnhanced::SchemaStatements.module_eval do
199-
def distinct_relation_for_primary_key(relation) # :nodoc:
200-
primary_key_columns = Array(relation.primary_key).map do |column|
201-
visitor.compile(relation.table[column])
202-
end
203-
204-
values = columns_for_distinct(
205-
primary_key_columns,
206-
relation.order_values
207-
)
208-
209-
limited = relation.reselect(values).distinct!
210-
211-
# The original code in https://github.com/rails/rails/blob/v7.1.5.1/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L1404-L1406
212-
# ----
213-
# limited_ids = select_rows(limited.arel, "SQL").map do |results|
214-
# results.last(Array(relation.primary_key).length) # ignores order values for MySQL and PostgreSQL
215-
# end
216-
# ----
217-
# The change is needed because in Oracle, because otherwise the resulting `limited_ids` array would be wrong. For example,
218-
# for a ServiceContract model that has the primary key "id" and a query with ordering and filtering you may get:
219-
# 1. `limited` variable can be something like: #<ActiveRecord::Relation [#<ServiceContract alias_0__: "live", id: 4, raw_rnum_: 1>]>
220-
# 2. `select_rows` would then return [["live",4,1]]
221-
# 3. `limited_ids` calculation will result in [[1]], which is an invalid IDs list (the expected is [[4]])
222-
# The updated code doesn't make assumptions about how many columns are selected or their order, but fetches the values according
223-
# to the primary key column names
224-
limited_ids = select_all(limited.arel, "SQL").to_ary.map do |result|
225-
result.values_at(*Array(relation.primary_key))
226-
end
227-
228-
if limited_ids.empty?
229-
relation.none!
230-
else
231-
relation.where!(**Array(relation.primary_key).zip(limited_ids.transpose).to_h)
232-
end
233-
234-
relation.limit_value = relation.offset_value = nil
235-
relation
236-
end
237-
end
238-
239203
# see https://github.com/rsim/oracle-enhanced/issues/2276
240204
module OracleEnhancedAdapterSchemaIssue2276
241205
def column_definitions(table_name)

lib/arel/visitors/oracle12_hack.rb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,19 @@ def visit_Arel_Nodes_Equality(o, collector)
2020
collector
2121
end
2222

23-
# remove when addressed: https://github.com/rsim/oracle-enhanced/pull/2247 - included in v7.1.0
24-
def visit_Arel_Nodes_Matches o, collector
25-
if !o.case_sensitive && o.left && o.right
26-
o.left = Arel::Nodes::NamedFunction.new('UPPER', [o.left])
27-
o.right = Arel::Nodes::NamedFunction.new('UPPER', [o.right])
23+
# remove once fixed in https://github.com/rsim/oracle-enhanced/pull/2573 (8.1.4+)
24+
# Note that I'm not fully happy with this as the other visitor is missing potential
25+
# patches that we have in this visitor. But limit+lock should be rare and simpler.
26+
# An example failing operation without this is ProxyRule#move_to_top
27+
def visit_Arel_Nodes_SelectStatement(o, collector)
28+
if o.limit && o.lock
29+
@oracle11_visitor ||= Arel::Visitors::Oracle.new(@connection)
30+
return @oracle11_visitor.accept(o.dup, collector)
2831
end
29-
30-
super o, collector
32+
super
3133
end
3234

33-
# Remove after upgrade to a version with
35+
# can remove both after upgrade to a version with (8.1.4+ perhaps)
3436
# https://github.com/rsim/oracle-enhanced/pull/2654
3537
def visit_Arel_Nodes_In(o, collector)
3638
attr, values = o.left, o.right

0 commit comments

Comments
 (0)