Sql server 未找到Ruby MSSQL查询错误消息
我在脚本中使用了Sql server 未找到Ruby MSSQL查询错误消息,sql-server,ruby,Sql Server,Ruby,我在脚本中使用了Ruby和tiny_tds gem。在mssql数据库上,节点_id 220不存在。当我运行此脚本时,它会通过,但我没有看到输出消息“无法找到节点id”。查看自述文件: 客户端将始终返回一个结果对象-因此,即使查询在数据库中没有找到匹配的行,结果也不会是nil是否确实进入循环?如果结果为nil(或空),则不会有任何行对象进入循环 result = client.execute("SELECT TOP (2000) node_id FROM [td].[node] WHERE
Ruby
和tiny_tds gem
。在mssql数据库上,节点_id 220不存在。当我运行此脚本时,它会通过,但我没有看到输出消息“无法找到节点id”。查看自述文件:
客户端将始终返回一个
结果
对象-因此,即使查询在数据库中没有找到匹配的行,结果也不会是nil
是否确实进入循环?如果结果为nil(或空),则不会有任何行对象进入循环
result = client.execute("SELECT TOP (2000) node_id FROM [td].[node] WHERE (node_id = 220)")
result.each do |row|
if result.nil?
puts 'Node id could not found'
else
puts row
puts 'Node is found on the database'
end
end
result = client.execute("SELECT TOP (2000) node_id FROM [td].[node] WHERE (node_id = 220)")
result.each do |row|
puts 'I came into the loop'
if result.nil?
puts 'Node id could not found'
else
puts row
puts 'Node is found on the database'
end
end
我很肯定这对你来说也不会有任何结果。您应该测试循环外的结果是否为空
result = client.execute("SELECT TOP (2000) node_id FROM [td].[node] WHERE (node_id = 220)")
result.each do |row|
if result.nil?
puts 'Node id could not found'
else
puts row
puts 'Node is found on the database'
end
end
result = client.execute("SELECT TOP (2000) node_id FROM [td].[node] WHERE (node_id = 220)")
result.each do |row|
puts 'I came into the loop'
if result.nil?
puts 'Node id could not found'
else
puts row
puts 'Node is found on the database'
end
end
如果result.empty将返回什么?可能是您想要的,但我不确定您的result对象的类型。你可以测试。