【问题标题】:Ruby-DBI MSSQL - When I try to make a select sentence, I only get nils as a resultsRuby-DBI MSSQL - 当我尝试选择句子时,我只得到 nils 作为结果
【发布时间】:2014-11-30 22:54:46
【问题描述】:

我想使用 Ruby-DBI 执行一个简单的查询,但是所有的结果都是 nil。 该查询应返回我已插入数据库的 6 行。

我的代码:

conn = DBI.connect("DBI:ODBC:myODBC", user, password)
sql = "select S.Name, S.InternalName, from sites S where S.IsEnabled = 1"

sth = conn.select_all(sql)

while row=sth.fetch do
    p row
end

conn.disconnect if conn

当我执行结果是:

nil
nil
nil
nil
nil
nil

所以,Ruby-DBI 似乎检索了 6 个结果,但我不知道为什么所有结果都是 nil。 我正在从 Windows 7 和 Ruby 2.0.0 运行代码。 32位

我尝试了微软工具:sqlrun.exe,该工具正确返回结果,所以查询和连接设置应该没问题。

这里有灯吗?可能是 ruby​​-dbi 问题?

【问题讨论】:

    标签: ruby sql-server database dbi null


    【解决方案1】:

    我没有发现问题,但我找到了解决方法。
    与其使用 dbi lib,不如直接使用 odbc 似乎可行。

    您可以在此处找到在 ruby​​ 中使用 odbc 的教程:

    http://social.technet.microsoft.com/wiki/contents/articles/3896.connect-to-windows-azure-sql-database-from-ruby-applications.aspx

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-02
      • 1970-01-01
      • 2021-04-11
      • 1970-01-01
      • 2013-06-05
      • 1970-01-01
      • 2022-10-04
      • 1970-01-01
      相关资源
      最近更新 更多