Merge pull request #776 from yitam/streamTests

Modified BVT stream tests to make them more robust
This commit is contained in:
Jenny Tam 2018-05-24 10:45:49 -07:00 committed by GitHub
commit f0eefafa2e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 165 additions and 99 deletions

View file

@ -1,56 +1,76 @@
--TEST-- --TEST--
insert stream. insert stream.
--SKIPIF-- --SKIPIF--
--FILE--
?>
--FILE--
<?php <?php
/* Connect to the local server using Windows Authentication and /* Connect to the local server using Windows Authentication and
specify the AdventureWorks database as the database in use. */ specify the AdventureWorks database as the database in use. */
require('connect.inc'); require('connect.inc');
$connectionInfo = array( "Database"=>"$databaseName", "UID"=>"$uid", "PWD"=>"$pwd"); $connectionInfo = array( "Database"=>"$databaseName", "UID"=>"$uid", "PWD"=>"$pwd");
$conn = sqlsrv_connect( $server, $connectionInfo); $conn = sqlsrv_connect($server, $connectionInfo);
if( $conn === false ) if ($conn === false) {
{ echo "Could not connect.\n";
echo "Could not connect.\n"; die(print_r(sqlsrv_errors(), true));
die( print_r( sqlsrv_errors(), true));
} }
/* Remove any records with from the table with ProductID = 999*/
$productID = 999;
$tsql = "DELETE FROM Production.ProductReview WHERE ProductID = $productID";
sqlsrv_query($conn, $tsql);
/* Set up the Transact-SQL query. */ /* Set up the Transact-SQL query. */
$tsql = "INSERT INTO Production.ProductReview (ProductID, $tsql = "INSERT INTO Production.ProductReview (ProductID,
ReviewerName, ReviewerName,
ReviewDate, ReviewDate,
EmailAddress, EmailAddress,
Rating, Rating,
Comments) Comments)
VALUES (?, ?, ?, ?, ?, ?)"; VALUES (?, ?, ?, ?, ?, ?)";
/* Set the parameter values and put them in an array. /* Set the parameter values and put them in an array.
Note that $comments is opened as a stream. */ Note that $comments is opened as a stream. */
$productID = '709';
$number = rand(99, 9999);
$input = "[Insert some number $number]";
/* There is no record in this table with ProductID = 999 */
$name = 'Customer Name'; $name = 'Customer Name';
$date = date("Y-m-d"); $date = date("Y-m-d");
$email = 'customer@name.com'; $email = 'customer@name.com';
$rating = 3; $rating = 3;
$comments = fopen( "data://text/plain,[ Insert lengthy comment here.]", $comments = fopen("data://text/plain,$input", "r");
"r");
$params = array($productID, $name, $date, $email, $rating, $comments); $params = array($productID, $name, $date, $email, $rating, $comments);
/* Execute the query. All stream data is sent upon execution.*/ /* Execute the query. All stream data is sent upon execution.*/
$stmt = sqlsrv_query($conn, $tsql, $params); $stmt = sqlsrv_query($conn, $tsql, $params);
if( $stmt === false ) if ($stmt === false) {
{ echo "Error in statement execution.\n";
echo "Error in statement execution.\n"; die(print_r(sqlsrv_errors(), true));
die( print_r( sqlsrv_errors(), true));
}
else
{
echo "The query was successfully executed.";
} }
/* Read it back to check the comment */
$tsql = "SELECT Comments FROM Production.ProductReview
WHERE ProductID = $productID";
$stmt = sqlsrv_query($conn, $tsql);
if (sqlsrv_fetch($stmt)) {
$review = sqlsrv_get_field($stmt, 0);
if ($review !== $input) {
echo "Comment retrieved \'$review\' is incorrect!" . PHP_EOL;
}
} else {
echo "Error in retrieving comments!" . PHP_EOL;
die(print_r(sqlsrv_errors(), true));
}
/* Remove the entry from the table */
$tsql = "DELETE FROM Production.ProductReview WHERE ProductID = $productID";
sqlsrv_query($conn, $tsql);
echo "Done" . PHP_EOL;
/* Free statement and connection resources. */ /* Free statement and connection resources. */
sqlsrv_free_stmt( $stmt); sqlsrv_free_stmt($stmt);
sqlsrv_close( $conn); sqlsrv_close($conn);
?> ?>
--EXPECT-- --EXPECT--
The query was successfully executed. The query was successfully executed.

