Simplifications to the sqlite3_trace() bound parameter substitution logic.

FossilOrigin-Name: cb4b928648504ce29d751834e9ee3b5278dfca65
This commit is contained in:
drh 2009-11-26 14:01:53 +00:00
parent f7829ad0e9
commit 5f18a221a1
5 changed files with 38 additions and 44 deletions

View File

@ -1,8 +1,8 @@
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
C Make\ssure\sthe\snew\sfts3Int.h\sheader\sfile\sis\sadded\sto\sthe\samalgamation.
D 2009-11-25T22:42:23
C Simplifications\sto\sthe\ssqlite3_trace()\sbound\sparameter\ssubstitution\slogic.
D 2009-11-26T14:01:53
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in c5827ead754ab32b9585487177c93bb00b9497b3
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@ -169,7 +169,7 @@ F src/select.c 2f9ed7482e7a25b0b127fc41693bbdbe1caf5647
F src/shell.c f4948cb6d30665d755a6b5e0ec313d1094aab828
F src/sqlite.h.in 4464e9772122f0447305d425e04d122b6f1bffec
F src/sqlite3ext.h 69dfb8116af51b84a029cddb3b35062354270c89
F src/sqliteInt.h 7577de4b889b2842fc98069a13eb6b4eaecb4971
F src/sqliteInt.h f79536c70bba65124b6fda0b09dfc35f1f513f51
F src/sqliteLimit.h 3afab2291762b5d09ae20c18feb8e9fa935a60a6
F src/status.c e651be6b30d397d86384c6867bc016e4913bcac7
F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
@ -215,11 +215,11 @@ F src/vacuum.c 03309a08d549f9389cc3a3589afd4fadbdaf0679
F src/vdbe.c 91b65712dcc35c80856ced6d64350059750dacc4
F src/vdbe.h bea1f0cd530775bdb58a340265f3cf3ee920e9b2
F src/vdbeInt.h d7ea821ac7813c9bea0fe87558c35e07b2c7c44d
F src/vdbeapi.c 17680ab7a75ec938c5ba039a6c87489d01faf2cb
F src/vdbeapi.c bb128b819b9ef1a2ce211a36a6cb70a1643fa239
F src/vdbeaux.c 0981dcb5b933b74ae7bc9bfa7770df5e4da849b3
F src/vdbeblob.c 84f924700a7a889152aeebef77ca5f4e3875ffb4
F src/vdbemem.c 1e16e3a16e55f4c3452834f0e041726021aa66e0
F src/vdbetrace.c f3f2516df6b6ce7573862691624e20e84c9bd71d
F src/vdbetrace.c d8984b1aa746a3d4852092733811573694e2bec2
F src/vtab.c 456fc226614569f0e46f216e33265bea268bd917
F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f
F src/where.c 11b5b00c49d53e767a7eb855bc60790edeca6185
@ -777,14 +777,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
P 5086bf8e838c824accda531afeb56a51dd40d795
R ed5087328424f39f06205bbc572f551d
P f25558f333637b83f98a649acbb8a0d5dbada9ba
R 7297b93801cb1b5f0f2d094aa4774976
U drh
Z f2bc54bbfa0e52f56ab37c3976d8a8d5
Z 9cc025af73edc8bbc9ede953398b7222
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFLDbLToxKgR168RlERAj/GAJ0WmBi/7iDV7uT+jg9HQqK1QWEcPgCfRHfu
F8LNHJsr2zwwkwQvbuskLOA=
=sLHP
iD8DBQFLDopUoxKgR168RlERAiBYAJ9naKwYidFTksJBSSLPAu1eSYKX2QCfe441
vCSQUiBaqpFdB03sRokfcyc=
=Cbq4
-----END PGP SIGNATURE-----

View File

@ -1 +1 @@
f25558f333637b83f98a649acbb8a0d5dbada9ba
cb4b928648504ce29d751834e9ee3b5278dfca65

View File

@ -2961,6 +2961,7 @@ int sqlite3VtabCallDestroy(sqlite3*, int, const char *);
int sqlite3VtabBegin(sqlite3 *, VTable *);
FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*);
void sqlite3InvalidFunction(sqlite3_context*,int,sqlite3_value**);
int sqlite3VdbeParameterIndex(Vdbe*, const char*, int);
int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *);
int sqlite3Reprepare(Vdbe*);
void sqlite3ExprListCheckLength(Parse*, ExprList*, const char*);

View File

