Beispiel #1
0
        /*
        ** 2001 September 15
        **
        ** The author disclaims copyright to this source code.  In place of
        ** a legal notice, here is a blessing:
        **
        **    May you do good and not evil.
        **    May you find forgiveness for yourself and forgive others.
        **    May you share freely, never taking more than you give.
        **
        *************************************************************************
        ** This file contains C code routines that are called by the parser
        ** in order to generate code for DELETE FROM statements.
        **
        ** $Id: delete.c,v 1.207 2009/08/08 18:01:08 drh Exp $
        **
        *************************************************************************
        **  Included in SQLite3 port to C#-SQLite;  2008 Noah B Hart
        **  C#-SQLite is an independent reimplementation of the SQLite software library
        **
        **  $Header$
        *************************************************************************
        */
        //#include "sqliteInt.h"

        /*
        ** Look up every table that is named in pSrc.  If any table is not found,
        ** add an error message to pParse.zErrMsg and return NULL.  If all tables
        ** are found, return a pointer to the last table.
        */
        static Table sqlite3SrcListLookup(Parse pParse, SrcList pSrc)
        {
            SrcList_item pItem = pSrc.a[0];
            Table        pTab;

            Debug.Assert(pItem != null && pSrc.nSrc == 1);
            pTab = sqlite3LocateTable(pParse, 0, pItem.zName, pItem.zDatabase);
            sqlite3DeleteTable(ref pItem.pTab);
            pItem.pTab = pTab;
            if (pTab != null)
            {
                pTab.nRef++;
            }
            if (sqlite3IndexedByLookup(pParse, pItem) != 0)
            {
                pTab = null;
            }
            return(pTab);
        }
Beispiel #2
0
 /*
 ** If the source-list item passed as an argument was augmented with an
 ** INDEXED BY clause, then try to locate the specified index. If there
 ** was such a clause and the named index cannot be found, return
 ** SQLITE_ERROR and leave an error in pParse. Otherwise, populate
 ** pFrom.pIndex and return SQLITE_OK.
 */
 static int sqlite3IndexedByLookup( Parse pParse, SrcList_item pFrom )
 {
   if ( pFrom.pTab != null && pFrom.zIndex != null && pFrom.zIndex.Length != 0 )
   {
     Table pTab = pFrom.pTab;
     string zIndex = pFrom.zIndex;
     Index pIdx;
     for ( pIdx = pTab.pIndex;
     pIdx != null && !pIdx.zName.Equals( zIndex, StringComparison.OrdinalIgnoreCase );
     pIdx = pIdx.pNext
     )
       ;
     if ( null == pIdx )
     {
       sqlite3ErrorMsg( pParse, "no such index: %s", zIndex );
       pParse.checkSchema = 1;
       return SQLITE_ERROR;
     }
     pFrom.pIndex = pIdx;
   }
   return SQLITE_OK;
 }
 /*
 ** If the source-list item passed as an argument was augmented with an
 ** INDEXED BY clause, then try to locate the specified index. If there
 ** was such a clause and the named index cannot be found, return
 ** SQLITE_ERROR and leave an error in pParse. Otherwise, populate
 ** pFrom.pIndex and return SQLITE_OK.
 */
 static int sqlite3IndexedByLookup( Parse pParse, SrcList_item pFrom )
 {
   if ( pFrom.pTab != null && pFrom.zIndex != null && pFrom.zIndex.Length != 0 )
   {
     Table pTab = pFrom.pTab;
     string zIndex = pFrom.zIndex;
     Index pIdx;
     for ( pIdx = pTab.pIndex;
     pIdx != null && sqlite3StrICmp( pIdx.zName, zIndex ) != 0;
     pIdx = pIdx.pNext
     ) ;
     if ( null == pIdx )
     {
       sqlite3ErrorMsg( pParse, "no such index: %s", zIndex );
       return SQLITE_ERROR;
     }
     pFrom.pIndex = pIdx;
   }
   return SQLITE_OK;
 }