加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 如何获取ActiveRecord :: Base.connection.exe

发布时间:2020-12-17 02:05:03 所属栏目:百科 来源:网络整理
导读: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)显示为: E
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

谢谢

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读