ActiveRecord Oracle and nvarchar2 or nclob datatype

Hi,

I ve got oracle database which exists prior to my rails app… :frowning:

I ve got trouble when I am updating/inserting records of a table which
includes nvarchar2 attributes.
These have a specific maximum length.

I often get an error Value too long for column when doing my inserts/
updates, but in fact that is not the case.
I ve taken a look at the generated sql statements…

As far as I know you should add a “N” in front of the quoted value for
oracle nvarchar2 or nclob datatypes…
That s not happening inside of ActiveRecord, which is in my opinion
the reason for my errors.

Has anybody a solution for this issue?

Thanks a lot in advance…
Volker

Just in case somebody is facing this issue as well…

It seems that ActiveRecord is not handling oracle nvarchar2 column
types correctly.

If somebody is facing my issue: Please find beloa the code for a fix
Many thanks to the oci adapter engineer who did the main work for it.

module ActiveRecord
module ConnectionAdapters #:nodoc:
class OracleColumn < Column #:nodoc:
attr_reader :nchar
def initialize(name, default, sql_type, null)
super
@nchar = (@type == :string && sql_type[0,1] == ‘N’)
end
end

class OracleAdapter < AbstractAdapter
  def quote(value, column = nil) #:nodoc:
    if value && column && [:text, :binary].include?(column.type)
      %Q{empty_#{ column.sql_type.downcase rescue 'blob' }()}
    elsif value && column && column.nchar
      'N' + super
    else
      super
    end
  end
end

end
end