Lines Matching refs:ib_query
155 static void _php_ibase_free_query(ibase_query *ib_query TSRMLS_DC) /* {{{ */ in _php_ibase_free_query()
159 if (ib_query->in_sqlda) { in _php_ibase_free_query()
160 efree(ib_query->in_sqlda); in _php_ibase_free_query()
162 if (ib_query->out_sqlda) { in _php_ibase_free_query()
163 efree(ib_query->out_sqlda); in _php_ibase_free_query()
165 if (ib_query->result != NULL) { in _php_ibase_free_query()
167 ib_query->result->query = NULL; /* Indicate to result, that query is released */ in _php_ibase_free_query()
169 _php_ibase_free_stmt_handle(ib_query->link, ib_query->stmt TSRMLS_CC); in _php_ibase_free_query()
171 if (ib_query->in_array) { in _php_ibase_free_query()
172 efree(ib_query->in_array); in _php_ibase_free_query()
174 if (ib_query->out_array) { in _php_ibase_free_query()
175 efree(ib_query->out_array); in _php_ibase_free_query()
177 if (ib_query->query) { in _php_ibase_free_query()
178 efree(ib_query->query); in _php_ibase_free_query()
185 ibase_query *ib_query = (ibase_query *)rsrc->ptr; in php_ibase_free_query_rsrc() local
187 if (ib_query != NULL) { in php_ibase_free_query_rsrc()
189 _php_ibase_free_query(ib_query TSRMLS_CC); in php_ibase_free_query_rsrc()
190 efree(ib_query); in php_ibase_free_query_rsrc()
315 static int _php_ibase_alloc_query(ibase_query *ib_query, ibase_db_link *link, /* {{{ */ in _php_ibase_alloc_query() argument
327 ib_query->link = link; in _php_ibase_alloc_query()
328 ib_query->trans = trans; in _php_ibase_alloc_query()
329 ib_query->result_res_id = 0; in _php_ibase_alloc_query()
330 ib_query->result = NULL; in _php_ibase_alloc_query()
331 ib_query->stmt = NULL; in _php_ibase_alloc_query()
332 ib_query->in_array = NULL; in _php_ibase_alloc_query()
333 ib_query->out_array = NULL; in _php_ibase_alloc_query()
334 ib_query->dialect = dialect; in _php_ibase_alloc_query()
335 ib_query->query = estrdup(query); in _php_ibase_alloc_query()
336 ib_query->trans_res_id = trans_res_id; in _php_ibase_alloc_query()
337 ib_query->out_sqlda = NULL; in _php_ibase_alloc_query()
338 ib_query->in_sqlda = NULL; in _php_ibase_alloc_query()
340 if (isc_dsql_allocate_statement(IB_STATUS, &link->handle, &ib_query->stmt)) { in _php_ibase_alloc_query()
345 ib_query->out_sqlda = (XSQLDA *) emalloc(XSQLDA_LENGTH(1)); in _php_ibase_alloc_query()
346 ib_query->out_sqlda->sqln = 1; in _php_ibase_alloc_query()
347 ib_query->out_sqlda->version = SQLDA_CURRENT_VERSION; in _php_ibase_alloc_query()
349 if (isc_dsql_prepare(IB_STATUS, &ib_query->trans->handle, &ib_query->stmt, in _php_ibase_alloc_query()
350 0, query, dialect, ib_query->out_sqlda)) { in _php_ibase_alloc_query()
356 if (isc_dsql_sql_info(IB_STATUS, &ib_query->stmt, sizeof(info_type), in _php_ibase_alloc_query()
361 ib_query->statement_type = result[3]; in _php_ibase_alloc_query()
364 if (ib_query->out_sqlda->sqld > ib_query->out_sqlda->sqln) { in _php_ibase_alloc_query()
365 ib_query->out_sqlda = erealloc(ib_query->out_sqlda, XSQLDA_LENGTH(ib_query->out_sqlda->sqld)); in _php_ibase_alloc_query()
366 ib_query->out_sqlda->sqln = ib_query->out_sqlda->sqld; in _php_ibase_alloc_query()
367 ib_query->out_sqlda->version = SQLDA_CURRENT_VERSION; in _php_ibase_alloc_query()
368 if (isc_dsql_describe(IB_STATUS, &ib_query->stmt, SQLDA_CURRENT_VERSION, ib_query->out_sqlda)) { in _php_ibase_alloc_query()
375 ib_query->in_sqlda = emalloc(XSQLDA_LENGTH(1)); in _php_ibase_alloc_query()
376 ib_query->in_sqlda->sqln = 1; in _php_ibase_alloc_query()
377 ib_query->in_sqlda->version = SQLDA_CURRENT_VERSION; in _php_ibase_alloc_query()
378 …if (isc_dsql_describe_bind(IB_STATUS, &ib_query->stmt, SQLDA_CURRENT_VERSION, ib_query->in_sqlda))… in _php_ibase_alloc_query()
384 if (ib_query->in_sqlda->sqln < ib_query->in_sqlda->sqld) { in _php_ibase_alloc_query()
385 ib_query->in_sqlda = erealloc(ib_query->in_sqlda, XSQLDA_LENGTH(ib_query->in_sqlda->sqld)); in _php_ibase_alloc_query()
386 ib_query->in_sqlda->sqln = ib_query->in_sqlda->sqld; in _php_ibase_alloc_query()
387 ib_query->in_sqlda->version = SQLDA_CURRENT_VERSION; in _php_ibase_alloc_query()
389 if (isc_dsql_describe_bind(IB_STATUS, &ib_query->stmt, in _php_ibase_alloc_query()
390 SQLDA_CURRENT_VERSION, ib_query->in_sqlda)) { in _php_ibase_alloc_query()
397 if (ib_query->in_sqlda->sqld == 0) { in _php_ibase_alloc_query()
398 efree(ib_query->in_sqlda); in _php_ibase_alloc_query()
399 ib_query->in_sqlda = NULL; in _php_ibase_alloc_query()
400 } else if (FAILURE == _php_ibase_alloc_array(&ib_query->in_array, ib_query->in_sqlda, in _php_ibase_alloc_query()
401 link->handle, trans->handle, &ib_query->in_array_cnt TSRMLS_CC)) { in _php_ibase_alloc_query()
405 if (ib_query->out_sqlda->sqld == 0) { in _php_ibase_alloc_query()
406 efree(ib_query->out_sqlda); in _php_ibase_alloc_query()
407 ib_query->out_sqlda = NULL; in _php_ibase_alloc_query()
408 } else if (FAILURE == _php_ibase_alloc_array(&ib_query->out_array, ib_query->out_sqlda, in _php_ibase_alloc_query()
409 link->handle, trans->handle, &ib_query->out_array_cnt TSRMLS_CC)) { in _php_ibase_alloc_query()
417 if (ib_query->out_sqlda) { in _php_ibase_alloc_query()
418 efree(ib_query->out_sqlda); in _php_ibase_alloc_query()
420 if (ib_query->in_sqlda) { in _php_ibase_alloc_query()
421 efree(ib_query->in_sqlda); in _php_ibase_alloc_query()
423 if (ib_query->out_array) { in _php_ibase_alloc_query()
424 efree(ib_query->out_array); in _php_ibase_alloc_query()
426 if (ib_query->query) { in _php_ibase_alloc_query()
427 efree(ib_query->query); in _php_ibase_alloc_query()
638 ibase_query *ib_query TSRMLS_DC) in _php_ibase_bind()
742 if (isc_create_blob(IB_STATUS, &ib_query->link->handle, in _php_ibase_bind()
743 &ib_query->trans->handle, &ib_blob.bl_handle, &ib_blob.bl_qd)) { in _php_ibase_bind()
773 ibase_array *ar = &ib_query->in_array[array_cnt]; in _php_ibase_bind()
786 if (isc_array_put_slice(IB_STATUS, &ib_query->link->handle, &ib_query->trans->handle, in _php_ibase_bind()
863 ibase_query *ib_query, zval ***args) in _php_ibase_exec() argument
871 int argc = ib_query->in_sqlda ? ib_query->in_sqlda->sqld : 0; in _php_ibase_exec()
879 switch (ib_query->statement_type) { in _php_ibase_exec()
889 if (isc_dsql_execute_immediate(IB_STATUS, &ib_query->link->handle, &tr, 0, in _php_ibase_exec()
890 ib_query->query, ib_query->dialect, NULL)) { in _php_ibase_exec()
899 trans->db_link[0] = ib_query->link; in _php_ibase_exec()
901 if (ib_query->link->tr_list == NULL) { in _php_ibase_exec()
902 ib_query->link->tr_list = (ibase_tr_list *) emalloc(sizeof(ibase_tr_list)); in _php_ibase_exec()
903 ib_query->link->tr_list->trans = NULL; in _php_ibase_exec()
904 ib_query->link->tr_list->next = NULL; in _php_ibase_exec()
908 for (l = &ib_query->link->tr_list; *l != NULL; l = &(*l)->next); in _php_ibase_exec()
920 if (isc_dsql_execute_immediate(IB_STATUS, &ib_query->link->handle, in _php_ibase_exec()
921 &ib_query->trans->handle, 0, ib_query->query, ib_query->dialect, NULL)) { in _php_ibase_exec()
926 if (ib_query->trans->handle == NULL && ib_query->trans_res_id != 0) { in _php_ibase_exec()
929 zend_list_delete(ib_query->trans_res_id); in _php_ibase_exec()
941 if (ib_query->out_sqlda) { /* output variables in select, select for update */ in _php_ibase_exec()
945 res = emalloc(sizeof(ibase_result)+sizeof(ibase_array)*max(0,ib_query->out_array_cnt-1)); in _php_ibase_exec()
946 res->link = ib_query->link; in _php_ibase_exec()
947 res->trans = ib_query->trans; in _php_ibase_exec()
948 res->stmt = ib_query->stmt; in _php_ibase_exec()
950 res->query = ib_query; in _php_ibase_exec()
951 ib_query->result = res; in _php_ibase_exec()
952 res->statement_type = ib_query->statement_type; in _php_ibase_exec()
955 out_sqlda = res->out_sqlda = emalloc(XSQLDA_LENGTH(ib_query->out_sqlda->sqld)); in _php_ibase_exec()
956 memcpy(out_sqlda, ib_query->out_sqlda, XSQLDA_LENGTH(ib_query->out_sqlda->sqld)); in _php_ibase_exec()
959 if (ib_query->out_array) { in _php_ibase_exec()
960 memcpy(&res->out_array, ib_query->out_array, sizeof(ibase_array)*ib_query->out_array_cnt); in _php_ibase_exec()
965 if (ib_query->in_sqlda) { /* has placeholders */ in _php_ibase_exec()
967 in_sqlda = emalloc(XSQLDA_LENGTH(ib_query->in_sqlda->sqld)); in _php_ibase_exec()
968 memcpy(in_sqlda, ib_query->in_sqlda, XSQLDA_LENGTH(ib_query->in_sqlda->sqld)); in _php_ibase_exec()
969 bind_buf = safe_emalloc(sizeof(BIND_BUF), ib_query->in_sqlda->sqld, 0); in _php_ibase_exec()
970 if (_php_ibase_bind(in_sqlda, args, bind_buf, ib_query TSRMLS_CC) == FAILURE) { in _php_ibase_exec()
976 if (ib_query->statement_type == isc_info_sql_stmt_exec_procedure) { in _php_ibase_exec()
977 isc_result = isc_dsql_execute2(IB_STATUS, &ib_query->trans->handle, in _php_ibase_exec()
978 &ib_query->stmt, SQLDA_CURRENT_VERSION, in_sqlda, out_sqlda); in _php_ibase_exec()
980 isc_result = isc_dsql_execute(IB_STATUS, &ib_query->trans->handle, in _php_ibase_exec()
981 &ib_query->stmt, SQLDA_CURRENT_VERSION, in_sqlda); in _php_ibase_exec()
988 ib_query->trans->affected_rows = 0; in _php_ibase_exec()
990 switch (ib_query->statement_type) { in _php_ibase_exec()
999 if (isc_dsql_sql_info(IB_STATUS, &ib_query->stmt, sizeof(info_count), in _php_ibase_exec()
1019 ib_query->trans->affected_rows = affected_rows; in _php_ibase_exec()
1021 if (!ib_query->out_sqlda) { /* no result set is being returned */ in _php_ibase_exec()
1067 ibase_query ib_query = { NULL, NULL, 0, 0 }; in PHP_FUNCTION() local
1154 || FAILURE == _php_ibase_alloc_query(&ib_query, ib_link, trans, query, ib_link->dialect, in PHP_FUNCTION()
1161 expected_n = ib_query.in_sqlda ? ib_query.in_sqlda->sqld : 0; in PHP_FUNCTION()
1175 if (FAILURE == _php_ibase_exec(INTERNAL_FUNCTION_PARAM_PASSTHRU, &result, &ib_query, in PHP_FUNCTION()
1184 if (ib_query.statement_type != isc_info_sql_stmt_exec_procedure) { in PHP_FUNCTION()
1185 ib_query.stmt = NULL; /* keep stmt when free query */ in PHP_FUNCTION()
1191 _php_ibase_free_query(&ib_query TSRMLS_CC); in PHP_FUNCTION()
1737 ibase_query *ib_query; in PHP_FUNCTION() local
1769 ib_query = (ibase_query *) emalloc(sizeof(ibase_query)); in PHP_FUNCTION()
1771 …if (FAILURE == _php_ibase_alloc_query(ib_query, ib_link, trans, query, ib_link->dialect, trans_res… in PHP_FUNCTION()
1772 efree(ib_query); in PHP_FUNCTION()
1775 ZEND_REGISTER_RESOURCE(return_value, ib_query, le_query); in PHP_FUNCTION()
1784 ibase_query *ib_query; in PHP_FUNCTION() local
1796 ZEND_FETCH_RESOURCE(ib_query, ibase_query *, &query, -1, LE_QUERY, le_query); in PHP_FUNCTION()
1800 expected_n = ib_query->in_sqlda ? ib_query->in_sqlda->sqld : 0; in PHP_FUNCTION()
1819 if (ib_query->result_res_id != 0 in PHP_FUNCTION()
1820 && ib_query->statement_type != isc_info_sql_stmt_exec_procedure) { in PHP_FUNCTION()
1823 if (isc_dsql_free_statement(IB_STATUS, &ib_query->stmt, DSQL_close)) { in PHP_FUNCTION()
1828 zend_list_delete(ib_query->result_res_id); in PHP_FUNCTION()
1831 if (FAILURE == _php_ibase_exec(INTERNAL_FUNCTION_PARAM_PASSTHRU, &result, ib_query, in PHP_FUNCTION()
1837 if (ib_query->trans->handle == NULL) { in PHP_FUNCTION()
1843 if (ib_query->statement_type == isc_info_sql_stmt_exec_procedure) { in PHP_FUNCTION()
1846 ib_query->result_res_id = zend_list_insert(result, le_result TSRMLS_CC); in PHP_FUNCTION()
1847 RETVAL_RESOURCE(ib_query->result_res_id); in PHP_FUNCTION()
1862 ibase_query *ib_query; in PHP_FUNCTION() local
1870 ZEND_FETCH_RESOURCE(ib_query, ibase_query *, &query_arg, -1, LE_QUERY, le_query); in PHP_FUNCTION()
1893 ibase_query *ib_query; in PHP_FUNCTION() local
1895 ZEND_FETCH_RESOURCE(ib_query, ibase_query *, &result, -1, LE_QUERY, le_query); in PHP_FUNCTION()
1896 sqlda = ib_query->out_sqlda; in PHP_FUNCTION()
2017 ibase_query *ib_query; in PHP_FUNCTION() local
2019 ZEND_FETCH_RESOURCE(ib_query, ibase_query *, &result_arg, -1, LE_QUERY, le_query); in PHP_FUNCTION()
2020 sqlda = ib_query->out_sqlda; in PHP_FUNCTION()
2045 ibase_query *ib_query; in PHP_FUNCTION() local
2053 ZEND_FETCH_RESOURCE(ib_query, ibase_query *, &result, -1, LE_QUERY, le_query); in PHP_FUNCTION()
2055 if (ib_query->in_sqlda == NULL) { in PHP_FUNCTION()
2058 RETURN_LONG(ib_query->in_sqlda->sqld); in PHP_FUNCTION()
2069 ibase_query *ib_query; in PHP_FUNCTION() local
2077 ZEND_FETCH_RESOURCE(ib_query, ibase_query *, &result_arg, -1, LE_QUERY, le_query); in PHP_FUNCTION()
2079 if (ib_query->in_sqlda == NULL) { in PHP_FUNCTION()
2083 if (field_arg < 0 || field_arg >= ib_query->in_sqlda->sqld) { in PHP_FUNCTION()
2087 _php_ibase_field_info(return_value,ib_query->in_sqlda->sqlvar + field_arg); in PHP_FUNCTION()