How to get ActiveRecord :: Base.connection.execute error?

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 

In the webrick console, an error ( 1967-07-16?00:00:00 ) is displayed as:

EXECUTE (0.0ms) ODBC :: Error: 22008 (241) [unixODBC] [FreeTDS] [SQL Server] Syntax error converting date and time from character string .: INSERT INTO pinfo (date of birth) VALUES ('1967-07-16 ? 00: 00: 00 ') EXECUTE (0.8 ms) IF @@ TRANCOUNT> 0 ROLLBACK TRANSACTION

How can I get the above error message ( ODBC::Error: 22008 (241) ... ) raised from ActiveRecord::Base.connection.execute in rescue ?

+4
source share
1 answer
  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 

thanks

+1
source

Source: https://habr.com/ru/post/1496706/


All Articles