/ Check-in [d012628a]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Minor code and comment cleanup. (CVS 2165)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d012628a78edaa8d3cb438a7dcc3770b2eb8588b
User & Date: drh 2004-12-14 03:34:34
Context
2004-12-16
21:09
Make sure LIMITs are handled correctly on UNION operators. Ticket #1035. (CVS 2166) check-in: ece0085f user: drh tags: trunk
2004-12-14
03:34
Minor code and comment cleanup. (CVS 2165) check-in: d012628a user: drh tags: trunk
2004-12-10
18:00
Factor the test for zName==NULL out of the loop. Ticket #1032. (CVS 2164) check-in: 7f38f67c user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/build.c.

    18     18   **     CREATE INDEX
    19     19   **     DROP INDEX
    20     20   **     creating ID lists
    21     21   **     BEGIN TRANSACTION
    22     22   **     COMMIT
    23     23   **     ROLLBACK
    24     24   **
    25         -** $Id: build.c,v 1.289 2004/12/07 12:29:18 drh Exp $
           25  +** $Id: build.c,v 1.290 2004/12/14 03:34:34 drh Exp $
    26     26   */
    27     27   #include "sqliteInt.h"
    28     28   #include <ctype.h>
    29     29   
    30     30   /*
    31     31   ** This routine is called when a new SQL statement is beginning to
    32         -** be parsed.  Check to see if the schema for the database needs
    33         -** to be read from the SQLITE_MASTER and SQLITE_TEMP_MASTER tables.
    34         -** If it does, then read it.
           32  +** be parsed.  Initialize the pParse structure as needed.
    35     33   */
    36     34   void sqlite3BeginParse(Parse *pParse, int explainFlag){
    37     35     pParse->explain = explainFlag;
    38     36     pParse->nVar = 0;
    39     37   }
    40     38   
    41     39   /*
................................................................................
    81     79         sqlite3VdbeAddOp(v, OP_Goto, 0, pParse->cookieGoto);
    82     80       }
    83     81   
    84     82       /* Add a No-op that contains the complete text of the compiled SQL
    85     83       ** statement as its P3 argument.  This does not change the functionality
    86     84       ** of the program. 
    87     85       **
    88         -    ** This is used to implement sqlite3_trace() functionality.
           86  +    ** This is used to implement sqlite3_trace().
    89     87       */
    90     88       sqlite3VdbeOp3(v, OP_Noop, 0, 0, pParse->zSql, pParse->zTail-pParse->zSql);
    91     89     }
    92     90   
    93     91   
    94     92     /* Get the VDBE program ready for execution
    95     93     */
