我在MySQL中有一个字段(使用Sequel Pro),用于tinyint
并允许null
。我正在尝试向其发送数据,现在Ruby中的所有数据都是1
,0
或nil
。但出于某种原因,当我发送nil
时,我得到:
错误的整数值:''对于第1行的列'blank'。
如何在Ruby中获取MySQL gem以了解nil
表示NULL
而不是''
?
def num_converter(type)
for i in 0 .. $ array_of_hashes.length() - 1 do
a = $ array_of_hashes [i] [type]
案例a
当“是”时
$ array_of_hashes [i] [type] = 1
当“不”时
$ array_of_hashes [i] [type] = 0
否则
$ array_of_hashes [i] [type] = nil
结束
结束
for i in 1 .. $ array_of_hashes.length() - 1 do con.query(“插入反馈(字段名称)” VALUES(来自数组的项目)
稍微清理一下 - 它将所有数字插入到数据库中,但一旦达到零值就停止 - 这是我收到错误消息的时候 - 即使我有续集pro允许null。我认为这是因为它将nil转换为字符串''。但我不知道如何改变这个