diff options
author | drh <drh@noemail.net> | 2016-12-23 03:59:31 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2016-12-23 03:59:31 +0000 |
commit | 9bf755cc4467dd1e2d2fb8257f14ef974ec8bc41 (patch) | |
tree | fe4338736e7319a9d947ecbf8a7a3231a4eceef9 /src/expr.c | |
parent | 344a1bf133771614774acd3233fc098eae26e5f7 (diff) | |
download | sqlite-9bf755cc4467dd1e2d2fb8257f14ef974ec8bc41.tar.gz sqlite-9bf755cc4467dd1e2d2fb8257f14ef974ec8bc41.zip |
Use the VList object to replace Parse.azVar for tracking the mapping between
SQL parameter names and parameter numbers. There is a performance
improvement, though there are still a few hiccups in the current code.
FossilOrigin-Name: 68ecafa1425a41358c88f41efea3262f1b4490f2
Diffstat (limited to 'src/expr.c')
-rw-r--r-- | src/expr.c | 35 |
1 files changed, 10 insertions, 25 deletions
diff --git a/src/expr.c b/src/expr.c index 60843bf52..ae6107449 100644 --- a/src/expr.c +++ b/src/expr.c @@ -934,7 +934,7 @@ Expr *sqlite3ExprFunction(Parse *pParse, ExprList *pList, Token *pToken){ ** variable number. ** ** Wildcards of the form "?nnn" are assigned the number "nnn". We make -** sure "nnn" is not too be to avoid a denial of service attack when +** sure "nnn" is not too big to avoid a denial of service attack when ** the SQL statement comes from an external source. ** ** Wildcards of the form ":aaa", "@aaa", or "$aaa" are assigned the same number @@ -981,30 +981,13 @@ void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr, u32 n){ ** number as the prior appearance of the same name, or if the name ** has never appeared before, reuse the same variable number */ - ynVar i; - for(i=x=0; i<pParse->nzVar; i++){ - if( pParse->azVar[i] && strcmp(pParse->azVar[i],z)==0 ){ - x = (ynVar)i+1; - break; - } + x = (ynVar)sqlite3VListNameToNum(pParse->pVList, z, n); + if( x==0 ){ + x = (ynVar)(++pParse->nVar); + pParse->pVList = sqlite3VListAdd(db, pParse->pVList, z, n, x); } - if( x==0 ) x = (ynVar)(++pParse->nVar); } pExpr->iColumn = x; - if( x>pParse->nzVar ){ - char **a; - a = sqlite3DbRealloc(db, pParse->azVar, x*sizeof(a[0])); - if( a==0 ){ - assert( db->mallocFailed ); /* Error reported through mallocFailed */ - return; - } - pParse->azVar = a; - memset(&a[pParse->nzVar], 0, (x-pParse->nzVar)*sizeof(a[0])); - pParse->nzVar = x; - } - if( pParse->azVar[x-1]==0 ){ - pParse->azVar[x-1] = sqlite3DbStrNDup(db, z, n); - } } if( pParse->nVar>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){ sqlite3ErrorMsg(pParse, "too many SQL variables"); @@ -3430,9 +3413,11 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){ assert( pExpr->u.zToken[0]!=0 ); sqlite3VdbeAddOp2(v, OP_Variable, pExpr->iColumn, target); if( pExpr->u.zToken[1]!=0 ){ - assert( pExpr->u.zToken[0]=='?' - || strcmp(pExpr->u.zToken, pParse->azVar[pExpr->iColumn-1])==0 ); - sqlite3VdbeAppendP4(v, pParse->azVar[pExpr->iColumn-1], P4_STATIC); + const char *z = sqlite3VListNumToName(pParse->pVList, pExpr->iColumn); + if( z ){ + assert( pExpr->u.zToken[0]=='?' || strcmp(pExpr->u.zToken, z)==0 ); + sqlite3VdbeAppendP4(v, (char*)z, P4_STATIC); + } } return target; } |