upgrade pq\Types
[m6w6/ext-pq] / src / php_pq_params.c
index 0f7ba503adbc6b8df6d5b142d77e848f1ccd0179..a691eebd62464efbe897c2f91533c064b7f85961 100644 (file)
@@ -75,14 +75,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)
 {
+#if PHP_PQ_HAVE_PHP_JSON_H && defined(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_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 +95,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 +123,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);
@@ -129,7 +134,7 @@ static int apply_to_param_from_array(zval *zparam, void *arg_ptr)
 
                ZVAL_LONG(&ztype, arg->type);
                zend_call_method_with_2_params(arg->zconv, NULL, NULL, "converttostring", &rv, zparam, &ztype);
-               str = zval_get_string(&rv);
+               tmpstr = zval_get_string(&rv);
                zval_ptr_dtor(&rv);
                goto append_string;
 
@@ -171,15 +176,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, '"');
@@ -198,9 +208,9 @@ static zend_string *array_param_to_string(php_pq_params_t *p, zval *zarr, Oid ty
 
        switch (type) {
 #if PHP_PQ_HAVE_PHP_JSON_H && defined(PHP_PQ_OID_JSON)
-#      ifdef PHP_PQ_OID_JSONB
+# 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;