1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-14 00:22:38 +03:00

Defer allocating memory space to hold the array of column values and

names in sqlite3_exec() until there is a need to use the array.  In
the common case where there is no callback, this avoids a malloc() call. (CVS 4905)

FossilOrigin-Name: d8686abcdf9e566571033f2f137142f742df9357
This commit is contained in:
drh
2008-03-21 18:01:14 +00:00
parent 35754aca0d
commit 3b6f734b44
3 changed files with 15 additions and 14 deletions

View File

@@ -14,7 +14,7 @@
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: legacy.c,v 1.23 2008/02/13 18:25:27 danielk1977 Exp $
** $Id: legacy.c,v 1.24 2008/03/21 18:01:14 drh Exp $
*/
#include "sqliteInt.h"
@@ -65,12 +65,7 @@ int sqlite3_exec(
}
nCallback = 0;
nCol = sqlite3_column_count(pStmt);
azCols = sqlite3DbMallocZero(db, 2*nCol*sizeof(const char *) + 1);
if( azCols==0 ){
goto exec_out;
}
while( 1 ){
int i;
@@ -80,6 +75,12 @@ int sqlite3_exec(
if( xCallback && (SQLITE_ROW==rc ||
(SQLITE_DONE==rc && !nCallback && db->flags&SQLITE_NullCallback)) ){
if( 0==nCallback ){
if( azCols==0 ){
azCols = sqlite3DbMallocZero(db, 2*nCol*sizeof(const char*) + 1);
if( azCols==0 ){
goto exec_out;
}
}
for(i=0; i<nCol; i++){
azCols[i] = (char *)sqlite3_column_name(pStmt, i);
if( !azCols[i] ){