From: Michael Wallner Date: Tue, 30 Sep 2014 12:53:13 +0000 (+0200) Subject: update from docs X-Git-Tag: v0.5.0~12 X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-pq;a=commitdiff_plain;h=7acdd4b540f114ac8e8103df42633d5f741fb210 update from docs --- diff --git a/src/php_pq_misc.c b/src/php_pq_misc.c index ab90936..7dfd2a5 100644 --- a/src/php_pq_misc.c +++ b/src/php_pq_misc.c @@ -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[] = { diff --git a/src/php_pq_params.c b/src/php_pq_params.c index 4a45ede..7208550 100644 --- a/src/php_pq_params.c +++ b/src/php_pq_params.c @@ -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); diff --git a/src/php_pqcopy.c b/src/php_pqcopy.c index 8ce08ef..d652ba6 100644 --- a/src/php_pqcopy.c +++ b/src/php_pqcopy.c @@ -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)); diff --git a/src/php_pqres.c b/src/php_pqres.c index eaaac69..9b35f21 100644 --- a/src/php_pqres.c +++ b/src/php_pqres.c @@ -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); diff --git a/tests/conv001.phpt b/tests/conv001.phpt index 27f41f1..084cb06 100644 --- a/tests/conv001.phpt +++ b/tests/conv001.phpt @@ -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); } }