make arg to fetchAllCols optional
authorMichael Wallner <mike@php.net>
Mon, 15 Sep 2014 11:22:20 +0000 (13:22 +0200)
committerMichael Wallner <mike@php.net>
Mon, 15 Sep 2014 11:22:20 +0000 (13:22 +0200)
src/php_pqres.c

index 03ad83a8348aacabec8e17211ec513ef0787c254..cd3b2b740b375f85cd7d06a9ac7135baa5019a4e 100644 (file)
@@ -593,20 +593,28 @@ static STATUS column_nn(php_pqres_object_t *obj, zval *zcol, php_pqres_col_t *co
        long index = -1;
        char *name = NULL;
 
-       switch (Z_TYPE_P(zcol)) {
-       case IS_LONG:
-               index = Z_LVAL_P(zcol);
-               break;
+       if (!zcol) {
+               index = 0;
+       } else {
+               switch (Z_TYPE_P(zcol)) {
+               case IS_NULL:
+                       index = 0;
+                       break;
 
-       default:
-               convert_to_string(zcol);
-               /* no break */
+               case IS_LONG:
+                       index = Z_LVAL_P(zcol);
+                       break;
 
-       case IS_STRING:
-               if (!is_numeric_string(Z_STRVAL_P(zcol), Z_STRLEN_P(zcol), &index, NULL, 0)) {
-                       name = Z_STRVAL_P(zcol);
+               default:
+                       convert_to_string(zcol);
+                       /* no break */
+
+               case IS_STRING:
+                       if (!is_numeric_string(Z_STRVAL_P(zcol), Z_STRLEN_P(zcol), &index, NULL, 0)) {
+                               name = Z_STRVAL_P(zcol);
+                       }
+                       break;
                }
-               break;
        }
 
        if (name) {
@@ -814,16 +822,16 @@ static PHP_METHOD(pqres, fetchCol) {
        }
 }
 
-ZEND_BEGIN_ARG_INFO_EX(ai_pqres_fetch_all_cols, 0, 0, 1)
+ZEND_BEGIN_ARG_INFO_EX(ai_pqres_fetch_all_cols, 0, 0, 0)
        ZEND_ARG_INFO(0, col)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(pqres, fetchAllCols) {
        zend_error_handling zeh;
-       zval *zcol;
+       zval *zcol = NULL;
        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", &zcol);
+       rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z!", &zcol);
        zend_restore_error_handling(&zeh TSRMLS_CC);
 
        if (SUCCESS == rv) {