................................................................................
   514    512   
   515    513   /*
   516    514   ** The token *pName contains the name of a database (either "main" or
   517    515   ** "temp" or the name of an attached db). This routine returns the
   518    516   ** index of the named database in db->aDb[], or -1 if the named db 
   519    517   ** does not exist.
   520    518   */
   521         -int findDb(sqlite3 *db, Token *pName){
          519  +static int findDb(sqlite3 *db, Token *pName){
   522    520     int i;         /* Database number */
   523    521     int n;         /* Number of characters in the name */
   524    522     Db *pDb;       /* A database whose name space is being searched */
   525    523     char *zName;   /* Name we are searching for */
   526    524   
   527    525     zName = sqlite3NameFromToken(pName);
   528    526     if( zName ){
................................................................................
   619    617     Token *pName1,   /* First part of the name of the table or view */
   620    618     Token *pName2,   /* Second part of the name of the table or view */
   621    619     int isTemp,      /* True if this is a TEMP table */
   622    620     int isView       /* True if this is a VIEW */
   623    621   ){
   624    622     Table *pTable;
   625    623     Index *pIdx;
   626         -  char *zName;
          624  +  char *zName = 0; /* The name of the new table */
   627    625     sqlite3 *db = pParse->db;
   628    626     Vdbe *v;
   629    627     int iDb;         /* Database number to create the table in */
   630    628     Token *pName;    /* Unqualified name of the table to create */
   631    629   
   632    630     /* The table or view name to create is passed to this routine via tokens
   633    631     ** pName1 and pName2. If the table name was fully qualified, for example:
................................................................................
   647    645     ** created in.
   648    646     */
   649    647     iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pName);
   650    648     if( iDb<0 ) return;
   651    649     if( isTemp && iDb>1 ){
   652    650       /* If creating a temp table, the name may not be qualified */
   653    651       sqlite3ErrorMsg(pParse, "temporary table name must be unqualified");
   654         -    pParse->nErr++;
   655    652       return;
   656    653     }
   657    654     if( isTemp ) iDb = 1;
   658    655   
   659    656     pParse->sNameToken = *pName;
   660    657     zName = sqlite3NameFromToken(pName);
   661    658     if( zName==0 ) return;
   662    659     if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){
   663         -    sqliteFree(zName);
   664         -    return;
          660  +    goto begin_table_error;
   665    661     }
   666    662     if( db->init.iDb==1 ) isTemp = 1;
   667    663   #ifndef SQLITE_OMIT_AUTHORIZATION
   668    664     assert( (isTemp & 1)==isTemp );
   669    665     {
   670    666       int code;
   671    667       char *zDb = db->aDb[iDb].zName;
   672    668       if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(isTemp), 0, zDb) ){
   673         -      sqliteFree(zName);
   674         -      return;
          669  +      goto begin_table_error;
   675    670       }
   676    671       if( isView ){
   677    672         if( isTemp ){
   678    673           code = SQLITE_CREATE_TEMP_VIEW;
   679    674         }else{
   680    675           code = SQLITE_CREATE_VIEW;
   681    676         }
................................................................................
   683    678         if( isTemp ){
   684    679           code = SQLITE_CREATE_TEMP_TABLE;
   685    680         }else{
   686    681           code = SQLITE_CREATE_TABLE;
   687    682         }
   688    683       }
   689    684       if( sqlite3AuthCheck(pParse, code, zName, 0, zDb) ){
   690         -      sqliteFree(zName);
   691         -      return;
          685  +      goto begin_table_error;
   692    686       }
   693    687     }
   694    688   #endif
   695    689   
   696    690     /* Make sure the new table name does not collide with an existing
   697    691     ** index or table name in the same database.  Issue an error message if
   698    692     ** it does.
   699    693     */
   700    694     if( SQLITE_OK!=sqlite3ReadSchema(pParse) ) return;
   701    695     pTable = sqlite3FindTable(db, zName, db->aDb[iDb].zName);
   702    696     if( pTable ){
   703    697       sqlite3ErrorMsg(pParse, "table %T already exists", pName);
   704         -    sqliteFree(zName);
   705         -    return;
          698  +    goto begin_table_error;
   706    699     }
   707    700     if( (pIdx = sqlite3FindIndex(db, zName, 0))!=0 && 
   708    701         ( iDb==0 || !db->init.busy) ){
   709    702       sqlite3ErrorMsg(pParse, "there is already an index named %s", zName);
   710         -    sqliteFree(zName);
   711         -    return;
          703  +    goto begin_table_error;
   712    704     }
   713    705     pTable = sqliteMalloc( sizeof(Table) );
   714    706     if( pTable==0 ){
   715    707       pParse->rc = SQLITE_NOMEM;
   716    708       pParse->nErr++;
   717         -    sqliteFree(zName);
   718         -    return;
          709  +    goto begin_table_error;
   719    710     }
   720    711     pTable->zName = zName;
   721    712     pTable->nCol = 0;
   722    713     pTable->aCol = 0;
   723    714     pTable->iPKey = -1;
   724    715     pTable->pIndex = 0;
   725    716     pTable->iDb = iDb;
