use the same method signature in fetchCol() and bind()
authorMichael Wallner <mike@php.net>
Fri, 19 Apr 2013 09:43:49 +0000 (11:43 +0200)
committerMichael Wallner <mike@php.net>
Fri, 19 Apr 2013 09:43:49 +0000 (11:43 +0200)
src/php_pqres.c
tests/basic002.phpt
tests/encoding001.phpt
tests/unbuffered001.phpt

index 8982b4f1915fdf9aca57a121fb69cbfb5a480c78..2b77dba500137583978108ce6e44a10867cfc303 100644 (file)
@@ -441,6 +441,10 @@ static STATUS column_nn(php_pqres_object_t *obj, zval *zcol, php_pqres_col_t *co
        char *name = NULL;
 
        switch (Z_TYPE_P(zcol)) {
+       case IS_LONG:
+               index = Z_LVAL_P(zcol);
+               break;
+
        default:
                convert_to_string(zcol);
                /* no break */
@@ -450,10 +454,6 @@ static STATUS column_nn(php_pqres_object_t *obj, zval *zcol, php_pqres_col_t *co
                        name = Z_STRVAL_P(zcol);
                }
                break;
-
-       case IS_LONG:
-               index = Z_LVAL_P(zcol);
-               break;
        }
 
        if (name) {
@@ -614,18 +614,17 @@ static zval **column_at(zval *row, int col TSRMLS_DC)
        return data;
 }
 
-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_BEGIN_ARG_INFO_EX(ai_pqres_fetch_col, 0, 0, 2)
+       ZEND_ARG_INFO(0, col)
+       ZEND_ARG_INFO(1, ref)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(pqres, fetchCol) {
        zend_error_handling zeh;
-       zval *fetch_val;
-       long fetch_col = 0;
+       zval *zcol, *zref;
        STATUS rv;
 
        zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
-       rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|l", &fetch_val, &fetch_col);
+       rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/z", &zcol, &zref);
        zend_restore_error_handling(&zeh TSRMLS_CC);
 
        if (SUCCESS == rv) {
@@ -641,14 +640,20 @@ static PHP_METHOD(pqres, fetchCol) {
                        if (!row) {
                                RETVAL_FALSE;
                        } else {
-                               zval **col = column_at(*row, fetch_col TSRMLS_CC);
+                               php_pqres_col_t col;
 
-                               if (!col) {
+                               if (SUCCESS != column_nn(obj, zcol, &col TSRMLS_CC)) {
                                        RETVAL_FALSE;
                                } else {
-                                       zval_dtor(fetch_val);
-                                       ZVAL_ZVAL(fetch_val, *col, 1, 1);
-                                       RETVAL_TRUE;
+                                       zval **zres = column_at(*row, col.num TSRMLS_CC);
+
+                                       if (!zres) {
+                                               RETVAL_FALSE;
+                                       } else {
+                                               zval_dtor(zref);
+                                               ZVAL_ZVAL(zref, *zres, 1, 1);
+                                               RETVAL_TRUE;
+                                       }
                                }
                        }
                        zend_restore_error_handling(&zeh TSRMLS_CC);
index 2afb78503e1baba56fb2ffea863c818c653100c4..4a6fbd82708503faa8873b9af03728e85dc35986 100644 (file)
@@ -13,7 +13,7 @@ $s = $c->prepare("test1", "SELECT \$1",array($t["text"]->oid));
 $r = $s->exec(array("fooo"));
 
 printf("%s\n", $r->errorMessage);
-$r->fetchCol($val);
+$r->fetchCol(0, $val);
 printf("%s\n", $val);
 ?>
 DONE
index 53bcef5f6222751c29073084658e8f634778cb7a..b4067bcebde53ec7a42c4241d477e63d06631585 100644 (file)
@@ -11,7 +11,7 @@ $c = new pq\Connection(PQ_DSN);
 var_dump($c->encoding);
 $c->encoding = "utf8";
 var_dump($c->encoding);
-$c->exec("SELECT 'ßüpä…'")->fetchCol($val);
+$c->exec("SELECT 'ßüpä…'")->fetchCol(0, $val);
 var_dump($val);
 $tmp = 12345;
 $c->encoding = $tmp;
index 11840adba79f8832848d33ed544df5770bc45d49..b0df231c007a863b433051a0da45302709946684 100644 (file)
@@ -16,7 +16,7 @@ var_dump($c->unbuffered);
 $c->execAsync("SELECT a from generate_series(1,10) a", function($res) {
        switch ($res->status) {
        case pq\Result::SINGLE_TUPLE:
-               $res->fetchCol($val);
+               $res->fetchCol("a", $val);
                printf("%s\n", $val);
                break;
        case pq\Result::TUPLES_OK: