Ejemplo n.º 1
0
/*
** This function is called to drop a trigger from the database schema. 
**
** This may be called directly from the parser and therefore identifies
** the trigger by name.  The sqlite3DropTriggerPtr() routine does the
** same job as this routine except it takes a pointer to the trigger
** instead of the trigger name.
**/
void sqlite3DropTrigger(Parse *pParse, SrcList *pName){
  Trigger *pTrigger = 0;
  int i;
  const char *zDb;
  const char *zName;
  int nName;
  sqlite *db = pParse->db;

  if( sqlite3_malloc_failed ) goto drop_trigger_cleanup;
  if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
    goto drop_trigger_cleanup;
  }

  assert( pName->nSrc==1 );
  zDb = pName->a[0].zDatabase;
  zName = pName->a[0].zName;
  nName = strlen(zName);
  for(i=0; i<db->nDb; i++){
    int j = (i<2) ? i^1 : i;  /* Search TEMP before MAIN */
    if( zDb && sqlite3StrICmp(db->aDb[j].zName, zDb) ) continue;
    pTrigger = sqlite3HashFind(&(db->aDb[j].trigHash), zName, nName+1);
    if( pTrigger ) break;
  }
  if( !pTrigger ){
    sqlite3ErrorMsg(pParse, "no such trigger: %S", pName, 0);
    goto drop_trigger_cleanup;
  }
  sqlite3DropTriggerPtr(pParse, pTrigger, 0);

drop_trigger_cleanup:
  sqlite3SrcListDelete(pName);
}
Ejemplo n.º 2
0
/*
** This function is called to drop a trigger from the database schema.
**
** This may be called directly from the parser and therefore identifies
** the trigger by name.  The sqlite3DropTriggerPtr() routine does the
** same job as this routine except it takes a pointer to the trigger
** instead of the trigger name.
**/
void sqlite3DropTrigger(Parse *pParse, SrcList *pName, int noErr){
    Trigger *pTrigger = 0;
    int i;
    const char *zDb;
    const char *zName;
    int nName;
    sqlite3 *db = pParse->db;

    if (db->mallocFailed) goto drop_trigger_cleanup;
    if (SQLITE_OK != sqlite3ReadSchema(pParse)){
        goto drop_trigger_cleanup;
    }

    assert(pName->nSrc == 1);
    zDb = pName->a[0].zDatabase;
    zName = pName->a[0].zName;
    nName = sqlite3Strlen30(zName);
    assert(zDb != 0 || sqlite3BtreeHoldsAllMutexes(db));
    for (i = OMIT_TEMPDB; i < db->nDb; i++){
        int j = (i < 2) ? i ^ 1 : i;  /* Search TEMP before MAIN */
        if (zDb && sqlite3StrICmp(db->aDb[j].zName, zDb)) continue;
        assert(sqlite3SchemaMutexHeld(db, j, 0));
        pTrigger = sqlite3HashFind(&(db->aDb[j].pSchema->trigHash), zName, nName);
        if (pTrigger) break;
    }
    if (!pTrigger){
        if (!noErr){
            sqlite3ErrorMsg(pParse, "no such trigger: %S", pName, 0);
        }
        else{
            sqlite3CodeVerifyNamedSchema(pParse, zDb);
        }
        pParse->checkSchema = 1;
        goto drop_trigger_cleanup;
    }
    sqlite3DropTriggerPtr(pParse, pTrigger);

drop_trigger_cleanup:
    sqlite3SrcListDelete(db, pName);
}