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

159 lines
4.1 KiB
Plaintext
Raw Normal View History

2017-05-04 18:16:29 +02:00
--TEST--
Send a large amount (10MB) using encryption. In a Linux CI environment use a smaller size.
2017-05-04 18:16:29 +02:00
--SKIPIF--
<?php require('skipif_azure_dw.inc'); ?>
2017-05-04 18:16:29 +02:00
--FILE--
<?php
class my_stream
{
public $total_read = 0;
2017-05-04 18:16:29 +02:00
public function stream_open($path, $mode, $options, &$opened_path)
2017-05-04 18:16:29 +02:00
{
$this->total_read = 0;
return true;
}
public function stream_read($count)
2017-05-04 18:16:29 +02:00
{
global $limit;
if ($this->total_read > $limit) {
2017-05-04 18:16:29 +02:00
return 0;
}
global $packets;
++$packets;
// 8192 is passed to stream_read as $count
$str = str_repeat("A", $count);
2017-05-04 18:16:29 +02:00
$this->total_read += $count;
return $str;
}
public function stream_write($data)
2017-05-04 18:16:29 +02:00
{
}
public function stream_tell()
2017-05-04 18:16:29 +02:00
{
return $this->total_read;
}
public function stream_eof()
2017-05-04 18:16:29 +02:00
{
global $limit;
return $this->total_read > $limit;
2017-05-04 18:16:29 +02:00
}
public function stream_seek($offset, $whence)
2017-05-04 18:16:29 +02:00
{
// For the purpose of this test only support SEEK_SET to $offset 0
if ($whence == SEEK_SET && $offset == 0) {
$this->total_read = $offset;
return true;
}
return false;
}
}
function isServerInLinux($conn)
{
// This checks if SQL Server is running in Linux (Docker) in a CI environment
// If so, the major version must be 14 or above (SQL Server 2017 or above)
$serverVer = sqlsrv_server_info($conn)['SQLServerVersion'];
if (explode('.', $serverVer)[0] < 14) {
return false;
2017-05-04 18:16:29 +02:00
}
// The view sys.dm_os_host_info, available starting in SQL Server 2017, is somewhat similar to sys.dm_os_windows_info.
// It returns one row that displays operating system version information and has columns to differentiate
// Windows and Linux.
$stmt = sqlsrv_query($conn, 'SELECT host_platform FROM sys.dm_os_host_info');
if ($stmt && sqlsrv_fetch($stmt)) {
$host = sqlsrv_get_field($stmt, 0);
return ($host === 'Linux');
}
return false;
2017-05-04 18:16:29 +02:00
}
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 0);
sqlsrv_configure('LogSubsystems', SQLSRV_LOG_SYSTEM_ALL);
2017-05-04 18:16:29 +02:00
$packets = 0;
$limit = 20000000;
2017-05-04 18:16:29 +02:00
$result = stream_wrapper_register("mystr", "my_stream");
if (!$result) {
die("Couldn't register stream class.");
2017-05-04 18:16:29 +02:00
}
require_once('MsCommon.inc');
2017-05-04 18:16:29 +02:00
$conn = Connect(array( 'Encrypt' => true, 'TrustServerCertificate' => true ));
if ($conn === false) {
die(print_r(sqlsrv_errors(), true));
2017-05-04 18:16:29 +02:00
}
// In a Linux CI environment use a smaller size
if (isServerInLinux($conn)) {
$limit /= 100;
}
$stmt = sqlsrv_query($conn, "IF OBJECT_ID('test_lob', 'U') IS NOT NULL DROP TABLE test_lob");
if ($stmt !== false) {
sqlsrv_free_stmt($stmt);
}
2017-05-04 18:16:29 +02:00
$stmt = sqlsrv_query($conn, "CREATE TABLE test_lob (id tinyint, stuff varbinary(max))");
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
2017-05-04 18:16:29 +02:00
}
sqlsrv_free_stmt($stmt);
2017-05-04 18:16:29 +02:00
$lob = fopen("mystr://test_data", "rb");
if (!$lob) {
die("failed opening test stream.\n");
2017-05-04 18:16:29 +02:00
}
$stmt = sqlsrv_query($conn, "INSERT INTO test_lob (id, stuff) VALUES (?,?)", array( 1, array( $lob, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_VARBINARY('max'))));
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
2017-05-04 18:16:29 +02:00
}
while ($result = sqlsrv_send_stream_data($stmt)) {
2017-05-04 18:16:29 +02:00
++$packets;
}
if ($result === false) {
die(print_r(sqlsrv_errors(), true));
2017-05-04 18:16:29 +02:00
}
// Number of packets sent should be $limit / 8192 (rounded up)
// Length of the varbinary = $packetsSent * 8192 + 1 (HEX 30 appended at the end)
$packetsSent = ceil($limit / 8192);
$length = $packetsSent * 8192 + 1;
if ($packets != $packetsSent) {
echo "$packets sent.\n";
2017-05-04 18:16:29 +02:00
}
$stmt = sqlsrv_query($conn, "SELECT LEN(stuff) FROM test_lob");
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
while ($result = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_NUMERIC)) {
if ($result[0] != $length) {
print_r($result);
}
2017-05-04 18:16:29 +02:00
}
sqlsrv_query($conn, "DROP TABLE test_lob");
2017-05-04 18:16:29 +02:00
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
2017-05-04 18:16:29 +02:00
sleep(10); // since this is a long test, we give the database some time to finish
echo "Done\n";
2017-05-04 18:16:29 +02:00
?>
--EXPECT--
Done