Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails jruby activerecord试图在ms sql中保存二进制数据时出错_Ruby On Rails_Sql Server_Activerecord_Jruby - Fatal编程技术网

Ruby on rails jruby activerecord试图在ms sql中保存二进制数据时出错

Ruby on rails jruby activerecord试图在ms sql中保存二进制数据时出错,ruby-on-rails,sql-server,activerecord,jruby,Ruby On Rails,Sql Server,Activerecord,Jruby,我正在使用 sql server 2008 jruby on rails 3.2.7 jruby 1.6.7.2(ruby-1.9.2-p312) 下表 create_table "Users", :primary_key => "id" do |t| t.integer "id", :limit => 19, :default => 1, :null => false t.string "login", :limit => 80, :null =>

我正在使用 sql server 2008 jruby on rails 3.2.7 jruby 1.6.7.2(ruby-1.9.2-p312)

下表

create_table "Users", :primary_key => "id" do |t|
  t.integer "id", :limit => 19, :default => 1, :null => false
  t.string "login", :limit => 80, :null => false
  t.binary "password"
end
当我用数据填充表时,我可以毫无问题地收回记录。当我尝试保存时,出现以下错误:

Failure/Error: @user.save!
 ActiveRecord::StatementInvalid:
   ActiveRecord::JDBCError: Implicit conversion from data type varchar to varbinary is not allowed. Use the CONVERT function to run this query.: INSERT INTO [Users] ( [login], [password]) VALUES ( N'user', '')
鉴于此

t.binary "password"
还有这个

INSERT INTO [Users] ( [login], [password]) VALUES ( N'user', '')
当字段定义为二进制时,
INSERT
语句有一个密码字符串

在SQL Server中,这两种类型不兼容。二进制值指定为
0x
,即
0xAABBCCDD

您需要将传递给
INSERT
语句的密码值转换为这种格式(可能是哈希函数的字节数组输出),或者将表列类型更改为字符串