................................................................................
   767    758       sqlite3OpenMasterTable(v, iDb);
   768    759       sqlite3VdbeAddOp(v, OP_NewRecno, 0, 0);
   769    760       sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
   770    761       sqlite3VdbeAddOp(v, OP_String8, 0, 0);
   771    762       sqlite3VdbeAddOp(v, OP_PutIntKey, 0, 0);
   772    763       sqlite3VdbeAddOp(v, OP_Close, 0, 0);
   773    764     }
          765  +
          766  +  /* Normal (non-error) return. */
          767  +  return;
          768  +
          769  +  /* If an error occurs, we jump here */
          770  +begin_table_error:
          771  +  sqliteFree(zName);
          772  +  return;
   774    773   }
   775    774   
   776    775   /*
   777    776   ** Add a new column to the table currently being constructed.
   778    777   **
   779    778   ** The parser calls this routine once for each column declaration
   780    779   ** in a CREATE TABLE statement.  sqlite3StartTable() gets called
................................................................................
   894    893   ** most recently added column of the table is the primary key.
   895    894   **
   896    895   ** A table can have at most one primary key.  If the table already has
   897    896   ** a primary key (and this is the second primary key) then create an
   898    897   ** error.
   899    898   **
   900    899   ** If the PRIMARY KEY is on a single column whose datatype is INTEGER,
   901         -** then we will try to use that column as the row id.  (Exception:
   902         -** For backwards compatibility with older databases, do not do this
   903         -** if the file format version number is less than 1.)  Set the Table.iPKey
          900  +** then we will try to use that column as the rowid.  Set the Table.iPKey
   904    901   ** field of the table under construction to be the index of the
   905    902   ** INTEGER PRIMARY KEY column.  Table.iPKey is set to -1 if there is
   906    903   ** no INTEGER PRIMARY KEY.
   907    904   **
   908    905   ** If the key is not an INTEGER PRIMARY KEY, then create a unique
   909    906   ** index for the key.  No index is created for INTEGER PRIMARY KEYs.
   910    907   */