View file

@ -1,48 +1,69 @@
--TEST-- --TEST--
Sends data from parameter streams to the server Sends data from parameter streams to the server
--SKIPIF-- --SKIPIF--
--FILE-- --FILE--
<?php <?php
require('connect.inc'); require('connect.inc');
$connectionInfo = array( "Database"=>"$databaseName", "UID"=>"$uid", "PWD"=>"$pwd"); $connectionInfo = array("Database"=>"$databaseName", "UID"=>"$uid", "PWD"=>"$pwd");
$conn = sqlsrv_connect( $server, $connectionInfo); $conn = sqlsrv_connect($server, $connectionInfo);
if( $conn === false ) if ($conn === false) {
{ echo "Could not connect.<br>";
echo "Could not connect.<br>"; die(print_r(sqlsrv_errors(), true));
die( print_r( sqlsrv_errors(), true));
} }
/* Define the query. */ /* Define the query. */
$tsql = "UPDATE Production.ProductReview $tsql = "UPDATE Production.ProductReview
SET Comments = ( ?) SET Comments = (?)
WHERE ProductReviewID = 3"; WHERE ProductReviewID = 3";
$number = rand(99, 9999);
$input = "[Insert some number $number]";
/* Open parameter data as a stream and put it in the $params array. */ /* Open parameter data as a stream and put it in the $params array. */
$comment = fopen( "data://text/plain,[ Insert lengthy comment.]", "r"); $comments = fopen("data://text/plain,$input", "r");
$params = array( &$comment); $params = array(&$comments);
/* Prepare the statement. Use the $options array to turn off the /* Prepare the statement. Use the $options array to turn off the
default behavior, which is to send all stream data at the time of query default behavior, which is to send all stream data at the time of query
execution. */ execution. */
$options = array("SendStreamParamsAtExec"=>0); $options = array("SendStreamParamsAtExec" => 0);
$stmt = sqlsrv_prepare( $conn, $tsql, $params, $options); $stmt = sqlsrv_prepare($conn, $tsql, $params, $options);
/* Execute the statement. */ /* Execute the statement. */
sqlsrv_execute( $stmt); sqlsrv_execute($stmt);
/* Send up to 8K of parameter data to the server with each call to /* Send up to 8K of parameter data to the server with each call to
sqlsrv_send_stream_data. Count the calls. */ sqlsrv_send_stream_data. Count the calls. */
$i = 1; $i = 1;
while( sqlsrv_send_stream_data( $stmt)) while (sqlsrv_send_stream_data($stmt)) {
{ $i++;
echo "$i call(s) made.<br>"; }
$i++;
} /* For PHP 7.2, it takes 2 calls whereas older PHP versions
take up to 3 calls */
if ($i < 2 || $i > 3) {
echo "Expects 2 to 3 calls only." . PHP_EOL;
}
/* Read it back to check the comments */
$tsql = "SELECT Comments FROM Production.ProductReview
WHERE ProductReviewID = 3";
$stmt = sqlsrv_query($conn, $tsql);
if (sqlsrv_fetch($stmt)) {
$review = sqlsrv_get_field($stmt, 0);
if ($review !== $input) {
echo "Comments retrieved \'$review\' is incorrect!" . PHP_EOL;
}
} else {
echo "Error in retrieving comments!" . PHP_EOL;
die(print_r(sqlsrv_errors(), true));
}
echo "Done" . PHP_EOL;
/* Free statement and connection resources. */ /* Free statement and connection resources. */
sqlsrv_free_stmt( $stmt); sqlsrv_free_stmt($stmt);
sqlsrv_close( $conn); sqlsrv_close($conn);
?> ?>
--EXPECT-- --EXPECT--
1 call(s) made.<br>2 call(s) made.<br>3 call(s) made.<br> Done

View file

