diff --git a/oci_statement.c b/oci_statement.c index 5f8f062..a56618b 100644 --- a/oci_statement.c +++ b/oci_statement.c @@ -225,23 +225,39 @@ static sb4 oci_bind_input_cb(dvoid *ctx, OCIBind *bindp, ub4 iter, ub4 index, dv *bufpp = 0; *alenp = -1; } else if (!P->thing) { - if(PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_BOOL) { - /* Handle boolean as "1"/ "0" */ - if(zend_is_true(parameter)) { - zval_ptr_dtor(parameter); - ZVAL_CHAR(parameter, '1'); - } else { - zval_ptr_dtor(parameter); - ZVAL_CHAR(parameter, '0'); + if (P->oci_type == SQLT_INT) + { + P->int_val = (sb4) zval_get_long(parameter); + *bufpp = &P->int_val; + *alenp = sizeof(sb4); + } + else + { + if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_BOOL) + { + /* Handle boolean as "1"/ "0" */ + if (zend_is_true(parameter)) + { + zval_ptr_dtor(parameter); + ZVAL_CHAR(parameter, '1'); + } + else + { + zval_ptr_dtor(parameter); + ZVAL_CHAR(parameter, '0'); + } } - } else { - /* regular string bind */ - if (!try_convert_to_string(parameter)) { - return OCI_ERROR; + else + { + /* regular string bind */ + if (!try_convert_to_string(parameter)) + { + return OCI_ERROR; + } } + *bufpp = Z_STRVAL_P(parameter); + *alenp = (ub4) Z_STRLEN_P(parameter); } - *bufpp = Z_STRVAL_P(parameter); - *alenp = (ub4) Z_STRLEN_P(parameter); } *piecep = OCI_ONE_PIECE; @@ -272,6 +288,17 @@ static sb4 oci_bind_output_cb(dvoid *ctx, OCIBind *bindp, ub4 iter, ub4 index, d return OCI_CONTINUE; } + if (P->oci_type == SQLT_INT) + { + P->actual_len = sizeof(sb4); + *bufpp = &P->int_val; + *alenpp = &P->actual_len; + *piecep = OCI_ONE_PIECE; + *rcodepp = &P->retcode; + *indpp = &P->indicator; + return OCI_CONTINUE; + } + if (Z_TYPE_P(parameter) == IS_OBJECT || Z_TYPE_P(parameter) == IS_RESOURCE) { return OCI_CONTINUE; } @@ -343,6 +370,11 @@ static int oci_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *pa value_sz = (sb4) sizeof(OCILobLocator*); break; + case PDO_PARAM_INT: + P->oci_type = SQLT_INT; + value_sz = (sb4) sizeof(sb4); + break; + case PDO_PARAM_STR: default: P->oci_type = SQLT_CHR; @@ -396,7 +428,7 @@ static int oci_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *pa } zval_ptr_dtor_str(parameter); ZVAL_UNDEF(parameter); - } else if (Z_TYPE_P(parameter) == IS_STRING) { + } else if (Z_TYPE_P(parameter) == IS_STRING) { ZVAL_STR(parameter, zend_string_truncate(Z_STR_P(parameter), P->actual_len, false)); Z_STRVAL_P(parameter)[Z_STRLEN_P(parameter)] = '\0'; } diff --git a/php_pdo_oci_int.h b/php_pdo_oci_int.h index dd513ff..0afd172 100644 --- a/php_pdo_oci_int.h +++ b/php_pdo_oci_int.h @@ -84,6 +84,8 @@ typedef struct { dvoid *thing; /* for LOBS, REFCURSORS etc. */ + sb4 int_val; + unsigned used_for_output; } pdo_oci_bound_param; diff --git a/tests/pdo_oci_bind_int.phpt b/tests/pdo_oci_bind_int.phpt new file mode 100644 index 0000000..d27ae5d --- /dev/null +++ b/tests/pdo_oci_bind_int.phpt @@ -0,0 +1,49 @@ +--TEST-- +PDO_OCI: Integer binding test +--EXTENSIONS-- +pdo +pdo_oci +--SKIPIF-- + +--FILE-- +prepare($sql); +$statement->bindValue(':a', $num, PDO::PARAM_INT); +$statement->bindValue(':b', $str); +$statement->execute(); +$row = $statement->fetch(PDO::FETCH_ASSOC); +print_r($row); +var_dump($row['a_where']); + +?> +--EXPECT-- +Array +( + [a] => 4 + [a_type] => Typ=2 Len=2: 193,5 + [b] => 4 + [b_type] => Typ=1 Len=1: 52 + [num] => 4 + [num_type] => Typ=2 Len=2: 193,5 + [str] => 4 + [str_type] => Typ=96 Len=1: 52 + [a_where] => 1 + [num_where] => 1 +) +string(1) "1"