Skip to content

Commit 29ca273

Browse files
committed
Fix GH-62
Other varchar-like types (i.e. nvarchar as wvarchar) need the same treatment so they use SQL_NTS, so that empty strings as the bound parameter will work.
1 parent 8cf053a commit 29ca273

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

ibm_db2.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4578,6 +4578,11 @@ static int _php_db2_bind_data( stmt_handle *stmt_res, param_node *curr, zval **b
45784578
paramValuePtr = (SQLPOINTER)(Z_STRVAL_P(curr->value));
45794579
break;
45804580
case SQL_VARCHAR:
4581+
case SQL_WVARCHAR:
4582+
case SQL_VARGRAPHIC:
4583+
case SQL_LONGVARCHAR:
4584+
case SQL_WLONGVARCHAR:
4585+
case SQL_LONGVARGRAPHIC:
45814586
valueType = SQL_C_CHAR;
45824587
if (origlen != -1) {
45834588
curr->bind_indicator = origlen;

tests/test_gh_62.phpt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 OR REPLACE TABLE $table (TEXTME NVARCHAR(1024))"; /* CCSID 1200? */
17+
$res = db2_exec($conn, $create);
18+
$insert = "INSERT INTO $table (TEXTME) VALUES (?)";
19+
$sth = db2_prepare($conn, $insert);
20+
$res = db2_execute($sth, array($input));
21+
$look = "select TEXTME from $table";
22+
$res = db2_exec($conn, $look);
23+
$row = db2_fetch_array($res);
24+
25+
if (bin2hex($row[0]) == bin2hex($input)) {
26+
echo "success\n";
27+
} else {
28+
echo "Failure\n";
29+
}
30+
31+
?>
32+
--EXPECTF--
33+
success
34+

0 commit comments

Comments
 (0)