mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-24 08:21:29 +03:00
Handle the case where a virtual table xBestIndex method called while coding a trigger fired by a top-level statement with a RETURNING clause prepares a statement that also contains a RETURNING clause.
FossilOrigin-Name: ec6bffa3b0fbf7cdee852cb0208de1f5869dafd88e2ee64c23cec89634219adc
This commit is contained in:
17
src/build.c
17
src/build.c
@@ -1407,20 +1407,13 @@ void sqlite3ColumnPropertiesFromName(Table *pTab, Column *pCol){
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Name of the special TEMP trigger used to implement RETURNING. The
|
||||
** name begins with "sqlite_" so that it is guaranteed not to collide
|
||||
** with any application-generated triggers.
|
||||
*/
|
||||
#define RETURNING_TRIGGER_NAME "sqlite_returning"
|
||||
|
||||
/*
|
||||
** Clean up the data structures associated with the RETURNING clause.
|
||||
*/
|
||||
static void sqlite3DeleteReturning(sqlite3 *db, Returning *pRet){
|
||||
Hash *pHash;
|
||||
pHash = &(db->aDb[1].pSchema->trigHash);
|
||||
sqlite3HashInsert(pHash, RETURNING_TRIGGER_NAME, 0);
|
||||
sqlite3HashInsert(pHash, pRet->zName, 0);
|
||||
sqlite3ExprListDelete(db, pRet->pReturnEL);
|
||||
sqlite3DbFree(db, pRet);
|
||||
}
|
||||
@@ -1463,7 +1456,9 @@ void sqlite3AddReturning(Parse *pParse, ExprList *pList){
|
||||
(void(*)(sqlite3*,void*))sqlite3DeleteReturning, pRet);
|
||||
testcase( pParse->earlyCleanup );
|
||||
if( db->mallocFailed ) return;
|
||||
pRet->retTrig.zName = RETURNING_TRIGGER_NAME;
|
||||
sqlite3_snprintf(sizeof(pRet->zName), pRet->zName,
|
||||
"sqlite_returning_%p", pParse);
|
||||
pRet->retTrig.zName = pRet->zName;
|
||||
pRet->retTrig.op = TK_RETURNING;
|
||||
pRet->retTrig.tr_tm = TRIGGER_AFTER;
|
||||
pRet->retTrig.bReturning = 1;
|
||||
@@ -1474,9 +1469,9 @@ void sqlite3AddReturning(Parse *pParse, ExprList *pList){
|
||||
pRet->retTStep.pTrig = &pRet->retTrig;
|
||||
pRet->retTStep.pExprList = pList;
|
||||
pHash = &(db->aDb[1].pSchema->trigHash);
|
||||
assert( sqlite3HashFind(pHash, RETURNING_TRIGGER_NAME)==0
|
||||
assert( sqlite3HashFind(pHash, pRet->zName)==0
|
||||
|| pParse->nErr || pParse->ifNotExists );
|
||||
if( sqlite3HashInsert(pHash, RETURNING_TRIGGER_NAME, &pRet->retTrig)
|
||||
if( sqlite3HashInsert(pHash, pRet->zName, &pRet->retTrig)
|
||||
==&pRet->retTrig ){
|
||||
sqlite3OomFault(db);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user