added error handling for using direct_query and emulate_prepare in a Column Encryption enabled connection
This commit is contained in:
parent
779c39abc2
commit
631f80a9af
|
@ -1146,10 +1146,20 @@ int pdo_sqlsrv_stmt_param_hook( _Inout_ pdo_stmt_t *stmt,
|
||||||
|
|
||||||
// since the param isn't reliable, we don't do anything here
|
// since the param isn't reliable, we don't do anything here
|
||||||
case PDO_PARAM_EVT_ALLOC:
|
case PDO_PARAM_EVT_ALLOC:
|
||||||
|
{
|
||||||
|
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)) {
|
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);
|
THROW_PDO_ERROR(driver_stmt, PDO_SQLSRV_ERROR_EMULATE_INOUT_UNSUPPORTED);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case PDO_PARAM_EVT_FREE:
|
case PDO_PARAM_EVT_FREE:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -409,6 +409,14 @@ pdo_error PDO_ERRORS[] = {
|
||||||
SQLSRV_ERROR_SPECIFIED_DRIVER_NOT_FOUND,
|
SQLSRV_ERROR_SPECIFIED_DRIVER_NOT_FOUND,
|
||||||
{ IMSSP, (SQLCHAR*) "The specified ODBC Driver is not found.", -80, false }
|
{ IMSSP, (SQLCHAR*) "The specified ODBC Driver is not found.", -80, false }
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
PDO_SQLSRV_ERROR_CE_DIRECT_QUERY_UNSUPPORTED,
|
||||||
|
{ IMSSP, (SQLCHAR*) "Connection with Column Encryption enabled do no support PDO::SQLSRV_ATTR_DIRECT_QUERY with binding parameters.", -81, false }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
PDO_SQLSRV_ERROR_CE_EMULATE_PREPARE_UNSUPPORTED,
|
||||||
|
{ IMSSP, (SQLCHAR*) "Connection with Column Encryption enabled do no support PDO::ATTR_EMULATE_PREPARES with binding parameters.", -82, false }
|
||||||
|
},
|
||||||
{ UINT_MAX, {} }
|
{ UINT_MAX, {} }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -393,7 +393,9 @@ enum PDO_ERROR_CODES {
|
||||||
PDO_SQLSRV_ERROR_INVALID_OUTPUT_PARAM_TYPE,
|
PDO_SQLSRV_ERROR_INVALID_OUTPUT_PARAM_TYPE,
|
||||||
PDO_SQLSRV_ERROR_INVALID_CURSOR_WITH_SCROLL_TYPE,
|
PDO_SQLSRV_ERROR_INVALID_CURSOR_WITH_SCROLL_TYPE,
|
||||||
PDO_SQLSRV_ERROR_EMULATE_INOUT_UNSUPPORTED,
|
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[];
|
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 emulate prepare utf8 encoding set at the statement level
|
||||||
|
--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] != "Connection with Column Encryption enabled do no support PDO::SQLSRV_ATTR_DIRECT_QUERY with binding parameters.") {
|
||||||
|
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] != "Connection with Column Encryption enabled do no support PDO::ATTR_EMULATE_PREPARES with binding parameters.") {
|
||||||
|
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