summaryrefslogtreecommitdiff
path: root/ext/pgsql/pgsql.c
diff options
context:
space:
mode:
authorSascha Schumann <sas@php.net>2002-04-21 10:44:31 +0000
committerSascha Schumann <sas@php.net>2002-04-21 10:44:31 +0000
commitc2c23ff6df298b6f8b428bade3b1515215c816d1 (patch)
treeee6edf2075e8145055ed2d441c4a0af2abe2fbfc /ext/pgsql/pgsql.c
parentbf879920401fe7a980fb63f1c56235b57c84fa76 (diff)
downloadphp-git-c2c23ff6df298b6f8b428bade3b1515215c816d1.tar.gz
Avoid allocating resources, if we know that the input array is empty.
Also pass tsrmls to do_exec.
Diffstat (limited to 'ext/pgsql/pgsql.c')
-rw-r--r--ext/pgsql/pgsql.c42
1 files changed, 21 insertions, 21 deletions
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c
index ae3b030076..55085d5301 100644
--- a/ext/pgsql/pgsql.c
+++ b/ext/pgsql/pgsql.c
@@ -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 ");