Skip to content

Commit

Permalink
revert changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mayorova committed Dec 3, 2024
1 parent 61437ad commit b61b6c4
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lib/arel/visitors/oracle12_hack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,37 @@ 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.columns_hash?(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 - included in v7.1.0
def visit_Arel_Nodes_Matches o, collector
if !o.case_sensitive && o.left && o.right
Expand Down

0 comments on commit b61b6c4

Please sign in to comment.