more internal conversions
authorMichael Wallner <mike@php.net>
Wed, 17 Sep 2014 12:13:53 +0000 (14:13 +0200)
committerMichael Wallner <mike@php.net>
Wed, 17 Sep 2014 12:13:53 +0000 (14:13 +0200)
14 files changed:
src/php_pq_misc.c
src/php_pq_misc.h
src/php_pq_params.c
src/php_pqconn.c
src/php_pqres.c
src/php_pqres.h
tests/async003.phpt
tests/async004.phpt
tests/async005.phpt
tests/async006.phpt
tests/cancel001.phpt
tests/conv001.phpt
tests/res001.phpt
tests/trans002.phpt

index ebbfa3ae9b7dc620ccb15b521c701df84b4a7a70..9ca158e43bbf97041151a577dd56316352be046a 100644 (file)
@@ -72,11 +72,13 @@ ZEND_BEGIN_ARG_INFO_EX(ai_pqdt_to_string, 0, 0, 0)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(pqdt, __toString)
 {
-       zval *rv;
+       zval *rv = NULL;
 
        zend_call_method_with_1_params(&getThis(), php_pqdt_class_entry, NULL, "format", &rv,
                        zend_read_property(php_pqdt_class_entry, getThis(), ZEND_STRL("format"), 0 TSRMLS_CC));
-       RETVAL_ZVAL(rv, 1, 1);
+       if (rv) {
+               RETVAL_ZVAL(rv, 1, 1);
+       }
 }
 
 static zend_function_entry php_pqdt_methods[] = {
@@ -105,6 +107,36 @@ zval *php_pqdt_from_string(char *dt_str, size_t dt_len, char *fmt, zval *zv TSRM
        return zv;
 }
 
+void php_pqdt_to_string(zval *zdt, const char *format, char **str_buf, size_t *str_len TSRMLS_DC)
+{
+       zval rv;
+
+       INIT_PZVAL(&rv);
+       ZVAL_NULL(&rv);
+
+       if (Z_OBJ_HT_P(zdt)->cast_object
+       &&      SUCCESS == Z_OBJ_HT_P(zdt)->cast_object(zdt, &rv, IS_STRING TSRMLS_CC)
+       ) {
+               *str_len = Z_STRLEN(rv);
+               *str_buf = Z_STRVAL(rv);
+       } else if (instanceof_function(Z_OBJCE_P(zdt), php_date_get_date_ce() TSRMLS_CC)) {
+               zval *rv = NULL, *zfmt;
+
+               MAKE_STD_ZVAL(zfmt);
+               ZVAL_STRING(zfmt, format, 1);
+               zend_call_method_with_1_params(&zdt, Z_OBJCE_P(zdt), NULL, "format", &rv, zfmt);
+               zval_ptr_dtor(&zfmt);
+
+               if (rv) {
+                       if (Z_TYPE_P(rv) == IS_STRING) {
+                               *str_len = Z_STRLEN_P(rv);
+                               *str_buf = estrndup(Z_STRVAL_P(rv), *str_len);
+                       }
+                       zval_ptr_dtor(&rv);
+               }
+       }
+}
+
 zend_class_entry *php_pqconv_class_entry;
 
 ZEND_BEGIN_ARG_INFO_EX(ai_pqconv_convert_types, 0, 0, 0)
@@ -137,7 +169,7 @@ PHP_MINIT_FUNCTION(pq_misc)
        INIT_NS_CLASS_ENTRY(ce ,"pq", "DateTime", php_pqdt_methods);
        php_pqdt_class_entry = zend_register_internal_class_ex(&ce, php_date_get_date_ce(), "DateTime" TSRMLS_CC);
 
-       zend_declare_property_stringl(php_pqdt_class_entry, ZEND_STRL("format"), ZEND_STRL("Y-m-d H:i:s.u"), ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_stringl(php_pqdt_class_entry, ZEND_STRL("format"), ZEND_STRL("Y-m-d H:i:s.uO"), ZEND_ACC_PUBLIC TSRMLS_CC);
 
        /* stop reading this file right here! */
        if (SUCCESS == zend_hash_find(CG(class_table), ZEND_STRS("jsonserializable"), (void *) &json)) {
index 196b35cc88e2f21c16d3966bd673499df99421a6..5bf81601b2d52f8145de9d7accee433c5989e506 100644 (file)
@@ -41,6 +41,7 @@ int compare_index(const void *lptr, const void *rptr TSRMLS_DC);
 
 zend_class_entry *php_pqdt_class_entry;
 zval *php_pqdt_from_string(char *datetime_str, size_t datetime_len, char *fmt, zval *zv TSRMLS_DC);
+void php_pqdt_to_string(zval *zdt, const char *format, char **str_buf, size_t *str_len TSRMLS_DC);
 
 zend_class_entry *php_pqconv_class_entry;
 
index 149da750ede70bf98224196e8b7564e8b54690ed..ffe5e70ba7b06b6d13fd72134c462c4a456b6c79 100644 (file)
@@ -17,6 +17,7 @@
 #include <php.h>
 #include <ext/standard/php_string.h>
 #include <ext/standard/php_smart_str.h>
+#include <ext/json/php_json.h>
 
 #include <Zend/zend_interfaces.h>
 
@@ -24,6 +25,7 @@
 
 #include "php_pq.h"
 #include "php_pq_params.h"
+#include "php_pq_misc.h"
 #undef PHP_PQ_TYPE
 #include "php_pq_type.h"
 
@@ -77,12 +79,61 @@ unsigned php_pq_params_add_type_oid(php_pq_params_t *p, Oid type)
        return p->type.count;
 }
 
-static int apply_to_param_from_array(void *p TSRMLS_DC, int argc, va_list argv, zend_hash_key *key)
+
+static zval *object_param_to_string(php_pq_params_t *p, zval *zobj, Oid type TSRMLS_DC)
+{
+       zval *return_value = NULL;
+       smart_str str = {0};
+
+       switch (type) {
+#ifdef PHP_PQ_OID_JSON
+#      ifdef PHP_PQ_OID_JSONB
+       case PHP_PQ_OID_JSONB:
+#      endif
+       case PHP_PQ_OID_JSON:
+               php_json_encode(&str, zobj, PHP_JSON_UNESCAPED_UNICODE TSRMLS_CC);
+               smart_str_0(&str);
+               break;
+#endif
+
+       case PHP_PQ_OID_DATE:
+               php_pqdt_to_string(zobj, "Y-m-d", &str.c, &str.len TSRMLS_CC);
+               break;
+
+       case PHP_PQ_OID_ABSTIME:
+               php_pqdt_to_string(zobj, "Y-m-d H:i:s", &str.c, &str.len TSRMLS_CC);
+               break;
+
+       case PHP_PQ_OID_TIMESTAMP:
+               php_pqdt_to_string(zobj, "Y-m-d H:i:s.u", &str.c, &str.len TSRMLS_CC);
+               break;
+
+       case PHP_PQ_OID_TIMESTAMPTZ:
+               php_pqdt_to_string(zobj, "Y-m-d H:i:s.uO", &str.c, &str.len TSRMLS_CC);
+               break;
+
+       default:
+               SEPARATE_ZVAL(&zobj);
+               convert_to_string(zobj);
+               return_value = zobj;
+               break;
+       }
+
+       if (str.c) {
+               MAKE_STD_ZVAL(return_value);
+               RETVAL_STRINGL(str.c, str.len, 0);
+       }
+
+       return return_value;
+}
+
+static int apply_to_param_from_array(void *ptr TSRMLS_DC, int argc, va_list argv, zend_hash_key *key)
 {
-       zval **zparam = p;
+       php_pq_params_t *p = va_arg(argv, php_pq_params_t *);
        unsigned j, *i = va_arg(argv, unsigned *);
        smart_str *s = va_arg(argv, smart_str *);
-       zval **zconv = va_arg(argv, zval **);
+       Oid type = va_arg(argv, Oid);
+       zval *ztmp, **zparam = ptr, *zcopy = *zparam, **zconv = va_arg(argv, zval **);
        char *tmp;
        size_t len;
        int tmp_len;
@@ -94,26 +145,26 @@ static int apply_to_param_from_array(void *p TSRMLS_DC, int argc, va_list argv,
        if (zconv) {
                zval *rv = NULL;
 
-               zend_call_method_with_1_params(zconv, NULL, NULL, "converttostring", &rv, *zparam);
+               zend_call_method_with_1_params(zconv, NULL, NULL, "converttostring", &rv, zcopy);
                convert_to_string(rv);
-               smart_str_appendl(s, Z_STRVAL_P(rv), Z_STRLEN_P(rv));
-               zval_ptr_dtor(&rv);
+               zcopy = rv;
+               goto append_string;
        } else {
-               switch (Z_TYPE_PP(zparam)) {
+               switch (Z_TYPE_P(zcopy)) {
                case IS_NULL:
                        smart_str_appends(s, "NULL");
                        break;
 
                case IS_BOOL:
-                       smart_str_appends(s, Z_BVAL_PP(zparam) ? "t" : "f");
+                       smart_str_appends(s, Z_BVAL_P(zcopy) ? "t" : "f");
                        break;
 
                case IS_LONG:
-                       smart_str_append_long(s, Z_LVAL_PP(zparam));
+                       smart_str_append_long(s, Z_LVAL_P(zcopy));
                        break;
 
                case IS_DOUBLE:
-                       len = spprintf(&tmp, 0, "%F", Z_DVAL_PP(zparam));
+                       len = spprintf(&tmp, 0, "%F", Z_DVAL_P(zcopy));
                        smart_str_appendl(s, tmp, len);
                        efree(tmp);
                        break;
@@ -121,23 +172,27 @@ static int apply_to_param_from_array(void *p TSRMLS_DC, int argc, va_list argv,
                case IS_ARRAY:
                        j = 0;
                        smart_str_appendc(s, '{');
-                       zend_hash_apply_with_arguments(Z_ARRVAL_PP(zparam) TSRMLS_CC, apply_to_param_from_array, 2, &j, s, zconv);
+                       zend_hash_apply_with_arguments(Z_ARRVAL_P(zcopy) TSRMLS_CC, apply_to_param_from_array, 5, p, &j, s, type, zconv);
                        smart_str_appendc(s, '}');
                        break;
 
-               default:
-                       SEPARATE_ZVAL(zparam);
-                       if (Z_TYPE_PP(zparam) != IS_STRING) {
-                               convert_to_string(*zparam);
+               case IS_OBJECT:
+                       if ((ztmp = object_param_to_string(p, zcopy, type TSRMLS_CC))) {
+                               zcopy = ztmp;
                        }
+                       /* no break */
+               default:
+                       SEPARATE_ZVAL(&zcopy);
+                       convert_to_string(zcopy);
 
-                       tmp = php_addslashes(Z_STRVAL_PP(zparam), Z_STRLEN_PP(zparam), &tmp_len, 0 TSRMLS_CC);
+                       append_string:
+                       tmp = php_addslashes(Z_STRVAL_P(zcopy), Z_STRLEN_P(zcopy), &tmp_len, 0 TSRMLS_CC);
                        smart_str_appendc(s, '"');
                        smart_str_appendl(s, tmp, tmp_len);
                        smart_str_appendc(s, '"');
 
-                       if (*zparam != *((zval **) p)) {
-                               zval_ptr_dtor(zparam);
+                       if (zcopy != *zparam) {
+                               zval_ptr_dtor(&zcopy);
                        }
                        efree(tmp);
                        break;
@@ -147,21 +202,46 @@ static int apply_to_param_from_array(void *p TSRMLS_DC, int argc, va_list argv,
        return ZEND_HASH_APPLY_KEEP;
 }
 
-static void array_param_to_string(zval **zconv, HashTable *ht, char **str, int *len TSRMLS_DC)
+static zval *array_param_to_string(php_pq_params_t *p, zval *zarr, Oid type TSRMLS_DC)
 {
+       zval *return_value, **zconv = NULL;
        smart_str s = {0};
        unsigned i = 0;
 
-       smart_str_appendc(&s, '{');
-       zend_hash_apply_with_arguments(ht TSRMLS_CC, apply_to_param_from_array, 3, &i, &s, zconv);
-       smart_str_appendc(&s, '}');
+       switch (type) {
+#ifdef PHP_PQ_OID_JSON
+#      ifdef PHP_PQ_OID_JSONB
+       case PHP_PQ_OID_JSONB:
+#      endif
+       case PHP_PQ_OID_JSON:
+               php_json_encode(&s, zarr, PHP_JSON_UNESCAPED_UNICODE TSRMLS_CC);
+               smart_str_0(&s);
+               break;
+#endif
+
+       default:
+               zend_hash_index_find(&p->type.conv, PHP_PQ_TYPE_OF_ARRAY(type), (void *) &zconv);
+
+               smart_str_appendc(&s, '{');
+               zend_hash_apply_with_arguments(Z_ARRVAL_P(zarr) TSRMLS_CC, apply_to_param_from_array, 5, p, &i, &s, (Oid) PHP_PQ_TYPE_OF_ARRAY(type), zconv);
+               smart_str_appendc(&s, '}');
+               smart_str_0(&s);
+               break;
+       }
+
+       /* must not return NULL */
+       MAKE_STD_ZVAL(return_value);
 
-       smart_str_0(&s);
-       *str = s.c;
-       *len = s.len;
+       if (s.c) {
+               RETVAL_STRINGL(s.c, s.len, 0);
+       } else {
+               RETVAL_EMPTY_STRING();
+       }
+
+       return return_value;
 }
 
-static void php_pq_params_set_param(php_pq_params_t *p, unsigned index, zval **zp)
+static void php_pq_params_set_param(php_pq_params_t *p, unsigned index, zval **zpp)
 {
        zval **zconv = NULL;
        Oid type = p->type.count > index ? p->type.oids[index] : 0;
@@ -170,48 +250,48 @@ static void php_pq_params_set_param(php_pq_params_t *p, unsigned index, zval **z
        if (type && SUCCESS == zend_hash_index_find(&p->type.conv, type, (void *) &zconv)) {
                zval *rv = NULL;
 
-               zend_call_method_with_1_params(zconv, NULL, NULL, "converttostring", &rv, *zp);
+               zend_call_method_with_1_params(zconv, NULL, NULL, "converttostring", &rv, *zpp);
                convert_to_string(rv);
                p->param.strings[index] = Z_STRVAL_P(rv);
                zend_hash_next_index_insert(&p->param.dtor, (void *) &rv, sizeof(zval *), NULL);
        } else {
-               zval **zpp = zp;
+               zval *tmp, *zcopy = *zpp;
 
-               switch (Z_TYPE_PP(zp)) {
+               switch (Z_TYPE_P(zcopy)) {
                case IS_NULL:
                        p->param.strings[index] = NULL;
                        return;
 
                case IS_BOOL:
-                       p->param.strings[index] = Z_BVAL_PP(zp) ? "t" : "f";
+                       p->param.strings[index] = Z_BVAL_P(zcopy) ? "t" : "f";
                        return;
 
                case IS_DOUBLE:
-                       SEPARATE_ZVAL(zp);
-                       Z_TYPE_PP(zp) = IS_STRING;
-                       Z_STRLEN_PP(zp) = spprintf(&Z_STRVAL_PP(zp), 0, "%F", Z_DVAL_PP(zpp));
+                       SEPARATE_ZVAL(&zcopy);
+                       Z_TYPE_P(zcopy) = IS_STRING;
+                       Z_STRLEN_P(zcopy) = spprintf(&Z_STRVAL_P(zcopy), 0, "%F", Z_DVAL_PP(zpp));
                        break;
 
                case IS_ARRAY:
-               {
-                       zval *tmp;
-                       MAKE_STD_ZVAL(tmp);
-                       Z_TYPE_P(tmp) = IS_STRING;
-                       zend_hash_index_find(&p->type.conv, PHP_PQ_TYPE_OF_ARRAY(type), (void *) &zconv);
-                       array_param_to_string(zconv, Z_ARRVAL_PP(zp), &Z_STRVAL_P(tmp), &Z_STRLEN_P(tmp) TSRMLS_CC);
-                       zp = &tmp;
+                       zcopy = array_param_to_string(p, zcopy, type TSRMLS_CC);
                        break;
-               }
+
+               case IS_OBJECT:
+                       if ((tmp = object_param_to_string(p, zcopy, type TSRMLS_CC))) {
+                               zcopy = tmp;
+                               break;
+                       }
+                       /* no break */
 
                default:
-                       convert_to_string_ex(zp);
+                       convert_to_string_ex(&zcopy);
                        break;
                }
 
-               p->param.strings[index] = Z_STRVAL_PP(zp);
+               p->param.strings[index] = Z_STRVAL_P(zcopy);
 
-               if (*zp != *zpp) {
-                       zend_hash_next_index_insert(&p->param.dtor, zp, sizeof(zval *), NULL);
+               if (zcopy != *zpp) {
+                       zend_hash_next_index_insert(&p->param.dtor, (void *) &zcopy, sizeof(zval *), NULL);
                }
        }
 }
index c4d6c806341de53295bfec4bc1a2578144a732be..e869d92acd9000ac7f8a2c10561cc96ceb2bca7d 100644 (file)
@@ -458,7 +458,7 @@ static void php_pqconn_object_write_def_auto_conv(zval*object, void *o, zval *va
                }
        }
 
-       obj->intern->default_auto_convert = Z_LVAL_P(zac) & 0xff;
+       obj->intern->default_auto_convert = Z_LVAL_P(zac) & PHP_PQRES_CONV_ALL;
 
        if (zac != value) {
                zval_ptr_dtor(&zac);
index eeda25899fbbff521836d2775c2ce4c3f43abd0b..88a226835e05460bac640b43595903f4b3b1dd22 100644 (file)
@@ -17,6 +17,7 @@
 #include <php.h>
 
 #include <ext/spl/spl_iterators.h>
+#include <ext/json/php_json.h>
 #include <libpq-events.h>
 
 #include "php_pq.h"
@@ -167,6 +168,18 @@ zval *php_pqres_typed_zval(php_pqres_t *res, char *val, size_t len, Oid typ TSRM
                php_pqdt_from_string(val, len, "Y-m-d H:i:s.uO", zv TSRMLS_CC);
                break;
 
+#ifdef PHP_PQ_OID_JSON
+#      ifdef PHP_PQ_OID_JSONB
+       case PHP_PQ_OID_JSONB:
+#      endif
+       case PHP_PQ_OID_JSON:
+               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);
+               break;
+#endif
+
        default:
                if (!(res->auto_convert & PHP_PQRES_CONV_ARRAY)) {
                        goto noconversion;
@@ -1153,7 +1166,7 @@ PHP_MINIT_FUNCTION(pqres)
        zend_hash_add(&php_pqres_object_prophandlers, "fetchType", sizeof("fetchType"), (void *) &ph, sizeof(ph), NULL);
        ph.write = NULL;
 
-       zend_declare_property_long(php_pqres_class_entry, ZEND_STRL("autoConvert"), PHP_PQRES_FETCH_ARRAY, ZEND_ACC_PUBLIC TSRMLS_CC);
+       zend_declare_property_long(php_pqres_class_entry, ZEND_STRL("autoConvert"), PHP_PQRES_CONV_ALL, ZEND_ACC_PUBLIC TSRMLS_CC);
        ph.read = php_pqres_object_read_auto_conv;
        ph.write = php_pqres_object_write_auto_conv;
        zend_hash_add(&php_pqres_object_prophandlers, "autoConvert", sizeof("autoConvert"), (void *) &ph, sizeof(ph), NULL);
index 4afff3948776a303dc9919c59f02b01d04b3a122..d2d35d465fa85cdcd73977a5f2e33531b3056366 100644 (file)
@@ -22,13 +22,14 @@ typedef enum php_pqres_fetch {
        PHP_PQRES_FETCH_OBJECT
 } php_pqres_fetch_t;
 
-#define PHP_PQRES_CONV_BOOL            0x01
-#define PHP_PQRES_CONV_INT             0x02
-#define PHP_PQRES_CONV_FLOAT   0x04
-#define PHP_PQRES_CONV_SCALAR  0x0f
-#define PHP_PQRES_CONV_ARRAY   0x10
-#define PHP_PQRES_CONV_DATETIME        0x20
-#define PHP_PQRES_CONV_ALL             0xff
+#define PHP_PQRES_CONV_BOOL            0x0001
+#define PHP_PQRES_CONV_INT             0x0002
+#define PHP_PQRES_CONV_FLOAT   0x0004
+#define PHP_PQRES_CONV_SCALAR  0x000f
+#define PHP_PQRES_CONV_ARRAY   0x0010
+#define PHP_PQRES_CONV_DATETIME        0x0020
+#define PHP_PQRES_CONV_JSON            0x0100
+#define PHP_PQRES_CONV_ALL             0xffff
 
 typedef struct php_pqres_iterator {
        zend_object_iterator zi;
index e94b963c905d1dfa6113606c9480ac24a1dca29c..32d9dfdabdefbe5b575f596f8fe4c504a489a7b9 100644 (file)
@@ -42,7 +42,7 @@ object(pq\Result)#%d (8) {
   ["fetchType"]=>
   int(0)
   ["autoConvert"]=>
-  int(255)
+  int(65535)
 }
 object(pq\Result)#%d (8) {
   ["status"]=>
@@ -60,6 +60,6 @@ object(pq\Result)#%d (8) {
   ["fetchType"]=>
   int(0)
   ["autoConvert"]=>
-  int(255)
+  int(65535)
 }
 DONE
index d3db3f70b65819b899a02ca086e5663ed8e72d65..6fc274362e3e38915c53b391ecef3808e485cb96 100644 (file)
@@ -43,6 +43,6 @@ object(pq\Result)#%d (8) {
   ["fetchType"]=>
   int(0)
   ["autoConvert"]=>
-  int(255)
+  int(65535)
 }
 DONE
index a956026ffa551074ac276ad58eedc55aeb23be68..102ba135524ab1bf04084610642e962dcef2c54b 100644 (file)
@@ -52,6 +52,6 @@ object(pq\Result)#%d (8) {
   ["fetchType"]=>
   int(0)
   ["autoConvert"]=>
-  int(255)
+  int(65535)
 }
 DONE
index 178d78c4adaf68d372aaca00fddd9797104f1969..4bcd8896e683c6b7c92729321e5e47d115b7de34 100644 (file)
@@ -43,7 +43,7 @@ object(pq\Result)#%d (8) {
   ["fetchType"]=>
   int(0)
   ["autoConvert"]=>
-  int(255)
+  int(65535)
 }
 object(pq\Result)#%d (8) {
   ["status"]=>
@@ -61,7 +61,7 @@ object(pq\Result)#%d (8) {
   ["fetchType"]=>
   int(0)
   ["autoConvert"]=>
-  int(255)
+  int(65535)
 }
 object(pq\Result)#%d (8) {
   ["status"]=>
@@ -79,7 +79,7 @@ object(pq\Result)#%d (8) {
   ["fetchType"]=>
   int(0)
   ["autoConvert"]=>
-  int(255)
+  int(65535)
 }
 object(pq\Result)#%d (8) {
   ["status"]=>
@@ -97,6 +97,6 @@ object(pq\Result)#%d (8) {
   ["fetchType"]=>
   int(0)
   ["autoConvert"]=>
-  int(255)
+  int(65535)
 }
 DONE
index f763847d1651424adb4b31c486efc703a1ea5c2c..5ccdf43198089f239ef4107b596bc56530d8f143 100644 (file)
@@ -40,7 +40,7 @@ object(pq\Result)#%d (8) {
   ["fetchType"]=>
   int(0)
   ["autoConvert"]=>
-  int(255)
+  int(65535)
 }
 ERROR:  canceling statement due to user request
 DONE
index 7340c49eb6aea5d86e7370cfa23a5be179086560..f8eef52a7583e8f8bd17a5d816c1c9da3dbc868a 100644 (file)
@@ -4,6 +4,8 @@ converter
 <?php
 include "_skipif.inc";
 ?>
+--INI--
+date.timezone=UTC
 --FILE--
 <?php
 echo "Test\n";
@@ -75,15 +77,27 @@ class JSONConverter extends Converter
        }
 }
 
+class Text {
+       private $data;
+       function __construct($data) {
+               $this->data = $data;
+       }
+       function __toString() {
+               return (string) $this->data;
+       }
+}
+
 $c = new pq\Connection(PQ_DSN);
 $c->exec("CREATE EXTENSION IF NOT EXISTS hstore");
 $t = new pq\Types($c);
 
 $c->setConverter(new HStoreConverter($t));
 $c->setConverter(new IntVectorConverter($t));
-$c->setConverter(new JSONConverter($t));
-
-$r = $c->execParams("SELECT \$1 as hs, \$2 as iv, \$3 as oids, \$4 as js, \$5 as ia, \$6 as ta, \$7 as ba, \$8 as da",
+if (!defined("pq\\Types::JSON")) {
+       $c->setConverter(new JSONConverter($t));
+}
+$r = $c->execParams("SELECT \$1 as hs, \$2 as iv, \$3 as oids, \$4 as js, \$5 as ia, \$6 as ta, \$7 as ba, \$8 as da, \$9 as dbl, \$10 as bln, ".
+               "\$11 as dt1, \$12 as dt2, \$13 as dt3, \$14 as dt4, \$15 as dt5, \$16 as dt6, \$17 as dt7, \$18 as dt8, \$19 as txta ",
        array(
                // hstore
                array(
@@ -112,7 +126,21 @@ $r = $c->execParams("SELECT \$1 as hs, \$2 as iv, \$3 as oids, \$4 as js, \$5 as
                array(array(array(1,2,3))),
                array(array("a\"","b}",null)),
                array(true,false),
-               array(1.1,2.2)
+               array(1.1,2.2),
+               // double
+               123.456,
+               // bool
+               true,
+               // datetimes
+               new pq\Datetime,
+               new pq\Datetime,
+               new pq\Datetime,
+               new pq\Datetime,
+               new pq\Datetime,
+               new pq\Datetime,
+               new pq\Datetime,
+               new pq\Datetime,
+               [new Text(0), new Text(" or "), new Text(true)],
        ),
        array(
                $t["hstore"]->oid,
@@ -122,7 +150,18 @@ $r = $c->execParams("SELECT \$1 as hs, \$2 as iv, \$3 as oids, \$4 as js, \$5 as
                $t["_int4"]->oid,
                $t["_text"]->oid,
                $t["_bool"]->oid,
-               $t["_float8"]->oid
+               $t["_float8"]->oid,
+               $t["float4"]->oid,
+               $t["bool"]->oid,
+               $t["date"]->oid,
+               $t["abstime"]->oid,
+               $t["timestamp"]->oid,
+               $t["timestamptz"]->oid,
+               $t["date"]->oid,
+               $t["abstime"]->oid,
+               $t["timestamp"]->oid,
+               $t["timestamptz"]->oid,
+               $t["_text"]->oid
        )
 );
 
@@ -225,6 +264,107 @@ array(1) {
       [1]=>
       float(2.2)
     }
+    [8]=>
+    float(123.456)
+    [9]=>
+    bool(true)
+    [10]=>
+    object(pq\DateTime)#%d (4) {
+      ["format"]=>
+      string(5) "Y-m-d"
+      ["date"]=>
+      string(26) "%d-%d-%d 00:00:00.000000"
+      ["timezone_type"]=>
+      int(3)
+      ["timezone"]=>
+      string(3) "UTC"
+    }
+    [11]=>
+    object(pq\DateTime)#%d (4) {
+      ["format"]=>
+      string(11) "Y-m-d H:i:s"
+      ["date"]=>
+      string(26) "%d-%d-%d %d:%d:%d.000000"
+      ["timezone_type"]=>
+      int(1)
+      ["timezone"]=>
+      string(%d) "%s"
+    }
+    [12]=>
+    object(pq\DateTime)#%d (4) {
+      ["format"]=>
+      string(13) "Y-m-d H:i:s.u"
+      ["date"]=>
+      string(26) "%d-%d-%d %d:%d:%d.000000"
+      ["timezone_type"]=>
+      int(3)
+      ["timezone"]=>
+      string(3) "UTC"
+    }
+    [13]=>
+    object(pq\DateTime)#%d (4) {
+      ["format"]=>
+      string(14) "Y-m-d H:i:s.uO"
+      ["date"]=>
+      string(26) "%d-%d-%d %d:%d:%d.000000"
+      ["timezone_type"]=>
+      int(1)
+      ["timezone"]=>
+      string(%d) "%s"
+    }
+    [14]=>
+    object(pq\DateTime)#%d (4) {
+      ["format"]=>
+      string(5) "Y-m-d"
+      ["date"]=>
+      string(26) "%d-%d-%d 00:00:00.000000"
+      ["timezone_type"]=>
+      int(3)
+      ["timezone"]=>
+      string(3) "UTC"
+    }
+    [15]=>
+    object(pq\DateTime)#%d (4) {
+      ["format"]=>
+      string(11) "Y-m-d H:i:s"
+      ["date"]=>
+      string(26) "%d-%d-%d %d:%d:%d.000000"
+      ["timezone_type"]=>
+      int(1)
+      ["timezone"]=>
+      string(%d) "%s"
+    }
+    [16]=>
+    object(pq\DateTime)#%d (4) {
+      ["format"]=>
+      string(13) "Y-m-d H:i:s.u"
+      ["date"]=>
+      string(26) "%d-%d-%d %d:%d:%d.000000"
+      ["timezone_type"]=>
+      int(3)
+      ["timezone"]=>
+      string(3) "UTC"
+    }
+    [17]=>
+    object(pq\DateTime)#159 (4) {
+      ["format"]=>
+      string(14) "Y-m-d H:i:s.uO"
+      ["date"]=>
+      string(26) "%d-%d-%d %d:%d:%d.000000"
+      ["timezone_type"]=>
+      int(1)
+      ["timezone"]=>
+      string(%d) "%s"
+    }
+    [18]=>
+    array(3) {
+      [0]=>
+      string(1) "0"
+      [1]=>
+      string(4) " or "
+      [2]=>
+      string(1) "1"
+    }
   }
 }
 Done
