update from docs
authorMichael Wallner <mike@php.net>
Tue, 30 Sep 2014 12:53:13 +0000 (14:53 +0200)
committerMichael Wallner <mike@php.net>
Tue, 30 Sep 2014 12:53:13 +0000 (14:53 +0200)
src/php_pq_misc.c
src/php_pq_params.c
src/php_pqcopy.c
src/php_pqres.c
tests/conv001.phpt

index ab90936428f20377d81c5ff84fdd915669c6ab07..7dfd2a52bb88f2227283697ec8d667a4b156ad01 100644 (file)
@@ -142,12 +142,14 @@ zend_class_entry *php_pqconv_class_entry;
 ZEND_BEGIN_ARG_INFO_EX(ai_pqconv_convert_types, 0, 0, 0)
 ZEND_END_ARG_INFO();
 
-ZEND_BEGIN_ARG_INFO_EX(ai_pqconv_convert_from_string, 0, 0, 1)
+ZEND_BEGIN_ARG_INFO_EX(ai_pqconv_convert_from_string, 0, 0, 2)
        ZEND_ARG_INFO(0, data)
+       ZEND_ARG_INFO(0, type)
 ZEND_END_ARG_INFO();
 
-ZEND_BEGIN_ARG_INFO_EX(ai_pqconv_convert_to_string, 0, 0, 1)
+ZEND_BEGIN_ARG_INFO_EX(ai_pqconv_convert_to_string, 0, 0, 2)
        ZEND_ARG_INFO(0, data)
+       ZEND_ARG_INFO(0, type)
 ZEND_END_ARG_INFO();
 
 zend_function_entry php_pqconv_methods[] = {
index 4a45edea242fcabfd039f446a4828fa106af625d..7208550a999d77fa025a5e23236fd20e7bb001fb 100644 (file)
@@ -148,9 +148,12 @@ static int apply_to_param_from_array(void *ptr, void *arg_ptr TSRMLS_DC)
        }
 
        if (arg->zconv) {
-               zval *rv = NULL;
+               zval *ztype, *rv = NULL;
 
-               zend_call_method_with_1_params(arg->zconv, NULL, NULL, "converttostring", &rv, zcopy);
+               MAKE_STD_ZVAL(ztype);
+               ZVAL_LONG(ztype, arg->type);
+               zend_call_method_with_2_params(arg->zconv, NULL, NULL, "converttostring", &rv, zcopy, ztype);
+               zval_ptr_dtor(&ztype);
                convert_to_string(rv);
                zcopy = rv;
                goto append_string;
@@ -256,9 +259,12 @@ static void php_pq_params_set_param(php_pq_params_t *p, unsigned index, zval **z
        TSRMLS_DF(p);
 
        if (type && SUCCESS == zend_hash_index_find(&p->type.conv, type, (void *) &zconv)) {
-               zval *rv = NULL;
+               zval *ztype, *rv = NULL;
 
-               zend_call_method_with_1_params(zconv, NULL, NULL, "converttostring", &rv, *zpp);
+               MAKE_STD_ZVAL(ztype);
+               ZVAL_LONG(ztype, type);
+               zend_call_method_with_2_params(zconv, NULL, NULL, "converttostring", &rv, *zpp, ztype);
+               zval_ptr_dtor(&ztype);
                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);
index 8ce08ef09515b7a41427a7725726c660060f533f..d652ba6ba6a143785b68652d338a89b27b1ccbf8 100644 (file)
@@ -192,7 +192,7 @@ static PHP_METHOD(pqcopy, put) {
                if (!obj->intern) {
                        throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\COPY not initialized");
                } else if (obj->intern->direction != PHP_PQCOPY_FROM_STDIN) {
-                       throw_exce(EX_RUNTIME TSRMLS_CC, "pq\\COPY was not initialized with FROM_STDIN");
+                       throw_exce(EX_BAD_METHODCALL TSRMLS_CC, "pq\\COPY was not initialized with FROM_STDIN");
                } else {
                        if (1 != PQputCopyData(obj->intern->conn->intern->conn, data_str, data_len)) {
                                throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to put COPY data (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
@@ -219,9 +219,9 @@ static PHP_METHOD(pqcopy, end) {
                php_pqcopy_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
                if (!obj->intern) {
-                       throw_exce(EX_RUNTIME TSRMLS_CC, "pq\\COPY not intitialized");
+                       throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\COPY not intitialized");
                } else if (obj->intern->direction != PHP_PQCOPY_FROM_STDIN) {
-                       throw_exce(EX_RUNTIME TSRMLS_CC, "pq\\COPY was not intitialized with FROM_STDIN");
+                       throw_exce(EX_BAD_METHODCALL TSRMLS_CC, "pq\\COPY was not intitialized with FROM_STDIN");
                } else {
                        if (1 != PQputCopyEnd(obj->intern->conn->intern->conn, error_str)) {
                                throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to end COPY (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
index eaaac6927dc96418e4708fac4413c2e7a2a791aa..9b35f21011bde83dce3db70fb7cfec92c3597897 100644 (file)
@@ -98,10 +98,13 @@ zval *php_pqres_typed_zval(php_pqres_t *res, char *val, size_t len, Oid typ TSRM
        MAKE_STD_ZVAL(zv);
 
        if (SUCCESS == zend_hash_index_find(&res->converters, typ, (void *) &zconv)) {
-               zval *tmp = NULL;
+               zval *ztype, *tmp = NULL;
 
+               MAKE_STD_ZVAL(ztype);
+               ZVAL_LONG(ztype, typ);
                ZVAL_STRINGL(zv, val, len, 1);
-               zend_call_method_with_1_params(zconv, NULL, NULL, "convertfromstring", &tmp, zv);
+               zend_call_method_with_2_params(zconv, NULL, NULL, "convertfromstring", &tmp, zv, ztype);
+               zval_ptr_dtor(&ztype);
 
                if (tmp) {
                        zval_ptr_dtor(&zv);
index 27f41f11af5c1b270070da326d978d1be9aafba5..084cb062ad5881204db880dc09bf9cf008845354 100644 (file)
@@ -27,11 +27,11 @@ class HStoreConverter extends Converter
                return [ $this->types["hstore"]->oid ];
        }
        
-       function convertFromString($string) {
+       function convertFromString($string, $type) {
                return eval("return [$string];");
        }
        
-       function convertToString($data) {
+       function convertToString($data, $type) {
                $string = "";
                foreach ($data as $k => $v) {
                        if (isset($v)) {
@@ -53,11 +53,11 @@ class IntVectorConverter extends Converter
                ];
        }
        
-       function convertFromString($string) {
+       function convertFromString($string, $type) {
                return array_map("intval", explode(" ", $string));
        }
        
-       function convertToString($data) {
+       function convertToString($data, $type) {
                return implode(" ", $data);
        }
 }
@@ -68,11 +68,11 @@ class JSONConverter extends Converter
                return [ $this->types["json"]->oid ];
        }
        
-       function convertFromString($string) {
+       function convertFromString($string, $type) {
                return json_decode($string);
        }
        
-       function convertToString($data) {
+       function convertToString($data, $type) {
                return json_encode($data);
        }
 }