ruby-on-rails – 如何获取ActiveRecord :: Base.connection.execute的错误?

ruby-on-rails – 如何获取ActiveRecord :: Base.connection.execute的错误?,第1张

概述begin ActiveRecord::Base.transaction do // ... sanitized_sql = "INSERT INTO pinfo ..." ActiveRecord::Base.connection.execute(sanitized_sql) end rescue // how can I
begin    ActiveRecord::Base.transaction do      // ...      sanitized_sql = "INSERT INTO pinfo ..."      ActiveRecord::Base.connection.execute(sanitized_sql)    end  rescue    // how can I get the error?         end

在webrick控制台中,错误(1967-07-16?00:00:00)显示为:

EXECUTE (0.0ms) ODBC::Error: 22008 (241) [unixODBC][FreeTDS][sql Server]Syntax error converting datetime from character string.: INSERT INTO pinfo (birthdate) VALUES (‘1967-07-16?00:00:00’)
EXECUTE (0.8ms) IF @@TRANCOUNT > 0 RolLBACK TRANSACTION

如何从救援中的ActiveRecord :: Base.connection.execute获取上述错误消息(ODBC ::错误:22008(241)…)?

解决方法
begin    ActiveRecord::Base.transaction do    // ...  sanitized_sql = "INSERT INTO pinfo ..."  ActiveRecord::Base.connection.execute(sanitized_sql)  end rescue Exception => exc    logger.error("Message for the log file #{exc.message}")    flash[:notice] = "Store error message #{exec.message}"  end

谢谢

总结

以上是内存溢出为你收集整理的ruby-on-rails – 如何获取ActiveRecord :: Base.connection.execute的错误?全部内容,希望文章能够帮你解决ruby-on-rails – 如何获取ActiveRecord :: Base.connection.execute的错误?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1269151.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存