Merge pull request #579 from v-kaywon/error_direct_emulate
added error handling for using direct_query and emulate_prepare in a Column Encryption enabled connection
This commit is contained in:
commit
9bbc673023
|
@ -1146,9 +1146,19 @@ int pdo_sqlsrv_stmt_param_hook( _Inout_ pdo_stmt_t *stmt,
|
|||
|
||||
// since the param isn't reliable, we don't do anything here
|
||||
case PDO_PARAM_EVT_ALLOC:
|
||||
if ( stmt->supports_placeholders == PDO_PLACEHOLDER_NONE && (param->param_type & PDO_PARAM_INPUT_OUTPUT )) {
|
||||
sqlsrv_stmt* driver_stmt = reinterpret_cast<sqlsrv_stmt*>( stmt->driver_data );
|
||||
THROW_PDO_ERROR( driver_stmt, PDO_SQLSRV_ERROR_EMULATE_INOUT_UNSUPPORTED );
|
||||
{
|
||||
pdo_sqlsrv_stmt* driver_stmt = reinterpret_cast<pdo_sqlsrv_stmt*>(stmt->driver_data);
|
||||
if (driver_stmt->conn->ce_option.enabled) {
|
||||
if (driver_stmt->direct_query) {
|
||||
THROW_PDO_ERROR(driver_stmt, PDO_SQLSRV_ERROR_CE_DIRECT_QUERY_UNSUPPORTED);
|
||||
}
|
||||
if (stmt->supports_placeholders == PDO_PLACEHOLDER_NONE) {
|
||||
THROW_PDO_ERROR(driver_stmt, PDO_SQLSRV_ERROR_CE_EMULATE_PREPARE_UNSUPPORTED);
|
||||
}
|
||||
}
|
||||
if (stmt->supports_placeholders == PDO_PLACEHOLDER_NONE && (param->param_type & PDO_PARAM_INPUT_OUTPUT)) {
|
||||
THROW_PDO_ERROR(driver_stmt, PDO_SQLSRV_ERROR_EMULATE_INOUT_UNSUPPORTED);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PDO_PARAM_EVT_FREE:
|
||||
|
|
|
@ -409,6 +409,14 @@ pdo_error PDO_ERRORS[] = {
|
|||
SQLSRV_ERROR_SPECIFIED_DRIVER_NOT_FOUND,
|
||||
{ IMSSP, (SQLCHAR*) "The specified ODBC Driver is not found.", -80, false }
|
||||
},
|
||||
{
|
||||
PDO_SQLSRV_ERROR_CE_DIRECT_QUERY_UNSUPPORTED,
|
||||
{ IMSSP, (SQLCHAR*) "Parameterized statement with attribute PDO::SQLSRV_ATTR_DIRECT_QUERY is not supported in a Column Encryption enabled Connection.", -81, false }
|
||||
},
|
||||
{
|
||||
PDO_SQLSRV_ERROR_CE_EMULATE_PREPARE_UNSUPPORTED,
|
||||
{ IMSSP, (SQLCHAR*) "Parameterized statement with attribute PDO::ATTR_EMULATE_PREPARES is not supported in a Column Encryption enabled Connection.", -82, false }
|
||||
},
|
||||
{ UINT_MAX, {} }
|
||||
};
|
||||
|
||||
|
|
|
@ -393,7 +393,9 @@ enum PDO_ERROR_CODES {
|
|||
PDO_SQLSRV_ERROR_INVALID_OUTPUT_PARAM_TYPE,
|
||||
PDO_SQLSRV_ERROR_INVALID_CURSOR_WITH_SCROLL_TYPE,
|
||||
PDO_SQLSRV_ERROR_EMULATE_INOUT_UNSUPPORTED,
|
||||
PDO_SQLSRV_ERROR_INVALID_AUTHENTICATION_OPTION
|
||||
PDO_SQLSRV_ERROR_INVALID_AUTHENTICATION_OPTION,
|
||||
PDO_SQLSRV_ERROR_CE_DIRECT_QUERY_UNSUPPORTED,
|
||||
PDO_SQLSRV_ERROR_CE_EMULATE_PREPARE_UNSUPPORTED
|
||||
};
|
||||
|
||||
extern pdo_error PDO_ERRORS[];
|
||||
|
|
66
test/functional/pdo_sqlsrv/pdo_ae_unsupported_stmt_attr.phpt
Normal file
66
test/functional/pdo_sqlsrv/pdo_ae_unsupported_stmt_attr.phpt
Normal file
|
@ -0,0 +1,66 @@
|
|||
--TEST--
|
||||
Test error from preparing a parameterized query with direct query or emulate prepare when Column Encryption is enabled
|
||||
--SKIPIF--
|
||||
<?php require('skipif_mid-refactor.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once("MsCommon_mid-refactor.inc");
|
||||
|
||||
try {
|
||||
$connection = connect();
|
||||
$tbname = "TEST";
|
||||
createTable($connection, $tbname, array(new ColumnMeta("int", "id", "IDENTITY(1,1) NOT NULL"), "name" => "nvarchar(max)"));
|
||||
} catch (PDOException $e) {
|
||||
var_dump($e->errorInfo);
|
||||
}
|
||||
|
||||
try {
|
||||
$name = "Edward";
|
||||
$st = $connection->prepare("INSERT INTO $tbname (name) VALUES (:p0)", array(PDO::SQLSRV_ATTR_DIRECT_QUERY => true));
|
||||
$st->execute(array("p0" => $name));
|
||||
} catch (PDOException $e) {
|
||||
$error = $e->errorInfo;
|
||||
// expects an exception if Column Encryption is enabled
|
||||
if (isColEncrypted()) {
|
||||
if ($error[0] != "IMSSP" ||
|
||||
$error[1] != -81 ||
|
||||
$error[2] != "Parameterized statement with attribute PDO::SQLSRV_ATTR_DIRECT_QUERY is not supported in a Column Encryption enabled Connection.") {
|
||||
echo "An unexpected exception was caught.\n";
|
||||
var_dump($error);
|
||||
}
|
||||
} else {
|
||||
var_dump($error);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$name = "Alphonse";
|
||||
$st = $connection->prepare("INSERT INTO $tbname (name) VALUES (:p0)", array(PDO::ATTR_EMULATE_PREPARES => true));
|
||||
$st->execute(array("p0" => $name));
|
||||
} catch (PDOException $e) {
|
||||
$error = $e->errorInfo;
|
||||
// expects an exception if Column Encryption is enabled
|
||||
if (isColEncrypted()) {
|
||||
if ($error[0] != "IMSSP" ||
|
||||
$error[1] != -82 ||
|
||||
$error[2] != "Parameterized statement with attribute PDO::ATTR_EMULATE_PREPARES is not supported in a Column Encryption enabled Connection.") {
|
||||
echo "An unexpected exception was caught.\n";
|
||||
var_dump($error);
|
||||
}
|
||||
} else {
|
||||
var_dump($error);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
dropTable($connection, $tbname);
|
||||
unset($st);
|
||||
unset($connection);
|
||||
} catch (PDOException $e) {
|
||||
var_dump($e->errorInfo);
|
||||
}
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
Done
|
Loading…
Reference in a new issue