Skip to content

Commit

Permalink
Merge pull request #63 from php/fix-gh-62
Browse files Browse the repository at this point in the history
Fix GH-62
  • Loading branch information
NattyNarwhal authored Nov 27, 2024
2 parents 8f50036 + cbcc729 commit 66c9ee1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ibm_db2.c
Original file line number Diff line number Diff line change
Expand Up @@ -4584,6 +4584,11 @@ static int _php_db2_bind_data( stmt_handle *stmt_res, param_node *curr, zval **b
paramValuePtr = (SQLPOINTER)(Z_STRVAL_P(curr->value));
break;
case SQL_VARCHAR:
case SQL_WVARCHAR:
case SQL_VARGRAPHIC:
case SQL_LONGVARCHAR:
case SQL_WLONGVARCHAR:
case SQL_LONGVARGRAPHIC:
valueType = SQL_C_CHAR;
if (origlen != -1) {
curr->bind_indicator = origlen;
Expand Down
40 changes: 40 additions & 0 deletions tests/test_gh_62.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
--TEST--
IBM-DB2: Binding empty string to NVARCHAR (GH-62)
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
require_once('connection.inc');

$conn = db2_connect($database, $user, $password);

$input = '';
$table = "EMPTY_NVARCHAR";
$drop = "DROP TABLE $table";
$res = @db2_exec($conn, $drop);
/* ensure that SQL_NTS is used so empty strings work for not just VARCHAR */
$create = "CREATE TABLE $table (TEXTME NVARCHAR(1024))"; /* CCSID 1200? */
$res = db2_exec($conn, $create);
if ($res == false) {
die("Failed to create table: " . db2_stmt_error($create) . " - " . db2_stmt_errormsg($create) . "\n");
}
$insert = "INSERT INTO $table (TEXTME) VALUES (?)";
$sth = db2_prepare($conn, $insert);
$res = db2_execute($sth, array($input));
if ($res == false) {
die("Failed to insert: " . db2_stmt_error($insert) . " - " . db2_stmt_errormsg($insert) . "\n");
}
$look = "select TEXTME from $table";
$res = db2_exec($conn, $look);
$row = db2_fetch_array($res);

if (bin2hex($row[0]) == bin2hex($input)) {
echo "success\n";
} else {
echo "Failure\n";
}

?>
--EXPECTF--
success

0 comments on commit 66c9ee1

Please sign in to comment.