From ea69c9661bede8e862400bf805d7411fb4dfc990 Mon Sep 17 00:00:00 2001 From: Daria Mayorova Date: Mon, 2 Dec 2024 16:33:26 +0100 Subject: [PATCH] Fix Oracle issues --- config/initializers/oracle.rb | 2 +- lib/arel/visitors/oracle12_hack.rb | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/config/initializers/oracle.rb b/config/initializers/oracle.rb index b02372b2e9..280b0efa25 100644 --- a/config/initializers/oracle.rb +++ b/config/initializers/oracle.rb @@ -5,7 +5,7 @@ require 'arel/visitors/oracle12_hack' ENV['SCHEMA'] = 'db/oracle_schema.rb' - Rails.configuration.active_record.schema_format = ActiveRecord::Base.schema_format = :ruby + Rails.configuration.active_record.schema_format = ActiveRecord.schema_format = :ruby ActiveRecord::ConnectionAdapters::TableDefinition.prepend(Module.new do def column(name, type, **options) diff --git a/lib/arel/visitors/oracle12_hack.rb b/lib/arel/visitors/oracle12_hack.rb index 6376c292ac..eaa620a334 100644 --- a/lib/arel/visitors/oracle12_hack.rb +++ b/lib/arel/visitors/oracle12_hack.rb @@ -29,6 +29,10 @@ def visit_Arel_Nodes_NotIn(o, collector) # Fixes ORA-00932: inconsistent datatypes: expected - got CLOB # remove if https://github.com/rsim/oracle-enhanced/issues/2239 is fixed (in Rails 7.0.1) def visit_Arel_Nodes_Equality(o, collector) + right = o.right + + return super if right.nil? + case (left = o.left) when Arel::Attributes::Attribute table = left.relation.table_name @@ -42,7 +46,7 @@ def visit_Arel_Nodes_Equality(o, collector) when :text, :binary # https://docs.oracle.com/cd/B19306_01/appdev.102/b14258/d_lob.htm#i1016668 # returns 0 when the comparison succeeds - comparator = Arel::Nodes::NamedFunction.new('DBMS_LOB.COMPARE', [left, o.right]) + comparator = Arel::Nodes::NamedFunction.new('DBMS_LOB.COMPARE', [left, right]) collector = visit comparator, collector collector << ' = 0' collector @@ -54,7 +58,7 @@ def visit_Arel_Nodes_Equality(o, collector) end end - # remove when addressed: https://github.com/rsim/oracle-enhanced/pull/2247 + # remove when addressed: https://github.com/rsim/oracle-enhanced/pull/2247 - included in v7.1.0 def visit_Arel_Nodes_Matches o, collector if !o.case_sensitive && o.left && o.right o.left = Arel::Nodes::NamedFunction.new('UPPER', [o.left])