diff --git a/source/shared/core_stmt.cpp b/source/shared/core_stmt.cpp index a2fd1501..87c58a36 100644 --- a/source/shared/core_stmt.cpp +++ b/source/shared/core_stmt.cpp @@ -1026,7 +1026,7 @@ void core_sqlsrv_sensitivity_metadata( _Inout_ sqlsrv_stmt* stmt TSRMLS_DC ) throw core::CoreException(); } - CHECK_CUSTOM_ERROR(true, stmt, SQLSRV_ERROR_DATA_CLASSIFICATION_FAILED, "Unexpected SQL Error state") { + CHECK_CUSTOM_ERROR(true, stmt, SQLSRV_ERROR_DATA_CLASSIFICATION_FAILED, "Check if ODBC driver or the server supports the Data Classification feature.") { throw core::CoreException(); } } diff --git a/test/functional/pdo_sqlsrv/pdo_data_classification.phpt b/test/functional/pdo_sqlsrv/pdo_data_classification.phpt index fd37e07f..13add5bb 100644 --- a/test/functional/pdo_sqlsrv/pdo_data_classification.phpt +++ b/test/functional/pdo_sqlsrv/pdo_data_classification.phpt @@ -57,7 +57,7 @@ function testConnAttrCases() } } -function testNotAvailable($conn, $tableName, $isSupported) +function testNotAvailable($conn, $tableName, $isSupported, $driverCapable) { // If supported, the query should return a column with no classification $options = array(PDO::SQLSRV_ATTR_DATA_CLASSIFICATION => true); @@ -66,25 +66,31 @@ function testNotAvailable($conn, $tableName, $isSupported) $stmt->execute(); $notAvailableErr = '*Failed to retrieve Data Classification Sensitivity Metadata. If the driver and the server both support the Data Classification feature, check whether the query returns columns with classification information.'; + + $unexpectedErrorState = '*Failed to retrieve Data Classification Sensitivity Metadata: Check if ODBC driver or the server supports the Data Classification feature.'; + + $error = ($driverCapable) ? $notAvailableErr : $unexpectedErrorState; try { $metadata = $stmt->getColumnMeta(0); echo "testNotAvailable: expected getColumnMeta to fail\n"; } catch (PDOException $e) { - if (!fnmatch($notAvailableErr, $e->getMessage())) { + if (!fnmatch($error, $e->getMessage())) { echo "testNotAvailable: exception unexpected\n"; var_dump($e->getMessage()); } } } -function isDataClassSupported($conn) +function isDataClassSupported($conn, &$driverCapable) { // Check both SQL Server version and ODBC driver version $msodbcsqlVer = $conn->getAttribute(PDO::ATTR_CLIENT_VERSION)["DriverVer"]; $version = explode(".", $msodbcsqlVer); // ODBC Driver must be 17.2 or above + $driverCapable = true; if ($version[0] < 17 || $version[1] < 2) { + $driverCapable = false; return false; } @@ -238,7 +244,8 @@ try { testConnAttrCases(); $conn = connect(); - $isSupported = isDataClassSupported($conn); + $driverCapable = true; + $isSupported = isDataClassSupported($conn, $driverCapable); // Create a test table $tableName = 'pdoPatients'; @@ -274,7 +281,7 @@ try { } // Test another error condition - testNotAvailable($conn, $tableName, $isSupported); + testNotAvailable($conn, $tableName, $isSupported, $driverCapable); // Run the query without data classification metadata $tsql = "SELECT * FROM $tableName"; diff --git a/test/functional/sqlsrv/sqlsrv_data_classification.phpt b/test/functional/sqlsrv/sqlsrv_data_classification.phpt index 2d6cce42..ab06cce6 100644 --- a/test/functional/sqlsrv/sqlsrv_data_classification.phpt +++ b/test/functional/sqlsrv/sqlsrv_data_classification.phpt @@ -10,7 +10,7 @@ PHPT_EXEC=true $timeout)); +$timeout = 20; +$maxAttempts = 3; +$numAttempts = 0; +$leeway = 1.0; +$missed = false; -$t1 = microtime(true); +do { + $t0 = microtime(true); -$elapsed = $t1 - $t0; -$diff = abs($elapsed - $timeout); + $conn = sqlsrv_connect($serverName , array("LoginTimeout" => $timeout)); + $numAttempts++; -if ($elapsed < $timeout || $diff > 1.0) { - echo "Connection failed at $elapsed secs. Leeway is 1.0 sec but the difference is $diff\n"; -} + $t1 = microtime(true); -print "Done"; + // Sometimes time elapsed might be less than expected timeout, such as 19.99* + // something, but 1.0 second leeway should be reasonable + $elapsed = $t1 - $t0; + $diff = abs($elapsed - $timeout); + + $missed = ($diff > $leeway); + if ($missed) { + if ($numAttempts == $maxAttempts) { + echo "Connection failed at $elapsed secs. Leeway is $leeway sec but the difference is $diff\n"; + } else { + // The test will fail but this helps us decide if this test should be redesigned + echo "$numAttempts\t"; + sleep(5); + } + } +} while ($missed && $numAttempts < $maxAttempts); + +print "Done\n"; ?> --EXPECT-- Done