return SUCCESS;
}
+#define PHP_PQRES_JSON_OPTIONS(res) \
+ (php_pqres_fetch_type(res) != PHP_PQRES_FETCH_OBJECT ? PHP_JSON_OBJECT_AS_ARRAY:0)
+
zval *php_pqres_typed_zval(php_pqres_t *res, char *val, size_t len, Oid typ TSRMLS_DC)
{
zval *zv, **zconv;
if (!(res->auto_convert & PHP_PQRES_CONV_JSON)) {
goto noconversion;
}
- php_json_decode_ex(zv, val, len, 0, 512 /* PHP_JSON_DEFAULT_DEPTH */ TSRMLS_CC);
+ php_json_decode_ex(zv, val, len, PHP_PQRES_JSON_OPTIONS(res), 512 /* PHP_JSON_DEFAULT_DEPTH */ TSRMLS_CC);
break;
#endif
}
}
+php_pqres_fetch_t php_pqres_fetch_type(php_pqres_t *res)
+{
+ return res->iter ? res->iter->fetch_type : res->default_fetch_type;
+}
+
static void php_pqres_object_free(void *o TSRMLS_DC)
{
php_pqres_object_t *obj = o;
{
php_pqres_object_t *obj = o;
- if (obj->intern->iter) {
- RETVAL_LONG(obj->intern->iter->fetch_type);
- } else {
- RETVAL_LONG(obj->intern->default_fetch_type);
- }
+ RETVAL_LONG(php_pqres_fetch_type(obj->intern));
}
static void php_pqres_object_write_fetch_type(zval *object, void *o, zval *value TSRMLS_DC)
zval **row = NULL;
if (fetch_type == -1) {
- fetch_type = obj->intern->iter ? obj->intern->iter->fetch_type : obj->intern->default_fetch_type;
+ fetch_type = php_pqres_fetch_type(obj->intern);
}
zend_replace_error_handling(EH_THROW, exce(EX_RUNTIME), &zeh TSRMLS_CC);
zval **row = NULL;
zend_replace_error_handling(EH_THROW, exce(EX_RUNTIME), &zeh TSRMLS_CC);
- php_pqres_iteration(getThis(), obj, obj->intern->iter ? obj->intern->iter->fetch_type : 0, &row TSRMLS_CC);
+ php_pqres_iteration(getThis(), obj, php_pqres_fetch_type(obj->intern), &row TSRMLS_CC);
if (row) {
php_pqres_col_t col;
}
if (fetch_type == -1) {
- fetch_type = obj->intern->iter ? obj->intern->iter->fetch_type : obj->intern->default_fetch_type;
+ fetch_type = php_pqres_fetch_type(obj->intern);
}
if (keys) {
int r, rows = PQntuples(obj->intern->res);
if (fetch_type == -1) {
- fetch_type = obj->intern->iter ? obj->intern->iter->fetch_type : obj->intern->default_fetch_type;
+ fetch_type = php_pqres_fetch_type(obj->intern);
}
array_init(return_value);
extern void php_pqres_init_instance_data(PGresult *res, php_pqconn_object_t *obj, php_pqres_object_t **ptr TSRMLS_DC);
extern zval *php_pqres_row_to_zval(PGresult *res, unsigned row, php_pqres_fetch_t fetch_type, zval **data_ptr TSRMLS_DC);
extern zval *php_pqres_typed_zval(php_pqres_t *res, char *val, size_t len, Oid typ TSRMLS_DC);
+extern php_pqres_fetch_t php_pqres_fetch_type(php_pqres_t *res);
#include "php_pq_object.h"
#include "php_pqconn_event.h"