cvs: php4 /ext/pgsql pgsql.c
| From: | Sascha Schumann | Date: | Sun, 21 Apr 2002 10:44:32 +0000 |
| Subject: | cvs: php4 /ext/pgsql pgsql.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-11291@lists.php.net to get a copy of this message | ||
sas Sun Apr 21 06:44:32 2002 EDT
Modified files:
/php4/ext/pgsql pgsql.c
Log:
Avoid allocating resources, if we know that the input array is empty.
Also pass tsrmls to do_exec.
Index: php4/ext/pgsql/pgsql.c
diff -u php4/ext/pgsql/pgsql.c:1.190 php4/ext/pgsql/pgsql.c:1.191
--- php4/ext/pgsql/pgsql.c:1.190 Sun Apr 21 06:37:40 2002
+++ php4/ext/pgsql/pgsql.c Sun Apr 21 06:44:31 2002
@@ -19,7 +19,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: pgsql.c,v 1.190 2002/04/21 10:37:40 sas Exp $ */
+/* $Id: pgsql.c,v 1.191 2002/04/21 10:44:31 sas Exp $ */
#include <stdlib.h>
@@ -3879,7 +3879,7 @@
}
/* }}} */
-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 @@
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 @@
}
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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);
@@ -4307,10 +4311,6 @@
goto cleanup;
}
ids_array = ids_converted;
- }
-
- if (zend_hash_num_elements(Z_ARRVAL_P(ids_array)) == 0) {
- goto cleanup;
}
smart_str_appends(&querystr, "SELECT * FROM ");