From cbd3c18cb6bcc5693f6b9f7c9619669cfbaef8e4 Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Tue, 20 Oct 2020 17:33:40 -0700 Subject: [PATCH] Extended sqlsrv large stream test --- .../pdo_sqlsrv/pdo_fetch_large_stream.phpt | 6 +- .../sqlsrv/sqlsrv_fetch_large_stream.phpt | 60 ++++++++++++++----- 2 files changed, 46 insertions(+), 20 deletions(-) diff --git a/test/functional/pdo_sqlsrv/pdo_fetch_large_stream.phpt b/test/functional/pdo_sqlsrv/pdo_fetch_large_stream.phpt index ff780694..5f106b2e 100644 --- a/test/functional/pdo_sqlsrv/pdo_fetch_large_stream.phpt +++ b/test/functional/pdo_sqlsrv/pdo_fetch_large_stream.phpt @@ -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(); diff --git a/test/functional/sqlsrv/sqlsrv_fetch_large_stream.phpt b/test/functional/sqlsrv/sqlsrv_fetch_large_stream.phpt index 7b6f6e40..92dd954b 100644 --- a/test/functional/sqlsrv/sqlsrv_fetch_large_stream.phpt +++ b/test/functional/sqlsrv/sqlsrv_fetch_large_stream.phpt @@ -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-- --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;