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]从字符串转换日期时间的语法错误。: INSERT INTO pinfo (birthdate) VALUES ('1967-07-16?00: 00:00') 执行 (0.8ms) 如果@@TRANCOUNT > 0 回滚事务
如何ODBC::Error: 22008 (241) ...
从ActiveRecord::Base.connection.execute
in 中获取上述错误消息 () rescue
?