From 61437adc4298fbbe955867ca5a8b9350cdd6051a 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 | 33 +----------------------------- 2 files changed, 2 insertions(+), 33 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..33e4012487 100644 --- a/lib/arel/visitors/oracle12_hack.rb +++ b/lib/arel/visitors/oracle12_hack.rb @@ -23,38 +23,7 @@ def visit_Arel_Nodes_NotIn(o, collector) super end - # Another wonderful piece. - # Oracle can't compare CLOB columns with standard SQL operators for comparison. - # We need to replace standard equality for text/binary columns to use DBMS_LOB.COMPARE function. - # 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) - case (left = o.left) - when Arel::Attributes::Attribute - table = left.relation.table_name - schema_cache = @connection.schema_cache - - return super unless schema_cache.data_source_exists?(table) - - column = schema_cache.columns_hash(table)[left.name.to_s] - - case column.type - 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]) - collector = visit comparator, collector - collector << ' = 0' - collector - else - super - end - else - super - 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])