Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/26.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
Sql server 未找到Ruby MSSQL查询错误消息_Sql Server_Ruby - Fatal编程技术网

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对象的类型。你可以测试。