]> granicus.if.org Git - php/commitdiff
Avoid allocating resources, if we know that the input array is empty.
authorSascha Schumann <sas@php.net>
Sun, 21 Apr 2002 10:44:31 +0000 (10:44 +0000)
committerSascha Schumann <sas@php.net>
Sun, 21 Apr 2002 10:44:31 +0000 (10:44 +0000)
Also pass tsrmls to do_exec.

ext/pgsql/pgsql.c

index ae3b03007648b3b0380455e8075fc8c943199ea3..55085d5301f32526ee2cdb625675159af6ead6a7 100644 (file)
@@ -3879,7 +3879,7 @@ PHP_FUNCTION(pg_convert)
 }
 /* }}} */
 
-static int do_exec(smart_str *querystr, int expect, PGconn *pg_link, zend_bool async)
+static int do_exec(smart_str *querystr, int expect, PGconn *pg_link, zend_bool async TSRMLS_DC)
 {
        if (async) {
                if (PQsendQuery(pg_link, querystr->c)) {
@@ -3920,6 +3920,10 @@ PHPAPI int php_pgsql_insert(PGconn *pg_link, const char *table, zval *var_array,
        assert(convert == 1 || convert == 0);
        assert(async == 1 || async == 0);
 
+       if (zend_hash_num_elements(Z_ARRVAL_P(var_array)) == 0) {
+               return FAILURE;
+       }
+
        /* convert input array if needed */
        if (convert) {
                MAKE_STD_ZVAL(converted);
@@ -3929,10 +3933,6 @@ PHPAPI int php_pgsql_insert(PGconn *pg_link, const char *table, zval *var_array,
                }
                var_array = converted;
        }
-
-       if (zend_hash_num_elements(Z_ARRVAL_P(var_array)) == 0) {
-               goto cleanup;
-       }
        
        smart_str_appends(&querystr, "INSERT INTO ");
        smart_str_appends(&querystr, table);
@@ -3981,7 +3981,7 @@ PHPAPI int php_pgsql_insert(PGconn *pg_link, const char *table, zval *var_array,
        smart_str_appends(&querystr, ");");
        smart_str_0(&querystr);
 
-       if (do_exec(&querystr, PGRES_COMMAND_OK, pg_link, async) == 0)
+       if (do_exec(&querystr, PGRES_COMMAND_OK, pg_link, async TSRMLS_CC) == 0)
                ret = SUCCESS;
 
 cleanup:
@@ -4083,6 +4083,11 @@ PHPAPI int php_pgsql_update(PGconn *pg_link, const char *table, zval *var_array,
        assert(convert == 1 || convert == 0);
        assert(async == 1 || async == 0);
 
+       if (zend_hash_num_elements(Z_ARRVAL_P(var_array)) == 0
+                       || zend_hash_num_elements(Z_ARRVAL_P(ids_array)) == 0) {
+               return FAILURE;
+       }
+
        if (convert) {
                MAKE_STD_ZVAL(var_converted);
                array_init(var_converted);
@@ -4098,11 +4103,6 @@ PHPAPI int php_pgsql_update(PGconn *pg_link, const char *table, zval *var_array,
                ids_array = ids_converted;
        }
 
-       if (zend_hash_num_elements(Z_ARRVAL_P(var_array)) == 0
-                       || zend_hash_num_elements(Z_ARRVAL_P(ids_array)) == 0) {
-               goto cleanup;
-       }
-
        smart_str_appends(&querystr, "UPDATE ");
        smart_str_appends(&querystr, table);
        smart_str_appends(&querystr, " SET ");
@@ -4118,7 +4118,7 @@ PHPAPI int php_pgsql_update(PGconn *pg_link, const char *table, zval *var_array,
        smart_str_appendc(&querystr, ';');      
        smart_str_0(&querystr);
 
-       if (do_exec(&querystr, PGRES_COMMAND_OK, pg_link, async) == 0)
+       if (do_exec(&querystr, PGRES_COMMAND_OK, pg_link, async TSRMLS_CC) == 0)
                ret = SUCCESS;
 
 cleanup:
@@ -4178,6 +4178,10 @@ PHPAPI int php_pgsql_delete(PGconn *pg_link, const char *table, zval *ids_array,
        assert(convert == 1 || convert == 0);
        assert(async == 1 || async == 0);
 
+       if (zend_hash_num_elements(Z_ARRVAL_P(ids_array)) == 0) {
+               return FAILURE;
+       }
+
        if (convert) {
                MAKE_STD_ZVAL(ids_converted);
                array_init(ids_converted);
@@ -4187,10 +4191,6 @@ PHPAPI int php_pgsql_delete(PGconn *pg_link, const char *table, zval *ids_array,
                ids_array = ids_converted;
        }
 
-       if (zend_hash_num_elements(Z_ARRVAL_P(ids_array)) == 0) {
-               goto cleanup;
-       }
-
        smart_str_appends(&querystr, "DELETE FROM ");
        smart_str_appends(&querystr, table);
        smart_str_appends(&querystr, " WHERE ");
@@ -4201,7 +4201,7 @@ PHPAPI int php_pgsql_delete(PGconn *pg_link, const char *table, zval *ids_array,
        smart_str_appendc(&querystr, ';');
        smart_str_0(&querystr);
 
-       if (do_exec(&querystr, PGRES_TUPLES_OK, pg_link, async) == 0)
+       if (do_exec(&querystr, PGRES_TUPLES_OK, pg_link, async TSRMLS_CC) == 0)
                ret = SUCCESS;
 
 cleanup:
@@ -4300,6 +4300,10 @@ PHPAPI int php_pgsql_select(PGconn *pg_link, const char *table, zval *ids_array,
        assert(Z_TYPE_P(ret_array) == IS_ARRAY);
        assert(convert == 1 || convert == 0);
 
+       if (zend_hash_num_elements(Z_ARRVAL_P(ids_array)) == 0) {
+               return FAILURE;
+       }
+
        if (convert) {
                MAKE_STD_ZVAL(ids_converted);
                array_init(ids_converted);
@@ -4309,10 +4313,6 @@ PHPAPI int php_pgsql_select(PGconn *pg_link, const char *table, zval *ids_array,
                ids_array = ids_converted;
        }
 
-       if (zend_hash_num_elements(Z_ARRVAL_P(ids_array)) == 0) {
-               goto cleanup;
-       }
-
        smart_str_appends(&querystr, "SELECT * FROM ");
        smart_str_appends(&querystr, table);
        smart_str_appends(&querystr, " WHERE ");