................................................................................
  2071   2068     sqlite3VdbeAddOp(v, OP_Next, iTab, addr1+1);
  2072   2069     sqlite3VdbeChangeP2(v, addr1, sqlite3VdbeCurrentAddr(v));
  2073   2070     sqlite3VdbeAddOp(v, OP_Close, iTab, 0);
  2074   2071     sqlite3VdbeAddOp(v, OP_Close, iIdx, 0);
  2075   2072   }
  2076   2073   
  2077   2074   /*
  2078         -** Create a new index for an SQL table.  pIndex is the name of the index 
  2079         -** and pTable is the name of the table that is to be indexed.  Both will 
         2075  +** Create a new index for an SQL table.  pName1.pName2 is the name of the index 
         2076  +** and pTblList is the name of the table that is to be indexed.  Both will 
  2080   2077   ** be NULL for a primary key or an index that is created to satisfy a
  2081   2078   ** UNIQUE constraint.  If pTable and pIndex are NULL, use pParse->pNewTable
  2082   2079   ** as the table to be indexed.  pParse->pNewTable is a table that is
  2083   2080   ** currently being constructed by a CREATE TABLE statement.
  2084   2081   **
  2085   2082   ** pList is a list of columns to be indexed.  pList will be NULL if this
  2086   2083   ** is a primary key or unique-constraint on the most recent column added
  2087   2084   ** to the table currently under construction.  
  2088   2085   */
  2089   2086   void sqlite3CreateIndex(
  2090         -  Parse *pParse,   /* All information about this parse */
  2091         -  Token *pName1,   /* First part of index name. May be NULL */
  2092         -  Token *pName2,   /* Second part of index name. May be NULL */
  2093         -  SrcList *pTblName,  /* Table to index. Use pParse->pNewTable if 0 */
         2087  +  Parse *pParse,     /* All information about this parse */
         2088  +  Token *pName1,     /* First part of index name. May be NULL */
         2089  +  Token *pName2,     /* Second part of index name. May be NULL */
         2090  +  SrcList *pTblName, /* Table to index. Use pParse->pNewTable if 0 */
  2094   2091     ExprList *pList,   /* A list of columns to be indexed */
  2095         -  int onError,     /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
  2096         -  Token *pStart,   /* The CREATE token that begins a CREATE TABLE statement */
  2097         -  Token *pEnd      /* The ")" that closes the CREATE INDEX statement */
         2092  +  int onError,       /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
         2093  +  Token *pStart,     /* The CREATE token that begins a CREATE TABLE statement */
         2094  +  Token *pEnd        /* The ")" that closes the CREATE INDEX statement */
  2098   2095   ){
  2099         -  Table *pTab = 0; /* Table to be indexed */
         2096  +  Table *pTab = 0;   /* Table to be indexed */
  2100   2097     Index *pIndex = 0; /* The index to be created */
  2101   2098     char *zName = 0;
  2102   2099     int i, j;
  2103   2100     Token nullId;    /* Fake token for an empty ID list */
  2104   2101     DbFixer sFix;    /* For assigning database names to pTable */
  2105   2102     int isTemp;      /* True for a temporary index */
  2106   2103     sqlite3 *db = pParse->db;

Changes to src/delete.c.

     6      6   **
     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains C code routines that are called by the parser
    13         -** to handle DELETE FROM statements.
           13  +** in order to generate code for DELETE FROM statements.
    14     14   **
    15         -** $Id: delete.c,v 1.92 2004/12/07 14:06:13 drh Exp $
           15  +** $Id: delete.c,v 1.93 2004/12/14 03:34:34 drh Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   /*
    20     20   ** Look up every table that is named in pSrc.  If any table is not found,
    21     21   ** add an error message to pParse->zErrMsg and return NULL.  If all tables
    22     22   ** are found, return a pointer to the last table.
................................................................................
    62     62     sqlite3VdbeAddOp(v, OP_OpenRead, iCur, pTab->tnum);
    63     63     VdbeComment((v, "# %s", pTab->zName));
    64     64     sqlite3VdbeAddOp(v, OP_SetNumColumns, iCur, pTab->nCol);
    65     65   }
    66     66   
    67     67   
    68     68   /*
    69         -** Process a DELETE FROM statement.
           69  +** Generate code for a DELETE FROM statement.
           70  +**
           71  +**     DELETE FROM table_wxyz WHERE a<5 AND b NOT NULL;
           72  +**                 \________/       \________________/
           73  +**                  pTabList              pWhere
    70     74   */
    71     75   void sqlite3DeleteFrom(
    72     76     Parse *pParse,         /* The parser context */
    73     77     SrcList *pTabList,     /* The table from which we should delete things */
    74     78     Expr *pWhere           /* The WHERE clause.  May be null */
    75     79   ){
    76     80     Vdbe *v;               /* The virtual database engine */

Changes to src/where.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This module contains C code that generates VDBE code used to process
    13     13   ** the WHERE clause of SQL statements.
    14     14   **
    15         -** $Id: where.c,v 1.120 2004/11/23 01:47:31 drh Exp $
           15  +** $Id: where.c,v 1.121 2004/12/14 03:34:34 drh Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   /*
    20     20   ** The query generator uses an array of instances of this structure to
    21     21   ** help it analyze the subexpressions of the WHERE clause.  Each WHERE
    22     22   ** clause subexpression is separated from the others by an AND operator.
................................................................................
   354    354   **
   355    355   ** Consider the term t2.z='ok' in the following queries:
   356    356   **
   357    357   **   (1)  SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.x WHERE t2.z='ok'
   358    358   **   (2)  SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.x AND t2.z='ok'
   359    359   **   (3)  SELECT * FROM t1, t2 WHERE t1.a=t2.x AND t2.z='ok'
   360    360   **
   361         -** The t2.z='ok' is disabled in the in (2) because it did not originate
          361  +** The t2.z='ok' is disabled in the in (2) because it originates
   362    362   ** in the ON clause.  The term is disabled in (3) because it is not part
   363    363   ** of a LEFT OUTER JOIN.  In (1), the term is not disabled.
   364    364   **
   365    365   ** Disabling a term causes that term to not be tested in the inner loop
   366    366   ** of the join.  Disabling is an optimization.  We would get the correct
   367    367   ** results if nothing were ever disabled, but joins might run a little
   368    368   ** slower.  The trick is to disable as much as we can without disabling