MrBanabas-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2008-Dec-05 12:18 UTC
ActiveRecord Oracle and nvarchar2 or nclob datatype
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
MrBanabas-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2008-Dec-15 17:01 UTC
Re: ActiveRecord Oracle and nvarchar2 or nclob datatype
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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---