mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-02 05:54:29 +03:00
Ensure that the CREATE TABLE AS statement correctly undoes partial changes
to the sqlite_master table if the SELECT on the right-hand side aborts with an error. Fix for ticket [873cae2b6e25b] FossilOrigin-Name: 400e025e7c61efab71b891743c07a0862e5bb934
This commit is contained in:
@@ -414,6 +414,7 @@ static Op *opIterNext(VdbeOpIter *p){
|
||||
** * OP_VUpdate
|
||||
** * OP_VRename
|
||||
** * OP_FkCounter with P2==0 (immediate foreign key constraint)
|
||||
** * OP_CreateTable and OP_InitCoroutine (for CREATE TABLE AS SELECT ...)
|
||||
**
|
||||
** Then check that the value of Parse.mayAbort is true if an
|
||||
** ABORT may be thrown, or false otherwise. Return true if it does
|
||||
@@ -425,6 +426,8 @@ static Op *opIterNext(VdbeOpIter *p){
|
||||
int sqlite3VdbeAssertMayAbort(Vdbe *v, int mayAbort){
|
||||
int hasAbort = 0;
|
||||
int hasFkCounter = 0;
|
||||
int hasCreateTable = 0;
|
||||
int hasInitCoroutine = 0;
|
||||
Op *pOp;
|
||||
VdbeOpIter sIter;
|
||||
memset(&sIter, 0, sizeof(sIter));
|
||||
@@ -439,6 +442,8 @@ int sqlite3VdbeAssertMayAbort(Vdbe *v, int mayAbort){
|
||||
hasAbort = 1;
|
||||
break;
|
||||
}
|
||||
if( opcode==OP_CreateTable ) hasCreateTable = 1;
|
||||
if( opcode==OP_InitCoroutine ) hasInitCoroutine = 1;
|
||||
#ifndef SQLITE_OMIT_FOREIGN_KEY
|
||||
if( opcode==OP_FkCounter && pOp->p1==0 && pOp->p2==1 ){
|
||||
hasFkCounter = 1;
|
||||
@@ -452,7 +457,8 @@ int sqlite3VdbeAssertMayAbort(Vdbe *v, int mayAbort){
|
||||
** through all opcodes and hasAbort may be set incorrectly. Return
|
||||
** true for this case to prevent the assert() in the callers frame
|
||||
** from failing. */
|
||||
return ( v->db->mallocFailed || hasAbort==mayAbort || hasFkCounter );
|
||||
return ( v->db->mallocFailed || hasAbort==mayAbort || hasFkCounter
|
||||
|| (hasCreateTable && hasInitCoroutine) );
|
||||
}
|
||||
#endif /* SQLITE_DEBUG - the sqlite3AssertMayAbort() function */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user