X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-pq;a=blobdiff_plain;f=src%2Fphp_pq_params.c;h=259fbb9a13b1c4b6e3c2d243e5106f39c1e9763d;hp=ead7fac8d720398b6c46c2fc5b70f706eb2af43d;hb=HEAD;hpb=6e28a8741be3fccdaca960e492c31bc26837a4ed diff --git a/src/php_pq_params.c b/src/php_pq_params.c index ead7fac..9e92226 100644 --- a/src/php_pq_params.c +++ b/src/php_pq_params.c @@ -16,9 +16,7 @@ #include #include -#if PHP_PQ_HAVE_PHP_JSON_H -#include /* we've added the include directory to INCLUDES */ -#endif +#include #include #include @@ -75,14 +73,19 @@ unsigned php_pq_params_add_type_oid(php_pq_params_t *p, Oid type) static zend_string *object_param_to_string(php_pq_params_t *p, zval *zobj, Oid type) { +#ifdef PHP_PQ_OID_JSON smart_str str = {0}; +#endif switch (type) { -#if PHP_PQ_HAVE_PHP_JSON_H && defined(PHP_PQ_OID_JSON) -# ifdef PHP_PQ_OID_JSONB +#ifdef PHP_PQ_OID_JSON +# ifdef PHP_PQ_OID_JSONB case PHP_PQ_OID_JSONB: -# endif +# endif case PHP_PQ_OID_JSON: +# if PHP_VERSION_ID >= 70100 + JSON_G(encode_max_depth) = PHP_JSON_PARSER_DEFAULT_DEPTH; +# endif php_json_encode(&str, zobj, PHP_JSON_UNESCAPED_UNICODE); smart_str_0(&str); return str.s; @@ -90,10 +93,10 @@ static zend_string *object_param_to_string(php_pq_params_t *p, zval *zobj, Oid t case PHP_PQ_OID_DATE: return php_pqdt_to_string(zobj, "Y-m-d"); - +#ifdef PHP_PQ_OID_ABSTIME case PHP_PQ_OID_ABSTIME: return php_pqdt_to_string(zobj, "Y-m-d H:i:s"); - +#endif case PHP_PQ_OID_TIMESTAMP: return php_pqdt_to_string(zobj, "Y-m-d H:i:s.u"); @@ -118,7 +121,7 @@ static int apply_to_param_from_array(zval *zparam, void *arg_ptr) struct apply_to_param_from_array_arg subarg, *arg = arg_ptr; char *tmp; size_t len; - zend_string *str; + zend_string *str, *tmpstr; if (arg->index++) { smart_str_appendc(arg->buffer, arg->delim); @@ -128,12 +131,18 @@ static int apply_to_param_from_array(zval *zparam, void *arg_ptr) zval ztype, rv; ZVAL_LONG(&ztype, arg->type); - zend_call_method_with_2_params(arg->zconv, NULL, NULL, "converttostring", &rv, zparam, &ztype); - str = zval_get_string(&rv); + php_pq_call_method(arg->zconv, "converttostring", 2, &rv, zparam, &ztype); + tmpstr = zval_get_string(&rv); + zval_ptr_dtor(&rv); goto append_string; } else { + again: switch (Z_TYPE_P(zparam)) { + case IS_REFERENCE: + ZVAL_DEREF(zparam); + goto again; + case IS_NULL: smart_str_appends(arg->buffer, "NULL"); break; @@ -165,15 +174,20 @@ static int apply_to_param_from_array(zval *zparam, void *arg_ptr) break; case IS_OBJECT: - if ((str = object_param_to_string(arg->params, zparam, arg->type))) { + if ((tmpstr = object_param_to_string(arg->params, zparam, arg->type))) { goto append_string; } /* no break */ default: - str = zval_get_string(zparam); + tmpstr = zval_get_string(zparam); append_string: - str = php_addslashes(str, 1); +#if PHP_VERSION_ID < 70300 + str = php_addslashes(tmpstr, 1); +#else + str = php_addslashes(tmpstr); + zend_string_release(tmpstr); +#endif smart_str_appendc(arg->buffer, '"'); smart_str_appendl(arg->buffer, str->val, str->len); smart_str_appendc(arg->buffer, '"'); @@ -191,10 +205,10 @@ static zend_string *array_param_to_string(php_pq_params_t *p, zval *zarr, Oid ty struct apply_to_param_from_array_arg arg = {NULL}; switch (type) { -#if PHP_PQ_HAVE_PHP_JSON_H && defined(PHP_PQ_OID_JSON) -# ifdef PHP_PQ_OID_JSONB +#ifdef PHP_PQ_OID_JSON +# ifdef PHP_PQ_OID_JSONB case PHP_PQ_OID_JSONB: -# endif +# endif case PHP_PQ_OID_JSON: php_json_encode(&s, zarr, PHP_JSON_UNESCAPED_UNICODE); break; @@ -209,7 +223,6 @@ static zend_string *array_param_to_string(php_pq_params_t *p, zval *zarr, Oid ty smart_str_appendc(arg.buffer, '{'); SEPARATE_ZVAL(zarr); zend_hash_apply_with_argument(Z_ARRVAL_P(zarr), apply_to_param_from_array, &arg); - zval_ptr_dtor(zarr); smart_str_appendc(arg.buffer, '}'); break; } @@ -228,7 +241,7 @@ static void php_pq_params_set_param(php_pq_params_t *p, unsigned index, zval *zp ZVAL_NULL(&rv); ZVAL_LONG(&ztype, type); - zend_call_method_with_2_params(zconv, NULL, NULL, "converttostring", &rv, zpp, &ztype); + php_pq_call_method(zconv, "converttostring", 2, &rv, zpp, &ztype); convert_to_string(&rv); p->param.strings[index] = Z_STRVAL_P(&rv); zend_hash_next_index_insert(&p->param.dtor, &rv); @@ -238,7 +251,12 @@ static void php_pq_params_set_param(php_pq_params_t *p, unsigned index, zval *zp char tmp_str[64]; size_t tmp_len = 0; + again: switch (Z_TYPE_P(zpp)) { + case IS_REFERENCE: + ZVAL_DEREF(zpp); + goto again; + case IS_NULL: p->param.strings[index] = NULL; return; @@ -257,7 +275,7 @@ static void php_pq_params_set_param(php_pq_params_t *p, unsigned index, zval *zp break; case IS_ARRAY: - str = array_param_to_string(p, &tmp, type); + str = array_param_to_string(p, zpp, type); break; case IS_OBJECT: @@ -265,7 +283,6 @@ static void php_pq_params_set_param(php_pq_params_t *p, unsigned index, zval *zp break; } /* no break */ - default: str = zval_get_string(zpp); break; @@ -288,7 +305,8 @@ static int apply_to_params(zval *zp, void *arg_ptr) { struct apply_to_params_arg *arg = arg_ptr; - SEPARATE_ZVAL_IF_NOT_REF(zp); + ZVAL_DEREF(zp); + SEPARATE_ZVAL(zp); php_pq_params_set_param(arg->params, arg->index++, zp); return ZEND_HASH_APPLY_KEEP; }