查询空表终止Ruby程序



我有一个简单的方法,它使用Ruby语言的存储过程查询Sql Server数据库的表。

@app_config = YAML.load_file("#{File.dirname(__FILE__)}/../../config/sa.gw.c.victim.yml")
connection_manager = ConnectionManager.new(@app_config["tpaldb"]) #H
 begin        
    sql = "exec spTPal_Vic_GetDeviceStateByIMEI '000000000000000'"
    result = connection_manager.execute_sproc(sql)
          result.each {|r| 
          #puts "#{r['DeviceID']} #{r['UniqueID']} #{r['DeviceType']}"
          puts r['DeviceID']           
          }
    connection_manager.connection.close()
     rescue => e
      puts "An error occurred while getting the device info for victimdevice_IMEI  #{victimdevice_IMEI} detail: #{e.message}"  
    end   

现在桌子是空的。当result=connection_manager.execute_sproc(sql)代码excutes时,ruby程序将以静默方式终止,并识别我的任何信息。我想知道的是,查询在前端返回了一个空的结果,而不是将存储过程更改为返回null或其他任何内容。ruby中标识查询或SP返回空结果的方法是什么。非常感谢。

根据我所看到的,这似乎是正确的行为。您运行的查询预期不会返回任何结果。然后对(空的)结果进行迭代。。。。什么也没发生。尝试检查result.count或任何合适的方法来获得结果集的大小——我不熟悉ConnectionManager返回的对象。但是,一个不返回行的查询本身并不是一个错误。

最新更新