1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-04 04:42:17 +03:00

Simplifications and additional comments on the sqlite3_get_table()

implementation.  Changes to facilitate full branch test coverage. (CVS 6482)

FossilOrigin-Name: 57e3e6b3cb54e6626bee41a084c927ee264b6d03
This commit is contained in:
drh
2009-04-10 14:27:59 +00:00
parent f7590db099
commit 73d34e92f4
3 changed files with 23 additions and 26 deletions

View File

@@ -1,5 +1,5 @@
C Changes\sto\sensure\sthat\swhen\srunning\sin\sshared-cache\smode\swith\sa\snon-threadsafe\sbuild,\sthe\scorrect\sbusy-handler\scallback\sis\salways\sinvoked.\s(CVS\s6481) C Simplifications\sand\sadditional\scomments\son\sthe\ssqlite3_get_table()\nimplementation.\s\sChanges\sto\sfacilitate\sfull\sbranch\stest\scoverage.\s(CVS\s6482)
D 2009-04-10T12:55:17 D 2009-04-10T14:28:00
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in 583e87706abc3026960ed759aff6371faf84c211 F Makefile.in 583e87706abc3026960ed759aff6371faf84c211
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -162,7 +162,7 @@ F src/sqlite3ext.h 1db7d63ab5de4b3e6b83dd03d1a4e64fef6d2a17
F src/sqliteInt.h fcdad0896da9c8b6372db974131e33b7a06606ce F src/sqliteInt.h fcdad0896da9c8b6372db974131e33b7a06606ce
F src/sqliteLimit.h ffe93f5a0c4e7bd13e70cd7bf84cfb5c3465f45d F src/sqliteLimit.h ffe93f5a0c4e7bd13e70cd7bf84cfb5c3465f45d
F src/status.c 237b193efae0cf6ac3f0817a208de6c6c6ef6d76 F src/status.c 237b193efae0cf6ac3f0817a208de6c6c6ef6d76
F src/table.c 332ab0ea691e63862e2a8bdfe2c0617ee61062a3 F src/table.c cc86ad3d6ad54df7c63a3e807b5783c90411a08d
F src/tclsqlite.c d3195e0738c101a155404ecdb1cd9532a2fd34f2 F src/tclsqlite.c d3195e0738c101a155404ecdb1cd9532a2fd34f2
F src/test1.c c4feac6518b0523e944e9cc6a4864854d81a2216 F src/test1.c c4feac6518b0523e944e9cc6a4864854d81a2216
F src/test2.c 71c22e2974f8094fe0fd1eba8f27872dde9b2a39 F src/test2.c 71c22e2974f8094fe0fd1eba8f27872dde9b2a39
@@ -717,7 +717,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
P ed6620ba589ddbb6ca86f42a7652e3b019195647 P 683e4bd74783e6e3f6cf75f9582008c7b7e02a01
R 59f76bf89532711f903241145d0b77ea R 65240198d5802c3e7624e2bd2d3785c6
U danielk1977 U drh
Z ac75d7099ed4abde9c5f40681fcfbea3 Z e03e042fa6bf5790b1eb4d8b0880d63a

View File

@@ -1 +1 @@
683e4bd74783e6e3f6cf75f9582008c7b7e02a01 57e3e6b3cb54e6626bee41a084c927ee264b6d03

View File

@@ -16,7 +16,7 @@
** These routines are in a separate files so that they will not be linked ** These routines are in a separate files so that they will not be linked
** if they are not used. ** if they are not used.
** **
** $Id: table.c,v 1.39 2009/01/19 20:49:10 drh Exp $ ** $Id: table.c,v 1.40 2009/04/10 14:28:00 drh Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include <stdlib.h> #include <stdlib.h>
@@ -29,14 +29,13 @@
** to the callback function is uses to build the result. ** to the callback function is uses to build the result.
*/ */
typedef struct TabResult { typedef struct TabResult {
char **azResult; char **azResult; /* Accumulated output */
char *zErrMsg; char *zErrMsg; /* Error message text, if an error occurs */
int nResult; int nAlloc; /* Slots allocated for azResult[] */
int nAlloc; int nRow; /* Number of rows in the result */
int nRow; int nColumn; /* Number of columns in the result */
int nColumn; int nData; /* Slots used in azResult[]. (nRow+1)*nColumn */
int nData; int rc; /* Return code from sqlite3_exec() */
int rc;
} TabResult; } TabResult;
/* /*
@@ -45,10 +44,10 @@ typedef struct TabResult {
** memory as necessary. ** memory as necessary.
*/ */
static int sqlite3_get_table_cb(void *pArg, int nCol, char **argv, char **colv){ static int sqlite3_get_table_cb(void *pArg, int nCol, char **argv, char **colv){
TabResult *p = (TabResult*)pArg; TabResult *p = (TabResult*)pArg; /* Result accumulator */
int need; int need; /* Slots needed in p->azResult[] */
int i; int i; /* Loop counter */
char *z; char *z; /* A single column of result */
/* Make sure there is enough space in p->azResult to hold everything /* Make sure there is enough space in p->azResult to hold everything
** we need to remember from this invocation of the callback. ** we need to remember from this invocation of the callback.
@@ -58,9 +57,9 @@ static int sqlite3_get_table_cb(void *pArg, int nCol, char **argv, char **colv){
}else{ }else{
need = nCol; need = nCol;
} }
if( p->nData + need >= p->nAlloc ){ if( p->nData + need > p->nAlloc ){
char **azNew; char **azNew;
p->nAlloc = p->nAlloc*2 + need + 1; p->nAlloc = p->nAlloc*2 + need;
azNew = sqlite3_realloc( p->azResult, sizeof(char*)*p->nAlloc ); azNew = sqlite3_realloc( p->azResult, sizeof(char*)*p->nAlloc );
if( azNew==0 ) goto malloc_failed; if( azNew==0 ) goto malloc_failed;
p->azResult = azNew; p->azResult = azNew;
@@ -134,7 +133,6 @@ int sqlite3_get_table(
if( pnRow ) *pnRow = 0; if( pnRow ) *pnRow = 0;
if( pzErrMsg ) *pzErrMsg = 0; if( pzErrMsg ) *pzErrMsg = 0;
res.zErrMsg = 0; res.zErrMsg = 0;
res.nResult = 0;
res.nRow = 0; res.nRow = 0;
res.nColumn = 0; res.nColumn = 0;
res.nData = 1; res.nData = 1;
@@ -168,13 +166,12 @@ int sqlite3_get_table(
} }
if( res.nAlloc>res.nData ){ if( res.nAlloc>res.nData ){
char **azNew; char **azNew;
azNew = sqlite3_realloc( res.azResult, sizeof(char*)*(res.nData+1) ); azNew = sqlite3_realloc( res.azResult, sizeof(char*)*res.nData );
if( azNew==0 ){ if( azNew==0 ){
sqlite3_free_table(&res.azResult[1]); sqlite3_free_table(&res.azResult[1]);
db->errCode = SQLITE_NOMEM; db->errCode = SQLITE_NOMEM;
return SQLITE_NOMEM; return SQLITE_NOMEM;
} }
res.nAlloc = res.nData+1;
res.azResult = azNew; res.azResult = azNew;
} }
*pazResult = &res.azResult[1]; *pazResult = &res.azResult[1];