andrey Mon May 8 15:06:52 2006 UTC
Modified files: (Branch: PHP_5_2)
/php-src/ext/mysqli mysqli_api.c
Log:
tweaks and optimizations
#tested on 32b and 64b
http://cvs.php.net/viewcvs.cgi/php-src/ext/mysqli/mysqli_api.c?r1=1.118.2.22&r2=1.118.2.22.2.1&diff_format=u
Index: php-src/ext/mysqli/mysqli_api.c
diff -u php-src/ext/mysqli/mysqli_api.c:1.118.2.22
php-src/ext/mysqli/mysqli_api.c:1.118.2.22.2.1
--- php-src/ext/mysqli/mysqli_api.c:1.118.2.22 Wed Apr 5 12:17:08 2006
+++ php-src/ext/mysqli/mysqli_api.c Mon May 8 15:06:51 2006
@@ -15,7 +15,7 @@
| Author: Georg Richter <[EMAIL PROTECTED]> |
+----------------------------------------------------------------------+
- $Id: mysqli_api.c,v 1.118.2.22 2006/04/05 12:17:08 georg Exp $
+ $Id: mysqli_api.c,v 1.118.2.22.2.1 2006/05/08 15:06:51 andrey Exp $
*/
#ifdef HAVE_CONFIG_H
@@ -89,11 +89,6 @@
unsigned long rc;
/* calculate and check number of parameters */
- num_vars = argc - 1;
- if (!getThis()) {
- /* ignore handle parameter in procedural interface*/
- --num_vars;
- }
if (argc < 2) {
/* there has to be at least one pair */
WRONG_PARAM_COUNT;
@@ -105,8 +100,12 @@
MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt",
MYSQLI_STATUS_VALID);
+ num_vars = argc - 1;
if (getThis()) {
start = 1;
+ } else {
+ /* ignore handle parameter in procedural interface*/
+ --num_vars;
}
if (typelen != argc - start) {
@@ -154,23 +153,19 @@
case 'b': /* Blob (send data) */
bind[ofs].buffer_type = MYSQL_TYPE_LONG_BLOB;
- bind[ofs].is_null = 0;
- bind[ofs].length = 0;
+ /* don't initialize is_null and length to 0
because we use ecalloc */
break;
case 's': /* string */
bind[ofs].buffer_type = MYSQL_TYPE_VAR_STRING;
- bind[ofs].buffer = NULL;
- bind[ofs].buffer_length = 0;
+ /* don't initialize buffer and buffer_length
because we use ecalloc */
bind[ofs].is_null = &stmt->param.is_null[ofs];
break;
default:
php_error_docref(NULL TSRMLS_CC, E_WARNING,
"Undefined fieldtype %c (parameter %d)", types[ofs], i+1);
- efree(args);
- efree(bind);
- RETURN_FALSE;
- break;
+ RETVAL_FALSE;
+ goto end;
}
ofs++;
}
@@ -178,9 +173,8 @@
MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
if (rc) {
- efree(args);
- efree(bind);
- RETURN_FALSE;
+ RETVAL_FALSE;
+ goto end;
}
stmt->param.var_cnt = num_vars;
@@ -193,10 +187,10 @@
stmt->param.vars[i] = NULL;
}
}
+ RETVAL_TRUE;
+end:
efree(args);
efree(bind);
-
- RETURN_TRUE;
}
/* }}} */
@@ -279,12 +273,16 @@
break;
case MYSQL_TYPE_NULL:
- stmt->result.buf[ofs].type = IS_NULL;
- stmt->result.buf[ofs].buflen = 0;
+ stmt->result.buf[ofs].type = IS_NULL;
+ /*
+ don't initialize to 0 :
+ 1. stmt->result.buf[ofs].buflen
+ 2. bind[ofs].buffer
+ 3. bind[ofs].buffer_length
+ because memory was allocated with ecalloc
+ */
bind[ofs].buffer_type = MYSQL_TYPE_NULL;
- bind[ofs].buffer = 0;
bind[ofs].is_null = &stmt->result.is_null[ofs];
- bind[ofs].buffer_length = 0;
break;
case MYSQL_TYPE_SHORT:
@@ -294,7 +292,7 @@
case MYSQL_TYPE_YEAR:
convert_to_long_ex(args[i]);
stmt->result.buf[ofs].type = IS_LONG;
- stmt->result.buf[ofs].buflen = 0;
+ /* don't set stmt->result.buf[ofs].buflen to 0,
we used ecalloc */
stmt->result.buf[ofs].val = (char
*)emalloc(sizeof(int));
bind[ofs].buffer_type = MYSQL_TYPE_LONG;
bind[ofs].buffer = stmt->result.buf[ofs].val;
@@ -369,30 +367,27 @@
MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
if (rc) {
- efree(bind);
- efree(args);
/* dont close the statement or subsequent usage (for example
->execute()) will lead to crash */
for (i=0; i < var_cnt ; i++) {
- if (stmt->result.buf[i].val)
+ if (stmt->result.buf[i].val) {
efree(stmt->result.buf[i].val);
+ }
}
efree(stmt->result.buf);
efree(stmt->result.is_null);
- RETURN_FALSE;
- }
-
- stmt->result.var_cnt = var_cnt;
- stmt->result.vars = (zval **)safe_emalloc((var_cnt), sizeof(zval), 0);
- for (i = start; i < var_cnt+start; i++) {
- ofs = i-start;
- ZVAL_ADDREF(*args[i]);
- stmt->result.vars[ofs] = *args[i];
+ RETVAL_FALSE;
+ } else {
+ stmt->result.var_cnt = var_cnt;
+ stmt->result.vars = (zval **)safe_emalloc((var_cnt),
sizeof(zval), 0);
+ for (i = start; i < var_cnt+start; i++) {
+ ofs = i-start;
+ ZVAL_ADDREF(*args[i]);
+ stmt->result.vars[ofs] = *args[i];
+ }
+ RETVAL_TRUE;
}
-
efree(args);
efree(bind);
-
- RETURN_TRUE;
}
/* }}} */
@@ -687,7 +682,7 @@
ZVAL_LONG(stmt->result.vars[i], *(unsigned int *)stmt->result.buf[i].val);
} else {
ZVAL_LONG(stmt->result.vars[i], *(int *)stmt->result.buf[i].val);
- };
+ }
break;
case IS_DOUBLE:
ZVAL_DOUBLE(stmt->result.vars[i], *(double *)stmt->result.buf[i].val);
@@ -972,8 +967,6 @@
mysql_free_result(result);
MYSQLI_CLEAR_RESOURCE(&mysql_result);
-
- return;
}
/* }}} */
@@ -1136,7 +1129,7 @@
}
/* }}} */
-/* {{{ proto mysqli_set_local_infile_default(object link)
+/* {{{ proto void mysqli_set_local_infile_default(object link)
unsets user defined handler for load local infile command */
PHP_FUNCTION(mysqli_set_local_infile_default)
{
@@ -1184,6 +1177,8 @@
/* save callback function */
ALLOC_ZVAL(mysql->li_read);
ZVAL_STRING(mysql->li_read, callback_func->value.str.val, 1);
+
+ RETURN_TRUE;
}
/* }}} */
@@ -1199,10 +1194,7 @@
}
MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link",
MYSQLI_STATUS_VALID);
- if (!mysql_more_results(mysql->mysql)) {
- RETURN_FALSE;
- }
- RETURN_TRUE;
+ RETURN_BOOL(mysql_more_results(mysql->mysql));
}
/* }}} */
@@ -1217,10 +1209,7 @@
}
MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link",
MYSQLI_STATUS_VALID);
- if (mysql_next_result(mysql->mysql)) {
- RETURN_FALSE;
- }
- RETURN_TRUE;
+ RETURN_BOOL(!mysql_next_result(mysql->mysql));
}
/* }}} */
@@ -1288,11 +1277,7 @@
break;
}
- if (ret != 0) {
- RETURN_FALSE;
- } else {
- RETURN_TRUE;
- }
+ RETURN_BOOL(!ret);
}
/* }}} */
@@ -1311,10 +1296,8 @@
MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link",
MYSQLI_STATUS_VALID);
rc = mysql_ping(mysql->mysql);
MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
- if (rc) {
- RETURN_FALSE;
- }
- RETURN_TRUE;
+
+ RETURN_BOOL(!rc);
}
/* }}} */
@@ -1359,8 +1342,8 @@
memcpy(mysql->mysql->net.last_error, last_error,
MYSQL_ERRMSG_SIZE);
memcpy(mysql->mysql->net.sqlstate, sqlstate,
SQLSTATE_LENGTH+1);
}
- }
-
+ }
+ /* don't joing to the previous if because it won't work if
mysql_stmt_prepare_fails */
if (!stmt->stmt) {
MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
efree(stmt);
@@ -1370,8 +1353,13 @@
mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1,
sizeof(MYSQLI_RESOURCE));
mysqli_resource->ptr = (void *)stmt;
- stmt->query = (query_len) ? (char *)emalloc(query_len + 1) : NULL;
- strcpy(stmt->query, query);
+ /* don't initialize stmt->query with NULL, we ecalloc()-ed the memory */
+ /* Get performance boost if reporting is switched off */
+ if (query_len && (MyG(report_mode) & MYSQLI_REPORT_INDEX)) {
+ stmt->query = (char *)emalloc(query_len + 1);
+ memcpy(stmt->query, query, query_len);
+ stmt->query[query_len] = '\0';
+ }
/* change status */
mysqli_resource->status = MYSQLI_STATUS_VALID;
@@ -1497,7 +1485,7 @@
newstr_len = mysql_real_escape_string(mysql->mysql, newstr, escapestr,
escapestr_len);
newstr = erealloc(newstr, newstr_len + 1);
- RETURN_STRING(newstr, 0);
+ RETURN_STRINGL(newstr, newstr_len, 0);
}
/* }}} */
@@ -1608,7 +1596,6 @@
MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt",
MYSQLI_STATUS_VALID);
mysql_stmt_data_seek(stmt->stmt, offset);
- return;
}
/* }}} */
@@ -1642,8 +1629,6 @@
MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt",
MYSQLI_STATUS_VALID);
mysql_stmt_free_result(stmt->stmt);
-
- return;
}
/* }}} */
@@ -1805,7 +1790,7 @@
/* }}} */
-/* {{{ proto int mysqli_stmt_attr_set(object stmt, long attr, bool mode)
+/* {{{ proto int mysqli_stmt_attr_set(object stmt, long attr, long mode)
*/
PHP_FUNCTION(mysqli_stmt_attr_set)
{
@@ -1833,7 +1818,11 @@
{
MY_STMT *stmt;
zval *mysql_stmt;
+#if MYSQL_VERSION_ID > 50099
+ my_bool value;
+#else
ulong value = 0;
+#endif
ulong attr;
int rc;
@@ -1845,7 +1834,7 @@
if ((rc = mysql_stmt_attr_get(stmt->stmt, attr, &value))) {
RETURN_FALSE;
}
- RETURN_LONG(value);
+ RETURN_LONG((long)value);
}
/* }}} */
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php