Fix and tests for issue #69

This commit is contained in:
yitam 2017-02-10 09:51:51 -08:00
parent e363a44cf5
commit 27d35af223
3 changed files with 88 additions and 0 deletions

View file

@ -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;
}
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
temp_string = reinterpret_cast<SQLCHAR*>( sqlsrv_malloc( field_len, sizeof(char), sizeof(char)));

View 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

View 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