Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH308 #310

Merged
merged 7 commits into from
Mar 1, 2017
Merged

GH308 #310

Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion source/shared/core_stmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2007,7 +2007,11 @@ void finalize_output_parameters( sqlsrv_stmt* stmt TSRMLS_DC )
// adjust the length of the string to the value returned by SQLBindParameter in the ind_ptr parameter
char* str = Z_STRVAL_P( value_z );
SQLLEN str_len = stmt->param_ind_ptrs[ output_param->param_num ];
if( str_len == SQL_NULL_DATA || str_len == 0 ) {
if( str_len == 0 ) {
core::sqlsrv_zval_stringl( value_z, "", 0 );
continue;
}
if( str_len == SQL_NULL_DATA ) {
zend_string_release( Z_STR_P( value_z ));
ZVAL_NULL( value_z );
continue;
Expand Down
46 changes: 46 additions & 0 deletions test/pdo_sqlsrv/pdo_308_empty_output_param.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
--TEST--
GitHub issue #308 - empty string set to output parameter on stored procedure
--SKIPIF--
--FILE--
<?php
require_once("pdo_tools.inc");

// Connect
require_once("autonomous_setup.php");

$dbName = "tempdb";

$conn = new PDO("sqlsrv:server=$serverName;Database=$dbName", $username, $password);
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

$procName = GetTempProcName();

$sql = "CREATE PROCEDURE $procName @TEST VARCHAR(200)='' OUTPUT
AS BEGIN
SET NOCOUNT ON;
SET @TEST='';
SELECT HELLO_WORLD_COLUMN='THIS IS A COLUMN IN A SINGLE DATASET';
END";
$stmt = $conn->exec($sql);

$sql = "EXEC $procName @Test = :Test";
$stmt = $conn->prepare($sql);
$out = '';
$stmt->bindParam(':Test', $out, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 200);
$stmt->execute();

$result = $stmt->fetchAll();
$stmt->closeCursor();

echo "OUT value: ";
var_dump($out);

// Free the statement and connection resources.
$stmt = null;
$conn = null;

print "Done";
?>
--EXPECT--
OUT value: string(0) ""
Done