Forum: Ruby on Rails ActiveRecord Oracle and nvarchar2 or nclob datatype

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
05b76b92415862cc4783d09a9009641b?d=identicon&s=25 MrBanabas@googlemail.com (Guest)
on 2008-12-05 13:20
(Received via mailing list)
Hi,

I ve got oracle database which exists prior to my rails app... :-(

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
05b76b92415862cc4783d09a9009641b?d=identicon&s=25 MrBanabas@googlemail.com (Guest)
on 2008-12-15 18:02
(Received via mailing list)
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
This topic is locked and can not be replied to.