mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-05 15:55:57 +03:00
Suppress errors associated with TEMP triggers that reference objects in
non-TEMP databases. This is a continuation of the fix for ticket #3810 shown in check-in [ba1afc040171810d] from [/timeline?c=trunk:200908061743|2009-08-06], based on a bug report in [forum:/forumpost/157dc791df|forum post 157dc791df] FossilOrigin-Name: 991ca9b26bacd8f6b64498057fe28f2068466a220f372fd365b6685f583f0e92
This commit is contained in:
@@ -157,22 +157,11 @@ void sqlite3BeginTrigger(
|
||||
pTab = sqlite3SrcListLookup(pParse, pTableName);
|
||||
if( !pTab ){
|
||||
/* The table does not exist. */
|
||||
if( db->init.iDb==1 ){
|
||||
/* Ticket #3810.
|
||||
** Normally, whenever a table is dropped, all associated triggers are
|
||||
** dropped too. But if a TEMP trigger is created on a non-TEMP table
|
||||
** and the table is dropped by a different database connection, the
|
||||
** trigger is not visible to the database connection that does the
|
||||
** drop so the trigger cannot be dropped. This results in an
|
||||
** "orphaned trigger" - a trigger whose associated table is missing.
|
||||
*/
|
||||
db->init.orphanTrigger = 1;
|
||||
}
|
||||
goto trigger_cleanup;
|
||||
goto trigger_orphan_error;
|
||||
}
|
||||
if( IsVirtual(pTab) ){
|
||||
sqlite3ErrorMsg(pParse, "cannot create triggers on virtual tables");
|
||||
goto trigger_cleanup;
|
||||
goto trigger_orphan_error;
|
||||
}
|
||||
|
||||
/* Check that the trigger name is not reserved and that no trigger of the
|
||||
@@ -210,12 +199,12 @@ void sqlite3BeginTrigger(
|
||||
if( pTab->pSelect && tr_tm!=TK_INSTEAD ){
|
||||
sqlite3ErrorMsg(pParse, "cannot create %s trigger on view: %S",
|
||||
(tr_tm == TK_BEFORE)?"BEFORE":"AFTER", pTableName, 0);
|
||||
goto trigger_cleanup;
|
||||
goto trigger_orphan_error;
|
||||
}
|
||||
if( !pTab->pSelect && tr_tm==TK_INSTEAD ){
|
||||
sqlite3ErrorMsg(pParse, "cannot create INSTEAD OF"
|
||||
" trigger on table: %S", pTableName, 0);
|
||||
goto trigger_cleanup;
|
||||
goto trigger_orphan_error;
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
@@ -275,6 +264,23 @@ trigger_cleanup:
|
||||
}else{
|
||||
assert( pParse->pNewTrigger==pTrigger );
|
||||
}
|
||||
return;
|
||||
|
||||
trigger_orphan_error:
|
||||
if( db->init.iDb==1 ){
|
||||
/* Ticket #3810.
|
||||
** Normally, whenever a table is dropped, all associated triggers are
|
||||
** dropped too. But if a TEMP trigger is created on a non-TEMP table
|
||||
** and the table is dropped by a different database connection, the
|
||||
** trigger is not visible to the database connection that does the
|
||||
** drop so the trigger cannot be dropped. This results in an
|
||||
** "orphaned trigger" - a trigger whose associated table is missing.
|
||||
**
|
||||
** 2020-11-05 see also https://sqlite.org/forum/forumpost/157dc791df
|
||||
*/
|
||||
db->init.orphanTrigger = 1;
|
||||
}
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user