tests with empty or null streams
This commit is contained in:
parent
4cacc6c770
commit
0b1b370a15
|
@ -1,5 +1,5 @@
|
|||
--TEST--
|
||||
Test various Katmai types, like geography, geometry, hierarchy, sparse, etc. and fetch them back as strings
|
||||
Populate a test table with many fields and fetch them back using wrong data types
|
||||
--FILE--
|
||||
<?php
|
||||
include 'tools.inc';
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
--TEST--
|
||||
Test various Katmai types, like geography, geometry, hierarchy, sparse, etc. and fetch them back as strings
|
||||
Insert with query params but with wrong parameters or types
|
||||
--FILE--
|
||||
<?php
|
||||
include 'tools.inc';
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
--TEST--
|
||||
Test various Katmai types, like geography, geometry, hierarchy, sparse, etc. and fetch them back as strings
|
||||
Insert with query params but with various invalid inputs or boundaries
|
||||
--FILE--
|
||||
<?php
|
||||
include 'tools.inc';
|
||||
|
|
135
test/sqlsrv/sqlsrv_streams_empty_char.phpt
Normal file
135
test/sqlsrv/sqlsrv_streams_empty_char.phpt
Normal file
|
@ -0,0 +1,135 @@
|
|||
--TEST--
|
||||
Populate different test tables with character fields using empty stream data as inputs
|
||||
--FILE--
|
||||
<?php
|
||||
include 'tools.inc';
|
||||
|
||||
function EmptyStream_Char2Stream($conn, $fileName)
|
||||
{
|
||||
$tableName = GetTempTableName();
|
||||
|
||||
// create another test table a char(512) column
|
||||
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_char] char(512))");
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
$fname = fopen($fileName, "r");
|
||||
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_char) VALUES (?, ?)", array(463787351, &$fname), array('SendStreamParamsAtExec' => 0));
|
||||
sqlsrv_send_stream_data($stmt);
|
||||
sqlsrv_free_stmt($stmt);
|
||||
fclose($fname);
|
||||
|
||||
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_varchar] varchar(512))");
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
$fname = fopen($fileName, "r");
|
||||
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar) VALUES (?, ?)", array(357113758, &$fname), array('SendStreamParamsAtExec' => 0));
|
||||
sqlsrv_send_stream_data($stmt);
|
||||
sqlsrv_free_stmt($stmt);
|
||||
fclose($fname);
|
||||
|
||||
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_varchar_max] varchar(max))");
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
$fname = fopen($fileName, "r");
|
||||
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(1120737010, &$fname), array('SendStreamParamsAtExec' => 0));
|
||||
sqlsrv_send_stream_data($stmt);
|
||||
sqlsrv_free_stmt($stmt);
|
||||
fclose($fname);
|
||||
|
||||
FetchData($conn, $tableName);
|
||||
|
||||
// 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");
|
||||
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_text) VALUES (?, ?)", array(1532347140, &$fname), array('SendStreamParamsAtExec' => 0));
|
||||
sqlsrv_send_stream_data($stmt);
|
||||
sqlsrv_free_stmt($stmt);
|
||||
fclose($fname);
|
||||
|
||||
FetchData($conn, $tableName);
|
||||
}
|
||||
|
||||
function FetchData($conn, $tableName)
|
||||
{
|
||||
$stmt = sqlsrv_prepare($conn, "SELECT * FROM $tableName");
|
||||
sqlsrv_execute($stmt);
|
||||
$result = sqlsrv_fetch($stmt);
|
||||
$stream = sqlsrv_get_field($stmt, 1, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY));
|
||||
var_dump($stream);
|
||||
|
||||
sqlsrv_execute($stmt);
|
||||
$result = sqlsrv_fetch($stmt);
|
||||
$value = sqlsrv_get_field($stmt, 1, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY));
|
||||
var_dump($value);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Repro
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
function Repro()
|
||||
{
|
||||
StartTest("sqlsrv_streams_empty_char");
|
||||
try
|
||||
{
|
||||
set_time_limit(0);
|
||||
sqlsrv_configure('WarningsReturnAsErrors', 1);
|
||||
|
||||
require_once("autonomous_setup.php");
|
||||
$database = "tempdb";
|
||||
|
||||
// Connect
|
||||
$connectionInfo = array('Database'=>$database, 'UID'=>$username, 'PWD'=>$password, 'CharacterSet'=>'UTF-8');
|
||||
$conn = sqlsrv_connect($serverName, $connectionInfo);
|
||||
if( !$conn ) { FatalError("Could not connect.\n"); }
|
||||
|
||||
// create an empty file
|
||||
$fileName = "sqlsrv_streams_empty_char.dat";
|
||||
$fp = fopen($fileName, "wb");
|
||||
fclose($fp);
|
||||
|
||||
EmptyStream_Char2Stream($conn, $fileName);
|
||||
|
||||
// delete the file
|
||||
unlink($fileName);
|
||||
sqlsrv_close($conn);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
}
|
||||
echo "\nDone\n";
|
||||
EndTest("sqlsrv_streams_empty_char");
|
||||
}
|
||||
|
||||
Repro();
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
|
||||
...Starting 'sqlsrv_streams_empty_char' test...
|
||||
bool(false)
|
||||
bool(false)
|
||||
bool(false)
|
||||
bool(false)
|
||||
bool(false)
|
||||
bool(false)
|
||||
bool(false)
|
||||
bool(false)
|
||||
|
||||
Done
|
||||
...Test 'sqlsrv_streams_empty_char' completed successfully.
|
111
test/sqlsrv/sqlsrv_streams_null_nchar.phpt
Normal file
111
test/sqlsrv/sqlsrv_streams_null_nchar.phpt
Normal file
|
@ -0,0 +1,111 @@
|
|||
--TEST--
|
||||
Populate different test tables with unicode character fields using null stream data as inputs
|
||||
--FILE--
|
||||
<?php
|
||||
include 'tools.inc';
|
||||
|
||||
function NullStream_Char2Stream($conn)
|
||||
{
|
||||
$tableName = GetTempTableName();
|
||||
|
||||
// create another test table a char(512) column
|
||||
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_nchar] nchar(512))");
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
$fname = null;
|
||||
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_nchar) VALUES (?, ?)", array(-187518515, &$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);
|
||||
|
||||
FetchData($conn, $tableName);
|
||||
}
|
||||
|
||||
function FetchData($conn, $tableName)
|
||||
{
|
||||
$stmt = sqlsrv_prepare($conn, "SELECT * FROM $tableName");
|
||||
sqlsrv_execute($stmt);
|
||||
$result = sqlsrv_fetch($stmt);
|
||||
$value = sqlsrv_get_field($stmt, 1, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY));
|
||||
var_dump($value);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Repro
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
function Repro()
|
||||
{
|
||||
StartTest("sqlsrv_streams_null_nchar");
|
||||
try
|
||||
{
|
||||
set_time_limit(0);
|
||||
sqlsrv_configure('WarningsReturnAsErrors', 1);
|
||||
|
||||
require_once("autonomous_setup.php");
|
||||
$database = "tempdb";
|
||||
|
||||
// Connect
|
||||
$connectionInfo = array('Database'=>$database, 'UID'=>$username, 'PWD'=>$password, 'CharacterSet'=>'UTF-8');
|
||||
$conn = sqlsrv_connect($serverName, $connectionInfo);
|
||||
if( !$conn ) { FatalError("Could not connect.\n"); }
|
||||
|
||||
NullStream_Char2Stream($conn);
|
||||
|
||||
sqlsrv_close($conn);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
}
|
||||
echo "\nDone\n";
|
||||
EndTest("sqlsrv_streams_null_nchar");
|
||||
}
|
||||
|
||||
Repro();
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
|
||||
...Starting 'sqlsrv_streams_null_nchar' test...
|
||||
NULL
|
||||
NULL
|
||||
NULL
|
||||
NULL
|
||||
|
||||
Done
|
||||
...Test 'sqlsrv_streams_null_nchar' completed successfully.
|
Loading…
Reference in a new issue