index 836a3bd8413b517db390fe1f28374bfe007552c3..d42524a466c3bfc1318792d41ebba3c785facbb3 100644 (file)
@@ -74,7 +74,7 @@ object(pq\Result)#%d (8) {
   ["fetchType"]=>
   int(0)
   ["autoConvert"]=>
-  int(0)
+  int(65535)
 }
 array(9) {
   ["dummy"]=>
@@ -94,6 +94,6 @@ array(9) {
   ["fetchType"]=>
   int(0)
   ["autoConvert"]=>
-  int(0)
+  int(65535)
 }
 Done
index 49c71d820fe37b46f5b4dd3aac7e938b33770da0..8c901d49ec0f0481b7348af95b51a228e3d87fa7 100644 (file)
@@ -68,7 +68,7 @@ object(pq\Connection)#%d (19) {
   ["defaultTransactionDeferrable"]=>
   bool(false)
   ["defaultAutoConvert"]=>
-  int(255)
+  int(65535)
 }
 int(0)
 bool(false)
@@ -112,7 +112,7 @@ object(pq\Connection)#%d (19) {
   ["defaultTransactionDeferrable"]=>
   bool(false)
   ["defaultAutoConvert"]=>
-  int(255)
+  int(65535)
 }
 int(2)
 bool(true)