From 6809f0f7ea4f2ec5d10bcaaf5699d6aebdeb82f1 Mon Sep 17 00:00:00 2001 From: ulvii Date: Mon, 27 Mar 2017 14:07:43 -0700 Subject: [PATCH] Workaround for a bug in unixODBC 2.3.4 (#334) * Adding a workaround for the error handling issue with unixODBC 2.3.4 when conneciton pooling is enabled * Adding a check to apply the workaround only to PDO SQLSRV * Update core_util.cpp * Unix Conn Pool test * Modifying the test to use autonomous_setup.php * Updating path to isPooled.php --- source/shared/core_util.cpp | 11 +++++++++ test/pdo_sqlsrv/PDO_ConnPool_Unix.phpt | 34 ++++++++++++++++++++++++++ test/pdo_sqlsrv/isPooled.php | 25 +++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 test/pdo_sqlsrv/PDO_ConnPool_Unix.phpt create mode 100644 test/pdo_sqlsrv/isPooled.php diff --git a/source/shared/core_util.cpp b/source/shared/core_util.cpp index 94b5bf6d..4eeeb6d0 100644 --- a/source/shared/core_util.cpp +++ b/source/shared/core_util.cpp @@ -247,6 +247,17 @@ bool core_sqlsrv_get_odbc_error( sqlsrv_context& ctx, int record_number, sqlsrv_ r = SQLGetDiagRecW( h_type, h, record_number, wsqlstate, &error->native_code, wnative_message, SQL_MAX_MESSAGE_LENGTH + 1, &wmessage_len ); // don't use the CHECK* macros here since it will trigger reentry into the error handling system + // Workaround for a bug in unixODBC 2.3.4 when connection pooling is enabled (PDO SQLSRV). + // Instead of returning false, we return an empty error message to prevent the driver from throwing an exception. + // To reproduce: + // Create a connection and close it (return it to the pool) + // Create a new connection from the pool. + // Prepare and execute a statement that generates an info message (such as 'USE tempdb;') +#ifdef __APPLE__ + if( r == SQL_NO_DATA && ctx.driver() != NULL /*PDO SQLSRV*/ ) { + r = SQL_SUCCESS; + } +#endif // __APPLE__ if( !SQL_SUCCEEDED( r ) || r == SQL_NO_DATA ) { return false; } diff --git a/test/pdo_sqlsrv/PDO_ConnPool_Unix.phpt b/test/pdo_sqlsrv/PDO_ConnPool_Unix.phpt new file mode 100644 index 00000000..d402ac93 --- /dev/null +++ b/test/pdo_sqlsrv/PDO_ConnPool_Unix.phpt @@ -0,0 +1,34 @@ +--TEST-- +PDO Connection Pooling Test on Unix +This test assumes odbcinst.ini has not been modified. +This test also requires root privileges to modify odbcinst.ini file on Linux. +--SKIPIF-- + +--EXPECT-- +Pooled +Not Pooled + + diff --git a/test/pdo_sqlsrv/isPooled.php b/test/pdo_sqlsrv/isPooled.php new file mode 100644 index 00000000..17ffea9f --- /dev/null +++ b/test/pdo_sqlsrv/isPooled.php @@ -0,0 +1,25 @@ +query($tsql); + $connID = $stmt->fetchColumn(0); + $stmt->closeCursor(); + $stmt = null; + return ($connID); +} +?>