Calvin Nguyen
2009-Aug-11 20:53 UTC
activerecord-sqlserver-adapter nvarchar datatype length
I''ve recently installed this adapter in hope that I can work with utf-8 encoding using the SQL Server nvarchar data type. I''ve installed and followed the steps detailed at this uri: http://github.com/adzap/rails-sqlserver-adapter/tree/master I have this following migration class definition: class CreateContacts < ActiveRecord::Migration def self.up create_table :contacts do |t| t.column :organization_id, :integer, :null=>false t.column :first_name, :nvarchar, :limit=>10, :null=>false t.column :last_name, :nvarchar, :null=>false t.column :title, :string t.column :contact_type_id, :integer, :null=>false t.column :fax, :string t.timestamps end end def self.down drop_table :contacts end end When I look at the generated table definition first_name column is created has a length of 2 rather than 10. In fact all of the columns of type :nvarchar get a length of 2. If I try what the web site documentation has, namely: t.column :body2_utf8, :nvarchar_max # Creates nvarchar(max) or in my case: t.column :first_name, :nvarchar_max, :null=>false I get an error that says: DBI::DatabaseError: Execute OLE error code:80040E14 in Microsoft OLE DB Provider for SQL Server Column, parameter, or variable #3: Cannot find data type nvarchar_max. HRESULT error code:0x80020009 Does anyone know how I can set the maximum length of the nvarchar data type successfully? Thanks in advance, Calvin. -- Posted via http://www.ruby-forum.com/.
I''ve recently installed this adapter in hope that I can work with utf-8 encoding using the SQL Server nvarchar data type. I''ve installed and followed the steps detailed at this uri: http://github.com/adzap/rails-sqlserver-adapter/tree/master I have this following migration class definition: class CreateContacts < ActiveRecord::Migration def self.up create_table :contacts do |t| t.column :organization_id, :integer, :null=>false t.column :first_name, :nvarchar, :limit=>10, :null=>false t.column :last_name, :nvarchar, :null=>false t.column :title, :string t.column :contact_type_id, :integer, :null=>false t.column :fax, :string t.timestamps end end def self.down drop_table :contacts end end When I look at the generated table definition, the first_name column created has a length of 2 rather than 10 as specified by the :limit parameter. In fact all of the columns of type :nvarchar get a length of 2. If I try what the web site documentation has, namely: t.column :body2_utf8, :nvarchar_max # Creates nvarchar(max) or in my case: t.column :first_name, :nvarchar_max, :null=>false I get an error that says: DBI::DatabaseError: Execute OLE error code:80040E14 in Microsoft OLE DB Provider for SQL Server Column, parameter, or variable #3: Cannot find data type nvarchar_max. HRESULT error code:0x80020009 What is the correct way to set the maximum length of the nvarchar data type?