From: Michael Wallner Date: Fri, 19 Apr 2013 09:04:56 +0000 (+0200) Subject: fix fetchCol to return true/false and pass value int pass-by-ref param X-Git-Tag: v0.2.0~4 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=377250ea430e2439d99ee519a95845b036b2090e;p=m6w6%2Fext-pq fix fetchCol to return true/false and pass value int pass-by-ref param --- diff --git a/src/php_pqres.c b/src/php_pqres.c index aee753d..8982b4f 100644 --- a/src/php_pqres.c +++ b/src/php_pqres.c @@ -614,16 +614,18 @@ static zval **column_at(zval *row, int col TSRMLS_DC) return data; } -ZEND_BEGIN_ARG_INFO_EX(ai_pqres_fetch_col, 0, 0, 0) +ZEND_BEGIN_ARG_INFO_EX(ai_pqres_fetch_col, 0, 0, 1) + ZEND_ARG_INFO(1, col_val) ZEND_ARG_INFO(0, col_num) ZEND_END_ARG_INFO(); static PHP_METHOD(pqres, fetchCol) { zend_error_handling zeh; + zval *fetch_val; long fetch_col = 0; STATUS rv; zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC); - rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &fetch_col); + rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|l", &fetch_val, &fetch_col); zend_restore_error_handling(&zeh TSRMLS_CC); if (SUCCESS == rv) { @@ -636,11 +638,17 @@ static PHP_METHOD(pqres, fetchCol) { zend_replace_error_handling(EH_THROW, exce(EX_RUNTIME), &zeh TSRMLS_CC); php_pqres_iteration(getThis(), obj, obj->intern->iter ? obj->intern->iter->fetch_type : 0, &row TSRMLS_CC); - if (row) { + if (!row) { + RETVAL_FALSE; + } else { zval **col = column_at(*row, fetch_col TSRMLS_CC); - if (col) { - RETVAL_ZVAL(*col, 1, 0); + if (!col) { + RETVAL_FALSE; + } else { + zval_dtor(fetch_val); + ZVAL_ZVAL(fetch_val, *col, 1, 1); + RETVAL_TRUE; } } zend_restore_error_handling(&zeh TSRMLS_CC); diff --git a/tests/basic002.phpt b/tests/basic002.phpt index a6455ab..2afb785 100644 --- a/tests/basic002.phpt +++ b/tests/basic002.phpt @@ -13,7 +13,8 @@ $s = $c->prepare("test1", "SELECT \$1",array($t["text"]->oid)); $r = $s->exec(array("fooo")); printf("%s\n", $r->errorMessage); -printf("%s\n", $r->fetchCol()); +$r->fetchCol($val); +printf("%s\n", $val); ?> DONE --EXPECT-- diff --git a/tests/encoding001.phpt b/tests/encoding001.phpt index 57f24c5..53bcef5 100644 --- a/tests/encoding001.phpt +++ b/tests/encoding001.phpt @@ -11,7 +11,8 @@ $c = new pq\Connection(PQ_DSN); var_dump($c->encoding); $c->encoding = "utf8"; var_dump($c->encoding); -var_dump($c->exec("SELECT 'ßüpä…'")->fetchCol()); +$c->exec("SELECT 'ßüpä…'")->fetchCol($val); +var_dump($val); $tmp = 12345; $c->encoding = $tmp; var_dump($c->encoding); diff --git a/tests/unbuffered001.phpt b/tests/unbuffered001.phpt index a009b63..11840ad 100644 --- a/tests/unbuffered001.phpt +++ b/tests/unbuffered001.phpt @@ -16,7 +16,8 @@ var_dump($c->unbuffered); $c->execAsync("SELECT a from generate_series(1,10) a", function($res) { switch ($res->status) { case pq\Result::SINGLE_TUPLE: - printf("%s\n", $res->fetchCol()); + $res->fetchCol($val); + printf("%s\n", $val); break; case pq\Result::TUPLES_OK: printf("-> fetching done\n");