Skip to content

Commit d2d663f

Browse files
committed
Include the first character for truncating spaces if needed
Resolves getting a single space back if a varchar out parameter returns an empty string on IBM i. Passes tests, should be fine on LUW.
1 parent 9191aa2 commit d2d663f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

ibm_db2.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4940,8 +4940,14 @@ PHP_FUNCTION(db2_execute)
49404940
bindlen = tmp_curr->bind_indicator;
49414941
origptr[bindlen] = '\0';
49424942
Z_STRLEN_P(tmp_curr->value) = bindlen;
4943-
/* trim (IBM i may return 0x40 for EBCDIC space when not 1208 ccsid -- yes, db2 bug, just handle)*/
4944-
for (;bindlen && (origptr[bindlen] == 0x20 || origptr[bindlen] == 0x40 || origptr[bindlen] == 0x00); bindlen--) {
4943+
/*
4944+
* trim (IBM i may return 0x40 for EBCDIC space when not 1208 ccsid -- yes, db2 bug, just handle)
4945+
*
4946+
* CB 20210426: when truncating, we might get an
4947+
* empty string, so be sure we can nullify the
4948+
* first character if needed
4949+
*/
4950+
for (;bindlen >= 0 && (origptr[bindlen] == 0x20 || origptr[bindlen] == 0x40 || origptr[bindlen] == 0x00); bindlen--) {
49454951
Z_STRLEN_P(tmp_curr->value) = bindlen;
49464952
origptr[bindlen] = '\0';
49474953
}

0 commit comments

Comments
 (0)