mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-12 13:01:09 +03:00
Fix the VList object so that it actually works.
FossilOrigin-Name: 9dcd85698af46fd5ba34004ca690d368c4ae3078
This commit is contained in:
29
src/expr.c
29
src/expr.c
@@ -945,6 +945,7 @@ Expr *sqlite3ExprFunction(Parse *pParse, ExprList *pList, Token *pToken){
|
||||
void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr, u32 n){
|
||||
sqlite3 *db = pParse->db;
|
||||
const char *z;
|
||||
ynVar x;
|
||||
|
||||
if( pExpr==0 ) return;
|
||||
assert( !ExprHasProperty(pExpr, EP_IntValue|EP_Reduced|EP_TokenOnly) );
|
||||
@@ -955,9 +956,9 @@ void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr, u32 n){
|
||||
if( z[1]==0 ){
|
||||
/* Wildcard of the form "?". Assign the next variable number */
|
||||
assert( z[0]=='?' );
|
||||
pExpr->iColumn = (ynVar)(++pParse->nVar);
|
||||
x = (ynVar)(++pParse->nVar);
|
||||
}else{
|
||||
ynVar x;
|
||||
int doAdd = 0;
|
||||
if( z[0]=='?' ){
|
||||
/* Wildcard of the form "?nnn". Convert "nnn" to an integer and
|
||||
** use it as the variable number */
|
||||
@@ -973,8 +974,11 @@ void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr, u32 n){
|
||||
db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]);
|
||||
return;
|
||||
}
|
||||
if( i>pParse->nVar ){
|
||||
pParse->nVar = (int)i;
|
||||
if( x>pParse->nVar ){
|
||||
pParse->nVar = (int)x;
|
||||
doAdd = 1;
|
||||
}else if( sqlite3VListNumToName(pParse->pVList, x)==0 ){
|
||||
doAdd = 1;
|
||||
}
|
||||
}else{
|
||||
/* Wildcards like ":aaa", "$aaa" or "@aaa". Reuse the same variable
|
||||
@@ -984,12 +988,15 @@ void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr, u32 n){
|
||||
x = (ynVar)sqlite3VListNameToNum(pParse->pVList, z, n);
|
||||
if( x==0 ){
|
||||
x = (ynVar)(++pParse->nVar);
|
||||
pParse->pVList = sqlite3VListAdd(db, pParse->pVList, z, n, x);
|
||||
doAdd = 1;
|
||||
}
|
||||
}
|
||||
pExpr->iColumn = x;
|
||||
}
|
||||
if( pParse->nVar>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
|
||||
if( doAdd ){
|
||||
pParse->pVList = sqlite3VListAdd(db, pParse->pVList, z, n, x);
|
||||
}
|
||||
}
|
||||
pExpr->iColumn = x;
|
||||
if( x>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
|
||||
sqlite3ErrorMsg(pParse, "too many SQL variables");
|
||||
}
|
||||
}
|
||||
@@ -3414,10 +3421,8 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){
|
||||
sqlite3VdbeAddOp2(v, OP_Variable, pExpr->iColumn, target);
|
||||
if( pExpr->u.zToken[1]!=0 ){
|
||||
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);
|
||||
}
|
||||
assert( pExpr->u.zToken[0]=='?' || strcmp(pExpr->u.zToken, z)==0 );
|
||||
sqlite3VdbeAppendP4(v, (char*)z, P4_STATIC);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user