From 53c280fe54b525dd02f37d895c98b163354055bf Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Tue, 28 Mar 2017 16:37:40 -0700 Subject: [PATCH] get error without recording it --- source/shared/core_sqlsrv.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/source/shared/core_sqlsrv.h b/source/shared/core_sqlsrv.h index af72ce7e..7f2dfc38 100644 --- a/source/shared/core_sqlsrv.h +++ b/source/shared/core_sqlsrv.h @@ -2041,17 +2041,20 @@ namespace core { SQLSMALLINT num_cols; r = ::SQLNumResultCols( stmt->handle(), &num_cols ); - // Workaround for a bug in unixODBC: after SQLExecDirect for an empty result set, + // Workaround for a bug in unixODBC: after SQLExecDirect returns SQL_NO_DATA, // r = ::SQLNumResultCols( stmt->handle(), &num_cols ); // returns r=-1 (SQL_ERROR) and error HY010 (Function sequence error) // but it should have succeeded with r=0 (SQL_SUCCESS) and no error // instead of throwing an exception, return 0 if the r=-1, stament has been executed, and has a HY010 error // (HY010 error should not return if stmt->execute is true) #ifndef _WIN32 - if ( r == -1 && stmt->executed && strcmp( reinterpret_cast( stmt->last_error()->sqlstate ), "HY010" ) == 0 ) + sqlsrv_error_auto_ptr error; + if ( stmt->current_results != NULL ) { + error = stmt->current_results->get_diag_rec( 1 ); + } + if ( r == -1 && stmt->executed && strcmp( reinterpret_cast( error->sqlstate ), "HY010" ) == 0 ) return 0; #endif // !_WIN32 - CHECK_SQL_ERROR_OR_WARNING( r, stmt ) { throw CoreException(); }