From 29ca2733e16fcf725cad2667c524704903f33860 Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Mon, 25 Nov 2024 17:09:16 -0400 Subject: [PATCH 1/2] 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. --- ibm_db2.c | 5 +++++ tests/test_gh_62.phpt | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 tests/test_gh_62.phpt diff --git a/ibm_db2.c b/ibm_db2.c index 6a4149e..e26b780 100644 --- a/ibm_db2.c +++ b/ibm_db2.c @@ -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; diff --git a/tests/test_gh_62.phpt b/tests/test_gh_62.phpt new file mode 100644 index 0000000..ea0927a --- /dev/null +++ b/tests/test_gh_62.phpt @@ -0,0 +1,34 @@ +--TEST-- +IBM-DB2: Binding empty string to NVARCHAR (GH-62) +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +success + From cbcc729bfedf7bcaacc5d64ee3f92675721933c3 Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Mon, 25 Nov 2024 18:07:28 -0400 Subject: [PATCH 2/2] more compatible SQL, error messages --- tests/test_gh_62.phpt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/test_gh_62.phpt b/tests/test_gh_62.phpt index ea0927a..5546c01 100644 --- a/tests/test_gh_62.phpt +++ b/tests/test_gh_62.phpt @@ -13,11 +13,17 @@ $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 OR REPLACE TABLE $table (TEXTME NVARCHAR(1024))"; /* CCSID 1200? */ +$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);