php-sqlsrv/test/functional/sqlsrv/TC54_StreamPrepared.phpt
Jenny Tam 9654020d67
Dev (#820)
* Fixed the potential error reported by Prefast code analysis

* Use SQLSRV_ASSERT for checking NULL ptrs

* For these AKV tests check env despite not AE connected

* Added the driver option to run functional tests

* Fixed connection pooling tests for more than one ODBC drivers

* added driver option to pdo isPooled.php

* Removed win32 ifdefs re connection resiliency (#802)

* Set the driver argument for getDSN to null by default (#798)

* Added the driver argument to getDSN

* Dropped the driver argument but set to null as default

* Removed the AE condition in locale support

* Modified the AE condition for locale support

* Changed int to SQLLEN to avoid infinite loop (#806)

* Version 5.3.0 (#803)

* Version 5.3.0

* Fixed the wrong replacements

* Added comments block to m4 files

* Use dnl for comments

*  Modified AE fetch phptypes test to insert only one row at a time and loop through php types (#801)

* Modified AE fetch phptypes test to insert only one row at a time and loop through php types

* Fixed formatting

* Streamlined two very similar large column name tests (#807)

* Streamlined two very similar large column name tests

* Changed the EOL

* Updates to change log and readme (#811)

* Updates to change log and readme

* Dropped support for Ubuntu 17

* Modified as per review comments

* Fixed connection resiliency tests for Unix, updated AppVeyor for ODBC 17.2

* Fixed expected output

* Fixed output and skipifs

* Fixed skipifs and output

* Fixed driver name

* Updated installation instructions and sample script (#813)

* Updated instructions and sample test for 5.3.0 RTW

* Fixed sample code to adhere to php coding standard

* Fixed cases and spaces

* Modified NOTE for UB 18.04 based on review comments

* Added 'exit'

* Modified change log and readme based on review to PR 811

* Applied review comments

* build output to debug appveyor failure

* removed debug output

* Streamlined two very similar large column name tests (#815)

* Streamlined two very similar large column name tests

* Added random number of test table names to avoid operand clash issues

* Replaced to with for based on review

* Changelog updated

* changelog updated, test skipif changed to run on unix platforms

* Fixed skipif typo

* Fixed typo in skipif for pdo

* Fixed some output for Travis

* Moved error checking inside pdo connres tests

* Added links back to changelog

* Fixed output for sqlsrv connres tests

* Fixed output

* Fixed output again
2018-07-20 17:24:48 -07:00

136 lines
3.7 KiB
PHP

--TEST--
Stream Prepared Test
--DESCRIPTION--
Verifies that all SQL types defined as capable of streaming (13 types)
can be successfully uploaded as streams via sqlsrv_prepare/sqlsvr_query.
Validates that a warning message is issued when parameters are not passed by reference.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');
function sendStream($minType, $maxType)
{
$testName = "Stream - Prepared Send";
startTest($testName);
setup();
$tableName = "TC54test" . rand(0, 100);
$fileName = "TC53test.dat";
$conn1 = AE\connect();
for ($k = $minType; $k <= $maxType; $k++) {
switch ($k) {
case 12: // char
case 13: // varchar
case 14: // varchar(max)
case 15: // nchar
case 16: // nvarchar
case 17: // nvarchar(max)
case 18: // text
case 19: // ntext
$data = "The quick brown fox jumps over the lazy dog 0123456789";
break;
case 20: // binary
case 21: // varbinary
case 22: // varbinary(max)
case 23: // image
$data = "01234567899876543210";
break;
default:
die("Unexpected data type: $k.");
break;
}
$fname1 = fopen($fileName, "w");
fwrite($fname1, $data);
fclose($fname1);
$fname2 = fopen($fileName, "r");
$sqlType = getSqlType($k);
$phpDriverType = getSqlsrvSqlType($k, strlen($data));
$dataOptions = array(array($k, SQLSRV_PARAM_IN),
array(&$fname2, SQLSRV_PARAM_IN, null, $phpDriverType));
traceData($sqlType, $data);
$columns = array(new AE\ColumnMeta('int', 'c1'),
new AE\ColumnMeta($sqlType, 'c2'));
AE\createTable($conn1, $tableName, $columns);
insertData($conn1, $tableName, "c1, c2", "?, ?", $dataOptions);
checkData($conn1, $tableName, 2, $data);
fclose($fname2);
}
dropTable($conn1, $tableName);
unlink($fileName);
sqlsrv_close($conn1);
endTest($testName);
}
function insertData($conn, $tableName, $dataCols, $dataValues, $dataOptions)
{
$sql = "INSERT INTO [$tableName] ($dataCols) VALUES ($dataValues)";
$stmt = sqlsrv_prepare($conn, $sql, $dataOptions);
if ($stmt === false) {
fatalError("Failed to prepare insert query: ".$sql);
}
$outcome = sqlsrv_execute($stmt);
if ($outcome === false) {
fatalError("Failed to execute prepared query: ".$sql);
}
while (sqlsrv_send_stream_data($stmt)) {
}
$numRows = sqlsrv_rows_affected($stmt);
sqlsrv_free_stmt($stmt);
if ($numRows != 1) {
die("Unexpected row count at insert: ".$numRows);
}
}
function checkData($conn, $table, $cols, $expectedValue)
{
$stmt = AE\selectFromTable($conn, $table);
if (!sqlsrv_fetch($stmt)) {
fatalError("Table $tableName was not expected to be empty.");
}
$numFields = sqlsrv_num_fields($stmt);
if ($numFields != $cols) {
die("Table $tableName was expected to have $cols fields.");
}
$actualValue = sqlsrv_get_field($stmt, 1, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
sqlsrv_free_stmt($stmt);
if (strncmp($actualValue, $expectedValue, strlen($expectedValue)) != 0) {
die("Data corruption: $expectedValue => $actualValue.");
}
}
//--------------------------------------------------------------------
// repro
//
//--------------------------------------------------------------------
function repro()
{
try {
sendStream(12, 23);
} catch (Exception $e) {
echo $e->getMessage();
}
}
repro();
?>
--EXPECTREGEX--
Test "Stream - Prepared Send" completed successfully.