Fix and tests for issue #69
This commit is contained in:
parent
e363a44cf5
commit
27d35af223
|
@ -1351,6 +1351,12 @@ SQLRETURN sqlsrv_buffered_result_set::wide_to_system_string( SQLSMALLINT field_i
|
||||||
field_data = &row[ meta[ field_index ].offset ] + sizeof( SQLULEN ) + read_so_far;
|
field_data = &row[ meta[ field_index ].offset ] + sizeof( SQLULEN ) + read_so_far;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (field_len == 0) // empty string, no need for conversion
|
||||||
|
{
|
||||||
|
*out_buffer_length = 0;
|
||||||
|
return SQL_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
// allocate enough to handle WC -> DBCS conversion if it happens
|
// allocate enough to handle WC -> DBCS conversion if it happens
|
||||||
temp_string = reinterpret_cast<SQLCHAR*>( sqlsrv_malloc( field_len, sizeof(char), sizeof(char)));
|
temp_string = reinterpret_cast<SQLCHAR*>( sqlsrv_malloc( field_len, sizeof(char), sizeof(char)));
|
||||||
|
|
||||||
|
|
38
test/pdo_sqlsrv/pdo_069_fetch_empty_nvarchar_buffered.phpt
Normal file
38
test/pdo_sqlsrv/pdo_069_fetch_empty_nvarchar_buffered.phpt
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
--TEST--
|
||||||
|
GitHub issue #69 - fetching an empty nvarchar using client buffer
|
||||||
|
--SKIPIF--
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
// Connect
|
||||||
|
require_once("autonomous_setup.php");
|
||||||
|
|
||||||
|
$conn = new PDO("sqlsrv:server=$serverName", $username, $password);
|
||||||
|
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
|
||||||
|
|
||||||
|
$sql = "EXEC dbo.sp_executesql
|
||||||
|
N'DECLARE @x nvarchar(max)
|
||||||
|
SET @x = '''' -- empty string
|
||||||
|
SELECT @x AS [Empty_Nvarchar_Max]'";
|
||||||
|
|
||||||
|
$stmt = $conn->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
|
||||||
|
$stmt->execute();
|
||||||
|
|
||||||
|
$return = $stmt->fetchAll( PDO::FETCH_ASSOC );
|
||||||
|
print_r($return);
|
||||||
|
|
||||||
|
// Free the statement and connection resources.
|
||||||
|
$stmt = null;
|
||||||
|
$conn = null;
|
||||||
|
|
||||||
|
print "Done";
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
Array
|
||||||
|
(
|
||||||
|
[0] => Array
|
||||||
|
(
|
||||||
|
[Empty_Nvarchar_Max] =>
|
||||||
|
)
|
||||||
|
|
||||||
|
)
|
||||||
|
Done
|
44
test/sqlsrv/srv_069_fetch_empty_nvarchar_buffered.phpt
Normal file
44
test/sqlsrv/srv_069_fetch_empty_nvarchar_buffered.phpt
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
--TEST--
|
||||||
|
GitHub issue #69 - fetching an empty nvarchar using client buffer
|
||||||
|
--SKIPIF--
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
function print_errors()
|
||||||
|
{
|
||||||
|
die( print_r( sqlsrv_errors(), true));
|
||||||
|
}
|
||||||
|
|
||||||
|
function test()
|
||||||
|
{
|
||||||
|
require_once("autonomous_setup.php");
|
||||||
|
|
||||||
|
// Connect
|
||||||
|
$conn = sqlsrv_connect($serverName, $connectionInfo);
|
||||||
|
if( !$conn ) { print_errors(); }
|
||||||
|
|
||||||
|
$sql = "EXEC dbo.sp_executesql
|
||||||
|
N'DECLARE @x nvarchar(max)
|
||||||
|
SET @x = '''' -- empty string
|
||||||
|
SELECT @x AS [Empty_Nvarchar_Max]'";
|
||||||
|
|
||||||
|
$stmt = sqlsrv_query($conn, $sql, [], ["Scrollable" => 'buffered']);
|
||||||
|
if (! $stmt) { print_errors(); }
|
||||||
|
|
||||||
|
$return = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC);
|
||||||
|
print_r($return);
|
||||||
|
|
||||||
|
// Free the statement and connection resources.
|
||||||
|
sqlsrv_free_stmt( $stmt);
|
||||||
|
sqlsrv_close( $conn);
|
||||||
|
}
|
||||||
|
|
||||||
|
test();
|
||||||
|
|
||||||
|
print "Done";
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
Array
|
||||||
|
(
|
||||||
|
[Empty_Nvarchar_Max] =>
|
||||||
|
)
|
||||||
|
Done
|
Loading…
Reference in a new issue