php-sqlsrv/test/functional/sqlsrv/sqlsrv_streams_null_binary.phpt

105 lines
3.4 KiB
Plaintext
Raw Normal View History

2017-04-01 00:09:05 +02:00
--TEST--
Populate different binary fields using null stream data as inputs.
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
2017-04-01 00:09:05 +02:00
--FILE--
<?php
require_once('MsCommon.inc');
2017-04-01 00:09:05 +02:00
function nullBin2String($conn, $tableName)
2017-04-01 00:09:05 +02:00
{
$fname = null;
2017-04-06 00:07:18 +02:00
$value = -2106133115;
$intType = AE\isColEncrypted() ? SQLSRV_SQLTYPE_INT : null;
$stmt = sqlsrv_query($conn,
"INSERT INTO $tableName (c1_int, c2_varbinary, c3_varbinary_max, c4_image) VALUES (?, ?, ?, ?)",
array(array($value, null, null, $intType),
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)));
2017-04-01 00:09:05 +02:00
sqlsrv_free_stmt($stmt);
fetchData($conn, $tableName, $value);
2017-04-01 00:09:05 +02:00
}
function nullPrepBin2String($conn, $tableName)
2017-04-01 00:09:05 +02:00
{
$fname = null;
2017-04-06 00:07:18 +02:00
$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)));
2017-04-01 00:09:05 +02:00
sqlsrv_execute($stmt);
sqlsrv_free_stmt($stmt);
fetchData($conn, $tableName, $value);
2017-04-01 00:09:05 +02:00
}
function fetchData($conn, $tableName, $value)
2017-04-01 00:09:05 +02:00
{
if (AE\isColEncrypted()) {
// bind param when AE is enabled
$stmt = sqlsrv_prepare($conn, "SELECT * FROM $tableName WHERE c1_int = ?", array($value));
if ($stmt) {
sqlsrv_execute($stmt);
}
} else {
$stmt = sqlsrv_query($conn, "SELECT * FROM $tableName WHERE c1_int = $value");
}
if (!$stmt) {
fatalError("Failed in fetch data with value $value\n");
}
2017-04-01 00:09:05 +02:00
$result = sqlsrv_fetch($stmt);
2017-04-06 00:07:18 +02:00
$numfields = sqlsrv_num_fields($stmt);
for ($i = 1; $i < $numfields; $i++) {
2017-04-06 00:07:18 +02:00
$value = sqlsrv_get_field($stmt, $i, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
var_dump($value);
2017-04-06 00:07:18 +02:00
}
2017-04-01 00:09:05 +02:00
}
echo "\nTest begins...\n";
try {
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
2017-04-01 00:09:05 +02:00
// connect
2017-12-05 22:43:53 +01:00
$conn = AE\connect();
// create a test table
$tableName = 'null_binary_stream';
2017-12-05 22:43:53 +01:00
$columns = array(new AE\ColumnMeta('int', 'c1_int'),
new AE\ColumnMeta('varbinary(512)', 'c2_varbinary'),
new AE\ColumnMeta('varbinary(max)', 'c3_varbinary_max'),
new AE\ColumnMeta('image', 'c4_image'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("Failed to create table.\n");
}
nullBin2String($conn, $tableName);
nullPrepBin2String($conn, $tableName);
dropTable($conn, $tableName);
2017-04-01 00:09:05 +02:00
sqlsrv_close($conn);
} catch (Exception $e) {
echo $e->getMessage();
2017-04-01 00:09:05 +02:00
}
echo "\nDone\n";
2017-04-01 00:09:05 +02:00
?>
--EXPECT--

Test begins...
2017-04-01 00:09:05 +02:00
NULL
NULL
NULL
NULL
NULL
NULL
Done