added more error checking when driver option is set
This commit is contained in:
parent
7e6ac5e7b6
commit
0cbc00384c
|
@ -405,6 +405,10 @@ pdo_error PDO_ERRORS[] = {
|
|||
SQLSRV_ERROR_CONNECT_INVALID_DRIVER,
|
||||
{ IMSSP, (SQLCHAR*) "Invalid value %1!s! was specified for Driver option.", -79, true }
|
||||
},
|
||||
{
|
||||
SQLSRV_ERROR_SPECIFIED_DRIVER_NOT_FOUND,
|
||||
{ IMSSP, (SQLCHAR*) "The specified ODBC Driver is not found.", -80, false }
|
||||
},
|
||||
{ UINT_MAX, {} }
|
||||
};
|
||||
|
||||
|
|
|
@ -153,11 +153,17 @@ sqlsrv_conn* core_sqlsrv_connect( _In_ sqlsrv_context& henv_cp, _In_ sqlsrv_cont
|
|||
if( conn->ce_option.enabled ) {
|
||||
// when AE is enabled, must use ODBC driver 17
|
||||
if( conn->driver_version != ODBC_DRIVER_UNKNOWN ) {
|
||||
CHECK_CUSTOM_ERROR( conn->driver_version != ODBC_DRIVER_17, conn, SQLSRV_ERROR_AE_DRIVER_REQUIRED, get_processor_arch()) {
|
||||
CHECK_CUSTOM_ERROR( conn->driver_version != ODBC_DRIVER_17, conn, SQLSRV_ERROR_AE_DRIVER_REQUIRED, get_processor_arch() ) {
|
||||
throw core::CoreException();
|
||||
}
|
||||
|
||||
r = core_odbc_connect( conn, conn_str, is_pooled );
|
||||
if( ! SQL_SUCCEEDED( r ) && core_compare_error_state( conn, r, "IM002" ) ) {
|
||||
// sql state IM002 means that the specified ODBC driver is not installed
|
||||
CHECK_CUSTOM_ERROR( true, conn, SQLSRV_ERROR_SPECIFIED_DRIVER_NOT_FOUND, CONNECTION_STRING_DRIVER_NAME[ conn->driver_version ].c_str() ) {
|
||||
throw core::CoreException();
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// driver not specified, so connect using ODBC 17
|
||||
|
@ -180,7 +186,7 @@ sqlsrv_conn* core_sqlsrv_connect( _In_ sqlsrv_context& henv_cp, _In_ sqlsrv_cont
|
|||
|
||||
if(! SQL_SUCCEEDED( r ) ) {
|
||||
// sql state IM002 means that the specified ODBC driver is not installed
|
||||
CHECK_CUSTOM_ERROR( core_compare_error_state( conn, r, "IM002" ) , conn, SQLSRV_ERROR_AE_DRIVER_REQUIRED, get_processor_arch()) {
|
||||
CHECK_CUSTOM_ERROR( core_compare_error_state( conn, r, "IM002" ) , conn, SQLSRV_ERROR_AE_DRIVER_REQUIRED, get_processor_arch() ) {
|
||||
throw core::CoreException();
|
||||
}
|
||||
}
|
||||
|
@ -190,6 +196,13 @@ sqlsrv_conn* core_sqlsrv_connect( _In_ sqlsrv_context& henv_cp, _In_ sqlsrv_cont
|
|||
else {
|
||||
if( conn->driver_version != ODBC_DRIVER_UNKNOWN ) {
|
||||
r = core_odbc_connect( conn, conn_str, is_pooled );
|
||||
|
||||
if( ! SQL_SUCCEEDED( r ) && core_compare_error_state( conn, r, "IM002" ) ) {
|
||||
// sql state IM002 means that the specified ODBC driver is not installed
|
||||
CHECK_CUSTOM_ERROR( true, conn, SQLSRV_ERROR_SPECIFIED_DRIVER_NOT_FOUND, CONNECTION_STRING_DRIVER_NAME[ conn->driver_version ].c_str() ) {
|
||||
throw core::CoreException();
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
#ifndef _WIN32
|
||||
|
|
|
@ -1644,6 +1644,7 @@ enum SQLSRV_ERROR_CODES {
|
|||
SQLSRV_ERROR_DRIVER_NOT_INSTALLED,
|
||||
SQLSRV_ERROR_AE_DRIVER_REQUIRED,
|
||||
SQLSRV_ERROR_CONNECT_INVALID_DRIVER,
|
||||
SQLSRV_ERROR_SPECIFIED_DRIVER_NOT_FOUND,
|
||||
SQLSRV_ERROR_ZEND_HASH,
|
||||
SQLSRV_ERROR_INVALID_PARAMETER_PHPTYPE,
|
||||
SQLSRV_ERROR_INVALID_PARAMETER_SQLTYPE,
|
||||
|
|
|
@ -404,6 +404,10 @@ ss_error SS_ERRORS[] = {
|
|||
SQLSRV_ERROR_CONNECT_INVALID_DRIVER,
|
||||
{ IMSSP, (SQLCHAR*) "Invalid value %1!s! was specified for Driver option.", -106, true }
|
||||
},
|
||||
{
|
||||
SQLSRV_ERROR_SPECIFIED_DRIVER_NOT_FOUND,
|
||||
{ IMSSP, (SQLCHAR*) "The specified ODBC Driver is not found.", -107, false }
|
||||
},
|
||||
// terminate the list of errors/warnings
|
||||
{ UINT_MAX, {} }
|
||||
};
|
||||
|
|
|
@ -24,7 +24,7 @@ $conn = null;
|
|||
// start test
|
||||
test_valid_values();
|
||||
test_invalid_values();
|
||||
test_encrypted_with_odbc13();
|
||||
test_encrypted_with_odbc();
|
||||
echo "Done";
|
||||
// end test
|
||||
|
||||
|
@ -121,14 +121,25 @@ function test_invalid_values()
|
|||
connect_verify_output( $connectionOptions, $expected );
|
||||
}
|
||||
|
||||
function test_encrypted_with_odbc13()
|
||||
function test_encrypted_with_odbc()
|
||||
{
|
||||
global $msodbcsql_maj;
|
||||
|
||||
$value = "ODBC Driver 13 for SQL Server";
|
||||
$connectionOptions = "Driver = $value; ColumnEncryption = Enabled;";
|
||||
|
||||
$connectionOptions = "Driver = $value; ColumnEncryption = Enabled;";
|
||||
$expected = "The Always Encrypted feature requires Microsoft ODBC Driver 17 for SQL Server.";
|
||||
|
||||
connect_verify_output( $connectionOptions, $expected );
|
||||
|
||||
$value = "ODBC Driver 11 for SQL Server";
|
||||
if ( $msodbcsql_maj == 17 || $msodbcsql_maj < 13 )
|
||||
{
|
||||
$value = "ODBC Driver 13 for SQL Server";
|
||||
}
|
||||
$connectionOptions = "Driver = $value;";
|
||||
$expected = "The specified ODBC Driver is not found";
|
||||
|
||||
connect_verify_output( $connectionOptions, $expected );
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -7,7 +7,7 @@ Test new connection keyword Driver with valid and invalid values
|
|||
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
|
||||
require( 'MsSetup.inc' );
|
||||
|
||||
$connectionOptions = array("Database"=>$database,"UID"=>$userName, "PWD"=>$userPassword);
|
||||
$connectionOptions = array("Database"=>$database, "UID"=>$userName, "PWD"=>$userPassword);
|
||||
$conn = sqlsrv_connect($server, $connectionOptions);
|
||||
if ($conn === false)
|
||||
{
|
||||
|
@ -20,7 +20,7 @@ sqlsrv_close($conn);
|
|||
// start test
|
||||
test_valid_values( $msodbcsql_maj, $server, $connectionOptions );
|
||||
test_invalid_values( $msodbcsql_maj, $server, $connectionOptions );
|
||||
test_encrypted_with_odbc13( $server, $connectionOptions );
|
||||
test_encrypted_with_odbc( $msodbcsql_maj, $server, $connectionOptions );
|
||||
echo "Done";
|
||||
// end test
|
||||
|
||||
|
@ -109,7 +109,7 @@ function test_invalid_values( $msodbcsql_maj, $server, $connectionOptions )
|
|||
connect_verify_output( $server, $connectionOptions, $expected );
|
||||
}
|
||||
|
||||
function test_encrypted_with_odbc13( $server, $connectionOptions )
|
||||
function test_encrypted_with_odbc( $msodbcsql_maj, $server, $connectionOptions )
|
||||
{
|
||||
$value = "ODBC Driver 13 for SQL Server";
|
||||
$connectionOptions['Driver']=$value;
|
||||
|
@ -118,6 +118,18 @@ function test_encrypted_with_odbc13( $server, $connectionOptions )
|
|||
$expected = "The Always Encrypted feature requires Microsoft ODBC Driver 17 for SQL Server.";
|
||||
|
||||
connect_verify_output( $server, $connectionOptions, $expected );
|
||||
|
||||
$value = "ODBC Driver 11 for SQL Server";
|
||||
if ( $msodbcsql_maj == 17 || $msodbcsql_maj < 13 )
|
||||
{
|
||||
$value = "ODBC Driver 13 for SQL Server";
|
||||
}
|
||||
|
||||
$connectionOptions['Driver']=$value;
|
||||
$connectionOptions['ColumnEncryption']='Disabled';
|
||||
$expected = "The specified ODBC Driver is not found";
|
||||
|
||||
connect_verify_output( $server, $connectionOptions, $expected );
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
Loading…
Reference in a new issue