1

我在 MySQL 中有一个字段(使用 Sequel Pro),用于tinyint并允许null. 我正在尝试向它发送数据,现在 Ruby 中的所有数据都是1,0nil. 然而由于某种原因,当我发送时nil,我得到:

不正确的整数值:第 1 行的“空白”列的“”。

如何让 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]
case a
when "Yes"
$array_of_hashes[i][type] = 1
when "No"
$array_of_hashes[i][type] = 0
否则
$array_of_hashes[i][type] = nil
end

end

插入数据库是

for i in 1..$array_of_hashes.length()-1 do con.query("INSERT INTO feedback(names of fields) VALUES (items from arrays)

稍微澄清一下-它将所有数字插入数据库,但一旦达到零值就停止-这是我收到错误消息的时候-即使我有sequel pro允许null。我认为这是因为它将 nil 转换为字符串 ''。但我不知道如何改变这个

4

0 回答 0