@ -1,39 +1,43 @@
--TEST-- --TEST--
sned stream data with SendStreamParamsAtExec turned off. Send stream data with SendStreamParamsAtExec turned off.
--SKIPIF-- --SKIPIF--
--FILE--
?>
--FILE--
<?php <?php
/* Connect to the local server using Windows Authentication and /* Connect to the local server using Windows Authentication and
specify the AdventureWorks database as the database in use. */ specify the AdventureWorks database as the database in use. */
require('connect.inc'); require('connect.inc');
$connectionInfo = array( "Database"=>"$databaseName", "UID"=>"$uid", "PWD"=>"$pwd"); $connectionInfo = array("Database"=>"$databaseName", "UID"=>"$uid", "PWD"=>"$pwd");
$conn = sqlsrv_connect( $server, $connectionInfo); $conn = sqlsrv_connect($server, $connectionInfo);
if( $conn === false ) if ($conn === false) {
{ echo "Could not connect.\n";
echo "Could not connect.\n"; die(print_r(sqlsrv_errors(), true));
die( print_r( sqlsrv_errors(), true));
} }
/* Remove any records with from the table with ProductID = 999*/
$productID = 999;
$tsql = "DELETE FROM Production.ProductReview WHERE ProductID = $productID";
sqlsrv_query($conn, $tsql);
/* Set up the Transact-SQL query. */ /* Set up the Transact-SQL query. */
$tsql = "INSERT INTO Production.ProductReview (ProductID, $tsql = "INSERT INTO Production.ProductReview (ProductID,
ReviewerName, ReviewerName,
ReviewDate, ReviewDate,
EmailAddress, EmailAddress,
Rating, Rating,
Comments) Comments)
VALUES (?, ?, ?, ?, ?, ?)"; VALUES (?, ?, ?, ?, ?, ?)";
/* Set the parameter values and put them in an array. /* Set the parameter values and put them in an array.
Note that $comments is opened as a stream. */ Note that $comments is opened as a stream. */
$productID = '709'; $number = rand(99, 9999);
$input = "[Insert some number $number]";
/* There is no record in this table with ProductID 999 */
$name = 'Customer Name'; $name = 'Customer Name';
$date = date("Y-m-d"); $date = date("Y-m-d");
$email = 'customer@name.com'; $email = 'customer@name.com';
$rating = 3; $rating = 3;
$comments = fopen( "data://text/plain,[ Insert lengthy comment here.]", $comments = fopen("data://text/plain,$input", "r");
"r");
$params = array($productID, $name, $date, $email, $rating, $comments); $params = array($productID, $name, $date, $email, $rating, $comments);
/* Turn off the default behavior of sending all stream data at /* Turn off the default behavior of sending all stream data at
@ -42,26 +46,47 @@ $options = array("SendStreamParamsAtExec" => 0);
/* Execute the query. */ /* Execute the query. */
$stmt = sqlsrv_query($conn, $tsql, $params, $options); $stmt = sqlsrv_query($conn, $tsql, $params, $options);
if( $stmt === false ) if ($stmt === false) {
{ echo "Error in statement execution.\n";
echo "Error in statement execution.\n"; die(print_r(sqlsrv_errors(), true));
die( print_r( sqlsrv_errors(), true));
} }
/* Send up to 8K of parameter data to the server with each call to /* Send up to 8K of parameter data to the server with each call to
sqlsrv_send_stream_data. Count the calls. */ sqlsrv_send_stream_data. Count the calls. */
$i = 1; $i = 1;
while( sqlsrv_send_stream_data( $stmt)) while (sqlsrv_send_stream_data($stmt)) {
{ $i++;
echo "$i call(s) made.\n";
$i++;
} }
/* For PHP 7.2, it takes 2 calls whereas older PHP versions
take up to 3 calls */
if ($i < 2 || $i > 3) {
echo "Expects 2 to 3 calls only." . PHP_EOL;
}
/* Read it back to check the comments */
$tsql = "SELECT Comments FROM Production.ProductReview
WHERE ProductID = $productID";
$stmt = sqlsrv_query($conn, $tsql);
if (sqlsrv_fetch($stmt)) {
$review = sqlsrv_get_field($stmt, 0);
if ($review !== $input) {
echo "Comments retrieved \'$review\' is incorrect!" . PHP_EOL;
}
} else {
echo "Error in retrieving comments!" . PHP_EOL;
die(print_r(sqlsrv_errors(), true));
}
/* Remove the entry from the table */
$tsql = "DELETE FROM Production.ProductReview WHERE ProductID = $productID";
sqlsrv_query($conn, $tsql);
echo "Done" . PHP_EOL;
/* Free statement and connection resources. */ /* Free statement and connection resources. */
sqlsrv_free_stmt( $stmt); sqlsrv_free_stmt($stmt);
sqlsrv_close( $conn); sqlsrv_close($conn);
?> ?>
--EXPECT-- --EXPECT--
1 call(s) made. Done
2 call(s) made.
3 call(s) made.