simplified the tests with streams
This commit is contained in:
parent
5a395d2e95
commit
daa157596e
|
@ -8,72 +8,56 @@ function EmptyStream_Char2Stream($conn, $fileName)
|
||||||
{
|
{
|
||||||
$tableName = GetTempTableName();
|
$tableName = GetTempTableName();
|
||||||
|
|
||||||
// create another test table a char(512) column
|
// create a test table
|
||||||
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_char] char(512))");
|
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_char] char(512), [c3_varchar] varchar(512), [c4_varchar_max] varchar(max), [c5_text] text)");
|
||||||
sqlsrv_free_stmt($stmt);
|
sqlsrv_free_stmt($stmt);
|
||||||
|
|
||||||
|
// insert data
|
||||||
$fname = fopen($fileName, "r");
|
$fname = fopen($fileName, "r");
|
||||||
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_char) VALUES (?, ?)", array(463787351, &$fname), array('SendStreamParamsAtExec' => 0));
|
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_char) VALUES (?, ?)", array(1, &$fname), array('SendStreamParamsAtExec' => 0));
|
||||||
sqlsrv_send_stream_data($stmt);
|
sqlsrv_send_stream_data($stmt);
|
||||||
sqlsrv_free_stmt($stmt);
|
sqlsrv_free_stmt($stmt);
|
||||||
fclose($fname);
|
fclose($fname);
|
||||||
|
|
||||||
FetchData($conn, $tableName);
|
FetchData($conn, $tableName, 1);
|
||||||
|
|
||||||
// create another test table with a varchar(512) column
|
|
||||||
$tableName = GetTempTableName();
|
|
||||||
|
|
||||||
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_varchar] varchar(512))");
|
|
||||||
sqlsrv_free_stmt($stmt);
|
|
||||||
|
|
||||||
$fname = fopen($fileName, "r");
|
$fname = fopen($fileName, "r");
|
||||||
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar) VALUES (?, ?)", array(357113758, &$fname), array('SendStreamParamsAtExec' => 0));
|
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c3_varchar) VALUES (?, ?)", array(2, &$fname), array('SendStreamParamsAtExec' => 0));
|
||||||
sqlsrv_send_stream_data($stmt);
|
sqlsrv_send_stream_data($stmt);
|
||||||
sqlsrv_free_stmt($stmt);
|
sqlsrv_free_stmt($stmt);
|
||||||
fclose($fname);
|
fclose($fname);
|
||||||
|
|
||||||
FetchData($conn, $tableName);
|
FetchData($conn, $tableName, 2);
|
||||||
|
|
||||||
// create another test table with a varchar(max) column
|
|
||||||
$tableName = GetTempTableName();
|
|
||||||
|
|
||||||
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_varchar_max] varchar(max))");
|
|
||||||
sqlsrv_free_stmt($stmt);
|
|
||||||
|
|
||||||
$fname = fopen($fileName, "r");
|
$fname = fopen($fileName, "r");
|
||||||
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(1120737010, &$fname), array('SendStreamParamsAtExec' => 0));
|
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c4_varchar_max) VALUES (?, ?)", array(3, &$fname), array('SendStreamParamsAtExec' => 0));
|
||||||
sqlsrv_send_stream_data($stmt);
|
sqlsrv_send_stream_data($stmt);
|
||||||
sqlsrv_free_stmt($stmt);
|
sqlsrv_free_stmt($stmt);
|
||||||
fclose($fname);
|
fclose($fname);
|
||||||
|
|
||||||
FetchData($conn, $tableName);
|
FetchData($conn, $tableName, 3);
|
||||||
|
|
||||||
// create another test table with a text column
|
|
||||||
$tableName = GetTempTableName();
|
|
||||||
|
|
||||||
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_text] text)");
|
|
||||||
sqlsrv_free_stmt($stmt);
|
|
||||||
|
|
||||||
$fname = fopen($fileName, "r");
|
$fname = fopen($fileName, "r");
|
||||||
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_text) VALUES (?, ?)", array(1532347140, &$fname), array('SendStreamParamsAtExec' => 0));
|
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c5_text) VALUES (?, ?)", array(4, &$fname), array('SendStreamParamsAtExec' => 0));
|
||||||
sqlsrv_send_stream_data($stmt);
|
sqlsrv_send_stream_data($stmt);
|
||||||
sqlsrv_free_stmt($stmt);
|
sqlsrv_free_stmt($stmt);
|
||||||
fclose($fname);
|
fclose($fname);
|
||||||
|
|
||||||
FetchData($conn, $tableName);
|
FetchData($conn, $tableName, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
function FetchData($conn, $tableName)
|
function FetchData($conn, $tableName, $value)
|
||||||
{
|
{
|
||||||
$stmt = sqlsrv_prepare($conn, "SELECT * FROM $tableName");
|
$stmt = sqlsrv_prepare($conn, "SELECT * FROM $tableName WHERE c1_int = $value");
|
||||||
sqlsrv_execute($stmt);
|
sqlsrv_execute($stmt);
|
||||||
|
$fld = $value;
|
||||||
$result = sqlsrv_fetch($stmt);
|
$result = sqlsrv_fetch($stmt);
|
||||||
$stream = sqlsrv_get_field($stmt, 1, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY));
|
$stream = sqlsrv_get_field($stmt, $fld, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY));
|
||||||
var_dump($stream);
|
var_dump($stream);
|
||||||
|
|
||||||
sqlsrv_execute($stmt);
|
sqlsrv_execute($stmt);
|
||||||
$result = sqlsrv_fetch($stmt);
|
$result = sqlsrv_fetch($stmt);
|
||||||
$value = sqlsrv_get_field($stmt, 1, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY));
|
$value = sqlsrv_get_field($stmt, $fld, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY));
|
||||||
var_dump($value);
|
var_dump($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,96 +1,41 @@
|
||||||
--TEST--
|
--TEST--
|
||||||
Populate different test tables with binary fields using null stream data as inputs.
|
Populate different binary fields using null stream data as inputs.
|
||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
include 'tools.inc';
|
include 'tools.inc';
|
||||||
|
|
||||||
function NullStream_Bin2String($conn)
|
function NullStream_Bin2String($conn, $tableName)
|
||||||
{
|
{
|
||||||
$tableName = GetTempTableName();
|
|
||||||
|
|
||||||
// create a test table with a varbinary(512) column
|
|
||||||
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_varbinary] varbinary(512))");
|
|
||||||
sqlsrv_free_stmt($stmt);
|
|
||||||
|
|
||||||
$fname = null;
|
$fname = null;
|
||||||
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varbinary) VALUES (?, ?)", array(-2106133115, array(&$fname, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_VARBINARY(512))));
|
$value = -2106133115;
|
||||||
|
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varbinary, c3_varbinary_max, c4_image) VALUES (?, ?, ?, ?)", array($value, array(&$fname, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_VARBINARY(512)), array(&$fname, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_VARBINARY('max')), array(&$fname, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_IMAGE)));
|
||||||
sqlsrv_free_stmt($stmt);
|
sqlsrv_free_stmt($stmt);
|
||||||
|
|
||||||
FetchData($conn, $tableName);
|
FetchData($conn, $tableName, $value);
|
||||||
|
|
||||||
// create another test table with a varbinary(max) column
|
|
||||||
$tableName = GetTempTableName();
|
|
||||||
|
|
||||||
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_varbinary_max] varbinary(max))");
|
|
||||||
sqlsrv_free_stmt($stmt);
|
|
||||||
|
|
||||||
$fname = null;
|
|
||||||
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varbinary_max) VALUES (?, ?)", array(1209714662, array(&$fname, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_VARBINARY('max'))));
|
|
||||||
sqlsrv_free_stmt($stmt);
|
|
||||||
|
|
||||||
FetchData($conn, $tableName);
|
|
||||||
|
|
||||||
// create another test table with an image column
|
|
||||||
$tableName = GetTempTableName();
|
|
||||||
|
|
||||||
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_image] image)");
|
|
||||||
sqlsrv_free_stmt($stmt);
|
|
||||||
|
|
||||||
$fname = null;
|
|
||||||
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_image) VALUES (?, ?)", array(429203895, array(&$fname, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_IMAGE)));
|
|
||||||
sqlsrv_free_stmt($stmt);
|
|
||||||
|
|
||||||
FetchData($conn, $tableName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function NullStreamPrep_Bin2String($conn)
|
function NullStreamPrep_Bin2String($conn, $tableName)
|
||||||
{
|
{
|
||||||
$tableName = GetTempTableName();
|
|
||||||
|
|
||||||
// create another test table a varbinary(512) column
|
|
||||||
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_varbinary] varbinary(512))");
|
|
||||||
sqlsrv_free_stmt($stmt);
|
|
||||||
|
|
||||||
$fname = null;
|
$fname = null;
|
||||||
$stmt = sqlsrv_prepare($conn, "INSERT INTO $tableName (c1_int, c2_varbinary) VALUES (?, ?)", array(-413736480, array(&$fname, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_VARBINARY(512))));
|
$value = -413736480;
|
||||||
|
$stmt = sqlsrv_prepare($conn, "INSERT INTO $tableName (c1_int, c2_varbinary, c3_varbinary_max, c4_image) VALUES (?, ?, ?, ?)", array($value, array(&$fname, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_VARBINARY(512)), array(&$fname, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_VARBINARY('max')), array(&$fname, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_IMAGE)));
|
||||||
sqlsrv_execute($stmt);
|
sqlsrv_execute($stmt);
|
||||||
sqlsrv_free_stmt($stmt);
|
sqlsrv_free_stmt($stmt);
|
||||||
|
|
||||||
FetchData($conn, $tableName);
|
FetchData($conn, $tableName, $value);
|
||||||
|
|
||||||
// create another test table with a varbinary(max) column
|
|
||||||
$tableName = GetTempTableName();
|
|
||||||
|
|
||||||
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_varbinary_max] varbinary(max))");
|
|
||||||
sqlsrv_free_stmt($stmt);
|
|
||||||
|
|
||||||
$fname = null;
|
|
||||||
$stmt = sqlsrv_prepare($conn, "INSERT INTO $tableName (c1_int, c2_varbinary_max) VALUES (?, ?)", array(-210414092, array(&$fname, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_VARBINARY('max'))));
|
|
||||||
sqlsrv_execute($stmt);
|
|
||||||
sqlsrv_free_stmt($stmt);
|
|
||||||
|
|
||||||
FetchData($conn, $tableName);
|
|
||||||
|
|
||||||
// create another test table with an image column
|
|
||||||
$tableName = GetTempTableName();
|
|
||||||
|
|
||||||
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_image] image)");
|
|
||||||
sqlsrv_free_stmt($stmt);
|
|
||||||
|
|
||||||
$fname = null;
|
|
||||||
$stmt = sqlsrv_prepare($conn, "INSERT INTO $tableName (c1_int, c2_image) VALUES (?, ?)", array(1657743705, array(&$fname, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_IMAGE)));
|
|
||||||
sqlsrv_execute($stmt);
|
|
||||||
sqlsrv_free_stmt($stmt);
|
|
||||||
|
|
||||||
FetchData($conn, $tableName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function FetchData($conn, $tableName)
|
function FetchData($conn, $tableName, $value)
|
||||||
{
|
{
|
||||||
$stmt = sqlsrv_query($conn, "SELECT * FROM $tableName");
|
$stmt = sqlsrv_query($conn, "SELECT * FROM $tableName WHERE c1_int = $value");
|
||||||
$result = sqlsrv_fetch($stmt);
|
$result = sqlsrv_fetch($stmt);
|
||||||
$value = sqlsrv_get_field($stmt, 1, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
|
$numfields = sqlsrv_num_fields($stmt);
|
||||||
var_dump($value);
|
for ($i = 1; $i < $numfields; $i++)
|
||||||
|
{
|
||||||
|
$value = sqlsrv_get_field($stmt, $i, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
|
||||||
|
var_dump($value);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
|
@ -113,8 +58,13 @@ function RunTest()
|
||||||
$conn = sqlsrv_connect($serverName, $connectionInfo);
|
$conn = sqlsrv_connect($serverName, $connectionInfo);
|
||||||
if( !$conn ) { FatalError("Could not connect.\n"); }
|
if( !$conn ) { FatalError("Could not connect.\n"); }
|
||||||
|
|
||||||
NullStream_Bin2String($conn);
|
// create a test table
|
||||||
NullStreamPrep_Bin2String($conn);
|
$tableName = GetTempTableName();
|
||||||
|
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_varbinary] varbinary(512), [c3_varbinary_max] varbinary(max), [c4_image] image)");
|
||||||
|
sqlsrv_free_stmt($stmt);
|
||||||
|
|
||||||
|
NullStream_Bin2String($conn, $tableName);
|
||||||
|
NullStreamPrep_Bin2String($conn, $tableName);
|
||||||
|
|
||||||
sqlsrv_close($conn);
|
sqlsrv_close($conn);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
--TEST--
|
--TEST--
|
||||||
Populate different test tables with unicode character fields using null stream data as inputs
|
Populate different unicode character fields using null stream data as inputs
|
||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
include 'tools.inc';
|
include 'tools.inc';
|
||||||
|
@ -8,48 +8,12 @@ function NullStream_Char2Stream($conn)
|
||||||
{
|
{
|
||||||
$tableName = GetTempTableName();
|
$tableName = GetTempTableName();
|
||||||
|
|
||||||
// create another test table a char(512) column
|
// create a test table
|
||||||
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_nchar] nchar(512))");
|
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_nchar] nchar(512), [c3_nvarchar] nvarchar(512), [c4_nvarchar_max] nvarchar(max), [c5_ntext] ntext)");
|
||||||
sqlsrv_free_stmt($stmt);
|
sqlsrv_free_stmt($stmt);
|
||||||
|
|
||||||
$fname = null;
|
$fname = null;
|
||||||
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_nchar) VALUES (?, ?)", array(-187518515, &$fname));
|
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_nchar, c3_nvarchar, c4_nvarchar_max, c5_ntext) VALUES (?, ?, ?, ?, ?)", array(-187518515, &$fname, &$fname, &$fname, &$fname));
|
||||||
sqlsrv_free_stmt($stmt);
|
|
||||||
|
|
||||||
FetchData($conn, $tableName);
|
|
||||||
|
|
||||||
// create another test table with a varchar(512) column
|
|
||||||
$tableName = GetTempTableName();
|
|
||||||
|
|
||||||
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_nvarchar] nvarchar(512))");
|
|
||||||
sqlsrv_free_stmt($stmt);
|
|
||||||
|
|
||||||
$fname = null;
|
|
||||||
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_nvarchar) VALUES (?, ?)", array(-2014452636, &$fname));
|
|
||||||
sqlsrv_free_stmt($stmt);
|
|
||||||
|
|
||||||
FetchData($conn, $tableName);
|
|
||||||
|
|
||||||
// create another test table with a varchar(max) column
|
|
||||||
$tableName = GetTempTableName();
|
|
||||||
|
|
||||||
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_nvarchar_max] nvarchar(max))");
|
|
||||||
sqlsrv_free_stmt($stmt);
|
|
||||||
|
|
||||||
$fname = null;
|
|
||||||
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_nvarchar_max) VALUES (?, ?)", array(1742573153, &$fname));
|
|
||||||
sqlsrv_free_stmt($stmt);
|
|
||||||
|
|
||||||
FetchData($conn, $tableName);
|
|
||||||
|
|
||||||
// create another test table with a text column
|
|
||||||
$tableName = GetTempTableName();
|
|
||||||
|
|
||||||
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_ntext] ntext)");
|
|
||||||
sqlsrv_free_stmt($stmt);
|
|
||||||
|
|
||||||
$fname = null;
|
|
||||||
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_ntext) VALUES (?, ?)", array(1477560975, &$fname));
|
|
||||||
sqlsrv_free_stmt($stmt);
|
sqlsrv_free_stmt($stmt);
|
||||||
|
|
||||||
FetchData($conn, $tableName);
|
FetchData($conn, $tableName);
|
||||||
|
@ -60,8 +24,12 @@ function FetchData($conn, $tableName)
|
||||||
$stmt = sqlsrv_prepare($conn, "SELECT * FROM $tableName");
|
$stmt = sqlsrv_prepare($conn, "SELECT * FROM $tableName");
|
||||||
sqlsrv_execute($stmt);
|
sqlsrv_execute($stmt);
|
||||||
$result = sqlsrv_fetch($stmt);
|
$result = sqlsrv_fetch($stmt);
|
||||||
$value = sqlsrv_get_field($stmt, 1, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY));
|
$numfields = sqlsrv_num_fields($stmt);
|
||||||
var_dump($value);
|
for ($i = 1; $i < $numfields; $i++)
|
||||||
|
{
|
||||||
|
$value = sqlsrv_get_field($stmt, $i, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY));
|
||||||
|
var_dump($value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in a new issue