Skip to content

Commit 9ccdffa

Browse files
committed
Initial boolean support
Works with db2_result (albeit returns an integer) and db2_fetch_* (which fetches booleans). Tested on IBM i 7.5. Parameter binding is untested. No CI tests yet, need to figure out a way to do it sanely. Fixes GH-56
1 parent 7c1458c commit 9ccdffa

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

ibm_db2.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,6 +2122,15 @@ static int _php_db2_bind_column_helper(stmt_handle *stmt_res)
21222122
}
21232123
break;
21242124

2125+
case SQL_BOOLEAN:
2126+
rc = SQLBindCol((SQLHSTMT)stmt_res->hstmt, (SQLUSMALLINT)(i + 1),
2127+
SQL_C_LONG, &row_data->i_val, sizeof(row_data->i_val),
2128+
(SQLINTEGER *)(&stmt_res->row_data[i].out_length));
2129+
if ( rc == SQL_ERROR ) {
2130+
_php_db2_check_sql_errors((SQLHSTMT)stmt_res->hstmt, SQL_HANDLE_STMT, rc, 1, NULL, -1, 1);
2131+
}
2132+
break;
2133+
21252134
case SQL_SMALLINT:
21262135
rc = SQLBindCol((SQLHSTMT)stmt_res->hstmt, (SQLUSMALLINT)(i + 1),
21272136
SQL_C_DEFAULT, &row_data->s_val, sizeof(row_data->s_val),
@@ -4444,6 +4453,7 @@ static int _php_db2_bind_data( stmt_handle *stmt_res, param_node *curr, zval **b
44444453
}
44454454

44464455
switch ( curr->data_type ) {
4456+
case SQL_BOOLEAN:
44474457
case SQL_SMALLINT:
44484458
case SQL_INTEGER:
44494459
case SQL_REAL:
@@ -5481,6 +5491,9 @@ PHP_FUNCTION(db2_field_type)
54815491
RETURN_FALSE;
54825492
}
54835493
switch (stmt_res->column_info[col].type) {
5494+
case SQL_BOOLEAN:
5495+
str_val = "boolean";
5496+
break;
54845497
case SQL_SMALLINT:
54855498
case SQL_INTEGER:
54865499
case SQL_BIGINT:
@@ -5931,6 +5944,8 @@ PHP_FUNCTION(db2_result)
59315944
}
59325945
break;
59335946

5947+
/* BOOLEAN can't be represented as true/false because false is considered an error */
5948+
case SQL_BOOLEAN:
59345949
case SQL_SMALLINT:
59355950
case SQL_INTEGER:
59365951
rc = _php_db2_get_data(stmt_res, col_num+1, SQL_C_LONG, (SQLPOINTER)&long_val, sizeof(long_val), &out_length);
@@ -6290,6 +6305,14 @@ static void _php_db2_bind_fetch_helper(INTERNAL_FUNCTION_PARAMETERS, int op)
62906305
strlen((char *)row_data->str_val));
62916306
}
62926307
break;
6308+
case SQL_BOOLEAN:
6309+
if ( op & DB2_FETCH_ASSOC ) {
6310+
add_assoc_bool(return_value, (char *)stmt_res->column_info[i].name, row_data->i_val);
6311+
}
6312+
if ( op & DB2_FETCH_INDEX ) {
6313+
add_index_bool(return_value, i, row_data->i_val);
6314+
}
6315+
break;
62936316
case SQL_SMALLINT:
62946317
if ( op & DB2_FETCH_ASSOC ) {
62956318
add_assoc_long(return_value, (char *)stmt_res->column_info[i].name, row_data->s_val);

php_ibm_db2_int.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ typedef uint32_t uintptr_t;
1515
#endif
1616
#endif
1717

18+
/*
19+
* Added in IBM i 7.5, also in LUW 11.1 MP1/FP1
20+
* see: https://www.ibm.com/docs/en/db2/11.1?topic=database-mod-pack-fix-pack-updates#c0061179__FP1
21+
*/
22+
#ifndef SQL_BOOLEAN
23+
#define SQL_BOOLEAN 16
24+
#endif
25+
1826
/* Needed for backward compatibility (SQL_ATTR_DBC_SYS_NAMING not defined prior to DB2 10.1.0.2) */
1927
#ifndef SQL_ATTR_DBC_SYS_NAMING
2028
#define SQL_ATTR_DBC_SYS_NAMING 3017

0 commit comments

Comments
 (0)