@ -1120,8 +1120,7 @@ const char *sqlite3_bind_parameter_name(sqlite3_stmt *pStmt, int i){
** with that name. If there is no variable with the given name,
** return 0.
*/
int sqlite3_bind_parameter_index(sqlite3_stmt *pStmt, const char *zName){
Vdbe *p = (Vdbe*)pStmt;
int sqlite3VdbeParameterIndex(Vdbe *p, const char *zName, int nName){
int i;
if( p==0 ){
return 0;
@ -1130,13 +1129,16 @@ int sqlite3_bind_parameter_index(sqlite3_stmt *pStmt, const char *zName){
if( zName ){
for(i=0; i<p->nVar; i++){
const char *z = p->azVar[i];
if( z && strcmp(z,zName)==0 ){
if( z && memcmp(z,zName,nName)==0 && z[nName]==0 ){
return i+1;
}
}
}
return 0;
}
int sqlite3_bind_parameter_index(sqlite3_stmt *pStmt, const char *zName){
return sqlite3VdbeParameterIndex((Vdbe*)pStmt, zName, sqlite3Strlen30(zName));
}
/*
** Transfer all bindings from the first statement over to the second.

View File

@ -24,15 +24,19 @@
** a host parameter. If the text contains no host parameters, return
** the total number of bytes in the text.
*/
static int findNextHostParameter(const char *zSql){
static int findNextHostParameter(const char *zSql, int *pnToken){
int tokenType;
int nTotal = 0;
int n;
*pnToken = 0;
while( zSql[0] ){
n = sqlite3GetToken((u8*)zSql, &tokenType);
assert( n>0 && tokenType!=TK_ILLEGAL );
if( tokenType==TK_VARIABLE ) break;
if( tokenType==TK_VARIABLE ){
*pnToken = n;
break;
}
nTotal += n;
zSql += n;
}
@ -40,9 +44,9 @@ static int findNextHostParameter(const char *zSql){
}
/*
** Return a pointer to a string in memory obtained form sqlite3Malloc() which
** Return a pointer to a string in memory obtained form sqlite3DbMalloc() which
** holds a copy of zRawSql but with host parameters expanded to their
** current values.
** current bindings.
**
** The calling function is responsible for making sure the memory returned
** is eventually freed.
@ -63,10 +67,9 @@ char *sqlite3VdbeExpandSql(
int idx; /* Index of a host parameter */
int nextIndex = 1; /* Index of next ? host parameter */
int n; /* Length of a token prefix */
int nToken; /* Length of the parameter token */
int i; /* Loop counter */
int dummy; /* For holding a unused return value */
Mem *pVar; /* Value of a host parameter */
VdbeOp *pOp; /* For looping over opcodes */
StrAccum out; /* Accumulate the output here */
char zBase[100]; /* Initial working space */
@ -75,19 +78,16 @@ char *sqlite3VdbeExpandSql(
db->aLimit[SQLITE_LIMIT_LENGTH]);
out.db = db;
while( zRawSql[0] ){
n = findNextHostParameter(zRawSql);
n = findNextHostParameter(zRawSql, &nToken);
assert( n>0 );
sqlite3StrAccumAppend(&out, zRawSql, n);
zRawSql += n;
if( zRawSql[0]==0 ) break;
assert( zRawSql[0] || nToken==0 );
if( nToken==0 ) break;
if( zRawSql[0]=='?' ){
zRawSql++;
if( sqlite3Isdigit(zRawSql[0]) ){
idx = 0;
while( sqlite3Isdigit(zRawSql[0]) ){
idx = idx*10 + zRawSql[0] - '0';
zRawSql++;
}
if( nToken>1 ){
assert( sqlite3Isdigit(zRawSql[1]) );
sqlite3GetInt32(&zRawSql[1], &idx);
}else{
idx = nextIndex;
}
@ -96,20 +96,10 @@ char *sqlite3VdbeExpandSql(
testcase( zRawSql[0]==':' );
testcase( zRawSql[0]=='$' );
testcase( zRawSql[0]=='@' );
n = sqlite3GetToken((u8*)zRawSql, &dummy);
idx = 0;
for(i=0, pOp=p->aOp; ALWAYS(i<p->nOp); i++, pOp++){
if( pOp->opcode!=OP_Variable ) continue;
if( pOp->p3>1 ) continue;
if( pOp->p4.z==0 ) continue;
if( memcmp(pOp->p4.z, zRawSql, n)==0 && pOp->p4.z[n]==0 ){
idx = pOp->p1;
break;
}
}
idx = sqlite3VdbeParameterIndex(p, zRawSql, nToken);
assert( idx>0 );
zRawSql += n;
}
zRawSql += nToken;
nextIndex = idx + 1;
assert( idx>0 && idx<=p->nVar );
pVar = &p->aVar[idx-1];
@ -121,11 +111,12 @@ char *sqlite3VdbeExpandSql(
sqlite3XPrintf(&out, "%!.15g", pVar->r);
}else if( pVar->flags & MEM_Str ){
#ifndef SQLITE_OMIT_UTF16
if( ENC(db)!=SQLITE_UTF8 ){
u8 enc = ENC(db);
if( enc!=SQLITE_UTF8 ){
Mem utf8;
memset(&utf8, 0, sizeof(utf8));
utf8.db = db;
sqlite3VdbeMemSetStr(&utf8, pVar->z, pVar->n, ENC(db), SQLITE_STATIC);
sqlite3VdbeMemSetStr(&utf8, pVar->z, pVar->n, enc, SQLITE_STATIC);
sqlite3VdbeChangeEncoding(&utf8, SQLITE_UTF8);
sqlite3XPrintf(&out, "'%.*q'", utf8.n, utf8.z);
sqlite3VdbeMemRelease(&utf8);