diff options
Diffstat (limited to 'ext/oci8/oci8_statement.c')
-rw-r--r-- | ext/oci8/oci8_statement.c | 148 |
1 files changed, 74 insertions, 74 deletions
diff --git a/ext/oci8/oci8_statement.c b/ext/oci8/oci8_statement.c index 97aa51b077..a0635fb7e6 100644 --- a/ext/oci8/oci8_statement.c +++ b/ext/oci8/oci8_statement.c @@ -60,9 +60,9 @@ php_oci_statement *php_oci_statement_create(php_oci_connection *connection, char /* do not allocate stmt handle for refcursors, we'll get it from OCIStmtPrepare2() */ PHP_OCI_CALL(OCIHandleAlloc, (connection->env, (dvoid **)&(statement->stmt), OCI_HTYPE_STMT, 0, NULL)); } - + PHP_OCI_CALL(OCIHandleAlloc, (connection->env, (dvoid **)&(statement->err), OCI_HTYPE_ERROR, 0, NULL)); - + if (query_len > 0) { PHP_OCI_CALL_RETURN(errstatus, OCIStmtPrepare2, ( @@ -93,7 +93,7 @@ php_oci_statement *php_oci_statement_create(php_oci_connection *connection, char return NULL; } } - + if (query && query_len) { statement->last_query = ecalloc(1, query_len + 1); memcpy(statement->last_query, query, query_len); @@ -118,11 +118,11 @@ php_oci_statement *php_oci_statement_create(php_oci_connection *connection, char } else { php_oci_statement_set_prefetch(statement, (ub4)100); /* semi-arbitrary, "sensible default" */ } - + PHP_OCI_REGISTER_RESOURCE(statement, le_statement); OCI_G(num_statements)++; - + return statement; } /* }}} */ @@ -153,7 +153,7 @@ php_oci_statement *php_oci_get_implicit_resultset(php_oci_statement *statement) statement2 = ecalloc(1,sizeof(php_oci_statement)); PHP_OCI_CALL(OCIHandleAlloc, (statement->connection->env, (dvoid **)&(statement2->err), OCI_HTYPE_ERROR, 0, NULL)); - statement2->stmt = (OCIStmt *)result; + statement2->stmt = (OCIStmt *)result; statement2->parent_stmtid = statement->id; statement2->impres_child_stmt = NULL; statement2->impres_count = 0; @@ -175,11 +175,11 @@ php_oci_statement *php_oci_get_implicit_resultset(php_oci_statement *statement) GC_REFCOUNT(statement2->connection->id)++; php_oci_statement_set_prefetch(statement2, statement->prefetch_count); - + PHP_OCI_REGISTER_RESOURCE(statement2, le_statement); - + OCI_G(num_statements)++; - + return statement2; } #endif /* OCI_MAJOR_VERSION < 12 */ @@ -197,7 +197,7 @@ int php_oci_statement_set_prefetch(php_oci_statement *statement, ub4 prefetch ) } PHP_OCI_CALL_RETURN(errstatus, OCIAttrSet, (statement->stmt, OCI_HTYPE_STMT, &prefetch, 0, OCI_ATTR_PREFETCH_ROWS, statement->err)); - + if (errstatus != OCI_SUCCESS) { statement->errcode = php_oci_error(statement->err, errstatus); PHP_OCI_HANDLE_ERROR(statement->connection, statement->errcode); @@ -293,7 +293,7 @@ int php_oci_statement_fetch(php_oci_statement *statement, ub4 nrows) piecewisecols = 1; } } - + while (errstatus == OCI_NEED_DATA) { if (piecewisecols) { PHP_OCI_CALL_RETURN(errstatus, @@ -359,11 +359,11 @@ int php_oci_statement_fetch(php_oci_statement *statement, ub4 nrows) if (column == NULL) { continue; } - + if (!column->define) { continue; } - + ZEND_ASSERT(Z_ISREF(column->define->val)); zval_ptr_dtor(Z_REFVAL(column->define->val)); ZVAL_NULL(Z_REFVAL(column->define->val)); @@ -419,11 +419,11 @@ sb4 php_oci_define_callback(dvoid *ctx, OCIDefine *define, ub4 iter, dvoid **buf php_oci_out_column *outcol = (php_oci_out_column *)ctx; if (!outcol) { - + php_error_docref(NULL, E_WARNING, "Invalid context pointer value"); return OCI_ERROR; } - + switch(outcol->data_type) { case SQLT_RSET: { php_oci_statement *nested_stmt; @@ -466,7 +466,7 @@ sb4 php_oci_define_callback(dvoid *ctx, OCIDefine *define, ub4 iter, dvoid **buf } outcol->descid = descr->id; descr->charset_form = outcol->charset_form; - + *bufpp = descr->descriptor; *alenpp = &(outcol->retlen4); *piecep = OCI_ONE_PIECE; @@ -512,7 +512,7 @@ int php_oci_statement_execute(php_oci_statement *statement, ub4 mode) return 1; break; } - + if (!statement->stmttype) { /* get statement type */ PHP_OCI_CALL_RETURN(errstatus, OCIAttrGet, ((dvoid *)statement->stmt, OCI_HTYPE_STMT, (ub2 *)&statement->stmttype, (ub4 *)0, OCI_ATTR_STMT_TYPE, statement->err)); @@ -531,7 +531,7 @@ int php_oci_statement_execute(php_oci_statement *statement, ub4 mode) } else { iters = 1; } - + if (statement->last_query) { /* Don't execute REFCURSORS or Implicit Result Set handles */ if (statement->binds) { @@ -550,7 +550,7 @@ int php_oci_statement_execute(php_oci_statement *statement, ub4 mode) PHP_OCI_HANDLE_ERROR(statement->connection, statement->errcode); return 1; } - + if (statement->binds) { zend_hash_apply(statement->binds, php_oci_bind_post_exec); } @@ -575,15 +575,15 @@ int php_oci_statement_execute(php_oci_statement *statement, ub4 mode) if (statement->stmttype == OCI_STMT_SELECT && statement->executed == 0) { /* we only need to do the define step is this very statement is executed the first time! */ statement->executed = 1; - + ALLOC_HASHTABLE(statement->columns); zend_hash_init(statement->columns, 13, NULL, php_oci_column_hash_dtor, 0); - + counter = 1; /* get number of columns */ PHP_OCI_CALL_RETURN(errstatus, OCIAttrGet, ((dvoid *)statement->stmt, OCI_HTYPE_STMT, (dvoid *)&colcount, (ub4 *)0, OCI_ATTR_PARAM_COUNT, statement->err)); - + if (errstatus != OCI_SUCCESS) { statement->errcode = php_oci_error(statement->err, errstatus); PHP_OCI_HANDLE_ERROR(statement->connection, statement->errcode); @@ -591,19 +591,19 @@ int php_oci_statement_execute(php_oci_statement *statement, ub4 mode) } statement->ncolumns = colcount; - + for (counter = 1; counter <= colcount; counter++) { outcol = (php_oci_out_column *) ecalloc(1, sizeof(php_oci_out_column)); - + if ((outcol = zend_hash_index_update_ptr(statement->columns, counter, outcol)) == NULL) { FREE_HASHTABLE(statement->columns); /* out of memory */ return 1; } - + /* get column */ PHP_OCI_CALL_RETURN(errstatus, OCIParamGet, ((dvoid *)statement->stmt, OCI_HTYPE_STMT, statement->err, (dvoid**)¶m, counter)); - + if (errstatus != OCI_SUCCESS) { statement->errcode = php_oci_error(statement->err, errstatus); PHP_OCI_HANDLE_ERROR(statement->connection, statement->errcode); @@ -629,7 +629,7 @@ int php_oci_statement_execute(php_oci_statement *statement, ub4 mode) PHP_OCI_HANDLE_ERROR(statement->connection, statement->errcode); return 1; } - + /* get character set id */ PHP_OCI_CALL_RETURN(errstatus, OCIAttrGet, ((dvoid *)param, OCI_DTYPE_PARAM, (dvoid *)&outcol->charset_id, (ub4 *)0, OCI_ATTR_CHARSET_ID, statement->err)); @@ -639,10 +639,10 @@ int php_oci_statement_execute(php_oci_statement *statement, ub4 mode) PHP_OCI_HANDLE_ERROR(statement->connection, statement->errcode); return 1; } - + /* get size of the column */ PHP_OCI_CALL_RETURN(errstatus, OCIAttrGet, ((dvoid *)param, OCI_DTYPE_PARAM, (dvoid *)&outcol->data_size, (dvoid *)0, OCI_ATTR_DATA_SIZE, statement->err)); - + if (errstatus != OCI_SUCCESS) { PHP_OCI_CALL(OCIDescriptorFree, (param, OCI_DTYPE_PARAM)); statement->errcode = php_oci_error(statement->err, errstatus); @@ -655,7 +655,7 @@ int php_oci_statement_execute(php_oci_statement *statement, ub4 mode) /* get scale of the column */ PHP_OCI_CALL_RETURN(errstatus, OCIAttrGet, ((dvoid *)param, OCI_DTYPE_PARAM, (dvoid *)&outcol->scale, (dvoid *)0, OCI_ATTR_SCALE, statement->err)); - + if (errstatus != OCI_SUCCESS) { PHP_OCI_CALL(OCIDescriptorFree, (param, OCI_DTYPE_PARAM)); statement->errcode = php_oci_error(statement->err, errstatus); @@ -665,17 +665,17 @@ int php_oci_statement_execute(php_oci_statement *statement, ub4 mode) /* get precision of the column */ PHP_OCI_CALL_RETURN(errstatus, OCIAttrGet, ((dvoid *)param, OCI_DTYPE_PARAM, (dvoid *)&outcol->precision, (dvoid *)0, OCI_ATTR_PRECISION, statement->err)); - + if (errstatus != OCI_SUCCESS) { PHP_OCI_CALL(OCIDescriptorFree, (param, OCI_DTYPE_PARAM)); statement->errcode = php_oci_error(statement->err, errstatus); PHP_OCI_HANDLE_ERROR(statement->connection, statement->errcode); return 1; } - + /* get name of the column */ PHP_OCI_CALL_RETURN(errstatus, OCIAttrGet, ((dvoid *)param, OCI_DTYPE_PARAM, (dvoid **)&colname, (ub4 *)&outcol->name_len, (ub4)OCI_ATTR_NAME, statement->err)); - + if (errstatus != OCI_SUCCESS) { PHP_OCI_CALL(OCIDescriptorFree, (param, OCI_DTYPE_PARAM)); statement->errcode = php_oci_error(statement->err, errstatus); @@ -766,9 +766,9 @@ int php_oci_statement_execute(php_oci_statement *statement, ub4 mode) } else { outcol->storage_size4++; /* add one for string terminator */ } - + outcol->storage_size4 *= 3; - + dynamic = OCI_DEFAULT; buf = outcol->data = (text *) safe_emalloc(1, outcol->storage_size4, 0); memset(buf, 0, outcol->storage_size4); @@ -812,7 +812,7 @@ int php_oci_statement_execute(php_oci_statement *statement, ub4 mode) ); } - + if (errstatus != OCI_SUCCESS) { statement->errcode = php_oci_error(statement->err, errstatus); PHP_OCI_HANDLE_ERROR(statement->connection, statement->errcode); @@ -902,7 +902,7 @@ void php_oci_statement_free(php_oci_statement *statement) zend_list_delete(statement->connection->id); efree(statement); - + OCI_G(num_statements)--; } /* }}} */ @@ -923,7 +923,7 @@ int php_oci_bind_pre_exec(zval *data, void *result) * bind->indicator are not used for oci_bind_array_by_name. */ return 0; - } + } switch (bind->type) { case SQLT_NTY: case SQLT_BFILEE: @@ -936,7 +936,7 @@ int php_oci_bind_pre_exec(zval *data, void *result) *(int *)result = 1; } break; - + case SQLT_CHR: case SQLT_AFC: case SQLT_INT: @@ -1036,7 +1036,7 @@ int php_oci_bind_post_exec(zval *data) ub4 buff_len = 1024; memset((void*)buff,0,sizeof(buff)); - + if ((i < (int) bind->array.old_length) && (entry = zend_hash_get_current_data(hash)) != NULL) { PHP_OCI_CALL_RETURN(errstatus, OCIDateToText, (connection->err, &(((OCIDate *)(bind->array.elements))[i]), 0, 0, 0, 0, &buff_len, buff)); zval_ptr_dtor(entry); @@ -1063,7 +1063,7 @@ int php_oci_bind_post_exec(zval *data) } } break; - + case SQLT_AFC: case SQLT_CHR: case SQLT_VCS: @@ -1119,7 +1119,7 @@ int php_oci_bind_by_name(php_oci_statement *statement, char *name, size_t name_l case SQLT_NTY: { zval *tmp; - + if (Z_TYPE_P(param) != IS_OBJECT || (tmp = zend_hash_str_find(Z_OBJPROP_P(param), "collection", sizeof("collection")-1)) == NULL) { php_error_docref(NULL, E_WARNING, "Unable to find collection property"); return 1; @@ -1128,7 +1128,7 @@ int php_oci_bind_by_name(php_oci_statement *statement, char *name, size_t name_l PHP_OCI_ZVAL_TO_COLLECTION_EX(tmp, bind_collection); value_sz = sizeof(void*); mode = OCI_DEFAULT; - + if (!bind_collection->collection) { return 1; } @@ -1141,7 +1141,7 @@ int php_oci_bind_by_name(php_oci_statement *statement, char *name, size_t name_l case SQLT_RDD: { zval *tmp; - + if (Z_TYPE_P(param) != IS_OBJECT || (tmp = zend_hash_str_find(Z_OBJPROP_P(param), "descriptor", sizeof("descriptor")-1)) == NULL) { php_error_docref(NULL, E_WARNING, "Unable to find descriptor property"); return 1; @@ -1150,15 +1150,15 @@ int php_oci_bind_by_name(php_oci_statement *statement, char *name, size_t name_l PHP_OCI_ZVAL_TO_DESCRIPTOR_EX(tmp, bind_descriptor); value_sz = sizeof(void*); - + oci_desc = bind_descriptor->descriptor; - + if (!oci_desc) { return 1; } } break; - + case SQLT_INT: case SQLT_NUM: if (Z_TYPE_P(param) == IS_RESOURCE || Z_TYPE_P(param) == IS_OBJECT) { @@ -1170,7 +1170,7 @@ int php_oci_bind_by_name(php_oci_statement *statement, char *name, size_t name_l value_sz = sizeof(oci_phpsized_int); mode = OCI_DEFAULT; break; - + case SQLT_LBI: case SQLT_BIN: case SQLT_LNG: @@ -1265,7 +1265,7 @@ int php_oci_bind_by_name(php_oci_statement *statement, char *name, size_t name_l */ if (value_sz == 0) value_sz = 1; - + bindp->descriptor = oci_desc; bindp->statement = oci_stmt; bindp->parent_statement = statement; @@ -1283,7 +1283,7 @@ int php_oci_bind_by_name(php_oci_statement *statement, char *name, size_t name_l statement->stmt, /* statement handle */ (OCIBind **)&bindp->bind, /* bind hdl (will alloc) */ statement->err, /* error handle */ - (text*) name, /* placeholder name */ + (text*) name, /* placeholder name */ (sb4) name_len, /* placeholder length */ (dvoid *)bind_data, /* in/out data */ value_sz, /* PHP_OCI_MAX_DATA_SIZE, */ /* max size of input/output data */ @@ -1335,14 +1335,14 @@ int php_oci_bind_by_name(php_oci_statement *statement, char *name, size_t name_l (ub4 *) 0 ) ); - + if (errstatus) { statement->errcode = php_oci_error(statement->err, errstatus); PHP_OCI_HANDLE_ERROR(statement->connection, statement->errcode); return 1; } } - + statement->errcode = 0; /* retain backwards compat with OCI8 1.4 */ return 0; } @@ -1484,7 +1484,7 @@ sb4 php_oci_bind_out_callback( Z_STRVAL_P(val) = ecalloc(1, Z_STRLEN_P(val) + 1); /* XXX is this right? */ ZVAL_STRINGL(val, NULL, Z_STRLEN(val) + 1); -#endif +#endif /* XXX we assume that zend-zval len has 4 bytes */ *alenpp = (ub4*) &Z_STRLEN_P(val); @@ -1520,7 +1520,7 @@ php_oci_out_column *php_oci_statement_get_column_helper(INTERNAL_FUNCTION_PARAME if (need_data && !statement->has_data) { return NULL; } - + if (Z_TYPE_P(column_index) == IS_STRING) { column = php_oci_statement_get_column(statement, -1, Z_STRVAL_P(column_index), (int) Z_STRLEN_P(column_index)); if (!column) { @@ -1551,9 +1551,9 @@ int php_oci_statement_get_type(php_oci_statement *statement, ub2 *type) { ub2 statement_type; sword errstatus; - + *type = 0; - + PHP_OCI_CALL_RETURN(errstatus, OCIAttrGet, ((dvoid *)statement->stmt, OCI_HTYPE_STMT, (ub2 *)&statement_type, (ub4 *)0, OCI_ATTR_STMT_TYPE, statement->err)); if (errstatus != OCI_SUCCESS) { @@ -1574,9 +1574,9 @@ int php_oci_statement_get_numrows(php_oci_statement *statement, ub4 *numrows) { ub4 statement_numrows; sword errstatus; - + *numrows = 0; - + PHP_OCI_CALL_RETURN(errstatus, OCIAttrGet, ((dvoid *)statement->stmt, OCI_HTYPE_STMT, (ub4 *)&statement_numrows, (ub4 *)0, OCI_ATTR_ROW_COUNT, statement->err)); if (errstatus != OCI_SUCCESS) { @@ -1609,7 +1609,7 @@ int php_oci_bind_array_by_name(php_oci_statement *statement, char *name, size_t php_error_docref(NULL, E_WARNING, "Invalid max length value (" ZEND_LONG_FMT ")", maxlength); return 1; } - + switch(type) { case SQLT_NUM: case SQLT_INT: @@ -1620,7 +1620,7 @@ int php_oci_bind_array_by_name(php_oci_statement *statement, char *name, size_t case SQLT_FLT: bind = php_oci_bind_array_helper_double(val, max_table_length); break; - + case SQLT_AFC: case SQLT_CHR: case SQLT_VCS: @@ -1646,7 +1646,7 @@ int php_oci_bind_array_by_name(php_oci_statement *statement, char *name, size_t /* failed to generate bind struct */ return 1; } - + bind->descriptor = NULL; bind->statement = NULL; bind->parent_statement = statement; @@ -1675,8 +1675,8 @@ int php_oci_bind_array_by_name(php_oci_statement *statement, char *name, size_t (ub4) OCI_DEFAULT ) ); - - + + if (errstatus != OCI_SUCCESS) { if (bind->array.elements) { efree(bind->array.elements); @@ -1737,7 +1737,7 @@ php_oci_bind *php_oci_bind_array_helper_string(zval *var, zend_long max_table_le zend_hash_move_forward(hash); } } - + bind = emalloc(sizeof(php_oci_bind)); ZVAL_UNDEF(&bind->val); bind->array.elements = (text *)safe_emalloc(max_table_length * (maxlength + 1), sizeof(text), 0); @@ -1749,9 +1749,9 @@ php_oci_bind *php_oci_bind_array_helper_string(zval *var, zend_long max_table_le memset(bind->array.element_lengths, 0, max_table_length*sizeof(ub2)); bind->array.indicators = safe_emalloc(max_table_length, sizeof(sb2), 0); memset(bind->array.indicators, 0, max_table_length*sizeof(sb2)); - + zend_hash_internal_pointer_reset(hash); - + for (i = 0; i < bind->array.current_length; i++) { if ((entry = zend_hash_get_current_data(hash)) != NULL) { convert_to_string_ex(entry); @@ -1769,13 +1769,13 @@ php_oci_bind *php_oci_bind_array_helper_string(zval *var, zend_long max_table_le for (i = 0; i < max_table_length; i++) { if ((i < bind->array.current_length) && (entry = zend_hash_get_current_data(hash)) != NULL) { int element_length; - + convert_to_string_ex(entry); element_length = ((size_t) maxlength > Z_STRLEN_P(entry)) ? (int) Z_STRLEN_P(entry) : (int) maxlength; - + memcpy((text *)bind->array.elements + i*maxlength, Z_STRVAL_P(entry), element_length); ((text *)bind->array.elements)[i*maxlength + element_length] = '\0'; - + zend_hash_move_forward(hash); } else { ((text *)bind->array.elements)[i*maxlength] = '\0'; @@ -1808,7 +1808,7 @@ php_oci_bind *php_oci_bind_array_helper_number(zval *var, zend_long max_table_le bind->array.element_lengths = safe_emalloc(max_table_length, sizeof(ub2), 0); memset(bind->array.element_lengths, 0, max_table_length * sizeof(ub2)); bind->array.indicators = NULL; - + zend_hash_internal_pointer_reset(hash); for (i = 0; i < max_table_length; i++) { if (i < bind->array.current_length) { @@ -1849,7 +1849,7 @@ php_oci_bind *php_oci_bind_array_helper_double(zval *var, zend_long max_table_le bind->array.element_lengths = safe_emalloc(max_table_length, sizeof(ub2), 0); memset(bind->array.element_lengths, 0, max_table_length * sizeof(ub2)); bind->array.indicators = NULL; - + zend_hash_internal_pointer_reset(hash); for (i = 0; i < max_table_length; i++) { if (i < bind->array.current_length) { @@ -1899,7 +1899,7 @@ php_oci_bind *php_oci_bind_array_helper_date(zval *var, zend_long max_table_leng bind->array.element_lengths[i] = sizeof(OCIDate); } if ((i < bind->array.current_length) && (entry = zend_hash_get_current_data(hash)) != NULL) { - + convert_to_string_ex(entry); PHP_OCI_CALL_RETURN(errstatus, OCIDateFromText, (connection->err, (CONST text *)Z_STRVAL_P(entry), (ub4) Z_STRLEN_P(entry), NULL, 0, NULL, 0, &oci_date)); @@ -1912,7 +1912,7 @@ php_oci_bind *php_oci_bind_array_helper_date(zval *var, zend_long max_table_leng PHP_OCI_HANDLE_ERROR(connection, connection->errcode); return NULL; } - + ((OCIDate *)bind->array.elements)[i] = oci_date; zend_hash_move_forward(hash); } else { @@ -1927,7 +1927,7 @@ php_oci_bind *php_oci_bind_array_helper_date(zval *var, zend_long max_table_leng PHP_OCI_HANDLE_ERROR(connection, connection->errcode); return NULL; } - + ((OCIDate *)bind->array.elements)[i] = oci_date; } connection->errcode = 0; /* retain backwards compat with OCI8 1.4 */ |