fix fetchCol to return true/false and pass value int pass-by-ref param
authorMichael Wallner <mike@php.net>
Fri, 19 Apr 2013 09:04:56 +0000 (11:04 +0200)
committerMichael Wallner <mike@php.net>
Fri, 19 Apr 2013 09:04:56 +0000 (11:04 +0200)
src/php_pqres.c
tests/basic002.phpt
tests/encoding001.phpt
tests/unbuffered001.phpt

index aee753d0acd0c78f42272bffa8de246633e57215..8982b4f1915fdf9aca57a121fb69cbfb5a480c78 100644 (file)
@@ -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);
index a6455ab816575a8f1187924852c74bb194bc5d0b..2afb78503e1baba56fb2ffea863c818c653100c4 100644 (file)
@@ -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--
index 57f24c55238dc1861af00bd6ed1b542b31732e05..53bcef5f6222751c29073084658e8f634778cb7a 100644 (file)
@@ -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);
index a009b632426be37d1d36b35adb579693fca957cd..11840adba79f8832848d33ed544df5770bc45d49 100644 (file)
@@ -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");