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
This commit is contained in:
Calvin Buckley
2023-09-15 10:53:06 -04:00
parent 7c1458c7da
commit 9ccdffaad4
2 changed files with 31 additions and 0 deletions

View File

@@ -2122,6 +2122,15 @@ static int _php_db2_bind_column_helper(stmt_handle *stmt_res)
}
break;
case SQL_BOOLEAN:
rc = SQLBindCol((SQLHSTMT)stmt_res->hstmt, (SQLUSMALLINT)(i + 1),
SQL_C_LONG, &row_data->i_val, sizeof(row_data->i_val),
(SQLINTEGER *)(&stmt_res->row_data[i].out_length));
if ( rc == SQL_ERROR ) {
_php_db2_check_sql_errors((SQLHSTMT)stmt_res->hstmt, SQL_HANDLE_STMT, rc, 1, NULL, -1, 1);
}
break;
case SQL_SMALLINT:
rc = SQLBindCol((SQLHSTMT)stmt_res->hstmt, (SQLUSMALLINT)(i + 1),
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
}
switch ( curr->data_type ) {
case SQL_BOOLEAN:
case SQL_SMALLINT:
case SQL_INTEGER:
case SQL_REAL:
@@ -5481,6 +5491,9 @@ PHP_FUNCTION(db2_field_type)
RETURN_FALSE;
}
switch (stmt_res->column_info[col].type) {
case SQL_BOOLEAN:
str_val = "boolean";
break;
case SQL_SMALLINT:
case SQL_INTEGER:
case SQL_BIGINT:
@@ -5931,6 +5944,8 @@ PHP_FUNCTION(db2_result)
}
break;
/* BOOLEAN can't be represented as true/false because false is considered an error */
case SQL_BOOLEAN:
case SQL_SMALLINT:
case SQL_INTEGER:
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)
strlen((char *)row_data->str_val));
}
break;
case SQL_BOOLEAN:
if ( op & DB2_FETCH_ASSOC ) {
add_assoc_bool(return_value, (char *)stmt_res->column_info[i].name, row_data->i_val);
}
if ( op & DB2_FETCH_INDEX ) {
add_index_bool(return_value, i, row_data->i_val);
}
break;
case SQL_SMALLINT:
if ( op & DB2_FETCH_ASSOC ) {
add_assoc_long(return_value, (char *)stmt_res->column_info[i].name, row_data->s_val);

View File

@@ -15,6 +15,14 @@ typedef uint32_t uintptr_t;
#endif
#endif
/*
* Added in IBM i 7.5, also in LUW 11.1 MP1/FP1
* see: https://www.ibm.com/docs/en/db2/11.1?topic=database-mod-pack-fix-pack-updates#c0061179__FP1
*/
#ifndef SQL_BOOLEAN
#define SQL_BOOLEAN 16
#endif
/* Needed for backward compatibility (SQL_ATTR_DBC_SYS_NAMING not defined prior to DB2 10.1.0.2) */
#ifndef SQL_ATTR_DBC_SYS_NAMING
#define SQL_ATTR_DBC_SYS_NAMING 3017