Merge pull request #636 from v-kaywon/fixPDOTests3

fix tests related to having parameter markers in the select list
This commit is contained in:
Yuki Wong 2017-12-19 16:12:04 -08:00 committed by GitHub
commit 32677998a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 71 additions and 25 deletions

View file

@ -15,9 +15,9 @@ try {
// Prepare test table
$tableName = "pdo_test_table";
createTable($conn1, $tableName, array("id" => "int", "class" => "int", "value" => "char(32)"));
createTable($conn1, $tableName, array(new ColumnMeta("int", "id", "IDENTITY NOT NULL"), "class" => "int", "value" => "char(32)"));
$conn1->exec("CREATE CLUSTERED INDEX [idx_test_int] ON $tableName (id)");
$tsql = "INSERT INTO [$tableName] (id, class, value) VALUES(:id, :class, :value)";
$tsql = "INSERT INTO [$tableName] (class, value) VALUES(:class, :value)";
$id = 0;
$class = 0;
@ -25,22 +25,18 @@ try {
// Prepare insert query$
$stmt1 = $conn1->prepare($tsql);
bindParam(1, $stmt1, ':id', $id);
bindParam(2, $stmt1, ':class', $class);
bindParam(3, $stmt1, ':value', $value);
bindParam(1, $stmt1, ':class', $class);
bindParam(2, $stmt1, ':value', $value);
// Insert test rows
$id = 1;
$class = 4;
$value = '2011';
execStmt(1, $stmt1);
$id = 2;
$class = 5;
$value = 'Sat, 20 Mar 10 21:29:13 -0600';
execStmt(2, $stmt1);
$id = 3;
$class = 6;
$value = 'Fri, 07 May 10 11:35:32 -0600';
execStmt(3, $stmt1);
@ -50,7 +46,7 @@ try {
// Check data
$id = 0;
$value = '';
$tsql = "SELECT id, value FROM [$tableName]";
$tsql = "SELECT id, value FROM [$tableName] ORDER BY id";
$stmt2 = $conn1->query($tsql);
bindColumn(1, $stmt2, $id, $value);
while ($stmt2->fetch(PDO::FETCH_BOUND)) {

View file

@ -12,9 +12,15 @@ function testSimpleSelect($conn, $tableName)
{
$count = 0;
$stmt = $conn->prepare("SELECT ? = COUNT(* ) FROM $tableName");
$stmt->bindParam(1, $count, PDO::PARAM_INT, 4);
$stmt->execute();
if (!isAEConnected()) {
$stmt = $conn->prepare("SELECT ? = COUNT(* ) FROM $tableName");
$stmt->bindParam(1, $count, PDO::PARAM_INT, 4);
$stmt->execute();
} else {
$stmt = $conn->prepare("SELECT COUNT(*) FROM $tableName");
$stmt->execute();
$count = $stmt->fetch()[0];
}
echo "Number of rows: $count\n";
$value = 'xx';
@ -51,6 +57,16 @@ function createVariantTable($conn, $tableName)
}
}
function checkError($e, $expMsg, $aeExpMsg)
{
$error = $e->getMessage();
if (!isAEConnected()) {
if (strpos($error, $expMsg) === false) echo $error;
} else {
if (strpos($error, $aeExpMsg) === false) echo $error;
}
}
try {
// Connect
$conn = connect();
@ -65,12 +81,14 @@ try {
dropTable($conn, $tableName);
unset($conn);
} catch (Exception $e) {
echo $e->getMessage();
// binding parameters in the select list is not supported with Column Encryption
$expMsg = "Implicit conversion from data type sql_variant to nvarchar(max) is not allowed. Use the CONVERT function to run this query.";
$aeExpMsg = "Invalid Descriptor Index";
checkError($e, $expMsg, $aeExpMsg);
}
echo "\nDone\n";
echo "Done\n";
?>
--EXPECTREGEX--
--EXPECT--
Number of rows: 1
SQLSTATE\[42000\]: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]\[SQL Server\]Implicit conversion from data type sql_variant to nvarchar\(max\) is not allowed. Use the CONVERT function to run this query.
Done

View file

@ -44,8 +44,13 @@ if (isAEConnected()) {
$option[PDO::ATTR_EMULATE_PREPARES] = false;
}
$s = $db->prepare("SELECT :prefix + TITLE FROM cd_info GROUP BY :prefix + TITLE", $option);
$s->bindValue(':prefix', "");
if (!isAEConnected()) {
$s = $db->prepare("SELECT :prefix + TITLE FROM cd_info GROUP BY :prefix + TITLE", $option);
$s->bindValue(':prefix', "");
} else {
// binding parameters in the select list is not supported with Column Encryption
$s = $db->prepare("SELECT TITLE FROM cd_info GROUP BY TITLE", $option);
}
$s->execute();
$param_titles = array();

View file

@ -70,9 +70,25 @@ try {
print_r("Prepare with emulate prepare and and SQLSRV_ENCODING_SYSTEM:\n");
$stmt = prepareStmt($conn, $query, $options, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_SYSTEM);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
print_r($row);
if ($stmt->rowCount() == 0) {
print_r("No results for this query\n");
// The combination of Column Encryption and Unix platforms support SQLSRV_ENCODING_SYSTEM because:
// With Column Encryption enabled, binding parameters uses exact datatypes as the column definition
// the default encoding in Linux and Mac is UTF8
$success = true;
if (!(strtoupper( substr( php_uname( 's' ),0,3 ) ) === 'WIN') && isAEConnected()) {
if ($row['name'] != "가각" || $row['status'] != 1 || $row['age'] != 30) {
print_r("Incorrect results retrieved.\n");
$success = false;
}
} else {
// the default encoding in Windows is non-UTF8, thus binding UTF8 parameters does not work
if ($stmt->rowCount() != 0) {
print_r("Binding UTF8 data when encoding is SQLSRV_ENCODING_SYSTEM should not work.\n");
$success = false;
}
}
if ($success) {
print_r("Binding UTF8 data with SQLSRV_ENCODING_SYSTEM is tested successfully.\n");
}
//with emulate prepare and encoding SQLSRV_ENCODING_BINARY
@ -110,6 +126,6 @@ Array
[age] => 30
)
Prepare with emulate prepare and and SQLSRV_ENCODING_SYSTEM:
No results for this query
Binding UTF8 data with SQLSRV_ENCODING_SYSTEM is tested successfully.
Prepare with emulate prepare and encoding SQLSRV_ENCODING_BINARY:
No results for this query

View file

@ -6,6 +6,16 @@ Test UTF8 Encoding with emulate prepare
<?php
require_once("MsCommon_mid-refactor.inc");
function checkError($e, $expMsg, $aeExpMsg)
{
$error = $e->getMessage();
if (!isAEConnected()) {
if (strpos($error, $expMsg) === false) echo $error;
} else {
if (strpos($error, $aeExpMsg) === false) echo $error;
}
}
try {
$inValue1 = pack('H*', '3C586D6C54657374446174613E4A65207072C3A966C3A87265206C27C3A974C3A93C2F586D6C54657374446174613E');
$inValueLen = strlen($inValue1);
@ -72,8 +82,10 @@ try {
dropTable($conn, $tbname);
unset($conn);
} catch (PDOexception $e) {
print_r(($e->errorInfo)[2]);
echo "\n";
// binding parameters in the select list is not supported with Column Encryption
$expMsg = "Statement with emulate prepare on does not support output or input_output parameters.";
$aeExpMsg = "Invalid Descriptor Index";
checkError($e, $expMsg, $aeExpMsg);
}
?>
--EXPECT--
@ -83,4 +95,3 @@ outValue is the same as inValue.
outValue is the same as inValue.
outValue is the same as inValue.
outValue is the same as inValue.
Statement with emulate prepare on does not support output or input_output parameters.