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

Fix GH-62 #63

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions ibm_db2.c
Original file line number Diff line number Diff line change
Expand Up @@ -4578,6 +4578,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

Loading