Extended sqlsrv large stream test

This commit is contained in:
Jenny Tam 2020-10-20 17:33:40 -07:00
parent a1a657f8c6
commit cbd3c18cb6
2 changed files with 46 additions and 20 deletions

View file

@ -70,8 +70,6 @@ function fetchBinary($conn, $buffered)
if (!checkData($value, $hexValue)) {
echo "Fetched binary value as UTF-8 string ($buffered): $value\n";
var_dump($hexValue);
var_dump($value);
}
} catch (PdoException $e) {
echo "Caught exception in fetchBinary ($buffered):\n";
@ -98,11 +96,11 @@ function fetchAsString($conn, $buffered)
$row = $stmt->fetch(PDO::FETCH_BOUND);
if (!checkData($value1, $strValue)) {
echo "Fetched string value: $value1\n";
echo "Fetched string value ($buffered): $value1\n";
}
if (!checkData($value2, $nstrValue)) {
echo "Fetched string value: $value2\n";
echo "Fetched string value ($buffered): $value2\n";
}
$stmt->execute();

View file

@ -1,7 +1,7 @@
--TEST--
Streaming Field Test
Test fetching varchar max and varbinary fields with client buffer
--DESCRIPTION--
Verifies the streaming behavior and proper error handling with Always Encrypted
Test fetching varbinary and varchar max fields as streams or strings with client buffer
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
--FILE--
@ -11,25 +11,44 @@ require_once('MsCommon.inc');
$conn = AE\connect();
$tableName = "test_max_fields";
AE\createTable($conn, $tableName, array(new AE\ColumnMeta("varchar(max)", "varchar_max_col")));
$inValue = str_repeat("ÃÜðßZZýA©", 600);
$insertSql = "INSERT INTO $tableName (varchar_max_col) VALUES (?)";
$params = array($inValue);
$columns = array(new AE\ColumnMeta("varchar(max)", "varchar_max_col"),
new AE\ColumnMeta("varbinary(max)", "varbinary_max_col"));
AE\createTable($conn, $tableName, $columns);
$strValue = str_repeat("ÃÜðßZZýA©", 600);
$input = strtoupper(bin2hex('abcdefghijklmnopqrstuvwxyz'));
$binaryValue = str_repeat($input, 100);
$insertSql = "INSERT INTO $tableName (varchar_max_col, varbinary_max_col) VALUES (?, ?)";
$params = array($strValue, array($binaryValue, null, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARBINARY('max')));
$stmt = sqlsrv_prepare($conn, $insertSql, $params);
if ($stmt) {
sqlsrv_execute($stmt);
}
$res = sqlsrv_execute($stmt);
if (!$res) {
fatalError("Failed to insert data");
}
} else {
fatalError("Failed to prepare insert statement");
}
$query = "SELECT * FROM $tableName";
$stmt = sqlsrv_prepare($conn, $query);
$stmt = sqlsrv_prepare($conn, $query, null, array("Scrollable"=>SQLSRV_CURSOR_CLIENT_BUFFERED));
if ($stmt) {
sqlsrv_execute($stmt);
}
$res = sqlsrv_execute($stmt);
if (!$res) {
fatalError("Failed to fetch data");
}
} else {
fatalError("Failed to prepare select statement");
}
if (!sqlsrv_fetch($stmt)) {
fatalError("Failed to fetch row ");
fatalError("Failed to fetch row");
}
$stream = sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_CHAR));
@ -42,16 +61,25 @@ if ($stream !== false) {
$value .= fread($stream, 8192);
}
fclose($stream);
if (checkData($value, $inValue)) { // compare the data to see if they match!
if (checkData($value, $strValue)) { // compare the data to see if they match!
$success = true;
}
}
if ($success) {
echo "Done.\n";
} else {
if (!$success) {
fatalError("Failed to fetch stream ");
}
$value = sqlsrv_get_field($stmt, 1, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
if (!checkData($value, $binaryValue)) { // compare the data to see if they match!
echo("Expected:\n$binaryValue\nActual:\n$value\n");
}
echo "Done.\n";
dropTable($conn, $tableName);
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
function checkData($actual, $expected)
{
$success = true;