Skip to content

Commit 66c9ee1

Browse files
authored
Merge pull request #63 from php/fix-gh-62
Fix GH-62
2 parents 8f50036 + cbcc729 commit 66c9ee1

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

ibm_db2.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4584,6 +4584,11 @@ static int _php_db2_bind_data( stmt_handle *stmt_res, param_node *curr, zval **b
45844584
paramValuePtr = (SQLPOINTER)(Z_STRVAL_P(curr->value));
45854585
break;
45864586
case SQL_VARCHAR:
4587+
case SQL_WVARCHAR:
4588+
case SQL_VARGRAPHIC:
4589+
case SQL_LONGVARCHAR:
4590+
case SQL_WLONGVARCHAR:
4591+
case SQL_LONGVARGRAPHIC:
45874592
valueType = SQL_C_CHAR;
45884593
if (origlen != -1) {
45894594
curr->bind_indicator = origlen;

tests/test_gh_62.phpt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
IBM-DB2: Binding empty string to NVARCHAR (GH-62)
3+
--SKIPIF--
4+
<?php require_once('skipif.inc'); ?>
5+
--FILE--
6+
<?php
7+
require_once('connection.inc');
8+
9+
$conn = db2_connect($database, $user, $password);
10+
11+
$input = '';
12+
$table = "EMPTY_NVARCHAR";
13+
$drop = "DROP TABLE $table";
14+
$res = @db2_exec($conn, $drop);
15+
/* ensure that SQL_NTS is used so empty strings work for not just VARCHAR */
16+
$create = "CREATE TABLE $table (TEXTME NVARCHAR(1024))"; /* CCSID 1200? */
17+
$res = db2_exec($conn, $create);
18+
if ($res == false) {
19+
die("Failed to create table: " . db2_stmt_error($create) . " - " . db2_stmt_errormsg($create) . "\n");
20+
}
21+
$insert = "INSERT INTO $table (TEXTME) VALUES (?)";
22+
$sth = db2_prepare($conn, $insert);
23+
$res = db2_execute($sth, array($input));
24+
if ($res == false) {
25+
die("Failed to insert: " . db2_stmt_error($insert) . " - " . db2_stmt_errormsg($insert) . "\n");
26+
}
27+
$look = "select TEXTME from $table";
28+
$res = db2_exec($conn, $look);
29+
$row = db2_fetch_array($res);
30+
31+
if (bin2hex($row[0]) == bin2hex($input)) {
32+
echo "success\n";
33+
} else {
34+
echo "Failure\n";
35+
}
36+
37+
?>
38+
--EXPECTF--
39+
success
40+

0 commit comments

Comments
 (0)