Index: mysqli_api.c =================================================================== RCS file: /repository/php-src/ext/mysqli/mysqli_api.c,v retrieving revision 1.118.2.21 diff -u -r1.118.2.21 mysqli_api.c --- mysqli_api.c 26 Mar 2006 21:10:13 -0000 1.118.2.21 +++ mysqli_api.c 26 Mar 2006 22:58:59 -0000 @@ -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,14 +153,12 @@ 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; @@ -170,7 +167,6 @@ efree(args); efree(bind); RETURN_FALSE; - break; } ofs++; } @@ -279,12 +275,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 +294,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; @@ -373,8 +373,9 @@ 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); @@ -687,7 +688,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 +973,6 @@ mysql_free_result(result); MYSQLI_CLEAR_RESOURCE(&mysql_result); - - return; } /* }}} */ @@ -1136,7 +1135,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 +1183,8 @@ /* save callback function */ ALLOC_ZVAL(mysql->li_read); ZVAL_STRING(mysql->li_read, callback_func->value.str.val, 1); + + RETURN_TRUE; } /* }}} */ @@ -1199,10 +1200,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 +1215,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 +1283,7 @@ break; } - if (ret != 0) { - RETURN_FALSE; - } else { - RETURN_TRUE; - } + RETURN_BOOL(!ret); } /* }}} */ @@ -1311,10 +1302,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 +1348,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 +1359,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 +1491,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 +1602,6 @@ MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt", MYSQLI_STATUS_VALID); mysql_stmt_data_seek(stmt->stmt, offset); - return; } /* }}} */ @@ -1642,8 +1635,6 @@ MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt", MYSQLI_STATUS_VALID); mysql_stmt_free_result(stmt->stmt); - - return; } /* }}} */ @@ -1805,7 +1796,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 +1824,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 +1840,7 @@ if ((rc = mysql_stmt_attr_get(stmt->stmt, attr, &value))) { RETURN_FALSE; } - RETURN_LONG(value); + RETURN_LONG((long)value); } /* }}} */