/ Check-in [c41d5544]
Login

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

Overview
Comment:Add the SQLITE_OMIT_TEMPDB compile time macro. (CVS 2427)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:c41d55443c2dd532147962b87f542fb7d37075fd
User & Date: danielk1977 2005-03-29 03:10:59
Context
2005-03-29
08:26
Reduce the space allocated for the runtime virtual machine stack. (CVS 2428) check-in: 7d6818da user: danielk1977 tags: trunk
03:10
Add the SQLITE_OMIT_TEMPDB compile time macro. (CVS 2427) check-in: c41d5544 user: danielk1977 tags: trunk
02:54
Fix segfault due to exception handler being run with uninitialised variable. (CVS 2426) check-in: 78df3d04 user: danielk1977 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.317 2005/03/28 03:39:56 drh Exp $
           25  +** $Id: build.c,v 1.318 2005/03/29 03:10:59 danielk1977 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     32   ** be parsed.  Initialize the pParse structure as needed.
................................................................................
   164    164   ** See also sqlite3LocateTable().
   165    165   */
   166    166   Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){
   167    167     Table *p = 0;
   168    168     int i;
   169    169     assert( zName!=0 );
   170    170     assert( (db->flags & SQLITE_Initialized) || db->init.busy );
   171         -  for(i=0; i<db->nDb; i++){
          171  +  for(i=OMIT_TEMPDB; i<db->nDb; i++){
   172    172       int j = (i<2) ? i^1 : i;   /* Search TEMP before MAIN */
   173    173       if( zDatabase!=0 && sqlite3StrICmp(zDatabase, db->aDb[j].zName) ) continue;
   174    174       p = sqlite3HashFind(&db->aDb[j].tblHash, zName, strlen(zName)+1);
   175    175       if( p ) break;
   176    176     }
   177    177     return p;
   178    178   }
................................................................................
   223    223   ** TEMP first, then MAIN, then any auxiliary databases added
   224    224   ** using the ATTACH command.
   225    225   */
   226    226   Index *sqlite3FindIndex(sqlite3 *db, const char *zName, const char *zDb){
   227    227     Index *p = 0;
   228    228     int i;
   229    229     assert( (db->flags & SQLITE_Initialized) || db->init.busy );
   230         -  for(i=0; i<db->nDb; i++){
          230  +  for(i=OMIT_TEMPDB; i<db->nDb; i++){
   231    231       int j = (i<2) ? i^1 : i;  /* Search TEMP before MAIN */
   232    232       if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zName) ) continue;
   233    233       p = sqlite3HashFind(&db->aDb[j].idxHash, zName, strlen(zName)+1);
   234    234       if( p ) break;
   235    235     }
   236    236     return p;
   237    237   }
................................................................................
   533    533     Db *pDb;       /* A database whose name space is being searched */
   534    534     char *zName;   /* Name we are searching for */
   535    535   
   536    536     zName = sqlite3NameFromToken(pName);
   537    537     if( zName ){
   538    538       n = strlen(zName);
   539    539       for(i=(db->nDb-1), pDb=&db->aDb[i]; i>=0; i--, pDb--){
   540         -      if( n==strlen(pDb->zName) && 0==sqlite3StrICmp(pDb->zName, zName) ){
          540  +      if( (!OMIT_TEMPDB || i!=1 ) && n==strlen(pDb->zName) && 
          541  +          0==sqlite3StrICmp(pDb->zName, zName) ){
   541    542           break;
   542    543         }
   543    544       }
   544    545       sqliteFree(zName);
   545    546     }
   546    547     return i;
   547    548   }
................................................................................
   652    653     ** The call below sets the pName pointer to point at the token (pName1 or
   653    654     ** pName2) that stores the unqualified table name. The variable iDb is
   654    655     ** set to the index of the database that the table or view is to be
   655    656     ** created in.
   656    657     */
   657    658     iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pName);
   658    659     if( iDb<0 ) return;
   659         -  if( isTemp && iDb>1 ){
          660  +  if( !OMIT_TEMPDB && isTemp && iDb>1 ){
   660    661       /* If creating a temp table, the name may not be qualified */
   661    662       sqlite3ErrorMsg(pParse, "temporary table name must be unqualified");
   662    663       return;
   663    664     }
   664         -  if( isTemp ) iDb = 1;
          665  +  if( !OMIT_TEMPDB && isTemp ) iDb = 1;
   665    666   
   666    667     pParse->sNameToken = *pName;
   667    668     zName = sqlite3NameFromToken(pName);
   668    669     if( zName==0 ) return;
   669    670     if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){
   670    671       goto begin_table_error;
   671    672     }
................................................................................
   675    676     {
   676    677       int code;
   677    678       char *zDb = db->aDb[iDb].zName;
   678    679       if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(isTemp), 0, zDb) ){
   679    680         goto begin_table_error;
   680    681       }
   681    682       if( isView ){
   682         -      if( isTemp ){
          683  +      if( !OMIT_TEMPDB && isTemp ){
   683    684           code = SQLITE_CREATE_TEMP_VIEW;
   684    685         }else{
   685    686           code = SQLITE_CREATE_VIEW;
   686    687         }
   687    688       }else{
   688         -      if( isTemp ){
          689  +      if( !OMIT_TEMPDB && isTemp ){
   689    690           code = SQLITE_CREATE_TEMP_TABLE;
   690    691         }else{
   691    692           code = SQLITE_CREATE_TABLE;
   692    693         }
   693    694       }
   694    695       if( sqlite3AuthCheck(pParse, code, zName, 0, zDb) ){
   695    696         goto begin_table_error;
................................................................................
  1372   1373       zSep = "\n  ";
  1373   1374       zSep2 = ",\n  ";
  1374   1375       zEnd = "\n)";
  1375   1376     }
  1376   1377     n += 35 + 6*p->nCol;
  1377   1378     zStmt = sqliteMallocRaw( n );
  1378   1379     if( zStmt==0 ) return 0;
  1379         -  strcpy(zStmt, p->iDb==1 ? "CREATE TEMP TABLE " : "CREATE TABLE ");
         1380  +  strcpy(zStmt, !OMIT_TEMPDB&&p->iDb==1 ? "CREATE TEMP TABLE ":"CREATE TABLE ");
  1380   1381     k = strlen(zStmt);
  1381   1382     identPut(zStmt, &k, p->zName);
  1382   1383     zStmt[k++] = '(';
  1383   1384     for(pCol=p->aCol, i=0; i<p->nCol; i++, pCol++){
  1384   1385       strcpy(&zStmt[k], zSep);
  1385   1386       k += strlen(&zStmt[k]);
  1386   1387       zSep = zSep2;
................................................................................
  1861   1862       int code;
  1862   1863       const char *zTab = SCHEMA_TABLE(pTab->iDb);
  1863   1864       const char *zDb = db->aDb[pTab->iDb].zName;
  1864   1865       if( sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb)){
  1865   1866         goto exit_drop_table;
  1866   1867       }
  1867   1868       if( isView ){
  1868         -      if( iDb==1 ){
         1869  +      if( !OMIT_TEMPDB && iDb==1 ){
  1869   1870           code = SQLITE_DROP_TEMP_VIEW;
  1870   1871         }else{
  1871   1872           code = SQLITE_DROP_VIEW;
  1872   1873         }
  1873   1874       }else{
  1874         -      if( iDb==1 ){
         1875  +      if( !OMIT_TEMPDB && iDb==1 ){
  1875   1876           code = SQLITE_DROP_TEMP_TABLE;
  1876   1877         }else{
  1877   1878           code = SQLITE_DROP_TABLE;
  1878   1879         }
  1879   1880       }
  1880   1881       if( sqlite3AuthCheck(pParse, code, pTab->zName, 0, zDb) ){
  1881   1882         goto exit_drop_table;
................................................................................
  2185   2186   ){
  2186   2187     Table *pTab = 0;   /* Table to be indexed */
  2187   2188     Index *pIndex = 0; /* The index to be created */
  2188   2189     char *zName = 0;
  2189   2190     int i, j;
  2190   2191     Token nullId;    /* Fake token for an empty ID list */
  2191   2192     DbFixer sFix;    /* For assigning database names to pTable */
  2192         -  int isTemp;      /* True for a temporary index */
  2193   2193     sqlite3 *db = pParse->db;
  2194   2194   
  2195   2195     int iDb;          /* Index of the database that is being written */
  2196   2196     Token *pName = 0; /* Unqualified name of the index to create */
  2197   2197   
  2198   2198     if( pParse->nErr || sqlite3_malloc_failed ) goto exit_create_index;
  2199   2199   
................................................................................
  2206   2206       ** to search for the table. 'Fix' the table name to this db
  2207   2207       ** before looking up the table.
  2208   2208       */
  2209   2209       assert( pName1 && pName2 );
  2210   2210       iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pName);
  2211   2211       if( iDb<0 ) goto exit_create_index;
  2212   2212   
         2213  +#ifndef SQLITE_OMIT_TEMPDB
  2213   2214       /* If the index name was unqualified, check if the the table
  2214   2215       ** is a temp table. If so, set the database to 1.
  2215   2216       */
  2216   2217       pTab = sqlite3SrcListLookup(pParse, pTblName);
  2217   2218       if( pName2 && pName2->n==0 && pTab && pTab->iDb==1 ){
  2218   2219         iDb = 1;
  2219   2220       }
         2221  +#endif
  2220   2222   
  2221   2223       if( sqlite3FixInit(&sFix, pParse, iDb, "index", pName) &&
  2222   2224           sqlite3FixSrcList(&sFix, pTblName)
  2223   2225       ){
  2224   2226         goto exit_create_index;
  2225   2227       }
  2226   2228       pTab = sqlite3LocateTable(pParse, pTblName->a[0].zName, 
................................................................................
  2240   2242     }
  2241   2243   #ifndef SQLITE_OMIT_VIEW
  2242   2244     if( pTab->pSelect ){
  2243   2245       sqlite3ErrorMsg(pParse, "views may not be indexed");
  2244   2246       goto exit_create_index;
  2245   2247     }
  2246   2248   #endif
  2247         -  isTemp = pTab->iDb==1;
  2248   2249   
  2249   2250     /*
  2250   2251     ** Find the name of the index.  Make sure there is not already another
  2251   2252     ** index or table with the same name.  
  2252   2253     **
  2253   2254     ** Exception:  If we are reading the names of permanent indices from the
  2254   2255     ** sqlite_master table (because some other process changed the schema) and
................................................................................
  2290   2291       if( zName==0 ) goto exit_create_index;
  2291   2292     }
  2292   2293   
  2293   2294     /* Check for authorization to create an index.
  2294   2295     */
  2295   2296   #ifndef SQLITE_OMIT_AUTHORIZATION
  2296   2297     {
  2297         -    const char *zDb = db->aDb[pTab->iDb].zName;
  2298         -    if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(isTemp), 0, zDb) ){
         2298  +    const char *zDb = db->aDb[iDb].zName;
         2299  +    if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(iDb), 0, zDb) ){
  2299   2300         goto exit_create_index;
  2300   2301       }
  2301   2302       i = SQLITE_CREATE_INDEX;
  2302         -    if( isTemp ) i = SQLITE_CREATE_TEMP_INDEX;
         2303  +    if( !OMIT_TEMPDB && iDb==1 ) i = SQLITE_CREATE_TEMP_INDEX;
  2303   2304       if( sqlite3AuthCheck(pParse, i, zName, pTab->zName, zDb) ){
  2304   2305         goto exit_create_index;
  2305   2306       }
  2306   2307     }
  2307   2308   #endif
  2308   2309   
  2309   2310     /* If pList==0, it means this routine was called to make a primary
................................................................................
  2558   2559       int code = SQLITE_DROP_INDEX;
  2559   2560       Table *pTab = pIndex->pTable;
  2560   2561       const char *zDb = db->aDb[pIndex->iDb].zName;
  2561   2562       const char *zTab = SCHEMA_TABLE(pIndex->iDb);
  2562   2563       if( sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
  2563   2564         goto exit_drop_index;
  2564   2565       }
  2565         -    if( pIndex->iDb ) code = SQLITE_DROP_TEMP_INDEX;
         2566  +    if( !OMIT_TEMPDB && pIndex->iDb ) code = SQLITE_DROP_TEMP_INDEX;
  2566   2567       if( sqlite3AuthCheck(pParse, code, pIndex->zName, pTab->zName, zDb) ){
  2567   2568         goto exit_drop_index;
  2568   2569       }
  2569   2570     }
  2570   2571   #endif
  2571   2572   
  2572   2573     /* Generate code to remove the index and from the master table */
................................................................................
  2866   2867       assert( iDb<db->nDb );
  2867   2868       assert( db->aDb[iDb].pBt!=0 || iDb==1 );
  2868   2869       assert( iDb<32 );
  2869   2870       mask = 1<<iDb;
  2870   2871       if( (pParse->cookieMask & mask)==0 ){
  2871   2872         pParse->cookieMask |= mask;
  2872   2873         pParse->cookieValue[iDb] = db->aDb[iDb].schema_cookie;
  2873         -      if( iDb==1 ){
         2874  +      if( !OMIT_TEMPDB && iDb==1 ){
  2874   2875           sqlite3OpenTempDatabase(pParse);
  2875   2876         }
  2876   2877       }
  2877   2878     }
  2878   2879   }
  2879   2880   
  2880   2881   /*
................................................................................
  2899   2900     Vdbe *v = sqlite3GetVdbe(pParse);
  2900   2901     if( v==0 ) return;
  2901   2902     sqlite3CodeVerifySchema(pParse, iDb);
  2902   2903     pParse->writeMask |= 1<<iDb;
  2903   2904     if( setStatement && pParse->nested==0 ){
  2904   2905       sqlite3VdbeAddOp(v, OP_Statement, iDb, 0);
  2905   2906     }
  2906         -  if( iDb!=1 && pParse->db->aDb[1].pBt!=0 ){
         2907  +  if( (OMIT_TEMPDB || iDb!=1) && pParse->db->aDb[1].pBt!=0 ){
  2907   2908       sqlite3BeginWriteOperation(pParse, setStatement, 1);
  2908   2909     }
  2909   2910   }
  2910   2911   
  2911   2912   #ifndef SQLITE_OMIT_UTF16
  2912   2913   /* 
  2913   2914   ** Return the transient sqlite3_value object used for encoding conversions

Changes to src/main.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** Main file for the SQLite library.  The routines in this file
    13     13   ** implement the programmer interface to the library.  Routines in
    14     14   ** other files are for internal use by SQLite and should not be
    15     15   ** accessed by users of the library.
    16     16   **
    17         -** $Id: main.c,v 1.283 2005/03/21 04:04:03 danielk1977 Exp $
           17  +** $Id: main.c,v 1.284 2005/03/29 03:10:59 danielk1977 Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include "os.h"
    21     21   #include <ctype.h>
    22     22   
    23     23   /*
    24     24   ** The following constant value is used by the SQLITE_BIGENDIAN and
................................................................................
   129    129     int size;
   130    130     Table *pTab;
   131    131     char const *azArg[5];
   132    132     char zDbNum[30];
   133    133     int meta[10];
   134    134     InitData initData;
   135    135     char const *zMasterSchema;
   136         -  char const *zMasterName;
          136  +  char const *zMasterName = SCHEMA_TABLE(iDb);
   137    137   
   138    138     /*
   139    139     ** The master database table has a structure like this
   140    140     */
   141    141     static const char master_schema[] = 
   142    142        "CREATE TABLE sqlite_master(\n"
   143    143        "  type text,\n"
   144    144        "  name text,\n"
   145    145        "  tbl_name text,\n"
   146    146        "  rootpage integer,\n"
   147    147        "  sql text\n"
   148    148        ")"
   149    149     ;
          150  +#ifndef SQLITE_OMIT_TEMPDB
   150    151     static const char temp_master_schema[] = 
   151    152        "CREATE TEMP TABLE sqlite_temp_master(\n"
   152    153        "  type text,\n"
   153    154        "  name text,\n"
   154    155        "  tbl_name text,\n"
   155    156        "  rootpage integer,\n"
   156    157        "  sql text\n"
   157    158        ")"
   158    159     ;
          160  +#else
          161  +  #define temp_master_schema 0
          162  +#endif
   159    163   
   160    164     assert( iDb>=0 && iDb<db->nDb );
   161    165   
   162    166     /* zMasterSchema and zInitScript are set to point at the master schema
   163    167     ** and initialisation script appropriate for the database being
   164    168     ** initialised. zMasterName is the name of the master table.
   165    169     */
   166         -  if( iDb==1 ){
          170  +  if( !OMIT_TEMPDB && iDb==1 ){
   167    171       zMasterSchema = temp_master_schema;
   168         -    zMasterName = TEMP_MASTER_NAME;
   169    172     }else{
   170    173       zMasterSchema = master_schema;
   171         -    zMasterName = MASTER_NAME;
   172    174     }
          175  +  zMasterName = SCHEMA_TABLE(iDb);
   173    176   
   174    177     /* Construct the schema tables.  */
   175    178     sqlite3SafetyOff(db);
   176    179     azArg[0] = zMasterName;
   177    180     azArg[1] = "1";
   178    181     azArg[2] = zMasterSchema;
   179    182     sprintf(zDbNum, "%d", iDb);
................................................................................
   191    194       pTab->readOnly = 1;
   192    195     }
   193    196     sqlite3SafetyOn(db);
   194    197   
   195    198     /* Create a cursor to hold the database open
   196    199     */
   197    200     if( db->aDb[iDb].pBt==0 ){
   198         -    if( iDb==1 ) DbSetProperty(db, 1, DB_SchemaLoaded);
          201  +    if( !OMIT_TEMPDB && iDb==1 ) DbSetProperty(db, 1, DB_SchemaLoaded);
   199    202       return SQLITE_OK;
   200    203     }
   201    204     rc = sqlite3BtreeCursor(db->aDb[iDb].pBt, MASTER_ROOT, 0, 0, 0, &curMain);
   202    205     if( rc!=SQLITE_OK && rc!=SQLITE_EMPTY ){
   203    206       sqlite3SetString(pzErrMsg, sqlite3ErrStr(rc), (char*)0);
   204    207       return rc;
   205    208     }
................................................................................
   347    350       }
   348    351     }
   349    352   
   350    353     /* Once all the other databases have been initialised, load the schema
   351    354     ** for the TEMP database. This is loaded last, as the TEMP database
   352    355     ** schema may contain references to objects in other databases.
   353    356     */
          357  +#ifndef SQLITE_OMIT_TEMPDB
   354    358     if( rc==SQLITE_OK && db->nDb>1 && !DbHasProperty(db, 1, DB_SchemaLoaded) ){
   355    359       rc = sqlite3InitOne(db, 1, pzErrMsg);
   356    360       if( rc ){
   357    361         sqlite3ResetInternalSchema(db, 1);
   358    362       }
   359    363     }
          364  +#endif
   360    365   
   361    366     db->init.busy = 0;
   362    367     if( rc==SQLITE_OK ){
   363    368       db->flags |= SQLITE_Initialized;
   364    369       sqlite3CommitInternalChanges(db);
   365    370     }
   366    371   
................................................................................
  1201   1206     /* Open the backend database driver */
  1202   1207     rc = sqlite3BtreeFactory(db, zFilename, 0, MAX_PAGES, &db->aDb[0].pBt);
  1203   1208     if( rc!=SQLITE_OK ){
  1204   1209       sqlite3Error(db, rc, 0);
  1205   1210       db->magic = SQLITE_MAGIC_CLOSED;
  1206   1211       goto opendb_out;
  1207   1212     }
         1213  +
         1214  +  /* The default safety_level for the main database is 'full'; for the temp
         1215  +  ** database it is 'NONE'. This matches the pager layer defaults.  
         1216  +  */
  1208   1217     db->aDb[0].zName = "main";
  1209         -  db->aDb[1].zName = "temp";
  1210         -
  1211         -  /* The default safety_level for the main database is 'full' for the temp
  1212         -  ** database it is 'NONE'. This matches the pager layer defaults.  */
  1213   1218     db->aDb[0].safety_level = 3;
         1219  +#ifndef SQLITE_OMIT_TEMPDB
         1220  +  db->aDb[1].zName = "temp";
  1214   1221     db->aDb[1].safety_level = 1;
         1222  +#endif
         1223  +
  1215   1224   
  1216   1225     /* Register all built-in functions, but do not attempt to read the
  1217   1226     ** database schema yet. This is delayed until the first time the database
  1218   1227     ** is accessed.
  1219   1228     */
  1220   1229     sqlite3RegisterBuiltinFunctions(db);
  1221   1230     sqlite3Error(db, SQLITE_OK, 0);

Changes to src/parse.y.

    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains SQLite's grammar for SQL.  Process this file
    13     13   ** using the lemon parser generator to generate C code that runs
    14     14   ** the parser.  Lemon will also generate a header file containing
    15     15   ** numeric codes for all of the tokens.
    16     16   **
    17         -** @(#) $Id: parse.y,v 1.169 2005/03/17 05:03:40 danielk1977 Exp $
           17  +** @(#) $Id: parse.y,v 1.170 2005/03/29 03:10:59 danielk1977 Exp $
    18     18   */
    19     19   %token_prefix TK_
    20     20   %token_type {Token}
    21     21   %default_type {Token}
    22     22   %extra_argument {Parse *pParse}
    23     23   %syntax_error {
    24     24     if( pParse->zErrMsg==0 ){
................................................................................
   108    108   ///////////////////// The CREATE TABLE statement ////////////////////////////
   109    109   //
   110    110   cmd ::= create_table create_table_args.
   111    111   create_table ::= CREATE(X) temp(T) TABLE nm(Y) dbnm(Z). {
   112    112      sqlite3StartTable(pParse,&X,&Y,&Z,T,0);
   113    113   }
   114    114   %type temp {int}
          115  +%ifndef SQLITE_OMIT_TEMPDB
   115    116   temp(A) ::= TEMP.  {A = 1;}
          117  +%endif
   116    118   temp(A) ::= .      {A = 0;}
   117    119   create_table_args ::= LP columnlist conslist_opt(X) RP(Y). {
   118    120     sqlite3EndTable(pParse,&X,&Y,0);
   119    121   }
   120    122   create_table_args ::= AS select(S). {
   121    123     sqlite3EndTable(pParse,0,0,S);
   122    124     sqlite3SelectDelete(S);

Changes to src/pragma.c.

     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 code used to implement the PRAGMA command.
    13     13   **
    14         -** $Id: pragma.c,v 1.90 2005/02/26 18:10:44 drh Exp $
           14  +** $Id: pragma.c,v 1.91 2005/03/29 03:10:59 danielk1977 Exp $
    15     15   */
    16     16   #include "sqliteInt.h"
    17     17   #include "os.h"
    18     18   #include <ctype.h>
    19     19   
    20     20   /* Ignore this whole file if pragmas are disabled
    21     21   */
................................................................................
   640    640       sqlite3VdbeSetColName(v, 0, "integrity_check", P3_STATIC);
   641    641       sqlite3VdbeAddOpList(v, ArraySize(initCode), initCode);
   642    642   
   643    643       /* Do an integrity check on each database file */
   644    644       for(i=0; i<db->nDb; i++){
   645    645         HashElem *x;
   646    646         int cnt = 0;
          647  +
          648  +      if( OMIT_TEMPDB && i==1 ) continue;
   647    649   
   648    650         sqlite3CodeVerifySchema(pParse, i);
   649    651   
   650    652         /* Do an integrity check of the B-Tree
   651    653         */
   652    654         for(x=sqliteHashFirst(&db->aDb[i].tblHash); x; x=sqliteHashNext(x)){
   653    655           Table *pTab = sqliteHashData(x);

Changes to src/sqliteInt.h.

     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   ** Internal interface definitions for SQLite.
    13     13   **
    14         -** @(#) $Id: sqliteInt.h,v 1.374 2005/03/21 04:04:03 danielk1977 Exp $
           14  +** @(#) $Id: sqliteInt.h,v 1.375 2005/03/29 03:10:59 danielk1977 Exp $
    15     15   */
    16     16   #ifndef _SQLITEINT_H_
    17     17   #define _SQLITEINT_H_
    18     18   
    19     19   /*
    20     20   ** These #defines should enable >2GB file support on Posix if the
    21     21   ** underlying operating system supports it.  If the OS lacks
................................................................................
    63     63   #endif
    64     64   #ifdef SQLITE_DEFAULT_TEMP_CACHE_SIZE
    65     65   # define TEMP_PAGES SQLITE_DEFAULT_TEMP_CACHE_SIZE
    66     66   #else
    67     67   # define TEMP_PAGES   500
    68     68   #endif
    69     69   
           70  +/*
           71  +** OMIT_TEMPDB is set to 1 if SQLITE_OMIT_TEMPDB is defined, or 0
           72  +** afterward. Having this macro allows us to cause the C compiler 
           73  +** to omit code used by TEMP tables without messy #ifndef statements.
           74  +*/
           75  +#ifdef SQLITE_OMIT_TEMPDB
           76  +#define OMIT_TEMPDB 1
           77  +#else
           78  +#define OMIT_TEMPDB 0
           79  +#endif
           80  +
    70     81   /*
    71     82   ** If the following macro is set to 1, then NULL values are considered
    72     83   ** distinct for the SELECT DISTINCT statement and for UNION or EXCEPT
    73     84   ** compound queries.  No other SQL database engine (among those tested) 
    74     85   ** works this way except for OCELOT.  But the SQL92 spec implies that
    75     86   ** this is how things should work.
    76     87   **
................................................................................
   288    299   ** The root-page of the master database table.
   289    300   */
   290    301   #define MASTER_ROOT       1
   291    302   
   292    303   /*
   293    304   ** The name of the schema table.
   294    305   */
   295         -#define SCHEMA_TABLE(x)  (x==1?TEMP_MASTER_NAME:MASTER_NAME)
          306  +#define SCHEMA_TABLE(x)  ((!OMIT_TEMPDB)&&(x==1)?TEMP_MASTER_NAME:MASTER_NAME)
   296    307   
   297    308   /*
   298    309   ** A convenience macro that returns the number of elements in
   299    310   ** an array.
   300    311   */
   301    312   #define ArraySize(X)    (sizeof(X)/sizeof(X[0]))
   302    313   

Changes to src/test1.c.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** Code for testing the printf() interface to SQLite.  This code
    13     13   ** is not included in the SQLite library.  It is used for automated
    14     14   ** testing of the SQLite library.
    15     15   **
    16         -** $Id: test1.c,v 1.135 2005/03/21 04:04:02 danielk1977 Exp $
           16  +** $Id: test1.c,v 1.136 2005/03/29 03:11:00 danielk1977 Exp $
    17     17   */
    18     18   #include "sqliteInt.h"
    19     19   #include "tcl.h"
    20     20   #include "os.h"
    21     21   #include <stdlib.h>
    22     22   #include <string.h>
    23     23   
................................................................................
  2857   2857   #endif
  2858   2858   
  2859   2859   #ifdef SQLITE_OMIT_TRIGGER
  2860   2860     Tcl_SetVar2(interp, "sqlite_options", "trigger", "0", TCL_GLOBAL_ONLY);
  2861   2861   #else
  2862   2862     Tcl_SetVar2(interp, "sqlite_options", "trigger", "1", TCL_GLOBAL_ONLY);
  2863   2863   #endif
         2864  +
         2865  +#ifdef SQLITE_OMIT_TEMPDB
         2866  +  Tcl_SetVar2(interp, "sqlite_options", "tempdb", "0", TCL_GLOBAL_ONLY);
         2867  +#else
         2868  +  Tcl_SetVar2(interp, "sqlite_options", "tempdb", "1", TCL_GLOBAL_ONLY);
         2869  +#endif
  2864   2870   
  2865   2871   #ifdef SQLITE_OMIT_UTF16
  2866   2872     Tcl_SetVar2(interp, "sqlite_options", "utf16", "0", TCL_GLOBAL_ONLY);
  2867   2873   #else
  2868   2874     Tcl_SetVar2(interp, "sqlite_options", "utf16", "1", TCL_GLOBAL_ONLY);
  2869   2875   #endif
  2870   2876   

Changes to src/trigger.c.

   193    193     TriggerStep *pStepList, /* The triggered program */
   194    194     Token *pAll             /* Token that describes the complete CREATE TRIGGER */
   195    195   ){
   196    196     Trigger *pTrig = 0;     /* The trigger whose construction is finishing up */
   197    197     sqlite3 *db = pParse->db;  /* The database */
   198    198     DbFixer sFix;
   199    199   
   200         -  if( pParse->nErr || pParse->pNewTrigger==0 ) goto triggerfinish_cleanup;
   201    200     pTrig = pParse->pNewTrigger;
   202    201     pParse->pNewTrigger = 0;
          202  +  if( pParse->nErr || pTrig==0 ) goto triggerfinish_cleanup;
   203    203     pTrig->step_list = pStepList;
   204    204     while( pStepList ){
   205    205       pStepList->pTrig = pTrig;
   206    206       pStepList = pStepList->pNext;
   207    207     }
   208    208     if( sqlite3FixInit(&sFix, pParse, pTrig->iDb, "trigger", &pTrig->nameToken) 
   209    209             && sqlite3FixTriggerStep(&sFix, pTrig->step_list) ){
................................................................................
   435    435       goto drop_trigger_cleanup;
   436    436     }
   437    437   
   438    438     assert( pName->nSrc==1 );
   439    439     zDb = pName->a[0].zDatabase;
   440    440     zName = pName->a[0].zName;
   441    441     nName = strlen(zName);
   442         -  for(i=0; i<db->nDb; i++){
          442  +  for(i=OMIT_TEMPDB; i<db->nDb; i++){
   443    443       int j = (i<2) ? i^1 : i;  /* Search TEMP before MAIN */
   444    444       if( zDb && sqlite3StrICmp(db->aDb[j].zName, zDb) ) continue;
   445    445       pTrigger = sqlite3HashFind(&(db->aDb[j].trigHash), zName, nName+1);
   446    446       if( pTrigger ) break;
   447    447     }
   448    448     if( !pTrigger ){
   449    449       sqlite3ErrorMsg(pParse, "no such trigger: %S", pName, 0);

Changes to src/vdbe.c.

    39     39   **
    40     40   ** Various scripts scan this source file in order to generate HTML
    41     41   ** documentation, headers files, or other derived files.  The formatting
    42     42   ** of the code in this file is, therefore, important.  See other comments
    43     43   ** in this file for details.  If in doubt, do not deviate from existing
    44     44   ** commenting and indentation practices when changing or adding code.
    45     45   **
    46         -** $Id: vdbe.c,v 1.460 2005/03/21 03:53:38 danielk1977 Exp $
           46  +** $Id: vdbe.c,v 1.461 2005/03/29 03:11:00 danielk1977 Exp $
    47     47   */
    48     48   #include "sqliteInt.h"
    49     49   #include "os.h"
    50     50   #include <ctype.h>
    51     51   #include "vdbeInt.h"
    52     52   
    53     53   /*
................................................................................
  3815   3815     char *zSql;
  3816   3816     int iDb = pOp->p1;
  3817   3817     const char *zMaster;
  3818   3818     InitData initData;
  3819   3819   
  3820   3820     assert( iDb>=0 && iDb<db->nDb );
  3821   3821     if( !DbHasProperty(db, iDb, DB_SchemaLoaded) ) break;
  3822         -  zMaster = iDb==1 ? TEMP_MASTER_NAME : MASTER_NAME;
         3822  +  zMaster = SCHEMA_TABLE(iDb);
  3823   3823     initData.db = db;
  3824   3824     initData.pzErrMsg = &p->zErrMsg;
  3825   3825     zSql = sqlite3MPrintf(
  3826   3826        "SELECT name, rootpage, sql, %d FROM '%q'.%s WHERE %s",
  3827   3827        pOp->p1, db->aDb[iDb].zName, zMaster, pOp->p3);
  3828   3828     if( zSql==0 ) goto no_mem;
  3829   3829     sqlite3SafetyOff(db);

Changes to test/alter.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #*************************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script is testing the ALTER TABLE statement.
    13     13   #
    14         -# $Id: alter.test,v 1.10 2005/02/14 06:38:40 danielk1977 Exp $
           14  +# $Id: alter.test,v 1.11 2005/03/29 03:11:00 danielk1977 Exp $
    15     15   #
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   # If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
    21     21   ifcapable !altertable {
................................................................................
    39     39   # alter-4.*: Test ALTER TABLE on tables that have AUTOINCREMENT fields.
    40     40   #
    41     41   
    42     42   # Create some tables to rename.  Be sure to include some TEMP tables
    43     43   # and some tables with odd names.
    44     44   #
    45     45   do_test alter-1.1 {
    46         -  execsql {
           46  +  ifcapable tempdb {
           47  +    set ::temp TEMP
           48  +  } else {
           49  +    set ::temp {}
           50  +  }
           51  +  execsql [subst -nocommands {
    47     52       CREATE TABLE t1(a,b);
    48     53       INSERT INTO t1 VALUES(1,2);
    49     54       CREATE TABLE [t1'x1](c UNIQUE, b PRIMARY KEY);
    50     55       INSERT INTO [t1'x1] VALUES(3,4);
    51     56       CREATE INDEX t1i1 ON T1(B);
    52     57       CREATE INDEX t1i2 ON t1(a,b);
    53     58       CREATE INDEX i3 ON [t1'x1](b,c);
    54         -    CREATE TEMP TABLE "temp table"(e,f,g UNIQUE);
           59  +    CREATE $::temp TABLE "temp table"(e,f,g UNIQUE);
    55     60       CREATE INDEX i2 ON [temp table](f);
    56     61       INSERT INTO [temp table] VALUES(5,6,7);
    57         -  }
           62  +  }]
    58     63     execsql {
    59     64       SELECT 't1', * FROM t1;
    60     65       SELECT 't1''x1', * FROM "t1'x1";
    61     66       SELECT * FROM [temp table];
    62     67     }
    63     68   } {t1 1 2 t1'x1 3 4 5 6 7}
    64     69   do_test alter-1.2 {
           70  +  execsql [subst {
           71  +    CREATE $::temp TABLE objlist(type, name, tbl_name);
           72  +    INSERT INTO objlist SELECT type, name, tbl_name 
           73  +        FROM sqlite_master WHERE NAME!='objlist';
           74  +  }]
           75  +  ifcapable tempdb {
           76  +    execsql {
           77  +      INSERT INTO objlist SELECT type, name, tbl_name 
           78  +          FROM sqlite_temp_master WHERE NAME!='objlist';
           79  +    }
           80  +  }
           81  +
    65     82     execsql {
    66         -    CREATE TEMP TABLE objlist(type, name, tbl_name);
    67         -    INSERT INTO objlist SELECT type, name, tbl_name FROM sqlite_master;
    68         -    INSERT INTO objlist 
    69         -      SELECT type, name, tbl_name FROM sqlite_temp_master WHERE NAME!='objlist';
    70     83       SELECT type, name, tbl_name FROM objlist ORDER BY tbl_name, type desc, name;
    71     84     }
    72     85   } [list \
    73     86        table t1                              t1             \
    74     87        index t1i1                            t1             \
    75     88        index t1i2                            t1             \
    76     89        table t1'x1                           t1'x1          \
................................................................................
    98    111       SELECT 't2', * FROM t2;
    99    112       SELECT * FROM temptab;
   100    113     }
   101    114   } {t1 1 2 t2 3 4 5 6 7}
   102    115   do_test alter-1.5 {
   103    116     execsql {
   104    117       DELETE FROM objlist;
   105         -    INSERT INTO objlist SELECT type, name, tbl_name FROM sqlite_master;
   106         -    INSERT INTO objlist 
   107         -      SELECT type, name, tbl_name FROM sqlite_temp_master WHERE NAME!='objlist';
          118  +    INSERT INTO objlist SELECT type, name, tbl_name
          119  +        FROM sqlite_master WHERE NAME!='objlist';
          120  +  }
          121  +  catchsql {
          122  +    INSERT INTO objlist SELECT type, name, tbl_name 
          123  +        FROM sqlite_temp_master WHERE NAME!='objlist';
          124  +  }
          125  +  execsql {
   108    126       SELECT type, name, tbl_name FROM objlist ORDER BY tbl_name, type desc, name;
   109    127     }
   110    128   } [list \
   111    129        table -t1-                         -t1-        \
   112    130        index t1i1                         -t1-        \
   113    131        index t1i2                         -t1-        \
   114    132        table T2                           T2          \
................................................................................
   119    137        index i2                           {TempTab}   \
   120    138        index {sqlite_autoindex_TempTab_1} {TempTab}   \
   121    139     ]
   122    140   
   123    141   # Make sure the changes persist after restarting the database.
   124    142   # (The TEMP table will not persist, of course.)
   125    143   #
   126         -do_test alter-1.6 {
   127         -  db close
   128         -  set DB [sqlite3 db test.db]
   129         -  execsql {
   130         -    CREATE TEMP TABLE objlist(type, name, tbl_name);
   131         -    INSERT INTO objlist SELECT type, name, tbl_name FROM sqlite_master;
   132         -    INSERT INTO objlist 
   133         -        SELECT type, name, tbl_name FROM sqlite_temp_master 
   134         -        WHERE NAME!='objlist';
   135         -    SELECT type, name, tbl_name FROM objlist 
   136         -        ORDER BY tbl_name, type desc, name;
   137         -  }
   138         -} [list \
   139         -     table -t1-                         -t1-           \
   140         -     index t1i1                         -t1-           \
   141         -     index t1i2                         -t1-           \
   142         -     table T2                           T2          \
   143         -     index i3                           T2          \
   144         -     index {sqlite_autoindex_T2_1}      T2          \
   145         -     index {sqlite_autoindex_T2_2}      T2          \
   146         -  ]
          144  +ifcapable tempdb {
          145  +  do_test alter-1.6 {
          146  +    db close
          147  +    set DB [sqlite3 db test.db]
          148  +    execsql {
          149  +      CREATE TEMP TABLE objlist(type, name, tbl_name);
          150  +      INSERT INTO objlist SELECT type, name, tbl_name FROM sqlite_master;
          151  +      INSERT INTO objlist 
          152  +          SELECT type, name, tbl_name FROM sqlite_temp_master 
          153  +          WHERE NAME!='objlist';
          154  +      SELECT type, name, tbl_name FROM objlist 
          155  +          ORDER BY tbl_name, type desc, name;
          156  +    }
          157  +  } [list \
          158  +       table -t1-                         -t1-           \
          159  +       index t1i1                         -t1-           \
          160  +       index t1i2                         -t1-           \
          161  +       table T2                           T2          \
          162  +       index i3                           T2          \
          163  +       index {sqlite_autoindex_T2_1}      T2          \
          164  +       index {sqlite_autoindex_T2_2}      T2          \
          165  +    ]
          166  +} else {
          167  +  execsql {
          168  +    DROP TABLE TempTab;
          169  +  }
          170  +}
   147    171   
   148    172   # Make sure the ALTER TABLE statements work with the
   149    173   # non-callback API
   150    174   #
   151    175   do_test alter-1.7 {
   152    176     stepsql $DB {
   153    177       ALTER TABLE [-t1-] RENAME to [*t1*];
   154    178       ALTER TABLE T2 RENAME TO [<t2>];
   155    179     }
   156    180     execsql {
   157    181       DELETE FROM objlist;
   158         -    INSERT INTO objlist SELECT type, name, tbl_name FROM sqlite_master;
   159         -    INSERT INTO objlist 
   160         -        SELECT type, name, tbl_name FROM sqlite_temp_master 
   161         -        WHERE NAME!='objlist';
   162         -    SELECT type, name, tbl_name FROM objlist 
   163         -        ORDER BY tbl_name, type desc, name;
          182  +    INSERT INTO objlist SELECT type, name, tbl_name
          183  +        FROM sqlite_master WHERE NAME!='objlist';
          184  +  }
          185  +  catchsql {
          186  +    INSERT INTO objlist SELECT type, name, tbl_name 
          187  +        FROM sqlite_temp_master WHERE NAME!='objlist';
          188  +  }
          189  +  execsql {
          190  +    SELECT type, name, tbl_name FROM objlist ORDER BY tbl_name, type desc, name;
   164    191     }
   165    192   } [list \
   166    193        table *t1*                         *t1*           \
   167    194        index t1i1                         *t1*           \
   168    195        index t1i2                         *t1*           \
   169    196        table <t2>                         <t2>          \
   170    197        index i3                           <t2>          \
................................................................................
   415    442   do_test alter-3.2.10 {
   416    443     execsql {
   417    444       DROP TABLE t10;
   418    445     }
   419    446   } {}
   420    447   
   421    448   do_test alter-3.3.1 {
   422         -  execsql {
          449  +  execsql [subst {
   423    450       CREATE TABLE tbl1(a, b, c);
   424         -    CREATE TEMP TRIGGER trig1 AFTER INSERT ON tbl1 BEGIN
          451  +    CREATE $::temp TRIGGER trig1 AFTER INSERT ON tbl1 BEGIN
   425    452         SELECT trigfunc('trig1', new.a, new.b, new.c);
   426    453       END;
   427         -  }
          454  +  }]
   428    455   } {}
   429    456   do_test alter-3.3.2 {
   430    457     execsql {
   431    458       INSERT INTO tbl1 VALUES('a', 'b', 'c');
   432    459     }
   433    460     set ::TRIGGER
   434    461   } {trig1 a b c}
................................................................................
   436    463     execsql {
   437    464       ALTER TABLE tbl1 RENAME TO tbl2;
   438    465       INSERT INTO tbl2 VALUES('d', 'e', 'f');
   439    466     } 
   440    467     set ::TRIGGER
   441    468   } {trig1 d e f}
   442    469   do_test alter-3.3.4 {
   443         -  execsql {
   444         -    CREATE TEMP TRIGGER trig2 AFTER UPDATE ON tbl2 BEGIN
          470  +  execsql [subst {
          471  +    CREATE $::temp TRIGGER trig2 AFTER UPDATE ON tbl2 BEGIN
   445    472         SELECT trigfunc('trig2', new.a, new.b, new.c);
   446    473       END;
   447         -  } 
          474  +  }] 
   448    475   } {}
   449    476   do_test alter-3.3.5 {
   450    477     execsql {
   451    478       ALTER TABLE tbl2 RENAME TO tbl3;
   452    479       INSERT INTO tbl3 VALUES('g', 'h', 'i');
   453    480     } 
   454    481     set ::TRIGGER
................................................................................
   458    485       UPDATE tbl3 SET a = 'G' where a = 'g';
   459    486     } 
   460    487     set ::TRIGGER
   461    488   } {trig2 G h i}
   462    489   do_test alter-3.3.7 {
   463    490     execsql {
   464    491       DROP TABLE tbl3;
   465         -    SELECT * FROM sqlite_temp_master WHERE type = 'trigger';
   466    492     }
   467    493   } {}
          494  +ifcapable tempdb {
          495  +  do_test alter-3.3.8 {
          496  +    execsql {
          497  +      SELECT * FROM sqlite_temp_master WHERE type = 'trigger';
          498  +    }
          499  +  } {}
          500  +}
   468    501   
   469    502   } ;# ifcapable trigger
   470    503   
   471    504   # If the build does not include AUTOINCREMENT fields, omit alter-4.*.
   472    505   ifcapable autoinc {
   473    506   
   474    507   do_test alter-4.1 {

Changes to test/alter3.test.

     9      9   #
    10     10   #*************************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script is testing that SQLite can handle a subtle 
    13     13   # file format change that may be used in the future to implement
    14     14   # "ALTER TABLE ... ADD COLUMN".
    15     15   #
    16         -# $Id: alter3.test,v 1.5 2005/03/28 16:50:22 drh Exp $
           16  +# $Id: alter3.test,v 1.6 2005/03/29 03:11:00 danielk1977 Exp $
    17     17   #
    18     18   
    19     19   set testdir [file dirname $argv0]
    20     20   
    21     21   source $testdir/tester.tcl
    22     22   
    23     23   # If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
................................................................................
   287    287     }
   288    288   } {}
   289    289   
   290    290   #----------------------------------------------------------------
   291    291   # Test that the table schema is correctly reloaded when a column
   292    292   # is added to a table.
   293    293   #
   294         -ifcapable trigger {
          294  +ifcapable trigger&&tempdb {
   295    295     do_test alter3-6.1 {
   296    296       execsql {
   297    297         CREATE TABLE t1(a, b);
   298    298         CREATE TABLE log(trig, a, b);
   299    299   
   300    300         CREATE TRIGGER t1_a AFTER INSERT ON t1 BEGIN
   301    301           INSERT INTO log VALUES('a', new.a, new.b);

Changes to test/attach.test.

     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script is testing the ATTACH and DETACH commands
    13     13   # and related functionality.
    14     14   #
    15         -# $Id: attach.test,v 1.39 2005/03/15 02:04:13 drh Exp $
           15  +# $Id: attach.test,v 1.40 2005/03/29 03:11:00 danielk1977 Exp $
    16     16   #
    17     17   
    18     18   set testdir [file dirname $argv0]
    19     19   source $testdir/tester.tcl
    20     20   
    21     21   for {set i 2} {$i<=15} {incr i} {
    22     22     file delete -force test$i.db
................................................................................
   123    123     }
   124    124   } {1 {database db9 is already in use}}
   125    125   do_test attach-1.15 {
   126    126     catchsql {
   127    127       ATTACH 'test.db' as main;
   128    128     }
   129    129   } {1 {database main is already in use}}
   130         -do_test attach-1.16 {
   131         -  catchsql {
   132         -    ATTACH 'test.db' as temp;
   133         -  }
   134         -} {1 {database temp is already in use}}
          130  +ifcapable tempdb {
          131  +  do_test attach-1.16 {
          132  +    catchsql {
          133  +      ATTACH 'test.db' as temp;
          134  +    }
          135  +  } {1 {database temp is already in use}}
          136  +}
   135    137   do_test attach-1.17 {
   136    138     catchsql {
   137    139       ATTACH 'test.db' as MAIN;
   138    140     }
   139    141   } {1 {database MAIN is already in use}}
   140    142   do_test attach-1.18 {
   141    143     catchsql {
................................................................................
   155    157   } {}
   156    158   ifcapable schema_pragmas {
   157    159   do_test attach-1.20.2 {
   158    160     db_list db
   159    161   } {0 main 2 db2 3 db3 4 db4 5 db6 6 db7 7 db8 8 db9 9 db10 10 db11}
   160    162   } ;# ifcapable schema_pragmas
   161    163   integrity_check attach-1.20.3
   162         -execsql {select * from sqlite_temp_master}
          164  +ifcapable tempdb {
          165  +  execsql {select * from sqlite_temp_master}
          166  +}
   163    167   do_test attach-1.21 {
   164    168     catchsql {
   165    169       ATTACH 'test.db' as db12;
   166    170     }
   167    171   } {0 {}}
   168    172   do_test attach-1.22 {
   169    173     catchsql {
................................................................................
   186    190     }
   187    191   } {1 {no such database: db12}}
   188    192   do_test attach-1.26 {
   189    193     catchsql {
   190    194       DETACH main;
   191    195     }
   192    196   } {1 {cannot detach database main}}
   193         -do_test attach-1.27 {
   194         -  catchsql {
   195         -    DETACH Temp;
   196         -  }
   197         -} {1 {cannot detach database Temp}}
          197  +
          198  +ifcapable tempdb {
          199  +  do_test attach-1.27 {
          200  +    catchsql {
          201  +      DETACH Temp;
          202  +    }
          203  +  } {1 {cannot detach database Temp}}
          204  +} else {
          205  +  do_test attach-1.27 {
          206  +    catchsql {
          207  +      DETACH Temp;
          208  +    }
          209  +  } {1 {no such database: Temp}}
          210  +}
          211  +
   198    212   do_test attach-1.28 {
   199    213     catchsql {
   200    214       DETACH db11;
   201    215       DETACH db10;
   202    216       DETACH db9;
   203    217       DETACH db8;
   204    218       DETACH db7;
................................................................................
   205    219       DETACH db6;
   206    220       DETACH db4;
   207    221       DETACH db3;
   208    222       DETACH db2;
   209    223     }
   210    224   } {0 {}}
   211    225   ifcapable schema_pragmas {
   212         -do_test attach-1.29 {
   213         -  db_list db
   214         -} {0 main 1 temp}
          226  +  ifcapable tempdb {
          227  +    do_test attach-1.29 {
          228  +      db_list db
          229  +    } {0 main 1 temp}
          230  +  } else {
          231  +    do_test attach-1.29 {
          232  +      db_list db
          233  +    } {0 main}
          234  +  }
   215    235   } ;# ifcapable schema_pragmas
   216    236   
   217    237   ifcapable {trigger} {  # Only do the following tests if triggers are enabled
   218    238   do_test attach-2.1 {
   219    239     execsql {
   220    240       CREATE TABLE tx(x1,x2,y1,y2);
   221    241       CREATE TRIGGER r1 AFTER UPDATE ON t2 FOR EACH ROW BEGIN
................................................................................
   253    273     }
   254    274   } {}
   255    275   do_test attach-2.7 {
   256    276     execsql {
   257    277       SELECT type, name, tbl_name FROM db2.sqlite_master;
   258    278     }
   259    279   } {table t2 t2 table tx tx trigger r1 t2}
   260         -ifcapable schema_pragmas {
   261         -do_test attach-2.8 {
   262         -  db_list db
   263         -} {0 main 1 temp 2 db2}
   264         -} ;# ifcapable schema_pragmas
          280  +
          281  +ifcapable schema_pragmas&&tempdb {
          282  +  do_test attach-2.8 {
          283  +    db_list db
          284  +  } {0 main 1 temp 2 db2}
          285  +} ;# ifcapable schema_pragmas&&tempdb
          286  +ifcapable schema_pragmas&&!tempdb {
          287  +  do_test attach-2.8 {
          288  +    db_list db
          289  +  } {0 main 2 db2}
          290  +} ;# ifcapable schema_pragmas&&!tempdb
          291  +
   265    292   do_test attach-2.9 {
   266    293     execsql {
   267    294       CREATE INDEX i2 ON t2(x);
   268    295       SELECT * FROM t2 WHERE x>5;
   269    296     } db2
   270    297   } {21 x 22 y}
   271    298   do_test attach-2.10 {
................................................................................
   275    302   } {table t2 t2 table tx tx trigger r1 t2 index i2 t2}
   276    303   #do_test attach-2.11 {
   277    304   #  catchsql { 
   278    305   #    SELECT * FROM t2 WHERE x>5;
   279    306   #  }
   280    307   #} {1 {database schema has changed}}
   281    308   ifcapable schema_pragmas {
   282         -do_test attach-2.12 {
   283         -  db_list db
   284         -} {0 main 1 temp 2 db2}
          309  +  ifcapable tempdb {
          310  +    do_test attach-2.12 {
          311  +      db_list db
          312  +    } {0 main 1 temp 2 db2}
          313  +  } else {
          314  +    do_test attach-2.12 {
          315  +      db_list db
          316  +    } {0 main 2 db2}
          317  +  }
   285    318   } ;# ifcapable schema_pragmas
   286    319   do_test attach-2.13 {
   287    320     catchsql {
   288    321       SELECT * FROM t2 WHERE x>5;
   289    322     }
   290    323   } {0 {21 x 22 y}}
   291    324   do_test attach-2.14 {
................................................................................
   602    635     catchsql {
   603    636       DROP TRIGGER r5;
   604    637       CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
   605    638         SELECT 'no-op' FROM orig.t1;
   606    639       END;
   607    640     } db2
   608    641   } {1 {trigger r5 cannot reference objects in database orig}}
   609         -do_test attach-5.4 {
   610         -  catchsql {
   611         -    CREATE TEMP TABLE t6(p,q,r);
   612         -    CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
   613         -      SELECT 'no-op' FROM temp.t6;
   614         -    END;
   615         -  } db2
   616         -} {1 {trigger r5 cannot reference objects in database temp}}
          642  +ifcapable tempdb {
          643  +  do_test attach-5.4 {
          644  +    catchsql {
          645  +      CREATE TEMP TABLE t6(p,q,r);
          646  +      CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
          647  +        SELECT 'no-op' FROM temp.t6;
          648  +      END;
          649  +    } db2
          650  +  } {1 {trigger r5 cannot reference objects in database temp}}
          651  +}
   617    652   ifcapable subquery {
   618    653     do_test attach-5.5 {
   619    654       catchsql {
   620    655         CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
   621    656           SELECT 'no-op' || (SELECT * FROM temp.t6);
   622    657         END;
   623    658       } db2

Changes to test/attach2.test.

     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script is testing the ATTACH and DETACH commands
    13     13   # and related functionality.
    14     14   #
    15         -# $Id: attach2.test,v 1.31 2005/01/24 01:38:33 drh Exp $
           15  +# $Id: attach2.test,v 1.32 2005/03/29 03:11:00 danielk1977 Exp $
    16     16   #
    17     17   
    18     18   set testdir [file dirname $argv0]
    19     19   source $testdir/tester.tcl
    20     20   
    21     21   
    22     22   # Ticket #354
................................................................................
   148    148   for {set i 2} {$i<=15} {incr i} {
   149    149     catch {db$i close}
   150    150   }
   151    151   
   152    152   # A procedure to verify the status of locks on a database.
   153    153   #
   154    154   proc lock_status {testnum db expected_result} {
          155  +  # If the database was compiled with OMIT_TEMPDB set, then 
          156  +  # the lock_status list will not contain an entry for the temp
          157  +  # db. But the test code doesn't know this, so it's easiest 
          158  +  # to filter it out here.
          159  +  ifcapable !tempdb {
          160  +    set expected_result [concat \
          161  +        [lrange $expected_result 0 1] \
          162  +        [lrange $expected_result 4 end] \
          163  +    ]
          164  +  }
   155    165     do_test attach2-$testnum [subst {
   156    166       $db cache flush  ;# The lock_status pragma should not be cached
   157    167       execsql {PRAGMA lock_status} $db
   158    168     }] $expected_result
   159    169   }
   160    170   set sqlite_os_trace 0
   161    171   

Changes to test/attach3.test.

     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script is testing the ATTACH and DETACH commands
    13     13   # and schema changes to attached databases.
    14     14   #
    15         -# $Id: attach3.test,v 1.14 2004/11/22 08:43:32 danielk1977 Exp $
           15  +# $Id: attach3.test,v 1.15 2005/03/29 03:11:00 danielk1977 Exp $
    16     16   #
    17     17   
    18     18   
    19     19   set testdir [file dirname $argv0]
    20     20   source $testdir/tester.tcl
    21     21   
    22     22   # Create tables t1 and t2 in the main database
................................................................................
   185    185   } {}
   186    186   do_test attach3-8.2 {
   187    187     execsql {
   188    188       SELECT * FROM aux.sqlite_master WHERE name = 'tr1';
   189    189     }
   190    190   } {}
   191    191   
   192         -# Try to trick SQLite into dropping the wrong temp trigger.
   193         -do_test attach3-9.0 {
   194         -  execsql {
   195         -    CREATE TABLE main.t4(a, b, c);
   196         -    CREATE TABLE aux.t4(a, b, c);
   197         -    CREATE TEMP TRIGGER tst_trigger BEFORE INSERT ON aux.t4 BEGIN 
   198         -      SELECT 'hello world';
   199         -    END;
   200         -    SELECT count(*) FROM sqlite_temp_master;
   201         -  }
   202         -} {1}
   203         -do_test attach3-9.1 {
   204         -  execsql {
   205         -    DROP TABLE main.t4;
   206         -    SELECT count(*) FROM sqlite_temp_master;
   207         -  }
   208         -} {1}
   209         -do_test attach3-9.2 {
   210         -  execsql {
   211         -    DROP TABLE aux.t4;
   212         -    SELECT count(*) FROM sqlite_temp_master;
   213         -  }
   214         -} {0}
          192  +ifcapable tempdb {
          193  +  # Try to trick SQLite into dropping the wrong temp trigger.
          194  +  do_test attach3-9.0 {
          195  +    execsql {
          196  +      CREATE TABLE main.t4(a, b, c);
          197  +      CREATE TABLE aux.t4(a, b, c);
          198  +      CREATE TEMP TRIGGER tst_trigger BEFORE INSERT ON aux.t4 BEGIN 
          199  +        SELECT 'hello world';
          200  +      END;
          201  +      SELECT count(*) FROM sqlite_temp_master;
          202  +    }
          203  +  } {1}
          204  +  do_test attach3-9.1 {
          205  +    execsql {
          206  +      DROP TABLE main.t4;
          207  +      SELECT count(*) FROM sqlite_temp_master;
          208  +    }
          209  +  } {1}
          210  +  do_test attach3-9.2 {
          211  +    execsql {
          212  +      DROP TABLE aux.t4;
          213  +      SELECT count(*) FROM sqlite_temp_master;
          214  +    }
          215  +  } {0}
          216  +}
   215    217   } ;# endif trigger
   216    218   
   217    219   # Make sure the aux.sqlite_master table is read-only
   218    220   do_test attach3-10.0 {
   219    221     catchsql {
   220    222       INSERT INTO aux.sqlite_master VALUES(1, 2, 3, 4, 5);
   221    223     }

Changes to test/auth.test.

     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script is testing the ATTACH and DETACH commands
    13     13   # and related functionality.
    14     14   #
    15         -# $Id: auth.test,v 1.26 2005/01/24 10:26:00 danielk1977 Exp $
           15  +# $Id: auth.test,v 1.27 2005/03/29 03:11:00 danielk1977 Exp $
    16     16   #
    17     17   
    18     18   set testdir [file dirname $argv0]
    19     19   source $testdir/tester.tcl
    20     20   
    21     21   # disable this test if the SQLITE_OMIT_AUTHORIZATION macro is
    22     22   # defined during compilation.
................................................................................
    76     76   do_test auth-1.3.3 {
    77     77     set ::authargs
    78     78   } {t1 {} main {}}
    79     79   do_test auth-1.4 {
    80     80     execsql {SELECT name FROM sqlite_master}
    81     81   } {}
    82     82   
    83         -do_test auth-1.5 {
    84         -  proc auth {code arg1 arg2 arg3 arg4} {
    85         -    if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
    86         -      return SQLITE_DENY
    87         -    }
    88         -    return SQLITE_OK
    89         -  }
    90         -  catchsql {CREATE TEMP TABLE t1(a,b,c)}
    91         -} {1 {not authorized}}
    92         -do_test auth-1.6 {
    93         -  execsql {SELECT name FROM sqlite_temp_master}
    94         -} {}
    95         -do_test auth-1.7.1 {
    96         -  proc auth {code arg1 arg2 arg3 arg4} {
    97         -    if {$code=="SQLITE_CREATE_TEMP_TABLE"} {
    98         -      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
    99         -      return SQLITE_DENY
   100         -    }
   101         -    return SQLITE_OK
   102         -  }
   103         -  catchsql {CREATE TEMP TABLE t1(a,b,c)}
   104         -} {1 {not authorized}}
   105         -do_test auth-1.7.2 {
   106         -   set ::authargs
   107         -} {t1 {} temp {}}
   108         -do_test auth-1.8 {
   109         -  execsql {SELECT name FROM sqlite_temp_master}
   110         -} {}
           83  +ifcapable tempdb {
           84  +  do_test auth-1.5 {
           85  +    proc auth {code arg1 arg2 arg3 arg4} {
           86  +      if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
           87  +        return SQLITE_DENY
           88  +      }
           89  +      return SQLITE_OK
           90  +    }
           91  +    catchsql {CREATE TEMP TABLE t1(a,b,c)}
           92  +  } {1 {not authorized}}
           93  +  do_test auth-1.6 {
           94  +    execsql {SELECT name FROM sqlite_temp_master}
           95  +  } {}
           96  +  do_test auth-1.7.1 {
           97  +    proc auth {code arg1 arg2 arg3 arg4} {
           98  +      if {$code=="SQLITE_CREATE_TEMP_TABLE"} {
           99  +        set ::authargs [list $arg1 $arg2 $arg3 $arg4]
          100  +        return SQLITE_DENY
          101  +      }
          102  +      return SQLITE_OK
          103  +    }
          104  +    catchsql {CREATE TEMP TABLE t1(a,b,c)}
          105  +  } {1 {not authorized}}
          106  +  do_test auth-1.7.2 {
          107  +     set ::authargs
          108  +  } {t1 {} temp {}}
          109  +  do_test auth-1.8 {
          110  +    execsql {SELECT name FROM sqlite_temp_master}
          111  +  } {}
          112  +}
   111    113   
   112    114   do_test auth-1.9 {
   113    115     proc auth {code arg1 arg2 arg3 arg4} {
   114    116       if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
   115    117         return SQLITE_IGNORE
   116    118       }
   117    119       return SQLITE_OK
................................................................................
   130    132       return SQLITE_OK
   131    133     }
   132    134     catchsql {CREATE TABLE t1(a,b,c)}
   133    135   } {0 {}}
   134    136   do_test auth-1.12 {
   135    137     execsql {SELECT name FROM sqlite_master}
   136    138   } {}
   137         -do_test auth-1.13 {
   138         -  proc auth {code arg1 arg2 arg3 arg4} {
   139         -    if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
   140         -      return SQLITE_IGNORE
   141         -    }
   142         -    return SQLITE_OK
   143         -  }
   144         -  catchsql {CREATE TEMP TABLE t1(a,b,c)}
   145         -} {0 {}}
   146         -do_test auth-1.14 {
   147         -  execsql {SELECT name FROM sqlite_temp_master}
   148         -} {}
   149         -do_test auth-1.15 {
   150         -  proc auth {code arg1 arg2 arg3 arg4} {
   151         -    if {$code=="SQLITE_CREATE_TEMP_TABLE"} {
   152         -      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
   153         -      return SQLITE_IGNORE
   154         -    }
   155         -    return SQLITE_OK
   156         -  }
   157         -  catchsql {CREATE TEMP TABLE t1(a,b,c)}
   158         -} {0 {}}
   159         -do_test auth-1.16 {
   160         -  execsql {SELECT name FROM sqlite_temp_master}
   161         -} {}
   162         -
   163         -do_test auth-1.17 {
   164         -  proc auth {code arg1 arg2 arg3 arg4} {
   165         -    if {$code=="SQLITE_CREATE_TABLE"} {
   166         -      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
   167         -      return SQLITE_DENY
   168         -    }
   169         -    return SQLITE_OK
   170         -  }
   171         -  catchsql {CREATE TEMP TABLE t1(a,b,c)}
   172         -} {0 {}}
   173         -do_test auth-1.18 {
   174         -  execsql {SELECT name FROM sqlite_temp_master}
   175         -} {t1}
          139  +
          140  +ifcapable tempdb {
          141  +  do_test auth-1.13 {
          142  +    proc auth {code arg1 arg2 arg3 arg4} {
          143  +      if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
          144  +        return SQLITE_IGNORE
          145  +      }
          146  +      return SQLITE_OK
          147  +    }
          148  +    catchsql {CREATE TEMP TABLE t1(a,b,c)}
          149  +  } {0 {}}
          150  +  do_test auth-1.14 {
          151  +    execsql {SELECT name FROM sqlite_temp_master}
          152  +  } {}
          153  +  do_test auth-1.15 {
          154  +    proc auth {code arg1 arg2 arg3 arg4} {
          155  +      if {$code=="SQLITE_CREATE_TEMP_TABLE"} {
          156  +        set ::authargs [list $arg1 $arg2 $arg3 $arg4]
          157  +        return SQLITE_IGNORE
          158  +      }
          159  +      return SQLITE_OK
          160  +    }
          161  +    catchsql {CREATE TEMP TABLE t1(a,b,c)}
          162  +  } {0 {}}
          163  +  do_test auth-1.16 {
          164  +    execsql {SELECT name FROM sqlite_temp_master}
          165  +  } {}
          166  +  
          167  +  do_test auth-1.17 {
          168  +    proc auth {code arg1 arg2 arg3 arg4} {
          169  +      if {$code=="SQLITE_CREATE_TABLE"} {
          170  +        set ::authargs [list $arg1 $arg2 $arg3 $arg4]
          171  +        return SQLITE_DENY
          172  +      }
          173  +      return SQLITE_OK
          174  +    }
          175  +    catchsql {CREATE TEMP TABLE t1(a,b,c)}
          176  +  } {0 {}}
          177  +  do_test auth-1.18 {
          178  +    execsql {SELECT name FROM sqlite_temp_master}
          179  +  } {t1}
          180  +}
          181  +
   176    182   do_test auth-1.19.1 {
   177    183     set ::authargs {}
   178    184     proc auth {code arg1 arg2 arg3 arg4} {
   179    185       if {$code=="SQLITE_CREATE_TEMP_TABLE"} {
   180    186         set ::authargs [list $arg1 $arg2 $arg3 $arg4]
   181    187         return SQLITE_DENY
   182    188       }
................................................................................
   220    226   do_test auth-1.23.2 {
   221    227     set ::authargs
   222    228   } {t2 {} main {}}
   223    229   do_test auth-1.24 {
   224    230     execsql {SELECT name FROM sqlite_master}
   225    231   } {t2}
   226    232   
   227         -do_test auth-1.25 {
   228         -  proc auth {code arg1 arg2 arg3 arg4} {
   229         -    if {$code=="SQLITE_DROP_TEMP_TABLE"} {
   230         -      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
   231         -      return SQLITE_DENY
   232         -    }
   233         -    return SQLITE_OK
   234         -  }
   235         -  catchsql {DROP TABLE t1}
   236         -} {1 {not authorized}}
   237         -do_test auth-1.26 {
   238         -  execsql {SELECT name FROM sqlite_temp_master}
   239         -} {t1}
   240         -do_test auth-1.27 {
   241         -  proc auth {code arg1 arg2 arg3 arg4} {
   242         -    if {$code=="SQLITE_DROP_TEMP_TABLE"} {
   243         -      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
   244         -      return SQLITE_IGNORE
   245         -    }
   246         -    return SQLITE_OK
   247         -  }
   248         -  catchsql {DROP TABLE t1}
   249         -} {0 {}}
   250         -do_test auth-1.28 {
   251         -  execsql {SELECT name FROM sqlite_temp_master}
   252         -} {t1}
          233  +ifcapable tempdb {
          234  +  do_test auth-1.25 {
          235  +    proc auth {code arg1 arg2 arg3 arg4} {
          236  +      if {$code=="SQLITE_DROP_TEMP_TABLE"} {
          237  +        set ::authargs [list $arg1 $arg2 $arg3 $arg4]
          238  +        return SQLITE_DENY
          239  +      }
          240  +      return SQLITE_OK
          241  +    }
          242  +    catchsql {DROP TABLE t1}
          243  +  } {1 {not authorized}}
          244  +  do_test auth-1.26 {
          245  +    execsql {SELECT name FROM sqlite_temp_master}
          246  +  } {t1}
          247  +  do_test auth-1.27 {
          248  +    proc auth {code arg1 arg2 arg3 arg4} {
          249  +      if {$code=="SQLITE_DROP_TEMP_TABLE"} {
          250  +        set ::authargs [list $arg1 $arg2 $arg3 $arg4]
          251  +        return SQLITE_IGNORE
          252  +      }
          253  +      return SQLITE_OK
          254  +    }
          255  +    catchsql {DROP TABLE t1}
          256  +  } {0 {}}
          257  +  do_test auth-1.28 {
          258  +    execsql {SELECT name FROM sqlite_temp_master}
          259  +  } {t1}
          260  +}
   253    261   
   254    262   do_test auth-1.29 {
   255    263     proc auth {code arg1 arg2 arg3 arg4} {
   256    264       if {$code=="SQLITE_INSERT" && $arg1=="t2"} {
   257    265         return SQLITE_DENY
   258    266       }
   259    267       return SQLITE_OK
................................................................................
   468    476       return SQLITE_OK
   469    477     }
   470    478     catchsql {DROP TABLE t2}
   471    479   } {1 {not authorized}}
   472    480   do_test auth-1.66 {
   473    481     execsql {SELECT name FROM sqlite_master}
   474    482   } {t2}
   475         -do_test auth-1.67 {
   476         -  proc auth {code arg1 arg2 arg3 arg4} {
   477         -    if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
   478         -       return SQLITE_DENY
   479         -    }
   480         -    return SQLITE_OK
   481         -  }
   482         -  catchsql {DROP TABLE t1}
   483         -} {1 {not authorized}}
   484         -do_test auth-1.68 {
   485         -  execsql {SELECT name FROM sqlite_temp_master}
   486         -} {t1}
   487         -do_test auth-1.69 {
   488         -  proc auth {code arg1 arg2 arg3 arg4} {
   489         -    if {$code=="SQLITE_DELETE" && $arg1=="t1"} {
   490         -       return SQLITE_DENY
   491         -    }
   492         -    return SQLITE_OK
   493         -  }
   494         -  catchsql {DROP TABLE t1}
   495         -} {1 {not authorized}}
   496         -do_test auth-1.70 {
   497         -  execsql {SELECT name FROM sqlite_temp_master}
   498         -} {t1}
          483  +
          484  +ifcapable tempdb {
          485  +  do_test auth-1.67 {
          486  +    proc auth {code arg1 arg2 arg3 arg4} {
          487  +      if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
          488  +         return SQLITE_DENY
          489  +      }
          490  +      return SQLITE_OK
          491  +    }
          492  +    catchsql {DROP TABLE t1}
          493  +  } {1 {not authorized}}
          494  +  do_test auth-1.68 {
          495  +    execsql {SELECT name FROM sqlite_temp_master}
          496  +  } {t1}
          497  +  do_test auth-1.69 {
          498  +    proc auth {code arg1 arg2 arg3 arg4} {
          499  +      if {$code=="SQLITE_DELETE" && $arg1=="t1"} {
          500  +         return SQLITE_DENY
          501  +      }
          502  +      return SQLITE_OK
          503  +    }
          504  +    catchsql {DROP TABLE t1}
          505  +  } {1 {not authorized}}
          506  +  do_test auth-1.70 {
          507  +    execsql {SELECT name FROM sqlite_temp_master}
          508  +  } {t1}
          509  +}
   499    510   
   500    511   do_test auth-1.71 {
   501    512     proc auth {code arg1 arg2 arg3 arg4} {
   502    513       if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
   503    514          return SQLITE_IGNORE
   504    515       }
   505    516       return SQLITE_OK
................................................................................
   517    528       return SQLITE_OK
   518    529     }
   519    530     catchsql {DROP TABLE t2}
   520    531   } {0 {}}
   521    532   do_test auth-1.74 {
   522    533     execsql {SELECT name FROM sqlite_master}
   523    534   } {t2}
   524         -do_test auth-1.75 {
   525         -  proc auth {code arg1 arg2 arg3 arg4} {
   526         -    if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
   527         -       return SQLITE_IGNORE
   528         -    }
   529         -    return SQLITE_OK
   530         -  }
   531         -  catchsql {DROP TABLE t1}
   532         -} {0 {}}
   533         -do_test auth-1.76 {
   534         -  execsql {SELECT name FROM sqlite_temp_master}
   535         -} {t1}
   536         -do_test auth-1.77 {
   537         -  proc auth {code arg1 arg2 arg3 arg4} {
   538         -    if {$code=="SQLITE_DELETE" && $arg1=="t1"} {
   539         -       return SQLITE_IGNORE
   540         -    }
   541         -    return SQLITE_OK
   542         -  }
   543         -  catchsql {DROP TABLE t1}
   544         -} {0 {}}
   545         -do_test auth-1.78 {
   546         -  execsql {SELECT name FROM sqlite_temp_master}
   547         -} {t1}
          535  +
          536  +ifcapable tempdb {
          537  +  do_test auth-1.75 {
          538  +    proc auth {code arg1 arg2 arg3 arg4} {
          539  +      if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
          540  +         return SQLITE_IGNORE
          541  +      }
          542  +      return SQLITE_OK
          543  +    }
          544  +    catchsql {DROP TABLE t1}
          545  +  } {0 {}}
          546  +  do_test auth-1.76 {
          547  +    execsql {SELECT name FROM sqlite_temp_master}
          548  +  } {t1}
          549  +  do_test auth-1.77 {
          550  +    proc auth {code arg1 arg2 arg3 arg4} {
          551  +      if {$code=="SQLITE_DELETE" && $arg1=="t1"} {
          552  +         return SQLITE_IGNORE
          553  +      }
          554  +      return SQLITE_OK
          555  +    }
          556  +    catchsql {DROP TABLE t1}
          557  +  } {0 {}}
          558  +  do_test auth-1.78 {
          559  +    execsql {SELECT name FROM sqlite_temp_master}
          560  +  } {t1}
          561  +}
   548    562   
   549    563   # Test cases auth-1.79 to auth-1.124 test creating and dropping views.
   550    564   # Omit these if the library was compiled with views omitted.
   551    565   ifcapable view {
   552    566   do_test auth-1.79 {
   553    567     proc auth {code arg1 arg2 arg3 arg4} {
   554    568       if {$code=="SQLITE_CREATE_VIEW"} {
................................................................................
   578    592   do_test auth-1.83 {
   579    593     set ::authargs
   580    594   } {v1 {} main {}}
   581    595   do_test auth-1.84 {
   582    596     execsql {SELECT name FROM sqlite_master}
   583    597   } {t2}
   584    598   
   585         -do_test auth-1.85 {
   586         -  proc auth {code arg1 arg2 arg3 arg4} {
   587         -    if {$code=="SQLITE_CREATE_TEMP_VIEW"} {
   588         -      set ::authargs [list $arg1 $arg2 $arg3 $arg4] 
   589         -      return SQLITE_DENY
   590         -    }
   591         -    return SQLITE_OK
   592         -  }
   593         -  catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
   594         -} {1 {not authorized}}
   595         -do_test auth-1.86 {
   596         -  set ::authargs
   597         -} {v1 {} temp {}}
   598         -do_test auth-1.87 {
   599         -  execsql {SELECT name FROM sqlite_temp_master}
   600         -} {t1}
   601         -do_test auth-1.88 {
   602         -  proc auth {code arg1 arg2 arg3 arg4} {
   603         -    if {$code=="SQLITE_CREATE_TEMP_VIEW"} {
   604         -      set ::authargs [list $arg1 $arg2 $arg3 $arg4] 
   605         -      return SQLITE_IGNORE
   606         -    }
   607         -    return SQLITE_OK
   608         -  }
   609         -  catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
   610         -} {0 {}}
   611         -do_test auth-1.89 {
   612         -  set ::authargs
   613         -} {v1 {} temp {}}
   614         -do_test auth-1.90 {
   615         -  execsql {SELECT name FROM sqlite_temp_master}
   616         -} {t1}
          599  +ifcapable tempdb {
          600  +  do_test auth-1.85 {
          601  +    proc auth {code arg1 arg2 arg3 arg4} {
          602  +      if {$code=="SQLITE_CREATE_TEMP_VIEW"} {
          603  +        set ::authargs [list $arg1 $arg2 $arg3 $arg4] 
          604  +        return SQLITE_DENY
          605  +      }
          606  +      return SQLITE_OK
          607  +    }
          608  +    catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
          609  +  } {1 {not authorized}}
          610  +  do_test auth-1.86 {
          611  +    set ::authargs
          612  +  } {v1 {} temp {}}
          613  +  do_test auth-1.87 {
          614  +    execsql {SELECT name FROM sqlite_temp_master}
          615  +  } {t1}
          616  +  do_test auth-1.88 {
          617  +    proc auth {code arg1 arg2 arg3 arg4} {
          618  +      if {$code=="SQLITE_CREATE_TEMP_VIEW"} {
          619  +        set ::authargs [list $arg1 $arg2 $arg3 $arg4] 
          620  +        return SQLITE_IGNORE
          621  +      }
          622  +      return SQLITE_OK
          623  +    }
          624  +    catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
          625  +  } {0 {}}
          626  +  do_test auth-1.89 {
          627  +    set ::authargs
          628  +  } {v1 {} temp {}}
          629  +  do_test auth-1.90 {
          630  +    execsql {SELECT name FROM sqlite_temp_master}
          631  +  } {t1}
          632  +}
   617    633   
   618    634   do_test auth-1.91 {
   619    635     proc auth {code arg1 arg2 arg3 arg4} {
   620    636       if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
   621    637         return SQLITE_DENY
   622    638       }
   623    639       return SQLITE_OK
................................................................................
   636    652     }
   637    653     catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2}
   638    654   } {0 {}}
   639    655   do_test auth-1.94 {
   640    656     execsql {SELECT name FROM sqlite_master}
   641    657   } {t2}
   642    658   
   643         -do_test auth-1.95 {
   644         -  proc auth {code arg1 arg2 arg3 arg4} {
   645         -    if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
   646         -      return SQLITE_DENY
   647         -    }
   648         -    return SQLITE_OK
   649         -  }
   650         -  catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
   651         -} {1 {not authorized}}
   652         -do_test auth-1.96 {
   653         -  execsql {SELECT name FROM sqlite_temp_master}
   654         -} {t1}
   655         -do_test auth-1.97 {
   656         -  proc auth {code arg1 arg2 arg3 arg4} {
   657         -    if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
   658         -      return SQLITE_IGNORE
   659         -    }
   660         -    return SQLITE_OK
   661         -  }
   662         -  catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
   663         -} {0 {}}
   664         -do_test auth-1.98 {
   665         -  execsql {SELECT name FROM sqlite_temp_master}
   666         -} {t1}
          659  +ifcapable tempdb {
          660  +  do_test auth-1.95 {
          661  +    proc auth {code arg1 arg2 arg3 arg4} {
          662  +      if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
          663  +        return SQLITE_DENY
          664  +      }
          665  +      return SQLITE_OK
          666  +    }
          667  +    catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
          668  +  } {1 {not authorized}}
          669  +  do_test auth-1.96 {
          670  +    execsql {SELECT name FROM sqlite_temp_master}
          671  +  } {t1}
          672  +  do_test auth-1.97 {
          673  +    proc auth {code arg1 arg2 arg3 arg4} {
          674  +      if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
          675  +        return SQLITE_IGNORE
          676  +      }
          677  +      return SQLITE_OK
          678  +    }
          679  +    catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
          680  +  } {0 {}}
          681  +  do_test auth-1.98 {
          682  +    execsql {SELECT name FROM sqlite_temp_master}
          683  +  } {t1}
          684  +}
   667    685   
   668    686   do_test auth-1.99 {
   669    687     proc auth {code arg1 arg2 arg3 arg4} {
   670    688       if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
   671    689         return SQLITE_DENY
   672    690       }
   673    691       return SQLITE_OK
................................................................................
   738    756     set ::authargs
   739    757   } {v2 {} main {}}
   740    758   do_test auth-1.111 {
   741    759     execsql {SELECT name FROM sqlite_master}
   742    760   } {t2}
   743    761   
   744    762   
   745         -do_test auth-1.112 {
   746         -  proc auth {code arg1 arg2 arg3 arg4} {
   747         -    if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
   748         -      return SQLITE_DENY
   749         -    }
   750         -    return SQLITE_OK
   751         -  }
   752         -  catchsql {
   753         -    CREATE TEMP VIEW v1 AS SELECT a+1,b+1 FROM t1;
   754         -    DROP VIEW v1
   755         -  }
   756         -} {1 {not authorized}}
   757         -do_test auth-1.113 {
   758         -  execsql {SELECT name FROM sqlite_temp_master}
   759         -} {t1 v1}
   760         -do_test auth-1.114 {
   761         -  proc auth {code arg1 arg2 arg3 arg4} {
   762         -    if {$code=="SQLITE_DROP_TEMP_VIEW"} {
   763         -      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
   764         -      return SQLITE_DENY
   765         -    }
   766         -    return SQLITE_OK
   767         -  }
   768         -  catchsql {DROP VIEW v1}
   769         -} {1 {not authorized}}
   770         -do_test auth-1.115 {
   771         -  set ::authargs
   772         -} {v1 {} temp {}}
   773         -do_test auth-1.116 {
   774         -  execsql {SELECT name FROM sqlite_temp_master}
   775         -} {t1 v1}
   776         -do_test auth-1.117 {
   777         -  proc auth {code arg1 arg2 arg3 arg4} {
   778         -    if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
   779         -      return SQLITE_IGNORE
   780         -    }
   781         -    return SQLITE_OK
   782         -  }
   783         -  catchsql {DROP VIEW v1}
   784         -} {0 {}}
   785         -do_test auth-1.118 {
   786         -  execsql {SELECT name FROM sqlite_temp_master}
   787         -} {t1 v1}
   788         -do_test auth-1.119 {
   789         -  proc auth {code arg1 arg2 arg3 arg4} {
   790         -    if {$code=="SQLITE_DROP_TEMP_VIEW"} {
   791         -      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
   792         -      return SQLITE_IGNORE
   793         -    }
   794         -    return SQLITE_OK
   795         -  }
   796         -  catchsql {DROP VIEW v1}
   797         -} {0 {}}
   798         -do_test auth-1.120 {
   799         -  set ::authargs
   800         -} {v1 {} temp {}}
   801         -do_test auth-1.121 {
   802         -  execsql {SELECT name FROM sqlite_temp_master}
   803         -} {t1 v1}
   804         -do_test auth-1.122 {
   805         -  proc auth {code arg1 arg2 arg3 arg4} {
   806         -    if {$code=="SQLITE_DROP_TEMP_VIEW"} {
   807         -      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
   808         -      return SQLITE_OK
   809         -    }
   810         -    return SQLITE_OK
   811         -  }
   812         -  catchsql {DROP VIEW v1}
   813         -} {0 {}}
   814         -do_test auth-1.123 {
   815         -  set ::authargs
   816         -} {v1 {} temp {}}
   817         -do_test auth-1.124 {
   818         -  execsql {SELECT name FROM sqlite_temp_master}
   819         -} {t1}
          763  +ifcapable tempdb {
          764  +  do_test auth-1.112 {
          765  +    proc auth {code arg1 arg2 arg3 arg4} {
          766  +      if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
          767  +        return SQLITE_DENY
          768  +      }
          769  +      return SQLITE_OK
          770  +    }
          771  +    catchsql {
          772  +      CREATE TEMP VIEW v1 AS SELECT a+1,b+1 FROM t1;
          773  +      DROP VIEW v1
          774  +    }
          775  +  } {1 {not authorized}}
          776  +  do_test auth-1.113 {
          777  +    execsql {SELECT name FROM sqlite_temp_master}
          778  +  } {t1 v1}
          779  +  do_test auth-1.114 {
          780  +    proc auth {code arg1 arg2 arg3 arg4} {
          781  +      if {$code=="SQLITE_DROP_TEMP_VIEW"} {
          782  +        set ::authargs [list $arg1 $arg2 $arg3 $arg4]
          783  +        return SQLITE_DENY
          784  +      }
          785  +      return SQLITE_OK
          786  +    }
          787  +    catchsql {DROP VIEW v1}
          788  +  } {1 {not authorized}}
          789  +  do_test auth-1.115 {
          790  +    set ::authargs
          791  +  } {v1 {} temp {}}
          792  +  do_test auth-1.116 {
          793  +    execsql {SELECT name FROM sqlite_temp_master}
          794  +  } {t1 v1}
          795  +  do_test auth-1.117 {
          796  +    proc auth {code arg1 arg2 arg3 arg4} {
          797  +      if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
          798  +        return SQLITE_IGNORE
          799  +      }
          800  +      return SQLITE_OK
          801  +    }
          802  +    catchsql {DROP VIEW v1}
          803  +  } {0 {}}
          804  +  do_test auth-1.118 {
          805  +    execsql {SELECT name FROM sqlite_temp_master}
          806  +  } {t1 v1}
          807  +  do_test auth-1.119 {
          808  +    proc auth {code arg1 arg2 arg3 arg4} {
          809  +      if {$code=="SQLITE_DROP_TEMP_VIEW"} {
          810  +        set ::authargs [list $arg1 $arg2 $arg3 $arg4]
          811  +        return SQLITE_IGNORE
          812  +      }
          813  +      return SQLITE_OK
          814  +    }
          815  +    catchsql {DROP VIEW v1}
          816  +  } {0 {}}
          817  +  do_test auth-1.120 {
          818  +    set ::authargs
          819  +  } {v1 {} temp {}}
          820  +  do_test auth-1.121 {
          821  +    execsql {SELECT name FROM sqlite_temp_master}
          822  +  } {t1 v1}
          823  +  do_test auth-1.122 {
          824  +    proc auth {code arg1 arg2 arg3 arg4} {
          825  +      if {$code=="SQLITE_DROP_TEMP_VIEW"} {
          826  +        set ::authargs [list $arg1 $arg2 $arg3 $arg4]
          827  +        return SQLITE_OK
          828  +      }
          829  +      return SQLITE_OK
          830  +    }
          831  +    catchsql {DROP VIEW v1}
          832  +  } {0 {}}
          833  +  do_test auth-1.123 {
          834  +    set ::authargs
          835  +  } {v1 {} temp {}}
          836  +  do_test auth-1.124 {
          837  +    execsql {SELECT name FROM sqlite_temp_master}
          838  +  } {t1}
          839  +}
   820    840   } ;# ifcapable view
   821    841   
   822    842   # Test cases auth-1.125 to auth-1.176 test creating and dropping triggers.
   823    843   # Omit these if the library was compiled with triggers omitted.
   824    844   #
   825         -ifcapable trigger {
          845  +ifcapable trigger&&tempdb {
   826    846   do_test auth-1.125 {
   827    847     proc auth {code arg1 arg2 arg3 arg4} {
   828    848       if {$code=="SQLITE_CREATE_TRIGGER"} {
   829    849         set ::authargs [list $arg1 $arg2 $arg3 $arg4]
   830    850         return SQLITE_DENY
   831    851       }
   832    852       return SQLITE_OK
................................................................................
  1250   1270   do_test auth-1.188 {
  1251   1271     set ::authargs
  1252   1272   } {i2 t2 main {}}
  1253   1273   do_test auth-1.189 {
  1254   1274     execsql {SELECT name FROM sqlite_master}
  1255   1275   } {t2 i2}
  1256   1276   
  1257         -do_test auth-1.190 {
  1258         -  proc auth {code arg1 arg2 arg3 arg4} {
  1259         -    if {$code=="SQLITE_CREATE_TEMP_INDEX"} {
  1260         -      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1261         -      return SQLITE_DENY
  1262         -    }
  1263         -    return SQLITE_OK
  1264         -  }
  1265         -  catchsql {CREATE INDEX i1 ON t1(a)}
  1266         -} {1 {not authorized}}
  1267         -do_test auth-1.191 {
  1268         -  set ::authargs
  1269         -} {i1 t1 temp {}}
  1270         -do_test auth-1.192 {
  1271         -  execsql {SELECT name FROM sqlite_temp_master}
  1272         -} {t1}
  1273         -do_test auth-1.193 {
  1274         -  proc auth {code arg1 arg2 arg3 arg4} {
  1275         -    if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
  1276         -      return SQLITE_DENY
  1277         -    }
  1278         -    return SQLITE_OK
  1279         -  }
  1280         -  catchsql {CREATE INDEX i1 ON t1(b)}
  1281         -} {1 {not authorized}}
  1282         -do_test auth-1.194 {
  1283         -  execsql {SELECT name FROM sqlite_temp_master}
  1284         -} {t1}
  1285         -do_test auth-1.195 {
  1286         -  proc auth {code arg1 arg2 arg3 arg4} {
  1287         -    if {$code=="SQLITE_CREATE_TEMP_INDEX"} {
  1288         -      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1289         -      return SQLITE_IGNORE
  1290         -    }
  1291         -    return SQLITE_OK
  1292         -  }
  1293         -  catchsql {CREATE INDEX i1 ON t1(b)}
  1294         -} {0 {}}
  1295         -do_test auth-1.196 {
  1296         -  set ::authargs
  1297         -} {i1 t1 temp {}}
  1298         -do_test auth-1.197 {
  1299         -  execsql {SELECT name FROM sqlite_temp_master}
  1300         -} {t1}
  1301         -do_test auth-1.198 {
  1302         -  proc auth {code arg1 arg2 arg3 arg4} {
  1303         -    if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
  1304         -      return SQLITE_IGNORE
  1305         -    }
  1306         -    return SQLITE_OK
  1307         -  }
  1308         -  catchsql {CREATE INDEX i1 ON t1(c)}
  1309         -} {0 {}}
  1310         -do_test auth-1.199 {
  1311         -  execsql {SELECT name FROM sqlite_temp_master}
  1312         -} {t1}
  1313         -do_test auth-1.200 {
  1314         -  proc auth {code arg1 arg2 arg3 arg4} {
  1315         -    if {$code=="SQLITE_CREATE_TEMP_INDEX"} {
  1316         -      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1317         -      return SQLITE_OK
  1318         -    }
  1319         -    return SQLITE_OK
  1320         -  }
  1321         -  catchsql {CREATE INDEX i1 ON t1(a)}
  1322         -} {0 {}}
  1323         -do_test auth-1.201 {
  1324         -  set ::authargs
  1325         -} {i1 t1 temp {}}
  1326         -do_test auth-1.202 {
  1327         -  execsql {SELECT name FROM sqlite_temp_master}
  1328         -} {t1 i1}
         1277  +ifcapable tempdb {
         1278  +  do_test auth-1.190 {
         1279  +    proc auth {code arg1 arg2 arg3 arg4} {
         1280  +      if {$code=="SQLITE_CREATE_TEMP_INDEX"} {
         1281  +        set ::authargs [list $arg1 $arg2 $arg3 $arg4]
         1282  +        return SQLITE_DENY
         1283  +      }
         1284  +      return SQLITE_OK
         1285  +    }
         1286  +    catchsql {CREATE INDEX i1 ON t1(a)}
         1287  +  } {1 {not authorized}}
         1288  +  do_test auth-1.191 {
         1289  +    set ::authargs
         1290  +  } {i1 t1 temp {}}
         1291  +  do_test auth-1.192 {
         1292  +    execsql {SELECT name FROM sqlite_temp_master}
         1293  +  } {t1}
         1294  +  do_test auth-1.193 {
         1295  +    proc auth {code arg1 arg2 arg3 arg4} {
         1296  +      if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
         1297  +        return SQLITE_DENY
         1298  +      }
         1299  +      return SQLITE_OK
         1300  +    }
         1301  +    catchsql {CREATE INDEX i1 ON t1(b)}
         1302  +  } {1 {not authorized}}
         1303  +  do_test auth-1.194 {
         1304  +    execsql {SELECT name FROM sqlite_temp_master}
         1305  +  } {t1}
         1306  +  do_test auth-1.195 {
         1307  +    proc auth {code arg1 arg2 arg3 arg4} {
         1308  +      if {$code=="SQLITE_CREATE_TEMP_INDEX"} {
         1309  +        set ::authargs [list $arg1 $arg2 $arg3 $arg4]
         1310  +        return SQLITE_IGNORE
         1311  +      }
         1312  +      return SQLITE_OK
         1313  +    }
         1314  +    catchsql {CREATE INDEX i1 ON t1(b)}
         1315  +  } {0 {}}
         1316  +  do_test auth-1.196 {
         1317  +    set ::authargs
         1318  +  } {i1 t1 temp {}}
         1319  +  do_test auth-1.197 {
         1320  +    execsql {SELECT name FROM sqlite_temp_master}
         1321  +  } {t1}
         1322  +  do_test auth-1.198 {
         1323  +    proc auth {code arg1 arg2 arg3 arg4} {
         1324  +      if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
         1325  +        return SQLITE_IGNORE
         1326  +      }
         1327  +      return SQLITE_OK
         1328  +    }
         1329  +    catchsql {CREATE INDEX i1 ON t1(c)}
         1330  +  } {0 {}}
         1331  +  do_test auth-1.199 {
         1332  +    execsql {SELECT name FROM sqlite_temp_master}
         1333  +  } {t1}
         1334  +  do_test auth-1.200 {
         1335  +    proc auth {code arg1 arg2 arg3 arg4} {
         1336  +      if {$code=="SQLITE_CREATE_TEMP_INDEX"} {
         1337  +        set ::authargs [list $arg1 $arg2 $arg3 $arg4]
         1338  +        return SQLITE_OK
         1339  +      }
         1340  +      return SQLITE_OK
         1341  +    }
         1342  +    catchsql {CREATE INDEX i1 ON t1(a)}
         1343  +  } {0 {}}
         1344  +  do_test auth-1.201 {
         1345  +    set ::authargs
         1346  +  } {i1 t1 temp {}}
         1347  +  do_test auth-1.202 {
         1348  +    execsql {SELECT name FROM sqlite_temp_master}
         1349  +  } {t1 i1}
         1350  +}
  1329   1351   
  1330   1352   do_test auth-1.203 {
  1331   1353     proc auth {code arg1 arg2 arg3 arg4} {
  1332   1354       if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
  1333   1355         return SQLITE_DENY
  1334   1356       }
  1335   1357       return SQLITE_OK
................................................................................
  1396   1418   do_test auth-1.214 {
  1397   1419     set ::authargs
  1398   1420   } {i2 t2 main {}}
  1399   1421   do_test auth-1.215 {
  1400   1422     execsql {SELECT name FROM sqlite_master}
  1401   1423   } {t2}
  1402   1424   
  1403         -do_test auth-1.216 {
  1404         -  proc auth {code arg1 arg2 arg3 arg4} {
  1405         -    if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
  1406         -      return SQLITE_DENY
  1407         -    }
  1408         -    return SQLITE_OK
  1409         -  }
  1410         -  catchsql {DROP INDEX i1}
  1411         -} {1 {not authorized}}
  1412         -do_test auth-1.217 {
  1413         -  execsql {SELECT name FROM sqlite_temp_master}
  1414         -} {t1 i1}
  1415         -do_test auth-1.218 {
  1416         -  proc auth {code arg1 arg2 arg3 arg4} {
  1417         -    if {$code=="SQLITE_DROP_TEMP_INDEX"} {
  1418         -      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1419         -      return SQLITE_DENY
  1420         -    }
  1421         -    return SQLITE_OK
  1422         -  }
  1423         -  catchsql {DROP INDEX i1}
  1424         -} {1 {not authorized}}
  1425         -do_test auth-1.219 {
  1426         -  set ::authargs
  1427         -} {i1 t1 temp {}}
  1428         -do_test auth-1.220 {
  1429         -  execsql {SELECT name FROM sqlite_temp_master}
  1430         -} {t1 i1}
  1431         -do_test auth-1.221 {
  1432         -  proc auth {code arg1 arg2 arg3 arg4} {
  1433         -    if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
  1434         -      return SQLITE_IGNORE
  1435         -    }
  1436         -    return SQLITE_OK
  1437         -  }
  1438         -  catchsql {DROP INDEX i1}
  1439         -} {0 {}}
  1440         -do_test auth-1.222 {
  1441         -  execsql {SELECT name FROM sqlite_temp_master}
  1442         -} {t1 i1}
  1443         -do_test auth-1.223 {
  1444         -  proc auth {code arg1 arg2 arg3 arg4} {
  1445         -    if {$code=="SQLITE_DROP_TEMP_INDEX"} {
  1446         -      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1447         -      return SQLITE_IGNORE
  1448         -    }
  1449         -    return SQLITE_OK
  1450         -  }
  1451         -  catchsql {DROP INDEX i1}
  1452         -} {0 {}}
  1453         -do_test auth-1.224 {
  1454         -  set ::authargs
  1455         -} {i1 t1 temp {}}
  1456         -do_test auth-1.225 {
  1457         -  execsql {SELECT name FROM sqlite_temp_master}
  1458         -} {t1 i1}
  1459         -do_test auth-1.226 {
  1460         -  proc auth {code arg1 arg2 arg3 arg4} {
  1461         -    if {$code=="SQLITE_DROP_TEMP_INDEX"} {
  1462         -      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
         1425  +ifcapable tempdb {
         1426  +  do_test auth-1.216 {
         1427  +    proc auth {code arg1 arg2 arg3 arg4} {
         1428  +      if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
         1429  +        return SQLITE_DENY
         1430  +      }
         1431  +      return SQLITE_OK
         1432  +    }
         1433  +    catchsql {DROP INDEX i1}
         1434  +  } {1 {not authorized}}
         1435  +  do_test auth-1.217 {
         1436  +    execsql {SELECT name FROM sqlite_temp_master}
         1437  +  } {t1 i1}
         1438  +  do_test auth-1.218 {
         1439  +    proc auth {code arg1 arg2 arg3 arg4} {
         1440  +      if {$code=="SQLITE_DROP_TEMP_INDEX"} {
         1441  +        set ::authargs [list $arg1 $arg2 $arg3 $arg4]
         1442  +        return SQLITE_DENY
         1443  +      }
         1444  +      return SQLITE_OK
         1445  +    }
         1446  +    catchsql {DROP INDEX i1}
         1447  +  } {1 {not authorized}}
         1448  +  do_test auth-1.219 {
         1449  +    set ::authargs
         1450  +  } {i1 t1 temp {}}
         1451  +  do_test auth-1.220 {
         1452  +    execsql {SELECT name FROM sqlite_temp_master}
         1453  +  } {t1 i1}
         1454  +  do_test auth-1.221 {
         1455  +    proc auth {code arg1 arg2 arg3 arg4} {
         1456  +      if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
         1457  +        return SQLITE_IGNORE
         1458  +      }
         1459  +      return SQLITE_OK
         1460  +    }
         1461  +    catchsql {DROP INDEX i1}
         1462  +  } {0 {}}
         1463  +  do_test auth-1.222 {
         1464  +    execsql {SELECT name FROM sqlite_temp_master}
         1465  +  } {t1 i1}
         1466  +  do_test auth-1.223 {
         1467  +    proc auth {code arg1 arg2 arg3 arg4} {
         1468  +      if {$code=="SQLITE_DROP_TEMP_INDEX"} {
         1469  +        set ::authargs [list $arg1 $arg2 $arg3 $arg4]
         1470  +        return SQLITE_IGNORE
         1471  +      }
         1472  +      return SQLITE_OK
         1473  +    }
         1474  +    catchsql {DROP INDEX i1}
         1475  +  } {0 {}}
         1476  +  do_test auth-1.224 {
         1477  +    set ::authargs
         1478  +  } {i1 t1 temp {}}
         1479  +  do_test auth-1.225 {
         1480  +    execsql {SELECT name FROM sqlite_temp_master}
         1481  +  } {t1 i1}
         1482  +  do_test auth-1.226 {
         1483  +    proc auth {code arg1 arg2 arg3 arg4} {
         1484  +      if {$code=="SQLITE_DROP_TEMP_INDEX"} {
         1485  +        set ::authargs [list $arg1 $arg2 $arg3 $arg4]
         1486  +        return SQLITE_OK
         1487  +      }
  1463   1488         return SQLITE_OK
  1464   1489       }
  1465         -    return SQLITE_OK
  1466         -  }
  1467         -  catchsql {DROP INDEX i1}
  1468         -} {0 {}}
  1469         -do_test auth-1.227 {
  1470         -  set ::authargs
  1471         -} {i1 t1 temp {}}
  1472         -do_test auth-1.228 {
  1473         -  execsql {SELECT name FROM sqlite_temp_master}
  1474         -} {t1}
         1490  +    catchsql {DROP INDEX i1}
         1491  +  } {0 {}}
         1492  +  do_test auth-1.227 {
         1493  +    set ::authargs
         1494  +  } {i1 t1 temp {}}
         1495  +  do_test auth-1.228 {
         1496  +    execsql {SELECT name FROM sqlite_temp_master}
         1497  +  } {t1}
         1498  +}
  1475   1499   
  1476   1500   do_test auth-1.229 {
  1477   1501     proc auth {code arg1 arg2 arg3 arg4} {
  1478   1502       if {$code=="SQLITE_PRAGMA"} {
  1479   1503         set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1480   1504         return SQLITE_DENY
  1481   1505       }
................................................................................
  1658   1682       }
  1659   1683       return SQLITE_OK
  1660   1684     }
  1661   1685     catchsql {
  1662   1686       DETACH DATABASE test1;
  1663   1687     }
  1664   1688   } {0 {}}
  1665         -ifcapable schema_pragmas {
  1666         -do_test auth-1.260 {
  1667         -  lindex [execsql {PRAGMA database_list}] 7
  1668         -} {test1}
  1669         -} ;# ifcapable schema_pragmas
  1670         -do_test auth-1.261 {
  1671         -  proc auth {code arg1 arg2 arg3 arg4} {
  1672         -    if {$code=="SQLITE_DETACH"} {
  1673         -      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1674         -      return SQLITE_DENY
  1675         -    }
  1676         -    return SQLITE_OK
  1677         -  }
  1678         -  catchsql {
  1679         -    DETACH DATABASE test1;
  1680         -  }
  1681         -} {1 {not authorized}}
  1682         -ifcapable schema_pragmas {
  1683         -do_test auth-1.262 {
  1684         -  lindex [execsql {PRAGMA database_list}] 7
  1685         -} {test1}
  1686         -} ;# ifcapable schema_pragmas
  1687         -db authorizer {}
  1688         -execsql {DETACH DATABASE test1}
  1689         -db authorizer ::auth
  1690         -
  1691         -# Authorization for ALTER TABLE. These tests are omitted if the library
  1692         -# was built without ALTER TABLE support.
  1693         -ifcapable altertable {
  1694         -
  1695         -do_test auth-1.263 {
  1696         -  proc auth {code arg1 arg2 arg3 arg4} {
  1697         -    if {$code=="SQLITE_ALTER_TABLE"} {
  1698         -      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
         1689  +ifcapable tempdb {
         1690  +  ifcapable schema_pragmas {
         1691  +  do_test auth-1.260 {
         1692  +    lindex [execsql {PRAGMA database_list}] 7
         1693  +  } {test1}
         1694  +  } ;# ifcapable schema_pragmas
         1695  +  do_test auth-1.261 {
         1696  +    proc auth {code arg1 arg2 arg3 arg4} {
         1697  +      if {$code=="SQLITE_DETACH"} {
         1698  +        set ::authargs [list $arg1 $arg2 $arg3 $arg4]
         1699  +        return SQLITE_DENY
         1700  +      }
  1699   1701         return SQLITE_OK
  1700   1702       }
  1701         -    return SQLITE_OK
  1702         -  }
  1703         -  catchsql {
  1704         -    ALTER TABLE t1 RENAME TO t1x
  1705         -  }
  1706         -} {0 {}}
  1707         -do_test auth-1.264 {
  1708         -  execsql {SELECT name FROM sqlite_temp_master WHERE type='table'}
  1709         -} {t1x}
  1710         -do_test auth-1.265 {
  1711         -  set authargs
  1712         -} {temp t1 {} {}}
  1713         -do_test auth-1.266 {
  1714         -  proc auth {code arg1 arg2 arg3 arg4} {
  1715         -    if {$code=="SQLITE_ALTER_TABLE"} {
  1716         -      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1717         -      return SQLITE_IGNORE
  1718         -    }
  1719         -    return SQLITE_OK
  1720         -  }
  1721         -  catchsql {
  1722         -    ALTER TABLE t1x RENAME TO t1
  1723         -  }
  1724         -} {0 {}}
  1725         -do_test auth-1.267 {
  1726         -  execsql {SELECT name FROM sqlite_temp_master WHERE type='table'}
  1727         -} {t1x}
  1728         -do_test auth-1.268 {
  1729         -  set authargs
  1730         -} {temp t1x {} {}}
  1731         -do_test auth-1.269 {
  1732         -  proc auth {code arg1 arg2 arg3 arg4} {
  1733         -    if {$code=="SQLITE_ALTER_TABLE"} {
  1734         -      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1735         -      return SQLITE_DENY
  1736         -    }
  1737         -    return SQLITE_OK
  1738         -  }
  1739         -  catchsql {
  1740         -    ALTER TABLE t1x RENAME TO t1
  1741         -  }
  1742         -} {1 {not authorized}}
  1743         -do_test auth-1.270 {
  1744         -  execsql {SELECT name FROM sqlite_temp_master WHERE type='table'}
  1745         -} {t1x}
  1746         -do_test auth-1.271 {
  1747         -  set authargs
  1748         -} {temp t1x {} {}}
         1703  +    catchsql {
         1704  +      DETACH DATABASE test1;
         1705  +    }
         1706  +  } {1 {not authorized}}
         1707  +  ifcapable schema_pragmas {
         1708  +  do_test auth-1.262 {
         1709  +    lindex [execsql {PRAGMA database_list}] 7
         1710  +  } {test1}
         1711  +  } ;# ifcapable schema_pragmas
         1712  +  db authorizer {}
         1713  +  execsql {DETACH DATABASE test1}
         1714  +  db authorizer ::auth
         1715  +  
         1716  +  # Authorization for ALTER TABLE. These tests are omitted if the library
         1717  +  # was built without ALTER TABLE support.
         1718  +  ifcapable altertable {
         1719  +  
         1720  +    do_test auth-1.263 {
         1721  +      proc auth {code arg1 arg2 arg3 arg4} {
         1722  +        if {$code=="SQLITE_ALTER_TABLE"} {
         1723  +          set ::authargs [list $arg1 $arg2 $arg3 $arg4]
         1724  +          return SQLITE_OK
         1725  +        }
         1726  +        return SQLITE_OK
         1727  +      }
         1728  +      catchsql {
         1729  +        ALTER TABLE t1 RENAME TO t1x
         1730  +      }
         1731  +    } {0 {}}
         1732  +    do_test auth-1.264 {
         1733  +      execsql {SELECT name FROM sqlite_temp_master WHERE type='table'}
         1734  +    } {t1x}
         1735  +    do_test auth-1.265 {
         1736  +      set authargs
         1737  +    } {temp t1 {} {}}
         1738  +    do_test auth-1.266 {
         1739  +      proc auth {code arg1 arg2 arg3 arg4} {
         1740  +        if {$code=="SQLITE_ALTER_TABLE"} {
         1741  +          set ::authargs [list $arg1 $arg2 $arg3 $arg4]
         1742  +          return SQLITE_IGNORE
         1743  +        }
         1744  +        return SQLITE_OK
         1745  +      }
         1746  +      catchsql {
         1747  +        ALTER TABLE t1x RENAME TO t1
         1748  +      }
         1749  +    } {0 {}}
         1750  +    do_test auth-1.267 {
         1751  +      execsql {SELECT name FROM sqlite_temp_master WHERE type='table'}
         1752  +    } {t1x}
         1753  +    do_test auth-1.268 {
         1754  +      set authargs
         1755  +    } {temp t1x {} {}}
         1756  +    do_test auth-1.269 {
         1757  +      proc auth {code arg1 arg2 arg3 arg4} {
         1758  +        if {$code=="SQLITE_ALTER_TABLE"} {
         1759  +          set ::authargs [list $arg1 $arg2 $arg3 $arg4]
         1760  +          return SQLITE_DENY
         1761  +        }
         1762  +        return SQLITE_OK
         1763  +      }
         1764  +      catchsql {
         1765  +        ALTER TABLE t1x RENAME TO t1
         1766  +      }
         1767  +    } {1 {not authorized}}
         1768  +    do_test auth-1.270 {
         1769  +      execsql {SELECT name FROM sqlite_temp_master WHERE type='table'}
         1770  +    } {t1x}
         1771  +  } ;# ifcapable altertable
         1772  +
         1773  +  do_test auth-1.271 {
         1774  +    set authargs
         1775  +  } {temp t1x {} {}}
         1776  +} else {
         1777  +  db authorizer {}
         1778  +  db eval {
         1779  +    DETACH DATABASE test1;
         1780  +  }
         1781  +}
         1782  +
         1783  +ifcapable  altertable {
  1749   1784   db authorizer {}
  1750   1785   catchsql {ALTER TABLE t1x RENAME TO t1}
  1751   1786   db authorizer ::auth
  1752   1787   do_test auth-1.272 {
  1753   1788     proc auth {code arg1 arg2 arg3 arg4} {
  1754   1789       if {$code=="SQLITE_ALTER_TABLE"} {
  1755   1790         set ::authargs [list $arg1 $arg2 $arg3 $arg4]
................................................................................
  1854   1889     set ::authargs
  1855   1890   } {t3_idx2 {} main {} t3_idx1 {} main {} sqlite_autoindex_t3_1 {} main {}}
  1856   1891   do_test auth-1.286 {
  1857   1892     execsql {
  1858   1893       DROP TABLE t3;
  1859   1894     }
  1860   1895   } {}
  1861         -do_test auth-1.287 {
  1862         -  execsql {
  1863         -    CREATE TEMP TABLE t3(a PRIMARY KEY, b, c);
  1864         -    CREATE INDEX t3_idx1 ON t3(c COLLATE BINARY);
  1865         -    CREATE INDEX t3_idx2 ON t3(b COLLATE NOCASE);
  1866         -  }
  1867         -} {}
  1868         -do_test auth-1.288 {
  1869         -  set ::authargs {}
  1870         -  execsql {
  1871         -    REINDEX temp.t3_idx1;
  1872         -  }
  1873         -  set ::authargs
  1874         -} {t3_idx1 {} temp {}}
  1875         -do_test auth-1.289 {
  1876         -  set ::authargs {}
  1877         -  execsql {
  1878         -    REINDEX BINARY;
  1879         -  }
  1880         -  set ::authargs
  1881         -} {t3_idx1 {} temp {} sqlite_autoindex_t3_1 {} temp {}}
  1882         -do_test auth-1.290 {
  1883         -  set ::authargs {}
  1884         -  execsql {
  1885         -    REINDEX NOCASE;
  1886         -  }
  1887         -  set ::authargs
  1888         -} {t3_idx2 {} temp {}}
  1889         -do_test auth-1.291 {
  1890         -  set ::authargs {}
  1891         -  execsql {
  1892         -    REINDEX temp.t3;
  1893         -  }
  1894         -  set ::authargs
  1895         -} {t3_idx2 {} temp {} t3_idx1 {} temp {} sqlite_autoindex_t3_1 {} temp {}}
  1896         -proc auth {code args} {
  1897         -  if {$code=="SQLITE_REINDEX"} {
  1898         -    set ::authargs [concat $::authargs $args]
  1899         -    return SQLITE_DENY
  1900         -  }
  1901         -  return SQLITE_OK
  1902         -}
  1903         -do_test auth-1.292 {
  1904         -  set ::authargs {}
  1905         -  catchsql {
  1906         -    REINDEX temp.t3;
  1907         -  }
  1908         -} {1 {not authorized}}
  1909         -do_test auth-1.293 {
  1910         -  execsql {
  1911         -    DROP TABLE t3;
  1912         -  }
  1913         -} {}
         1896  +ifcapable tempdb {
         1897  +  do_test auth-1.287 {
         1898  +    execsql {
         1899  +      CREATE TEMP TABLE t3(a PRIMARY KEY, b, c);
         1900  +      CREATE INDEX t3_idx1 ON t3(c COLLATE BINARY);
         1901  +      CREATE INDEX t3_idx2 ON t3(b COLLATE NOCASE);
         1902  +    }
         1903  +  } {}
         1904  +  do_test auth-1.288 {
         1905  +    set ::authargs {}
         1906  +    execsql {
         1907  +      REINDEX temp.t3_idx1;
         1908  +    }
         1909  +    set ::authargs
         1910  +  } {t3_idx1 {} temp {}}
         1911  +  do_test auth-1.289 {
         1912  +    set ::authargs {}
         1913  +    execsql {
         1914  +      REINDEX BINARY;
         1915  +    }
         1916  +    set ::authargs
         1917  +  } {t3_idx1 {} temp {} sqlite_autoindex_t3_1 {} temp {}}
         1918  +  do_test auth-1.290 {
         1919  +    set ::authargs {}
         1920  +    execsql {
         1921  +      REINDEX NOCASE;
         1922  +    }
         1923  +    set ::authargs
         1924  +  } {t3_idx2 {} temp {}}
         1925  +  do_test auth-1.291 {
         1926  +    set ::authargs {}
         1927  +    execsql {
         1928  +      REINDEX temp.t3;
         1929  +    }
         1930  +    set ::authargs
         1931  +  } {t3_idx2 {} temp {} t3_idx1 {} temp {} sqlite_autoindex_t3_1 {} temp {}}
         1932  +  proc auth {code args} {
         1933  +    if {$code=="SQLITE_REINDEX"} {
         1934  +      set ::authargs [concat $::authargs $args]
         1935  +      return SQLITE_DENY
         1936  +    }
         1937  +    return SQLITE_OK
         1938  +  }
         1939  +  do_test auth-1.292 {
         1940  +    set ::authargs {}
         1941  +    catchsql {
         1942  +      REINDEX temp.t3;
         1943  +    }
         1944  +  } {1 {not authorized}}
         1945  +  do_test auth-1.293 {
         1946  +    execsql {
         1947  +      DROP TABLE t3;
         1948  +    }
         1949  +  } {}
         1950  +}
  1914   1951   
  1915   1952   } ;# ifcapable reindex 
  1916         -
  1917   1953   
  1918   1954   do_test auth-2.1 {
  1919   1955     proc auth {code arg1 arg2 arg3 arg4} {
  1920   1956       if {$code=="SQLITE_READ" && $arg1=="t3" && $arg2=="x"} {
  1921   1957         return SQLITE_DENY
  1922   1958       }
  1923   1959       return SQLITE_OK

Changes to test/autoinc.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #*************************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script is testing the AUTOINCREMENT features.
    13     13   #
    14         -# $Id: autoinc.test,v 1.4 2005/02/17 00:03:07 drh Exp $
           14  +# $Id: autoinc.test,v 1.5 2005/03/29 03:11:00 danielk1977 Exp $
    15     15   #
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   # If the library is not compiled with autoincrement support then
    21     21   # skip all tests in this file.
................................................................................
   231    231     }
   232    232   } {235 1 1235 2 1240 3 1241 4}
   233    233   do_test autoinc-2.51 {
   234    234     execsql {
   235    235       SELECT * FROM sqlite_sequence
   236    236     }
   237    237   } {t1 1241}
   238         -do_test autoinc-2.52 {
   239         -  execsql {
   240         -    CREATE TEMP TABLE t2 AS SELECT y FROM t1;
   241         -    INSERT INTO t1 SELECT NULL, y+4 FROM t2;
   242         -    SELECT * FROM t1;
   243         -  }
   244         -} {235 1 1235 2 1240 3 1241 4 1242 5 1243 6 1244 7 1245 8}
   245         -do_test autoinc-2.53 {
   246         -  execsql {
   247         -    SELECT * FROM sqlite_sequence
   248         -  }
   249         -} {t1 1245}
   250         -do_test autoinc-2.54 {
   251         -  execsql {
   252         -    DELETE FROM t1;
   253         -    INSERT INTO t1 SELECT NULL, y FROM t2;
   254         -    SELECT * FROM t1;
   255         -  }
   256         -} {1246 1 1247 2 1248 3 1249 4}
   257         -do_test autoinc-2.55 {
   258         -  execsql {
   259         -    SELECT * FROM sqlite_sequence
   260         -  }
   261         -} {t1 1249}
          238  +
          239  +ifcapable tempdb {
          240  +  do_test autoinc-2.52 {
          241  +    execsql {
          242  +      CREATE TEMP TABLE t2 AS SELECT y FROM t1;
          243  +      INSERT INTO t1 SELECT NULL, y+4 FROM t2;
          244  +      SELECT * FROM t1;
          245  +    }
          246  +  } {235 1 1235 2 1240 3 1241 4 1242 5 1243 6 1244 7 1245 8}
          247  +  do_test autoinc-2.53 {
          248  +    execsql {
          249  +      SELECT * FROM sqlite_sequence
          250  +    }
          251  +  } {t1 1245}
          252  +  do_test autoinc-2.54 {
          253  +    execsql {
          254  +      DELETE FROM t1;
          255  +      INSERT INTO t1 SELECT NULL, y FROM t2;
          256  +      SELECT * FROM t1;
          257  +    }
          258  +  } {1246 1 1247 2 1248 3 1249 4}
          259  +  do_test autoinc-2.55 {
          260  +    execsql {
          261  +      SELECT * FROM sqlite_sequence
          262  +    }
          263  +  } {t1 1249}
          264  +}
   262    265   
   263    266   # Create multiple AUTOINCREMENT tables.  Make sure all sequences are
   264    267   # tracked separately and do not interfere with one another.
   265    268   #
   266    269   do_test autoinc-2.70 {
   267         -  execsql {
          270  +  catchsql {
   268    271       DROP TABLE t2;
          272  +  }
          273  +  execsql {
   269    274       CREATE TABLE t2(d, e INTEGER PRIMARY KEY AUTOINCREMENT, f);
   270    275       INSERT INTO t2(d) VALUES(1);
   271    276       SELECT * FROM sqlite_sequence;
   272    277     }
   273         -} {t1 1249 t2 1}
          278  +} [ifcapable tempdb {list t1 1249 t2 1} else {list t1 1241 t2 1}]
   274    279   do_test autoinc-2.71 {
   275    280     execsql {
   276    281       INSERT INTO t2(d) VALUES(2);
   277    282       SELECT * FROM sqlite_sequence;
   278    283     }
   279         -} {t1 1249 t2 2}
          284  +} [ifcapable tempdb {list t1 1249 t2 2} else {list t1 1241 t2 2}]
   280    285   do_test autoinc-2.72 {
   281    286     execsql {
   282    287       INSERT INTO t1(x) VALUES(10000);
   283    288       SELECT * FROM sqlite_sequence;
   284    289     }
   285    290   } {t1 10000 t2 2}
   286    291   do_test autoinc-2.73 {
................................................................................
   322    327       DROP TABLE t2;
   323    328       SELECT name FROM sqlite_sequence;
   324    329     }
   325    330   } {}
   326    331   
   327    332   # AUTOINCREMENT on TEMP tables.
   328    333   #
   329         -do_test autoinc-4.1 {
   330         -  execsql {
   331         -    SELECT 1, name FROM sqlite_master WHERE type='table';
   332         -    SELECT 2, name FROM sqlite_temp_master WHERE type='table';
   333         -  }
   334         -} {1 sqlite_sequence}
   335         -do_test autoinc-4.2 {
   336         -  execsql {
   337         -    CREATE TABLE t1(x INTEGER PRIMARY KEY AUTOINCREMENT, y);
   338         -    CREATE TEMP TABLE t3(a INTEGER PRIMARY KEY AUTOINCREMENT, b);
   339         -    SELECT 1, name FROM sqlite_master WHERE type='table';
   340         -    SELECT 2, name FROM sqlite_temp_master WHERE type='table';
   341         -  }
   342         -} {1 sqlite_sequence 1 t1 2 t3 2 sqlite_sequence}
   343         -do_test autoinc-4.3 {
   344         -  execsql {
   345         -    SELECT 1, * FROM main.sqlite_sequence;
   346         -    SELECT 2, * FROM temp.sqlite_sequence;
   347         -  }
   348         -} {}
   349         -do_test autoinc-4.4 {
   350         -  execsql {
   351         -    INSERT INTO t1 VALUES(10,1);
   352         -    INSERT INTO t3 VALUES(20,2);
   353         -    INSERT INTO t1 VALUES(NULL,3);
   354         -    INSERT INTO t3 VALUES(NULL,4);
   355         -  }
   356         -} {}
   357         -
   358         -ifcapable compound {
   359         -do_test autoinc-4.4.1 {
   360         -  execsql {
   361         -    SELECT * FROM t1 UNION ALL SELECT * FROM t3;
   362         -  }
   363         -} {10 1 11 3 20 2 21 4}
   364         -} ;# ifcapable compound
   365         -
   366         -do_test autoinc-4.5 {
   367         -  execsql {
   368         -    SELECT 1, * FROM main.sqlite_sequence;
   369         -    SELECT 2, * FROM temp.sqlite_sequence;
   370         -  }
   371         -} {1 t1 11 2 t3 21}
   372         -do_test autoinc-4.6 {
   373         -  execsql {
   374         -    INSERT INTO t1 SELECT * FROM t3;
   375         -    SELECT 1, * FROM main.sqlite_sequence;
   376         -    SELECT 2, * FROM temp.sqlite_sequence;
   377         -  }
   378         -} {1 t1 21 2 t3 21}
   379         -do_test autoinc-4.7 {
   380         -  execsql {
   381         -    INSERT INTO t3 SELECT x+100, y  FROM t1;
   382         -    SELECT 1, * FROM main.sqlite_sequence;
   383         -    SELECT 2, * FROM temp.sqlite_sequence;
   384         -  }
   385         -} {1 t1 21 2 t3 121}
   386         -do_test autoinc-4.8 {
   387         -  execsql {
   388         -    DROP TABLE t3;
   389         -    SELECT 1, * FROM main.sqlite_sequence;
   390         -    SELECT 2, * FROM temp.sqlite_sequence;
   391         -  }
   392         -} {1 t1 21}
   393         -do_test autoinc-4.9 {
   394         -  execsql {
   395         -    CREATE TEMP TABLE t2(p INTEGER PRIMARY KEY AUTOINCREMENT, q);
   396         -    INSERT INTO t2 SELECT * FROM t1;
   397         -    DROP TABLE t1;
   398         -    SELECT 1, * FROM main.sqlite_sequence;
   399         -    SELECT 2, * FROM temp.sqlite_sequence;
   400         -  }
   401         -} {2 t2 21}
   402         -do_test autoinc-4.10 {
   403         -  execsql {
   404         -    DROP TABLE t2;
   405         -    SELECT 1, * FROM main.sqlite_sequence;
   406         -    SELECT 2, * FROM temp.sqlite_sequence;
   407         -  }
   408         -} {}
          334  +ifcapable tempdb {
          335  +  do_test autoinc-4.1 {
          336  +    execsql {
          337  +      SELECT 1, name FROM sqlite_master WHERE type='table';
          338  +      SELECT 2, name FROM sqlite_temp_master WHERE type='table';
          339  +    }
          340  +  } {1 sqlite_sequence}
          341  +  do_test autoinc-4.2 {
          342  +    execsql {
          343  +      CREATE TABLE t1(x INTEGER PRIMARY KEY AUTOINCREMENT, y);
          344  +      CREATE TEMP TABLE t3(a INTEGER PRIMARY KEY AUTOINCREMENT, b);
          345  +      SELECT 1, name FROM sqlite_master WHERE type='table';
          346  +      SELECT 2, name FROM sqlite_temp_master WHERE type='table';
          347  +    }
          348  +  } {1 sqlite_sequence 1 t1 2 t3 2 sqlite_sequence}
          349  +  do_test autoinc-4.3 {
          350  +    execsql {
          351  +      SELECT 1, * FROM main.sqlite_sequence;
          352  +      SELECT 2, * FROM temp.sqlite_sequence;
          353  +    }
          354  +  } {}
          355  +  do_test autoinc-4.4 {
          356  +    execsql {
          357  +      INSERT INTO t1 VALUES(10,1);
          358  +      INSERT INTO t3 VALUES(20,2);
          359  +      INSERT INTO t1 VALUES(NULL,3);
          360  +      INSERT INTO t3 VALUES(NULL,4);
          361  +    }
          362  +  } {}
          363  +  
          364  +  ifcapable compound {
          365  +  do_test autoinc-4.4.1 {
          366  +    execsql {
          367  +      SELECT * FROM t1 UNION ALL SELECT * FROM t3;
          368  +    }
          369  +  } {10 1 11 3 20 2 21 4}
          370  +  } ;# ifcapable compound
          371  +  
          372  +  do_test autoinc-4.5 {
          373  +    execsql {
          374  +      SELECT 1, * FROM main.sqlite_sequence;
          375  +      SELECT 2, * FROM temp.sqlite_sequence;
          376  +    }
          377  +  } {1 t1 11 2 t3 21}
          378  +  do_test autoinc-4.6 {
          379  +    execsql {
          380  +      INSERT INTO t1 SELECT * FROM t3;
          381  +      SELECT 1, * FROM main.sqlite_sequence;
          382  +      SELECT 2, * FROM temp.sqlite_sequence;
          383  +    }
          384  +  } {1 t1 21 2 t3 21}
          385  +  do_test autoinc-4.7 {
          386  +    execsql {
          387  +      INSERT INTO t3 SELECT x+100, y  FROM t1;
          388  +      SELECT 1, * FROM main.sqlite_sequence;
          389  +      SELECT 2, * FROM temp.sqlite_sequence;
          390  +    }
          391  +  } {1 t1 21 2 t3 121}
          392  +  do_test autoinc-4.8 {
          393  +    execsql {
          394  +      DROP TABLE t3;
          395  +      SELECT 1, * FROM main.sqlite_sequence;
          396  +      SELECT 2, * FROM temp.sqlite_sequence;
          397  +    }
          398  +  } {1 t1 21}
          399  +  do_test autoinc-4.9 {
          400  +    execsql {
          401  +      CREATE TEMP TABLE t2(p INTEGER PRIMARY KEY AUTOINCREMENT, q);
          402  +      INSERT INTO t2 SELECT * FROM t1;
          403  +      DROP TABLE t1;
          404  +      SELECT 1, * FROM main.sqlite_sequence;
          405  +      SELECT 2, * FROM temp.sqlite_sequence;
          406  +    }
          407  +  } {2 t2 21}
          408  +  do_test autoinc-4.10 {
          409  +    execsql {
          410  +      DROP TABLE t2;
          411  +      SELECT 1, * FROM main.sqlite_sequence;
          412  +      SELECT 2, * FROM temp.sqlite_sequence;
          413  +    }
          414  +  } {}
          415  +}
   409    416   
   410    417   # Make sure AUTOINCREMENT works on ATTACH-ed tables.
   411    418   #
   412         -do_test autoinc-5.1 {
   413         -  file delete -force test2.db
   414         -  file delete -force test2.db-journal
   415         -  sqlite3 db2 test2.db
   416         -  execsql {
   417         -    CREATE TABLE t4(m INTEGER PRIMARY KEY AUTOINCREMENT, n);
   418         -    CREATE TABLE t5(o, p INTEGER PRIMARY KEY AUTOINCREMENT);
   419         -  } db2;
   420         -  execsql {
   421         -    ATTACH 'test2.db' as aux;
   422         -    SELECT 1, * FROM main.sqlite_sequence;
   423         -    SELECT 2, * FROM temp.sqlite_sequence;
   424         -    SELECT 3, * FROM aux.sqlite_sequence;
   425         -  }
   426         -} {}
   427         -do_test autoinc-5.2 {
   428         -  execsql {
   429         -    INSERT INTO t4 VALUES(NULL,1);
   430         -    SELECT 1, * FROM main.sqlite_sequence;
   431         -    SELECT 2, * FROM temp.sqlite_sequence;
   432         -    SELECT 3, * FROM aux.sqlite_sequence;
   433         -  }
   434         -} {3 t4 1}
   435         -do_test autoinc-5.3 {
   436         -  execsql {
   437         -    INSERT INTO t5 VALUES(100,200);
   438         -    SELECT * FROM sqlite_sequence
   439         -  } db2
   440         -} {t4 1 t5 200}
   441         -do_test autoinc-5.4 {
   442         -  execsql {
   443         -    SELECT 1, * FROM main.sqlite_sequence;
   444         -    SELECT 2, * FROM temp.sqlite_sequence;
   445         -    SELECT 3, * FROM aux.sqlite_sequence;
   446         -  }
   447         -} {3 t4 1 3 t5 200}
          419  +ifcapable tempdb {
          420  +  do_test autoinc-5.1 {
          421  +    file delete -force test2.db
          422  +    file delete -force test2.db-journal
          423  +    sqlite3 db2 test2.db
          424  +    execsql {
          425  +      CREATE TABLE t4(m INTEGER PRIMARY KEY AUTOINCREMENT, n);
          426  +      CREATE TABLE t5(o, p INTEGER PRIMARY KEY AUTOINCREMENT);
          427  +    } db2;
          428  +    execsql {
          429  +      ATTACH 'test2.db' as aux;
          430  +      SELECT 1, * FROM main.sqlite_sequence;
          431  +      SELECT 2, * FROM temp.sqlite_sequence;
          432  +      SELECT 3, * FROM aux.sqlite_sequence;
          433  +    }
          434  +  } {}
          435  +  do_test autoinc-5.2 {
          436  +    execsql {
          437  +      INSERT INTO t4 VALUES(NULL,1);
          438  +      SELECT 1, * FROM main.sqlite_sequence;
          439  +      SELECT 2, * FROM temp.sqlite_sequence;
          440  +      SELECT 3, * FROM aux.sqlite_sequence;
          441  +    }
          442  +  } {3 t4 1}
          443  +  do_test autoinc-5.3 {
          444  +    execsql {
          445  +      INSERT INTO t5 VALUES(100,200);
          446  +      SELECT * FROM sqlite_sequence
          447  +    } db2
          448  +  } {t4 1 t5 200}
          449  +  do_test autoinc-5.4 {
          450  +    execsql {
          451  +      SELECT 1, * FROM main.sqlite_sequence;
          452  +      SELECT 2, * FROM temp.sqlite_sequence;
          453  +      SELECT 3, * FROM aux.sqlite_sequence;
          454  +    }
          455  +  } {3 t4 1 3 t5 200}
          456  +}
   448    457   
   449    458   # Requirement REQ00310:  Make sure an insert fails if the sequence is
   450    459   # already at its maximum value.
   451    460   #
   452    461   ifcapable {rowid32} {
   453    462     do_test autoinc-6.1 {
   454    463       execsql {

Changes to test/capi2.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script testing the callback-free C/C++ API.
    13     13   #
    14         -# $Id: capi2.test,v 1.25 2005/02/04 04:07:18 danielk1977 Exp $
           14  +# $Id: capi2.test,v 1.26 2005/03/29 03:11:00 danielk1977 Exp $
    15     15   #
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   # Return the text values from the current row pointed at by STMT as a list.
    21     21   proc get_row_values {STMT} {
................................................................................
    93     93   
    94     94   # Check to make sure that the "tail" of a multi-statement SQL script
    95     95   # is returned by sqlite3_prepare.
    96     96   #
    97     97   do_test capi2-2.1 {
    98     98     set SQL {
    99     99       SELECT name, rowid FROM sqlite_master;
   100         -    SELECT name, rowid FROM sqlite_temp_master;
          100  +    SELECT name, rowid FROM sqlite_master WHERE 0;
   101    101       -- A comment at the end
   102    102     }
   103    103     set VM [sqlite3_prepare $DB $SQL -1 SQL]
   104    104     set SQL
   105    105   } {
   106         -    SELECT name, rowid FROM sqlite_temp_master;
          106  +    SELECT name, rowid FROM sqlite_master WHERE 0;
   107    107       -- A comment at the end
   108    108     }
   109    109   do_test capi2-2.2 {
   110    110     set r [sqlite3_step $VM]
   111    111     lappend r [sqlite3_column_count $VM] \
   112    112               [get_row_values $VM] \
   113    113               [get_column_names $VM]

Changes to test/func.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this file is testing built-in functions.
    13     13   #
    14         -# $Id: func.test,v 1.33 2005/01/21 11:55:28 danielk1977 Exp $
           14  +# $Id: func.test,v 1.34 2005/03/29 03:11:00 danielk1977 Exp $
    15     15   
    16     16   set testdir [file dirname $argv0]
    17     17   source $testdir/tester.tcl
    18     18   
    19     19   # Create a table to work with.
    20     20   #
    21     21   do_test func-0.0 {
................................................................................
   256    256     }
   257    257   } {68236.0 3 22745.33 1 67890 5}
   258    258   do_test func-8.2 {
   259    259     execsql {
   260    260       SELECT max('z+'||a||'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP') FROM t2;
   261    261     }
   262    262   } {z+67890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP}
   263         -do_test func-8.3 {
   264         -  execsql {
   265         -    CREATE TEMP TABLE t3 AS SELECT a FROM t2 ORDER BY a DESC;
   266         -    SELECT min('z+'||a||'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP') FROM t3;
   267         -  }
   268         -} {z+1abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP}
          263  +
          264  +ifcapable tempdb {
          265  +  do_test func-8.3 {
          266  +    execsql {
          267  +      CREATE TEMP TABLE t3 AS SELECT a FROM t2 ORDER BY a DESC;
          268  +      SELECT min('z+'||a||'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP') FROM t3;
          269  +    }
          270  +  } {z+1abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP}
          271  +} else {
          272  +  do_test func-8.3 {
          273  +    execsql {
          274  +      CREATE TABLE t3 AS SELECT a FROM t2 ORDER BY a DESC;
          275  +      SELECT min('z+'||a||'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP') FROM t3;
          276  +    }
          277  +  } {z+1abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP}
          278  +}
   269    279   do_test func-8.4 {
   270    280     execsql {
   271    281       SELECT max('z+'||a||'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP') FROM t3;
   272    282     }
   273    283   } {z+67890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP}
   274    284   
   275    285   # How do you test the random() function in a meaningful, deterministic way?

Changes to test/insert.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this file is testing the INSERT statement.
    13     13   #
    14         -# $Id: insert.test,v 1.24 2005/03/21 01:20:58 drh Exp $
           14  +# $Id: insert.test,v 1.25 2005/03/29 03:11:00 danielk1977 Exp $
    15     15   
    16     16   set testdir [file dirname $argv0]
    17     17   source $testdir/tester.tcl
    18     18   
    19     19   # Try to insert into a non-existant table.
    20     20   #
    21     21   do_test insert-1.1 {
................................................................................
   223    223       SELECT * FROM t3 WHERE c=99;
   224    224     }
   225    225   } {1 3 99}
   226    226   
   227    227   # Test the ability to insert from a temporary table into itself.
   228    228   # Ticket #275.
   229    229   #
   230         -do_test insert-5.1 {
   231         -  execsql {
   232         -    CREATE TEMP TABLE t4(x);
   233         -    INSERT INTO t4 VALUES(1);
   234         -    SELECT * FROM t4;
   235         -  }
   236         -} {1}
   237         -do_test insert-5.2 {
   238         -  execsql {
   239         -    INSERT INTO t4 SELECT x+1 FROM t4;
   240         -    SELECT * FROM t4;
   241         -  }
   242         -} {1 2}
   243         -ifcapable {explain} {
   244         -  do_test insert-5.3 {
   245         -    # verify that a temporary table is used to copy t4 to t4
   246         -    set x [execsql {
   247         -      EXPLAIN INSERT INTO t4 SELECT x+2 FROM t4;
   248         -    }]
   249         -    expr {[lsearch $x OpenTemp]>0}
          230  +ifcapable tempdb {
          231  +  do_test insert-5.1 {
          232  +    execsql {
          233  +      CREATE TEMP TABLE t4(x);
          234  +      INSERT INTO t4 VALUES(1);
          235  +      SELECT * FROM t4;
          236  +    }
   250    237     } {1}
   251         -}
   252         -
   253         -do_test insert-5.4 {
   254         -  # Verify that table "test1" begins on page 3.  This should be the same
   255         -  # page number used by "t4" above.
   256         -  #
   257         -  # Update for v3 - the first table now begins on page 2 of each file, not 3.
   258         -  execsql {
   259         -    SELECT rootpage FROM sqlite_master WHERE name='test1';
          238  +  do_test insert-5.2 {
          239  +    execsql {
          240  +      INSERT INTO t4 SELECT x+1 FROM t4;
          241  +      SELECT * FROM t4;
          242  +    }
          243  +  } {1 2}
          244  +  ifcapable {explain} {
          245  +    do_test insert-5.3 {
          246  +      # verify that a temporary table is used to copy t4 to t4
          247  +      set x [execsql {
          248  +        EXPLAIN INSERT INTO t4 SELECT x+2 FROM t4;
          249  +      }]
          250  +      expr {[lsearch $x OpenTemp]>0}
          251  +    } {1}
   260    252     }
   261         -} [expr $AUTOVACUUM?3:2]
   262         -do_test insert-5.5 {
   263         -  # Verify that "t4" begins on page 3.
   264         -  #
   265         -  # Update for v3 - the first table now begins on page 2 of each file, not 3.
   266         -  execsql {
   267         -    SELECT rootpage FROM sqlite_temp_master WHERE name='t4';
   268         -  }
   269         -} {2}
   270         -do_test insert-5.6 {
   271         -  # This should not use an intermediate temporary table.
   272         -  execsql {
   273         -    INSERT INTO t4 SELECT one FROM test1 WHERE three=7;
   274         -    SELECT * FROM t4
   275         -  }
   276         -} {1 2 8}
   277         -ifcapable {explain} {
   278         -  do_test insert-5.7 {
   279         -    # verify that no temporary table is used to copy test1 to t4
   280         -    set x [execsql {
   281         -      EXPLAIN INSERT INTO t4 SELECT one FROM test1;
   282         -    }]
   283         -    expr {[lsearch $x OpenTemp]>0}
   284         -  } {0}
          253  +  
          254  +  do_test insert-5.4 {
          255  +    # Verify that table "test1" begins on page 3.  This should be the same
          256  +    # page number used by "t4" above.
          257  +    #
          258  +    # Update for v3 - the first table now begins on page 2 of each file, not 3.
          259  +    execsql {
          260  +      SELECT rootpage FROM sqlite_master WHERE name='test1';
          261  +    }
          262  +  } [expr $AUTOVACUUM?3:2]
          263  +  do_test insert-5.5 {
          264  +    # Verify that "t4" begins on page 3.
          265  +    #
          266  +    # Update for v3 - the first table now begins on page 2 of each file, not 3.
          267  +    execsql {
          268  +      SELECT rootpage FROM sqlite_temp_master WHERE name='t4';
          269  +    }
          270  +  } {2}
          271  +  do_test insert-5.6 {
          272  +    # This should not use an intermediate temporary table.
          273  +    execsql {
          274  +      INSERT INTO t4 SELECT one FROM test1 WHERE three=7;
          275  +      SELECT * FROM t4
          276  +    }
          277  +  } {1 2 8}
          278  +  ifcapable {explain} {
          279  +    do_test insert-5.7 {
          280  +      # verify that no temporary table is used to copy test1 to t4
          281  +      set x [execsql {
          282  +        EXPLAIN INSERT INTO t4 SELECT one FROM test1;
          283  +      }]
          284  +      expr {[lsearch $x OpenTemp]>0}
          285  +    } {0}
          286  +  }
   285    287   }
   286    288   
   287    289   # Ticket #334:  REPLACE statement corrupting indices.
   288    290   #
   289    291   do_test insert-6.1 {
   290    292     execsql {
   291    293       CREATE TABLE t1(a INTEGER PRIMARY KEY, b UNIQUE);

Changes to test/insert2.test.

     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this file is testing the INSERT statement that takes is
    13     13   # result from a SELECT.
    14     14   #
    15         -# $Id: insert2.test,v 1.15 2005/02/08 08:42:29 danielk1977 Exp $
           15  +# $Id: insert2.test,v 1.16 2005/03/29 03:11:00 danielk1977 Exp $
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   # Create some tables with data that we can select against
    21     21   #
    22     22   do_test insert2-1.0 {
................................................................................
   216    216   do_test insert2-3.8 {
   217    217     db changes
   218    218   } {159}
   219    219   integrity_check insert2-3.9
   220    220   
   221    221   # Ticket #901
   222    222   #
   223         -do_test insert2-4.1 {
   224         -  execsql {
   225         -    CREATE TABLE Dependencies(depId integer primary key,
   226         -      class integer, name str, flag str);
   227         -    CREATE TEMPORARY TABLE DepCheck(troveId INT, depNum INT,
   228         -      flagCount INT, isProvides BOOL, class INTEGER, name STRING,
   229         -      flag STRING);
   230         -    INSERT INTO DepCheck 
   231         -       VALUES(-1, 0, 1, 0, 2, 'libc.so.6', 'GLIBC_2.0');
   232         -    INSERT INTO Dependencies 
   233         -       SELECT DISTINCT 
   234         -           NULL, 
   235         -           DepCheck.class, 
   236         -           DepCheck.name, 
   237         -           DepCheck.flag 
   238         -       FROM DepCheck LEFT OUTER JOIN Dependencies ON 
   239         -           DepCheck.class == Dependencies.class AND 
   240         -           DepCheck.name == Dependencies.name AND 
   241         -           DepCheck.flag == Dependencies.flag 
   242         -       WHERE 
   243         -           Dependencies.depId is NULL;
   244         -  };
   245         -} {}
          223  +ifcapable tempdb {
          224  +  do_test insert2-4.1 {
          225  +    execsql {
          226  +      CREATE TABLE Dependencies(depId integer primary key,
          227  +        class integer, name str, flag str);
          228  +      CREATE TEMPORARY TABLE DepCheck(troveId INT, depNum INT,
          229  +        flagCount INT, isProvides BOOL, class INTEGER, name STRING,
          230  +        flag STRING);
          231  +      INSERT INTO DepCheck 
          232  +         VALUES(-1, 0, 1, 0, 2, 'libc.so.6', 'GLIBC_2.0');
          233  +      INSERT INTO Dependencies 
          234  +         SELECT DISTINCT 
          235  +             NULL, 
          236  +             DepCheck.class, 
          237  +             DepCheck.name, 
          238  +             DepCheck.flag 
          239  +         FROM DepCheck LEFT OUTER JOIN Dependencies ON 
          240  +             DepCheck.class == Dependencies.class AND 
          241  +             DepCheck.name == Dependencies.name AND 
          242  +             DepCheck.flag == Dependencies.flag 
          243  +         WHERE 
          244  +             Dependencies.depId is NULL;
          245  +    };
          246  +  } {}
          247  +}
   246    248   
   247    249   #--------------------------------------------------------------------
   248    250   # Test that the INSERT works when the SELECT statement (a) references
   249    251   # the table being inserted into and (b) is optimized to use an index
   250    252   # only.
   251    253   do_test insert2-5.1 {
   252    254     execsql {

Changes to test/interrupt.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script is the sqlite_interrupt() API.
    13     13   #
    14         -# $Id: interrupt.test,v 1.10 2005/01/11 17:46:42 drh Exp $
           14  +# $Id: interrupt.test,v 1.11 2005/03/29 03:11:00 danielk1977 Exp $
    15     15   
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   db close
    20     20   set DB [sqlite3 db test.db]
    21     21   
................................................................................
   119    119   }
   120    120   integrity_check interrupt-2.6
   121    121   
   122    122   # Ticket #594.  If an interrupt occurs in the middle of a transaction
   123    123   # and that transaction is later rolled back, the internal schema tables do
   124    124   # not reset.
   125    125   #
   126         -for {set i 1} {$i<50} {incr i 5} {
   127         -  do_test interrupt-3.$i.1 {
   128         -    execsql {
   129         -      BEGIN;
   130         -      CREATE TEMP TABLE t2(x,y);
   131         -      SELECT name FROM sqlite_temp_master;
   132         -    }
   133         -  } {t2}
   134         -  do_test interrupt-3.$i.2 {
   135         -    set ::sqlite_interrupt_count $::i
   136         -    catchsql {
   137         -      INSERT INTO t2 SELECT * FROM t1;
   138         -    }
   139         -  } {1 interrupted}
   140         -  do_test interrupt-3.$i.3 {
   141         -    execsql {
   142         -      SELECT name FROM sqlite_temp_master;
   143         -    }
   144         -  } {t2}
   145         -  do_test interrupt-3.$i.4 {
   146         -    catchsql {
   147         -      ROLLBACK
   148         -    }
   149         -  } {0 {}}
   150         -  do_test interrupt-3.$i.5 {
   151         -    catchsql {SELECT name FROM sqlite_temp_master};
   152         -    execsql {
   153         -      SELECT name FROM sqlite_temp_master;
   154         -    }
   155         -  } {}
          126  +ifcapable tempdb {
          127  +  for {set i 1} {$i<50} {incr i 5} {
          128  +    do_test interrupt-3.$i.1 {
          129  +      execsql {
          130  +        BEGIN;
          131  +        CREATE TEMP TABLE t2(x,y);
          132  +        SELECT name FROM sqlite_temp_master;
          133  +      }
          134  +    } {t2}
          135  +    do_test interrupt-3.$i.2 {
          136  +      set ::sqlite_interrupt_count $::i
          137  +      catchsql {
          138  +        INSERT INTO t2 SELECT * FROM t1;
          139  +      }
          140  +    } {1 interrupted}
          141  +    do_test interrupt-3.$i.3 {
          142  +      execsql {
          143  +        SELECT name FROM sqlite_temp_master;
          144  +      }
          145  +    } {t2}
          146  +    do_test interrupt-3.$i.4 {
          147  +      catchsql {
          148  +        ROLLBACK
          149  +      }
          150  +    } {0 {}}
          151  +    do_test interrupt-3.$i.5 {
          152  +      catchsql {SELECT name FROM sqlite_temp_master};
          153  +      execsql {
          154  +        SELECT name FROM sqlite_temp_master;
          155  +      }
          156  +    } {}
          157  +  }
   156    158   }
   157    159   
   158    160   # There are reports of a memory leak if an interrupt occurs during
   159    161   # the beginning of a complex query - before the first callback.  We
   160    162   # will try to reproduce it here:
   161    163   #
   162    164   execsql {

Changes to test/join4.test.

     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.
    12     12   #
    13     13   # This file implements tests for left outer joins containing WHERE
    14     14   # clauses that restrict the scope of the left term of the join.
    15     15   #
    16         -# $Id: join4.test,v 1.3 2005/01/21 03:12:16 danielk1977 Exp $
           16  +# $Id: join4.test,v 1.4 2005/03/29 03:11:00 danielk1977 Exp $
    17     17   
    18     18   set testdir [file dirname $argv0]
    19     19   source $testdir/tester.tcl
    20     20   
    21         -do_test join4-1.1 {
    22         -  execsql {
    23         -    create temp table t1(a integer, b varchar(10));
    24         -    insert into t1 values(1,'one');
    25         -    insert into t1 values(2,'two');
    26         -    insert into t1 values(3,'three');
    27         -    insert into t1 values(4,'four');
    28         -
    29         -    create temp table t2(x integer, y varchar(10), z varchar(10));
    30         -    insert into t2 values(2,'niban','ok');
    31         -    insert into t2 values(4,'yonban','err');
    32         -  }
    33         -  execsql {
    34         -    select * from t1 left outer join t2 on t1.a=t2.x where t2.z='ok'
    35         -  }
    36         -} {2 two 2 niban ok}
           21  +ifcapable tempdb {
           22  +  do_test join4-1.1 {
           23  +    execsql {
           24  +      create temp table t1(a integer, b varchar(10));
           25  +      insert into t1 values(1,'one');
           26  +      insert into t1 values(2,'two');
           27  +      insert into t1 values(3,'three');
           28  +      insert into t1 values(4,'four');
           29  +  
           30  +      create temp table t2(x integer, y varchar(10), z varchar(10));
           31  +      insert into t2 values(2,'niban','ok');
           32  +      insert into t2 values(4,'yonban','err');
           33  +    }
           34  +    execsql {
           35  +      select * from t1 left outer join t2 on t1.a=t2.x where t2.z='ok'
           36  +    }
           37  +  } {2 two 2 niban ok}
           38  +} else {
           39  +  do_test join4-1.1 {
           40  +    execsql {
           41  +      create table t1(a integer, b varchar(10));
           42  +      insert into t1 values(1,'one');
           43  +      insert into t1 values(2,'two');
           44  +      insert into t1 values(3,'three');
           45  +      insert into t1 values(4,'four');
           46  +  
           47  +      create table t2(x integer, y varchar(10), z varchar(10));
           48  +      insert into t2 values(2,'niban','ok');
           49  +      insert into t2 values(4,'yonban','err');
           50  +    }
           51  +    execsql {
           52  +      select * from t1 left outer join t2 on t1.a=t2.x where t2.z='ok'
           53  +    }
           54  +  } {2 two 2 niban ok}
           55  +}
    37     56   do_test join4-1.2 {
    38     57     execsql {
    39     58       select * from t1 left outer join t2 on t1.a=t2.x and t2.z='ok'
    40     59     }
    41     60   } {1 one {} {} {} 2 two 2 niban ok 3 three {} {} {} 4 four {} {} {}}
    42     61   do_test join4-1.3 {
    43     62     execsql {

Changes to test/lastinsert.test.

   279    279   } {0 1032}
   280    280   } ;# ifcapable (view && trigger)
   281    281   
   282    282   # ----------------------------------------------------------------------------
   283    283   # 7.x - complex tests with temporary tables and nested instead of triggers
   284    284   # These do not run if views or triggers are disabled.
   285    285   
   286         -ifcapable {trigger && view} {
          286  +ifcapable {trigger && view && tempdb} {
   287    287   do_test lastinsert-7.1 {
   288    288       catchsql {
   289    289           drop table t1; drop table t2; drop trigger r1;
   290    290           create temp table t1 (k integer primary key);
   291    291           create temp table t2 (k integer primary key);
   292    292           create temp view v1 as select * from t1;
   293    293           create temp view v2 as select * from t2;

Changes to test/laststmtchanges.test.

   191    191       }
   192    192   } {0 1}
   193    193   
   194    194   # ----------------------------------------------------------------------------
   195    195   # 5.x - complex tests with temporary tables and nested instead of triggers
   196    196   # These tests cannot run if the library does not have view support enabled.
   197    197   
   198         -ifcapable view {
          198  +ifcapable view&&tempdb {
   199    199   
   200    200   do_test laststmtchanges-5.1 {
   201    201       catchsql {
   202    202           drop table t0; drop table t1; drop table t2;
   203    203           create temp table t0(x);
   204    204           create temp table t1 (k integer primary key);
   205    205           create temp table t2 (k integer primary key);

Changes to test/lock.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script is database locks.
    13     13   #
    14         -# $Id: lock.test,v 1.31 2005/03/14 02:01:50 drh Exp $
           14  +# $Id: lock.test,v 1.32 2005/03/29 03:11:00 danielk1977 Exp $
    15     15   
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   # Create an alternative connection to the database
    21     21   #
................................................................................
   299    299   } {2 1}
   300    300   do_test lock-5.2 {
   301    301     db function tx_exec tx_exec
   302    302     catchsql {
   303    303       INSERT INTO t1(a,b) SELECT 3, tx_exec('SELECT y FROM t2 LIMIT 1');
   304    304     }
   305    305   } {0 {}}
   306         -do_test lock-5.3 {
   307         -  execsql {
   308         -    CREATE TEMP TABLE t3(x);
   309         -    SELECT * FROM t3;
   310         -  }
   311         -} {}
   312         -do_test lock-5.4 {
   313         -  catchsql {
   314         -    INSERT INTO t3 SELECT tx_exec('SELECT y FROM t2 LIMIT 1');
   315         -  }
   316         -} {0 {}}
   317         -do_test lock-5.5 {
   318         -  execsql {
   319         -    SELECT * FROM t3;
   320         -  }
   321         -} {8}
   322         -do_test lock-5.6 {
   323         -  catchsql {
   324         -    UPDATE t1 SET a=tx_exec('SELECT x FROM t2');
   325         -  }
   326         -} {0 {}}
   327         -do_test lock-5.7 {
   328         -  execsql {
   329         -    SELECT * FROM t1;
   330         -  }
   331         -} {9 1 9 8}
   332         -do_test lock-5.8 {
   333         -  catchsql {
   334         -    UPDATE t3 SET x=tx_exec('SELECT x FROM t2');
   335         -  }
   336         -} {0 {}}
   337         -do_test lock-5.9 {
   338         -  execsql {
   339         -    SELECT * FROM t3;
   340         -  }
   341         -} {9}
          306  +
          307  +ifcapable tempdb {
          308  +  do_test lock-5.3 {
          309  +    execsql {
          310  +      CREATE TEMP TABLE t3(x);
          311  +      SELECT * FROM t3;
          312  +    }
          313  +  } {}
          314  +  do_test lock-5.4 {
          315  +    catchsql {
          316  +      INSERT INTO t3 SELECT tx_exec('SELECT y FROM t2 LIMIT 1');
          317  +    }
          318  +  } {0 {}}
          319  +  do_test lock-5.5 {
          320  +    execsql {
          321  +      SELECT * FROM t3;
          322  +    }
          323  +  } {8}
          324  +  do_test lock-5.6 {
          325  +    catchsql {
          326  +      UPDATE t1 SET a=tx_exec('SELECT x FROM t2');
          327  +    }
          328  +  } {0 {}}
          329  +  do_test lock-5.7 {
          330  +    execsql {
          331  +      SELECT * FROM t1;
          332  +    }
          333  +  } {9 1 9 8}
          334  +  do_test lock-5.8 {
          335  +    catchsql {
          336  +      UPDATE t3 SET x=tx_exec('SELECT x FROM t2');
          337  +    }
          338  +  } {0 {}}
          339  +  do_test lock-5.9 {
          340  +    execsql {
          341  +      SELECT * FROM t3;
          342  +    }
          343  +  } {9}
          344  +}
   342    345   
   343    346   do_test lock-999.1 {
   344    347     rename db2 {}
   345    348   } {}
   346    349   
   347    350   finish_test

Changes to test/malloc2.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file attempts to check that the library can recover from a malloc()
    12     12   # failure when sqlite3_global_recover() is invoked.
    13     13   #
    14         -# $Id: malloc2.test,v 1.1 2005/03/21 04:04:03 danielk1977 Exp $
           14  +# $Id: malloc2.test,v 1.2 2005/03/29 03:11:00 danielk1977 Exp $
    15     15   
    16     16   set testdir [file dirname $argv0]
    17     17   source $testdir/tester.tcl
    18     18   
    19     19   # Only run these tests if memory debugging is turned on.
    20     20   #
    21     21   if {[info command sqlite_malloc_stat]==""} {
................................................................................
    31     31   
    32     32   # Generate a checksum based on the contents of the database. If the
    33     33   # checksum of two databases is the same, and the integrity-check passes
    34     34   # for both, the two databases are identical.
    35     35   #
    36     36   proc cksum {db} {
    37     37     set ret [list]
    38         -  set sql {
    39         -    SELECT name FROM sqlite_master WHERE type = 'table' UNION
    40         -    SELECT name FROM sqlite_temp_master WHERE type = 'table' UNION
    41         -    SELECT 'sqlite_master' UNION
    42         -    SELECT 'sqlite_temp_master'
           38  +  ifcapable tempdb {
           39  +    set sql {
           40  +      SELECT name FROM sqlite_master WHERE type = 'table' UNION
           41  +      SELECT name FROM sqlite_temp_master WHERE type = 'table' UNION
           42  +      SELECT 'sqlite_master' UNION
           43  +      SELECT 'sqlite_temp_master'
           44  +    }
           45  +  } else {
           46  +    set sql {
           47  +      SELECT name FROM sqlite_master WHERE type = 'table' UNION
           48  +      SELECT 'sqlite_master'
           49  +    }
    43     50     }
    44     51     foreach tbl [$db eval $sql] {
    45     52       set cols [list]
    46     53       $db eval "PRAGMA table_info($tbl)" {
    47     54         lappend cols $name
    48     55       }
    49     56       set sql "SELECT md5sum([join $cols ,]) FROM $tbl"
................................................................................
   167    174     DROP TABLE def2;
   168    175   
   169    176     DELETE FROM def WHERE (oid%9)==2;
   170    177     INSERT INTO def SELECT * FROM def WHERE (oid%13)==2;
   171    178     COMMIT;
   172    179   }
   173    180   
   174         -do_test malloc2.3.setup {
   175         -  execsql {
   176         -    CREATE TEMP TABLE ghi(a, b, c);
   177         -    BEGIN;
   178         -  }
   179         -  for {set i 0} {$i<20} {incr i} {
          181  +ifcapable tempdb {
          182  +  do_test malloc2.3.setup {
          183  +    execsql {
          184  +      CREATE TEMP TABLE ghi(a, b, c);
          185  +      BEGIN;
          186  +    }
          187  +    for {set i 0} {$i<20} {incr i} {
          188  +      execsql {
          189  +      INSERT INTO ghi VALUES(randstr(300,300),randstr(300,300),randstr(300,300));
          190  +      }
          191  +    }
   180    192       execsql {
   181         -    INSERT INTO ghi VALUES(randstr(300,300),randstr(300,300),randstr(300,300));
          193  +      COMMIT;
   182    194       }
   183         -  }
   184         -  execsql {
          195  +  } {}
          196  +  do_malloc2_test 3 -sql {
          197  +    BEGIN;
          198  +    CREATE INDEX ghi_i1 ON ghi(a);
          199  +    UPDATE def SET a = randstr(100,100) WHERE (oid%2)==0;
          200  +    UPDATE ghi SET a = randstr(100,100) WHERE (oid%2)==0;
   185    201       COMMIT;
   186    202     }
   187         -} {}
   188         -do_malloc2_test 3 -sql {
   189         -  BEGIN;
   190         -  CREATE INDEX ghi_i1 ON ghi(a);
   191         -  UPDATE def SET a = randstr(100,100) WHERE (oid%2)==0;
   192         -  UPDATE ghi SET a = randstr(100,100) WHERE (oid%2)==0;
   193         -  COMMIT;
   194    203   }
   195    204   
   196    205   ############################################################################
   197    206   # The test cases below are to increase the code coverage in btree.c and 
   198    207   # pager.c of this test file. The idea is that each malloc() that occurs in
   199    208   # these two source files should be made to fail at least once.
   200    209   #

Changes to test/misc1.test.

     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.
    12     12   #
    13     13   # This file implements tests for miscellanous features that were
    14     14   # left out of other test files.
    15     15   #
    16         -# $Id: misc1.test,v 1.33 2005/01/21 04:25:47 danielk1977 Exp $
           16  +# $Id: misc1.test,v 1.34 2005/03/29 03:11:00 danielk1977 Exp $
    17     17   
    18     18   set testdir [file dirname $argv0]
    19     19   source $testdir/tester.tcl
    20     20   
    21     21   # Mimic the SQLite 2 collation type NUMERIC.
    22     22   db collate numeric numeric_collate
    23     23   proc numeric_collate {lhs rhs} {
................................................................................
   536    536   do_test misc1-16.6 {
   537    537     execsql {
   538    538       INSERT INTO test VALUES(NULL);
   539    539       SELECT rowid, a FROM test;
   540    540     }
   541    541   } {1 1 5 5 6 6}
   542    542   
   543         -ifcapable {trigger} {
          543  +ifcapable trigger&&tempdb {
   544    544   # Ticket #333: Temp triggers that modify persistent tables.
   545    545   #
   546    546   do_test misc1-17.1 {
   547    547     execsql {
   548    548       BEGIN;
   549    549       CREATE TABLE RealTable(TestID INTEGER PRIMARY KEY, TestString TEXT);
   550    550       CREATE TEMP TABLE TempTable(TestID INTEGER PRIMARY KEY, TestString TEXT);

Changes to test/misc2.test.

     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.
    12     12   #
    13     13   # This file implements tests for miscellanous features that were
    14     14   # left out of other test files.
    15     15   #
    16         -# $Id: misc2.test,v 1.20 2005/01/21 04:25:47 danielk1977 Exp $
           16  +# $Id: misc2.test,v 1.21 2005/03/29 03:11:00 danielk1977 Exp $
    17     17   
    18     18   set testdir [file dirname $argv0]
    19     19   source $testdir/tester.tcl
    20     20   
    21     21   ifcapable {trigger} {
    22     22   # Test for ticket #360
    23     23   #
................................................................................
   202    202   #
   203    203   do_test misc2-8.1 {
   204    204     catchsql {-}
   205    205   } {1 {near "-": syntax error}}
   206    206   
   207    207   # Ticket #513.  Make sure the VDBE stack does not grow on a 3-way join.
   208    208   #
   209         -do_test misc2-9.1 {
   210         -  execsql {
   211         -    BEGIN;
   212         -    CREATE TABLE counts(n INTEGER PRIMARY KEY);
   213         -    INSERT INTO counts VALUES(0);
   214         -    INSERT INTO counts VALUES(1);
   215         -    INSERT INTO counts SELECT n+2 FROM counts;
   216         -    INSERT INTO counts SELECT n+4 FROM counts;
   217         -    INSERT INTO counts SELECT n+8 FROM counts;
   218         -    COMMIT;
   219         -
   220         -    CREATE TEMP TABLE x AS
   221         -    SELECT dim1.n, dim2.n, dim3.n
   222         -    FROM counts AS dim1, counts AS dim2, counts AS dim3
   223         -    WHERE dim1.n<10 AND dim2.n<10 AND dim3.n<10;
   224         -
   225         -    SELECT count(*) FROM x;
   226         -  }
   227         -} {1000}
   228         -do_test misc2-9.2 {
   229         -  execsql {
   230         -    DROP TABLE x;
   231         -    CREATE TEMP TABLE x AS
   232         -    SELECT dim1.n, dim2.n, dim3.n
   233         -    FROM counts AS dim1, counts AS dim2, counts AS dim3
   234         -    WHERE dim1.n>=6 AND dim2.n>=6 AND dim3.n>=6;
   235         -
   236         -    SELECT count(*) FROM x;
   237         -  }
   238         -} {1000}
   239         -do_test misc2-9.3 {
   240         -  execsql {
   241         -    DROP TABLE x;
   242         -    CREATE TEMP TABLE x AS
   243         -    SELECT dim1.n, dim2.n, dim3.n, dim4.n
   244         -    FROM counts AS dim1, counts AS dim2, counts AS dim3, counts AS dim4
   245         -    WHERE dim1.n<5 AND dim2.n<5 AND dim3.n<5 AND dim4.n<5;
   246         -
   247         -    SELECT count(*) FROM x;
   248         -  }
   249         -} [expr 5*5*5*5]
          209  +ifcapable tempdb {
          210  +  do_test misc2-9.1 {
          211  +    execsql {
          212  +      BEGIN;
          213  +      CREATE TABLE counts(n INTEGER PRIMARY KEY);
          214  +      INSERT INTO counts VALUES(0);
          215  +      INSERT INTO counts VALUES(1);
          216  +      INSERT INTO counts SELECT n+2 FROM counts;
          217  +      INSERT INTO counts SELECT n+4 FROM counts;
          218  +      INSERT INTO counts SELECT n+8 FROM counts;
          219  +      COMMIT;
          220  +  
          221  +      CREATE TEMP TABLE x AS
          222  +      SELECT dim1.n, dim2.n, dim3.n
          223  +      FROM counts AS dim1, counts AS dim2, counts AS dim3
          224  +      WHERE dim1.n<10 AND dim2.n<10 AND dim3.n<10;
          225  +  
          226  +      SELECT count(*) FROM x;
          227  +    }
          228  +  } {1000}
          229  +  do_test misc2-9.2 {
          230  +    execsql {
          231  +      DROP TABLE x;
          232  +      CREATE TEMP TABLE x AS
          233  +      SELECT dim1.n, dim2.n, dim3.n
          234  +      FROM counts AS dim1, counts AS dim2, counts AS dim3
          235  +      WHERE dim1.n>=6 AND dim2.n>=6 AND dim3.n>=6;
          236  +  
          237  +      SELECT count(*) FROM x;
          238  +    }
          239  +  } {1000}
          240  +  do_test misc2-9.3 {
          241  +    execsql {
          242  +      DROP TABLE x;
          243  +      CREATE TEMP TABLE x AS
          244  +      SELECT dim1.n, dim2.n, dim3.n, dim4.n
          245  +      FROM counts AS dim1, counts AS dim2, counts AS dim3, counts AS dim4
          246  +      WHERE dim1.n<5 AND dim2.n<5 AND dim3.n<5 AND dim4.n<5;
          247  +  
          248  +      SELECT count(*) FROM x;
          249  +    }
          250  +  } [expr 5*5*5*5]
          251  +}
   250    252   
   251    253   finish_test

Changes to test/misc4.test.

     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.
    12     12   #
    13     13   # This file implements tests for miscellanous features that were
    14     14   # left out of other test files.
    15     15   #
    16         -# $Id: misc4.test,v 1.15 2005/01/30 09:17:59 danielk1977 Exp $
           16  +# $Id: misc4.test,v 1.16 2005/03/29 03:11:00 danielk1977 Exp $
    17     17   
    18     18   set testdir [file dirname $argv0]
    19     19   source $testdir/tester.tcl
    20     20   
    21     21   # Prepare a statement that will create a temporary table.  Then do
    22     22   # a rollback.  Then try to execute the prepared statement.
    23     23   #
................................................................................
    25     25     db close
    26     26     set DB [sqlite3 db test.db]
    27     27     execsql {
    28     28       CREATE TABLE t1(x);
    29     29       INSERT INTO t1 VALUES(1);
    30     30     }
    31     31   } {}
    32         -do_test misc4-1.2 {
    33         -  set sql {CREATE TEMP TABLE t2 AS SELECT * FROM t1}
    34         -  set stmt [sqlite3_prepare $DB $sql -1 TAIL]
    35         -  execsql {
    36         -    BEGIN;
    37         -    CREATE TABLE t3(a,b,c);
    38         -    INSERT INTO t1 SELECT * FROM t1;
    39         -    ROLLBACK;
    40         -  }
    41         -} {}
    42         -do_test misc4-1.3 {
    43         -  sqlite3_step $stmt
    44         -} SQLITE_DONE
    45         -do_test misc4-1.4 {
    46         -  execsql {
    47         -    SELECT * FROM temp.t2;
    48         -  }
    49         -} {1}
    50     32   
    51         -# Drop the temporary table, then rerun the prepared  statement to
    52         -# recreate it again.  This recreates ticket #807.
    53         -#
    54         -do_test misc4-1.5 {
    55         -  execsql {DROP TABLE t2}
    56         -  sqlite3_reset $stmt
    57         -  sqlite3_step $stmt
    58         -} {SQLITE_ERROR}
    59         -do_test misc4-1.6 {
    60         -  sqlite3_finalize $stmt
    61         -} {SQLITE_SCHEMA}
           33  +ifcapable tempdb {
           34  +  do_test misc4-1.2 {
           35  +    set sql {CREATE TEMP TABLE t2 AS SELECT * FROM t1}
           36  +    set stmt [sqlite3_prepare $DB $sql -1 TAIL]
           37  +    execsql {
           38  +      BEGIN;
           39  +      CREATE TABLE t3(a,b,c);
           40  +      INSERT INTO t1 SELECT * FROM t1;
           41  +      ROLLBACK;
           42  +    }
           43  +  } {}
           44  +  do_test misc4-1.3 {
           45  +    sqlite3_step $stmt
           46  +  } SQLITE_DONE
           47  +  do_test misc4-1.4 {
           48  +    execsql {
           49  +      SELECT * FROM temp.t2;
           50  +    }
           51  +  } {1}
           52  +  
           53  +  # Drop the temporary table, then rerun the prepared  statement to
           54  +  # recreate it again.  This recreates ticket #807.
           55  +  #
           56  +  do_test misc4-1.5 {
           57  +    execsql {DROP TABLE t2}
           58  +    sqlite3_reset $stmt
           59  +    sqlite3_step $stmt
           60  +  } {SQLITE_ERROR}
           61  +  do_test misc4-1.6 {
           62  +    sqlite3_finalize $stmt
           63  +  } {SQLITE_SCHEMA}
           64  +}
    62     65   
    63     66   # Prepare but do not execute various CREATE statements.  Then before
    64     67   # those statements are executed, try to use the tables, indices, views,
    65     68   # are triggers that were created.
    66     69   #
    67     70   do_test misc4-2.1 {
    68     71     set stmt [sqlite3_prepare $DB {CREATE TABLE t3(x);} -1 TAIL]

Changes to test/pager3.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script is page cache subsystem.
    13     13   #
    14         -# $Id: pager3.test,v 1.2 2004/11/04 14:47:13 drh Exp $
           14  +# $Id: pager3.test,v 1.3 2005/03/29 03:11:00 danielk1977 Exp $
    15     15   
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   # This test makes sure the database file is truncated back to the correct
    21     21   # length on a rollback.
................................................................................
    32     32   # written so the file is actually lengthened by this truncate.  Finally,
    33     33   # the rollback at NOTE (3) is called to undo all the changes since the
    34     34   # begin.  This rollback should truncate the database again.
    35     35   # 
    36     36   # This test was added because the second truncate at NOTE (3) was not
    37     37   # occurring on early versions of SQLite 3.0.
    38     38   #
    39         -do_test pager3-1.1 {
    40         -  execsql {
    41         -    create table t1(a unique, b);
    42         -    insert into t1 values(1, 'abcdefghijklmnopqrstuvwxyz');
    43         -    insert into t1 values(2, 'abcdefghijklmnopqrstuvwxyz');
    44         -    update t1 set b=b||a||b;
    45         -    update t1 set b=b||a||b;
    46         -    update t1 set b=b||a||b;
    47         -    update t1 set b=b||a||b;
    48         -    update t1 set b=b||a||b;
    49         -    update t1 set b=b||a||b;
    50         -    create temp table t2 as select * from t1;
    51         -    begin;                  ------- NOTE (1)
    52         -    create table t3(x);
    53         -  }
    54         -  catchsql {
    55         -    insert into t1 select 4-a, b from t2;  ----- NOTE (2)
    56         -  }
    57         -  execsql {
    58         -    rollback;  ------- NOTE (3)
    59         -  }
    60         -  db close
    61         -  sqlite3 db test.db
    62         -  set r ok
    63         -  ifcapable {integrityck} {
    64         -    set r [execsql {
    65         -      pragma integrity_check;
    66         -    }]
    67         -  }
    68         -  set r
    69         -} ok
           39  +ifcapable tempdb {
           40  +  do_test pager3-1.1 {
           41  +    execsql {
           42  +      create table t1(a unique, b);
           43  +      insert into t1 values(1, 'abcdefghijklmnopqrstuvwxyz');
           44  +      insert into t1 values(2, 'abcdefghijklmnopqrstuvwxyz');
           45  +      update t1 set b=b||a||b;
           46  +      update t1 set b=b||a||b;
           47  +      update t1 set b=b||a||b;
           48  +      update t1 set b=b||a||b;
           49  +      update t1 set b=b||a||b;
           50  +      update t1 set b=b||a||b;
           51  +      create temp table t2 as select * from t1;
           52  +      begin;                  ------- NOTE (1)
           53  +      create table t3(x);
           54  +    }
           55  +    catchsql {
           56  +      insert into t1 select 4-a, b from t2;  ----- NOTE (2)
           57  +    }
           58  +    execsql {
           59  +      rollback;  ------- NOTE (3)
           60  +    }
           61  +    db close
           62  +    sqlite3 db test.db
           63  +    set r ok
           64  +    ifcapable {integrityck} {
           65  +      set r [execsql {
           66  +        pragma integrity_check;
           67  +      }]
           68  +    }
           69  +    set r
           70  +  } ok
           71  +}
    70     72   
    71     73   finish_test

Changes to test/pragma.test.

     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.
    12     12   #
    13     13   # This file implements tests for the PRAGMA command.
    14     14   #
    15         -# $Id: pragma.test,v 1.34 2005/02/13 23:34:25 drh Exp $
           15  +# $Id: pragma.test,v 1.35 2005/03/29 03:11:00 danielk1977 Exp $
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   # Test organization:
    21     21   #
    22     22   # pragma-1.*: Test cache_size, default_cache_size and synchronous on main db.
................................................................................
   326    326   } {2}
   327    327   catchsql {COMMIT;}
   328    328   } ;# ifcapable pager_pragmas
   329    329   
   330    330   # Test schema-query pragmas
   331    331   #
   332    332   ifcapable schema_pragmas {
   333         -do_test pragma-6.1 {
   334         -  set res {}
   335         -  execsql {SELECT * FROM sqlite_temp_master}
   336         -  foreach {idx name file} [execsql {pragma database_list}] {
   337         -    lappend res $idx $name
   338         -  }
   339         -  set res
   340         -} {0 main 1 temp 2 aux}
          333  +ifcapable tempdb {
          334  +  do_test pragma-6.1 {
          335  +    set res {}
          336  +    execsql {SELECT * FROM sqlite_temp_master}
          337  +    foreach {idx name file} [execsql {pragma database_list}] {
          338  +      lappend res $idx $name
          339  +    }
          340  +    set res
          341  +  } {0 main 1 temp 2 aux}
          342  +}
   341    343   do_test pragma-6.2 {
   342    344     execsql {
   343    345       pragma table_info(t2)
   344    346     }
   345    347   } {0 a numeric 0 {} 0 1 b numeric 0 {} 0 2 c numeric 0 {} 0}
   346    348   ifcapable {foreignkey} {
   347    349     do_test pragma-6.3 {
................................................................................
   383    385       db close
   384    386       sqlite3 db test.db
   385    387       catchsql {
   386    388         pragma encoding=bogus;
   387    389       }
   388    390     } {1 {unsupported encoding: bogus}}
   389    391   }
   390         -do_test pragma-7.3 {
   391         -  db close
   392         -  sqlite3 db test.db
   393         -  execsql {
   394         -    pragma lock_status;
   395         -  }
   396         -} {main unlocked temp closed}
          392  +ifcapable tempdb {
          393  +  do_test pragma-7.3 {
          394  +    db close
          395  +    sqlite3 db test.db
          396  +    execsql {
          397  +      pragma lock_status;
          398  +    }
          399  +  } {main unlocked temp closed}
          400  +} else {
          401  +  do_test pragma-7.3 {
          402  +    db close
          403  +    sqlite3 db test.db
          404  +    execsql {
          405  +      pragma lock_status;
          406  +    }
          407  +  } {main unlocked}
          408  +}
   397    409   
   398    410   
   399    411   #----------------------------------------------------------------------
   400    412   # Test cases pragma-8.* test the "PRAGMA schema_version" and "PRAGMA
   401    413   # user_version" statements.
   402    414   #
   403    415   # pragma-8.1: PRAGMA schema_version
................................................................................
   669    681     }
   670    682   } {1 {not a writable directory}}
   671    683   do_test pragma-9.8 {
   672    684     execsql { 
   673    685       PRAGMA temp_store_directory='';
   674    686     }
   675    687   } {}
   676         -do_test pragma-9.9 {
   677         -  execsql { 
   678         -    PRAGMA temp_store_directory;
   679         -    PRAGMA temp_store=FILE;
   680         -    CREATE TEMP TABLE temp_store_directory_test(a integer);
   681         -    INSERT INTO temp_store_directory_test values (2);
   682         -    SELECT * FROM temp_store_directory_test;
   683         -  }
   684         -} {2}
          688  +ifcapable tempdb {
          689  +  do_test pragma-9.9 {
          690  +    execsql { 
          691  +      PRAGMA temp_store_directory;
          692  +      PRAGMA temp_store=FILE;
          693  +      CREATE TEMP TABLE temp_store_directory_test(a integer);
          694  +      INSERT INTO temp_store_directory_test values (2);
          695  +      SELECT * FROM temp_store_directory_test;
          696  +    }
          697  +  } {2}
          698  +}
   685    699   do_test pragma-9.10 {
   686    700     catchsql "
   687    701       PRAGMA temp_store_directory='$pwd';
   688    702       SELECT * FROM temp_store_directory_test;
   689    703     "
   690    704   } {1 {no such table: temp_store_directory_test}}
   691    705   } ;# ifcapable pager_pragmas

Changes to test/quick.test.

     6      6   #    May you do good and not evil.
     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file runs all tests.
    12     12   #
    13         -# $Id: quick.test,v 1.34 2005/03/21 04:04:03 danielk1977 Exp $
           13  +# $Id: quick.test,v 1.35 2005/03/29 03:11:00 danielk1977 Exp $
    14     14   
    15     15   set testdir [file dirname $argv0]
    16     16   source $testdir/tester.tcl
    17     17   rename finish_test really_finish_test
    18     18   proc finish_test {} {}
    19     19   set ISQUICK 1
    20     20   
    21     21   set EXCLUDE {
           22  +  alter.test
    22     23     all.test
    23     24     btree2.test
    24     25     btree3.test
    25     26     btree4.test
    26     27     btree5.test
    27     28     btree6.test
    28     29     corrupt.test

Changes to test/select7.test.

     6      6   #    May you share freely, never taking more than you give.
     7      7   #
     8      8   #***********************************************************************
     9      9   # This file implements regression tests for SQLite library.  The
    10     10   # focus of this file is testing compute SELECT statements and nested
    11     11   # views.
    12     12   #
    13         -# $Id: select7.test,v 1.6 2005/01/26 03:58:37 danielk1977 Exp $
           13  +# $Id: select7.test,v 1.7 2005/03/29 03:11:00 danielk1977 Exp $
    14     14   
    15     15   
    16     16   set testdir [file dirname $argv0]
    17     17   source $testdir/tester.tcl
    18     18   
    19     19   ifcapable compound {
    20     20   
    21     21   # A 3-way INTERSECT.  Ticket #875
    22         -do_test select7-1.1 {
    23         -  execsql {
    24         -    create temp table t1(x);
    25         -    insert into t1 values('amx');
    26         -    insert into t1 values('anx');
    27         -    insert into t1 values('amy');
    28         -    insert into t1 values('bmy');
    29         -    select * from t1 where x like 'a__'
    30         -      intersect select * from t1 where x like '_m_'
    31         -      intersect select * from t1 where x like '__x';
    32         -  }
    33         -} {amx}
           22  +ifcapable tempdb {
           23  +  do_test select7-1.1 {
           24  +    execsql {
           25  +      create temp table t1(x);
           26  +      insert into t1 values('amx');
           27  +      insert into t1 values('anx');
           28  +      insert into t1 values('amy');
           29  +      insert into t1 values('bmy');
           30  +      select * from t1 where x like 'a__'
           31  +        intersect select * from t1 where x like '_m_'
           32  +        intersect select * from t1 where x like '__x';
           33  +    }
           34  +  } {amx}
           35  +}
    34     36   
    35     37   
    36     38   # Nested views do not handle * properly.  Ticket #826.
    37     39   #
    38     40   ifcapable view {
    39     41   do_test select7-2.1 {
    40     42     execsql {

Changes to test/table.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this file is testing the CREATE TABLE statement.
    13     13   #
    14         -# $Id: table.test,v 1.38 2005/01/24 10:26:00 danielk1977 Exp $
           14  +# $Id: table.test,v 1.39 2005/03/29 03:11:00 danielk1977 Exp $
    15     15   
    16     16   set testdir [file dirname $argv0]
    17     17   source $testdir/tester.tcl
    18     18   
    19     19   # Create a basic table and verify it is added to sqlite_master
    20     20   #
    21     21   do_test table-1.1 {
................................................................................
   345    345   # NULL pointer, so the created table has no column types. (Changed result
   346    346   # from {{CREATE TABLE 't4"abc'(cnt NUMERIC,"max(b+c)" NUMERIC)}}).
   347    347   do_test table-8.3.1 {
   348    348     execsql {
   349    349       SELECT sql FROM sqlite_master WHERE name='t4"abc'
   350    350     }
   351    351   } {{CREATE TABLE "t4""abc"(cnt,"max(b+c)")}}
   352         -do_test table-8.4 {
   353         -  execsql2 {
   354         -    CREATE TEMPORARY TABLE t5 AS SELECT count(*) AS [y'all] FROM [t3"xyz];
   355         -    SELECT * FROM t5;
   356         -  }
   357         -} {y'all 1}
          352  +
          353  +ifcapable tempdb {
          354  +  do_test table-8.4 {
          355  +    execsql2 {
          356  +      CREATE TEMPORARY TABLE t5 AS SELECT count(*) AS [y'all] FROM [t3"xyz];
          357  +      SELECT * FROM t5;
          358  +    }
          359  +  } {y'all 1}
          360  +}
          361  +
   358    362   do_test table-8.5 {
   359    363     db close
   360    364     sqlite3 db test.db
   361    365     execsql2 {
   362    366       SELECT * FROM [t4"abc];
   363    367     }
   364    368   } {cnt 1 max(b+c) 5}

Changes to test/temptable.test.

     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.
    12     12   #
    13     13   # This file implements tests for temporary tables and indices.
    14     14   #
    15         -# $Id: temptable.test,v 1.14 2004/06/19 00:16:31 drh Exp $
           15  +# $Id: temptable.test,v 1.15 2005/03/29 03:11:00 danielk1977 Exp $
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
           19  +
           20  +ifcapable !tempdb {
           21  +  finish_test
           22  +  return
           23  +}
    19     24   
    20     25   # Create an alternative connection to the database
    21     26   #
    22     27   do_test temptable-1.0 {
    23     28     sqlite3 db2 ./test.db
    24     29     set dummy {}
    25     30   } {}

Changes to test/trans.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script is database locks.
    13     13   #
    14         -# $Id: trans.test,v 1.25 2005/03/11 04:41:40 drh Exp $
           14  +# $Id: trans.test,v 1.26 2005/03/29 03:11:00 danielk1977 Exp $
    15     15   
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   
    21     21   # Create several tables to work with.
................................................................................
   724    724       ROLLBACK;
   725    725       SELECT md5sum(x,y,z) FROM t2;
   726    726     }
   727    727   } $checksum
   728    728   do_test trans-7.8 {
   729    729     execsql {SELECT md5sum(type,name,tbl_name,rootpage,sql) FROM sqlite_master}
   730    730   } $checksum2
   731         -do_test trans-7.9 {
   732         -  execsql {
   733         -    BEGIN;
   734         -    CREATE TEMP TABLE t3 AS SELECT * FROM t2;
   735         -    INSERT INTO t2 SELECT * FROM t3;
   736         -    ROLLBACK;
   737         -    SELECT md5sum(x,y,z) FROM t2;
   738         -  }
   739         -} $checksum
          731  +ifcapable tempdb {
          732  +  do_test trans-7.9 {
          733  +    execsql {
          734  +      BEGIN;
          735  +      CREATE TEMP TABLE t3 AS SELECT * FROM t2;
          736  +      INSERT INTO t2 SELECT * FROM t3;
          737  +      ROLLBACK;
          738  +      SELECT md5sum(x,y,z) FROM t2;
          739  +    }
          740  +  } $checksum
          741  +}
   740    742   do_test trans-7.10 {
   741    743     execsql {SELECT md5sum(type,name,tbl_name,rootpage,sql) FROM sqlite_master}
   742    744   } $checksum2
   743         -do_test trans-7.11 {
   744         -  execsql {
   745         -    BEGIN;
   746         -    CREATE TEMP TABLE t3 AS SELECT * FROM t2;
   747         -    INSERT INTO t2 SELECT * FROM t3;
   748         -    DROP INDEX i2x;
   749         -    DROP INDEX i2y;
   750         -    CREATE INDEX i3a ON t3(x);
   751         -    ROLLBACK;
   752         -    SELECT md5sum(x,y,z) FROM t2;
   753         -  }
   754         -} $checksum
          745  +ifcapable tempdb {
          746  +  do_test trans-7.11 {
          747  +    execsql {
          748  +      BEGIN;
          749  +      CREATE TEMP TABLE t3 AS SELECT * FROM t2;
          750  +      INSERT INTO t2 SELECT * FROM t3;
          751  +      DROP INDEX i2x;
          752  +      DROP INDEX i2y;
          753  +      CREATE INDEX i3a ON t3(x);
          754  +      ROLLBACK;
          755  +      SELECT md5sum(x,y,z) FROM t2;
          756  +    }
          757  +  } $checksum
          758  +}
   755    759   do_test trans-7.12 {
   756    760     execsql {SELECT md5sum(type,name,tbl_name,rootpage,sql) FROM sqlite_master}
   757    761   } $checksum2
   758         -do_test trans-7.13 {
   759         -  execsql {
   760         -    BEGIN;
   761         -    DROP TABLE t2;
   762         -    ROLLBACK;
   763         -    SELECT md5sum(x,y,z) FROM t2;
   764         -  }
   765         -} $checksum
          762  +ifcapable tempdb {
          763  +  do_test trans-7.13 {
          764  +    execsql {
          765  +      BEGIN;
          766  +      DROP TABLE t2;
          767  +      ROLLBACK;
          768  +      SELECT md5sum(x,y,z) FROM t2;
          769  +    }
          770  +  } $checksum
          771  +}
   766    772   do_test trans-7.14 {
   767    773     execsql {SELECT md5sum(type,name,tbl_name,rootpage,sql) FROM sqlite_master}
   768    774   } $checksum2
   769    775   integrity_check trans-7.15
   770    776   
   771    777   # Arrange for another process to begin modifying the database but abort
   772    778   # and die in the middle of the modification.  Then have this process read

Changes to test/trigger1.test.

    37     37   do_test trigger1-1.1.1 {
    38     38      catchsql {
    39     39        CREATE TRIGGER trig UPDATE ON no_such_table BEGIN
    40     40          SELECT * from sqlite_master;
    41     41        END;
    42     42      } 
    43     43   } {1 {no such table: main.no_such_table}}
    44         -do_test trigger1-1.1.2 {
    45         -   catchsql {
    46         -     CREATE TEMP TRIGGER trig UPDATE ON no_such_table BEGIN
    47         -       SELECT * from sqlite_master;
    48         -     END;
    49         -   } 
    50         -} {1 {no such table: no_such_table}}
           44  +
           45  +ifcapable tempdb {
           46  +  do_test trigger1-1.1.2 {
           47  +     catchsql {
           48  +       CREATE TEMP TRIGGER trig UPDATE ON no_such_table BEGIN
           49  +         SELECT * from sqlite_master;
           50  +       END;
           51  +     } 
           52  +  } {1 {no such table: no_such_table}}
           53  +}
    51     54   
    52     55   execsql {
    53     56       CREATE TABLE t1(a);
    54     57   }
    55     58   execsql {
    56     59   	CREATE TRIGGER tr1 INSERT ON t1 BEGIN
    57     60   	  INSERT INTO t1 values(1);
................................................................................
   103    106   do_test trigger1-1.7 {
   104    107       catchsql {
   105    108   	DROP TABLE t1;
   106    109   	DROP TRIGGER tr1;
   107    110       }
   108    111   } {1 {no such trigger: tr1}}
   109    112   
   110         -execsql {
   111         -  CREATE TEMP TABLE temp_table(a);
          113  +ifcapable tempdb {
          114  +  execsql {
          115  +    CREATE TEMP TABLE temp_table(a);
          116  +  }
          117  +  do_test trigger1-1.8 {
          118  +    execsql {
          119  +  	CREATE TRIGGER temp_trig UPDATE ON temp_table BEGIN
          120  +  	    SELECT * from sqlite_master;
          121  +  	END;
          122  +  	SELECT count(*) FROM sqlite_master WHERE name = 'temp_trig';
          123  +    } 
          124  +  } {0}
   112    125   }
   113         -do_test trigger1-1.8 {
   114         -  execsql {
   115         -	CREATE TRIGGER temp_trig UPDATE ON temp_table BEGIN
   116         -	    SELECT * from sqlite_master;
   117         -	END;
   118         -	SELECT count(*) FROM sqlite_master WHERE name = 'temp_trig';
   119         -  } 
   120         -} {0}
   121    126   
   122    127   do_test trigger1-1.9 {
   123    128     catchsql {
   124    129       CREATE TRIGGER tr1 AFTER UPDATE ON sqlite_master BEGIN
   125    130          SELECT * FROM sqlite_master;
   126    131       END;
   127    132     }
................................................................................
   211    216         SELECT * FROM;  -- Syntax error
   212    217       END;
   213    218     }
   214    219   } {1 {near ";": syntax error}}
   215    220   
   216    221   # Create a trigger that refers to a table that might not exist.
   217    222   #
   218         -do_test trigger1-3.1 {
   219         -  execsql {
   220         -    CREATE TEMP TABLE t2(x,y);
   221         -  }
   222         -  catchsql {
   223         -    CREATE TRIGGER r1 AFTER INSERT ON t1 BEGIN
   224         -      INSERT INTO t2 VALUES(NEW.a,NEW.b);
   225         -    END;
   226         -  }
   227         -} {0 {}}
   228         -do_test trigger-3.2 {
   229         -  catchsql {
   230         -    INSERT INTO t1 VALUES(1,2);
   231         -    SELECT * FROM t2;
   232         -  }
   233         -} {1 {no such table: main.t2}}
   234         -do_test trigger-3.3 {
   235         -  db close
   236         -  set rc [catch {sqlite3 db test.db} err]
   237         -  if {$rc} {lappend rc $err}
   238         -  set rc
   239         -} {0}
   240         -do_test trigger-3.4 {
   241         -  catchsql {
   242         -    INSERT INTO t1 VALUES(1,2);
   243         -    SELECT * FROM t2;
   244         -  }
   245         -} {1 {no such table: main.t2}}
   246         -do_test trigger-3.5 {
   247         -  catchsql {
   248         -    CREATE TEMP TABLE t2(x,y);
   249         -    INSERT INTO t1 VALUES(1,2);
   250         -    SELECT * FROM t2;
   251         -  }
   252         -} {1 {no such table: main.t2}}
   253         -do_test trigger-3.6 {
   254         -  catchsql {
   255         -    DROP TRIGGER r1;
   256         -    CREATE TEMP TRIGGER r1 AFTER INSERT ON t1 BEGIN
   257         -      INSERT INTO t2 VALUES(NEW.a,NEW.b);
   258         -    END;
   259         -    INSERT INTO t1 VALUES(1,2);
   260         -    SELECT * FROM t2;
   261         -  }
   262         -} {0 {1 2}}
   263         -do_test trigger-3.7 {
   264         -  execsql {
   265         -    DROP TABLE t2;
   266         -    CREATE TABLE t2(x,y);
   267         -    SELECT * FROM t2;
   268         -  }
   269         -} {}
          223  +ifcapable tempdb {
          224  +  do_test trigger1-3.1 {
          225  +    execsql {
          226  +      CREATE TEMP TABLE t2(x,y);
          227  +    }
          228  +    catchsql {
          229  +      CREATE TRIGGER r1 AFTER INSERT ON t1 BEGIN
          230  +        INSERT INTO t2 VALUES(NEW.a,NEW.b);
          231  +      END;
          232  +    }
          233  +  } {0 {}}
          234  +  do_test trigger-3.2 {
          235  +    catchsql {
          236  +      INSERT INTO t1 VALUES(1,2);
          237  +      SELECT * FROM t2;
          238  +    }
          239  +  } {1 {no such table: main.t2}}
          240  +  do_test trigger-3.3 {
          241  +    db close
          242  +    set rc [catch {sqlite3 db test.db} err]
          243  +    if {$rc} {lappend rc $err}
          244  +    set rc
          245  +  } {0}
          246  +  do_test trigger-3.4 {
          247  +    catchsql {
          248  +      INSERT INTO t1 VALUES(1,2);
          249  +      SELECT * FROM t2;
          250  +    }
          251  +  } {1 {no such table: main.t2}}
          252  +  do_test trigger-3.5 {
          253  +    catchsql {
          254  +      CREATE TEMP TABLE t2(x,y);
          255  +      INSERT INTO t1 VALUES(1,2);
          256  +      SELECT * FROM t2;
          257  +    }
          258  +  } {1 {no such table: main.t2}}
          259  +  do_test trigger-3.6 {
          260  +    catchsql {
          261  +      DROP TRIGGER r1;
          262  +      CREATE TEMP TRIGGER r1 AFTER INSERT ON t1 BEGIN
          263  +        INSERT INTO t2 VALUES(NEW.a,NEW.b);
          264  +      END;
          265  +      INSERT INTO t1 VALUES(1,2);
          266  +      SELECT * FROM t2;
          267  +    }
          268  +  } {0 {1 2}}
          269  +  do_test trigger-3.7 {
          270  +    execsql {
          271  +      DROP TABLE t2;
          272  +      CREATE TABLE t2(x,y);
          273  +      SELECT * FROM t2;
          274  +    }
          275  +  } {}
   270    276   
   271         -# There are two versions of trigger-3.8 and trigger-3.9. One that uses
   272         -# compound SELECT statements, and another that does not.
   273         -ifcapable compound {
   274         -do_test trigger-3.8 {
   275         -  execsql {
   276         -    INSERT INTO t1 VALUES(3,4);
   277         -    SELECT * FROM t1 UNION ALL SELECT * FROM t2;
   278         -  }
   279         -} {1 2 3 4 3 4}
   280         -do_test trigger-3.9 {
   281         -  db close
   282         -  sqlite3 db test.db
   283         -  execsql {
   284         -    INSERT INTO t1 VALUES(5,6);
   285         -    SELECT * FROM t1 UNION ALL SELECT * FROM t2;
   286         -  }
   287         -} {1 2 3 4 5 6 3 4}
   288         -} ;# ifcapable compound
   289         -ifcapable !compound {
   290         -do_test trigger-3.8 {
   291         -  execsql {
   292         -    INSERT INTO t1 VALUES(3,4);
   293         -    SELECT * FROM t1; 
   294         -    SELECT * FROM t2;
   295         -  }
   296         -} {1 2 3 4 3 4}
   297         -do_test trigger-3.9 {
   298         -  db close
   299         -  sqlite3 db test.db
   300         -  execsql {
   301         -    INSERT INTO t1 VALUES(5,6);
   302         -    SELECT * FROM t1;
   303         -    SELECT * FROM t2;
   304         -  }
   305         -} {1 2 3 4 5 6 3 4}
   306         -} ;# ifcapable !compound
          277  +  # There are two versions of trigger-3.8 and trigger-3.9. One that uses
          278  +  # compound SELECT statements, and another that does not.
          279  +  ifcapable compound {
          280  +  do_test trigger1-3.8 {
          281  +    execsql {
          282  +      INSERT INTO t1 VALUES(3,4);
          283  +      SELECT * FROM t1 UNION ALL SELECT * FROM t2;
          284  +    }
          285  +  } {1 2 3 4 3 4}
          286  +  do_test trigger1-3.9 {
          287  +    db close
          288  +    sqlite3 db test.db
          289  +    execsql {
          290  +      INSERT INTO t1 VALUES(5,6);
          291  +      SELECT * FROM t1 UNION ALL SELECT * FROM t2;
          292  +    }
          293  +  } {1 2 3 4 5 6 3 4}
          294  +  } ;# ifcapable compound
          295  +  ifcapable !compound {
          296  +  do_test trigger1-3.8 {
          297  +    execsql {
          298  +      INSERT INTO t1 VALUES(3,4);
          299  +      SELECT * FROM t1; 
          300  +      SELECT * FROM t2;
          301  +    }
          302  +  } {1 2 3 4 3 4}
          303  +  do_test trigger1-3.9 {
          304  +    db close
          305  +    sqlite3 db test.db
          306  +    execsql {
          307  +      INSERT INTO t1 VALUES(5,6);
          308  +      SELECT * FROM t1;
          309  +      SELECT * FROM t2;
          310  +    }
          311  +  } {1 2 3 4 5 6 3 4}
          312  +  } ;# ifcapable !compound
   307    313   
   308         -do_test trigger-4.1 {
   309         -  execsql {
   310         -    CREATE TEMP TRIGGER r1 BEFORE INSERT ON t1 BEGIN
   311         -      INSERT INTO t2 VALUES(NEW.a,NEW.b);
   312         -    END;
   313         -    INSERT INTO t1 VALUES(7,8);
   314         -    SELECT * FROM t2;
   315         -  }
   316         -} {3 4 7 8}
   317         -do_test trigger-4.2 {
   318         -  sqlite3 db2 test.db
   319         -  execsql {
   320         -    INSERT INTO t1 VALUES(9,10);
   321         -  } db2;
   322         -  db2 close
   323         -  execsql {
   324         -    SELECT * FROM t2;
   325         -  }
   326         -} {3 4 7 8}
   327         -do_test trigger-4.3 {
   328         -  execsql {
          314  +  do_test trigger1-4.1 {
          315  +    execsql {
          316  +      CREATE TEMP TRIGGER r1 BEFORE INSERT ON t1 BEGIN
          317  +        INSERT INTO t2 VALUES(NEW.a,NEW.b);
          318  +      END;
          319  +      INSERT INTO t1 VALUES(7,8);
          320  +      SELECT * FROM t2;
          321  +    }
          322  +  } {3 4 7 8}
          323  +  do_test trigger1-4.2 {
          324  +    sqlite3 db2 test.db
          325  +    execsql {
          326  +      INSERT INTO t1 VALUES(9,10);
          327  +    } db2;
          328  +    db2 close
          329  +    execsql {
          330  +      SELECT * FROM t2;
          331  +    }
          332  +  } {3 4 7 8}
          333  +  do_test trigger1-4.3 {
          334  +    execsql {
          335  +      DROP TABLE t1;
          336  +      SELECT * FROM t2;
          337  +    };
          338  +  } {3 4 7 8}
          339  +  do_test trigger1-4.4 {
          340  +    db close
          341  +    sqlite3 db test.db
          342  +    execsql {
          343  +      SELECT * FROM t2;
          344  +    };
          345  +  } {3 4 7 8}
          346  +} else {
          347  +  execsql {
          348  +    CREATE TABLE t2(x,y);
   329    349       DROP TABLE t1;
   330         -    SELECT * FROM t2;
   331         -  };
   332         -} {3 4 7 8}
   333         -do_test trigger-4.4 {
   334         -  db close
   335         -  sqlite3 db test.db
   336         -  execsql {
   337         -    SELECT * FROM t2;
   338         -  };
   339         -} {3 4 7 8}
          350  +    INSERT INTO t2 VALUES(3, 4);
          351  +    INSERT INTO t2 VALUES(7, 8);
          352  +  }
          353  +}
          354  +
   340    355   
   341         -integrity_check trigger-5.1
          356  +integrity_check trigger1-5.1
   342    357   
   343    358   # Create a trigger with the same name as a table.  Make sure the
   344    359   # trigger works.  Then drop the trigger.  Make sure the table is
   345    360   # still there.
   346    361   #
   347    362   set view_v1 {}
   348    363   ifcapable view {
   349    364     set view_v1 {view v1}
   350    365   }
   351         -do_test trigger-6.1 {
          366  +do_test trigger1-6.1 {
   352    367     execsql {SELECT type, name FROM sqlite_master}
   353    368   } [concat $view_v1 {table t2}]
   354         -do_test trigger-6.2 {
          369  +do_test trigger1-6.2 {
   355    370     execsql {
   356    371       CREATE TRIGGER t2 BEFORE DELETE ON t2 BEGIN
   357    372         SELECT RAISE(ABORT,'deletes are not allows');
   358    373       END;
   359    374       SELECT type, name FROM sqlite_master;
   360    375     }
   361    376   } [concat $view_v1 {table t2 trigger t2}]
   362         -do_test trigger-6.3 {
          377  +do_test trigger1-6.3 {
   363    378     catchsql {DELETE FROM t2}
   364    379   } {1 {deletes are not allows}}
   365         -do_test trigger-6.4 {
          380  +do_test trigger1-6.4 {
   366    381     execsql {SELECT * FROM t2}
   367    382   } {3 4 7 8}
   368         -do_test trigger-6.5 {
          383  +do_test trigger1-6.5 {
   369    384     db close
   370    385     sqlite3 db test.db
   371    386     execsql {SELECT type, name FROM sqlite_master}
   372    387   } [concat $view_v1 {table t2 trigger t2}]
   373         -do_test trigger-6.6 {
          388  +do_test trigger1-6.6 {
   374    389     execsql {
   375    390       DROP TRIGGER t2;
   376    391       SELECT type, name FROM sqlite_master;
   377    392     }
   378    393   } [concat $view_v1 {table t2}]
   379         -do_test trigger-6.7 {
          394  +do_test trigger1-6.7 {
   380    395     execsql {SELECT * FROM t2}
   381    396   } {3 4 7 8}
   382         -do_test trigger-6.8 {
          397  +do_test trigger1-6.8 {
   383    398     db close
   384    399     sqlite3 db test.db
   385    400     execsql {SELECT * FROM t2}
   386    401   } {3 4 7 8}
   387    402   
   388    403   integrity_check trigger-7.1
   389    404   
   390    405   # Check to make sure the name of a trigger can be quoted so that keywords
   391    406   # can be used as trigger names.  Ticket #468
   392    407   #
   393         -do_test trigger-8.1 {
          408  +do_test trigger1-8.1 {
   394    409     execsql {
   395    410       CREATE TRIGGER 'trigger' AFTER INSERT ON t2 BEGIN SELECT 1; END;
   396    411       SELECT name FROM sqlite_master WHERE type='trigger';
   397    412     }
   398    413   } {trigger}
   399         -do_test trigger-8.2 {
          414  +do_test trigger1-8.2 {
   400    415     execsql {
   401    416       DROP TRIGGER 'trigger';
   402    417       SELECT name FROM sqlite_master WHERE type='trigger';
   403    418     }
   404    419   } {}
   405         -do_test trigger-8.3 {
          420  +do_test trigger1-8.3 {
   406    421     execsql {
   407    422       CREATE TRIGGER "trigger" AFTER INSERT ON t2 BEGIN SELECT 1; END;
   408    423       SELECT name FROM sqlite_master WHERE type='trigger';
   409    424     }
   410    425   } {trigger}
   411         -do_test trigger-8.4 {
          426  +do_test trigger1-8.4 {
   412    427     execsql {
   413    428       DROP TRIGGER "trigger";
   414    429       SELECT name FROM sqlite_master WHERE type='trigger';
   415    430     }
   416    431   } {}
   417         -do_test trigger-8.5 {
          432  +do_test trigger1-8.5 {
   418    433     execsql {
   419    434       CREATE TRIGGER [trigger] AFTER INSERT ON t2 BEGIN SELECT 1; END;
   420    435       SELECT name FROM sqlite_master WHERE type='trigger';
   421    436     }
   422    437   } {trigger}
   423         -do_test trigger-8.6 {
          438  +do_test trigger1-8.6 {
   424    439     execsql {
   425    440       DROP TRIGGER [trigger];
   426    441       SELECT name FROM sqlite_master WHERE type='trigger';
   427    442     }
   428    443   } {}
   429    444   
   430    445   # Make sure REPLACE works inside of triggers.
   431    446   #
   432    447   # There are two versions of trigger-9.1 and trigger-9.2. One that uses
   433    448   # compound SELECT statements, and another that does not.
   434    449   ifcapable compound {
   435         -do_test trigger-9.1 {
          450  +do_test trigger1-9.1 {
   436    451     execsql {
   437    452       CREATE TABLE t3(a,b);
   438    453       CREATE TABLE t4(x UNIQUE, b);
   439    454       CREATE TRIGGER r34 AFTER INSERT ON t3 BEGIN
   440    455         REPLACE INTO t4 VALUES(new.a,new.b);
   441    456       END;
   442    457       INSERT INTO t3 VALUES(1,2);
   443    458       SELECT * FROM t3 UNION ALL SELECT 99, 99 UNION ALL SELECT * FROM t4;
   444    459     }
   445    460   } {1 2 99 99 1 2}
   446         -do_test trigger-9.2 {
          461  +do_test trigger1-9.2 {
   447    462     execsql {
   448    463       INSERT INTO t3 VALUES(1,3);
   449    464       SELECT * FROM t3 UNION ALL SELECT 99, 99 UNION ALL SELECT * FROM t4;
   450    465     }
   451    466   } {1 2 1 3 99 99 1 3}
   452    467   }
   453    468   ifcapable !compound {
   454         -do_test trigger-9.1 {
          469  +do_test trigger1-9.1 {
   455    470     execsql {
   456    471       CREATE TABLE t3(a,b);
   457    472       CREATE TABLE t4(x UNIQUE, b);
   458    473       CREATE TRIGGER r34 AFTER INSERT ON t3 BEGIN
   459    474         REPLACE INTO t4 VALUES(new.a,new.b);
   460    475       END;
   461    476       INSERT INTO t3 VALUES(1,2);
   462    477       SELECT * FROM t3; SELECT 99, 99; SELECT * FROM t4;
   463    478     }
   464    479   } {1 2 99 99 1 2}
   465         -do_test trigger-9.2 {
          480  +do_test trigger1-9.2 {
   466    481     execsql {
   467    482       INSERT INTO t3 VALUES(1,3);
   468    483       SELECT * FROM t3; SELECT 99, 99; SELECT * FROM t4;
   469    484     }
   470    485   } {1 2 1 3 99 99 1 3}
   471    486   }
   472    487   
................................................................................
   479    494   # Ticket #764. At one stage TEMP triggers would fail to re-install when the
   480    495   # schema was reloaded. The following tests ensure that TEMP triggers are
   481    496   # correctly re-installed.
   482    497   #
   483    498   # Also verify that references within trigger programs are resolved at
   484    499   # statement compile time, not trigger installation time. This means, for
   485    500   # example, that you can drop and re-create tables referenced by triggers. 
   486         -do_test trigger-10.0 {
   487         -  file delete -force test2.db
   488         -  file delete -force test2.db-journal
   489         -  execsql {
   490         -    ATTACH 'test2.db' AS aux;
   491         -  }
   492         -} {}
   493         -do_test trigger-10.1 {
   494         -  execsql {
   495         -    CREATE TABLE main.t4(a, b, c);
   496         -    CREATE TABLE temp.t4(a, b, c);
   497         -    CREATE TABLE aux.t4(a, b, c);
   498         -    CREATE TABLE insert_log(db, a, b, c);
   499         -  }
   500         -} {}
   501         -do_test trigger-10.2 {
   502         -  execsql {
   503         -    CREATE TEMP TRIGGER trig1 AFTER INSERT ON main.t4 BEGIN 
   504         -      INSERT INTO insert_log VALUES('main', new.a, new.b, new.c);
   505         -    END;
   506         -    CREATE TEMP TRIGGER trig2 AFTER INSERT ON temp.t4 BEGIN 
   507         -      INSERT INTO insert_log VALUES('temp', new.a, new.b, new.c);
   508         -    END;
   509         -    CREATE TEMP TRIGGER trig3 AFTER INSERT ON aux.t4 BEGIN 
   510         -      INSERT INTO insert_log VALUES('aux', new.a, new.b, new.c);
   511         -    END;
   512         -  }
   513         -} {}
   514         -do_test trigger-10.3 {
   515         -  execsql {
   516         -    INSERT INTO main.t4 VALUES(1, 2, 3);
   517         -    INSERT INTO temp.t4 VALUES(4, 5, 6);
   518         -    INSERT INTO aux.t4  VALUES(7, 8, 9);
   519         -  }
   520         -} {}
   521         -do_test trigger-10.4 {
   522         -  execsql {
   523         -    SELECT * FROM insert_log;
   524         -  }
   525         -} {main 1 2 3 temp 4 5 6 aux 7 8 9}
   526         -do_test trigger-10.5 {
   527         -  execsql {
   528         -    BEGIN;
   529         -    INSERT INTO main.t4 VALUES(1, 2, 3);
   530         -    INSERT INTO temp.t4 VALUES(4, 5, 6);
   531         -    INSERT INTO aux.t4  VALUES(7, 8, 9);
   532         -    ROLLBACK;
   533         -  }
   534         -} {}
   535         -do_test trigger-10.6 {
   536         -  execsql {
   537         -    SELECT * FROM insert_log;
   538         -  }
   539         -} {main 1 2 3 temp 4 5 6 aux 7 8 9}
   540         -do_test trigger-10.7 {
   541         -  execsql {
   542         -    DELETE FROM insert_log;
   543         -    INSERT INTO main.t4 VALUES(11, 12, 13);
   544         -    INSERT INTO temp.t4 VALUES(14, 15, 16);
   545         -    INSERT INTO aux.t4  VALUES(17, 18, 19);
   546         -  }
   547         -} {}
   548         -do_test trigger-10.8 {
   549         -  execsql {
   550         -    SELECT * FROM insert_log;
   551         -  }
   552         -} {main 11 12 13 temp 14 15 16 aux 17 18 19}
   553         -do_test trigger-10.8 {
   554         -# Drop and re-create the insert_log table in a different database. Note
   555         -# that we can change the column names because the trigger programs don't
   556         -# use them explicitly.
   557         -  execsql {
   558         -    DROP TABLE insert_log;
   559         -    CREATE TABLE aux.insert_log(db, d, e, f);
   560         -  }
   561         -} {}
   562         -do_test trigger-10.10 {
   563         -  execsql {
   564         -    INSERT INTO main.t4 VALUES(21, 22, 23);
   565         -    INSERT INTO temp.t4 VALUES(24, 25, 26);
   566         -    INSERT INTO aux.t4  VALUES(27, 28, 29);
   567         -  }
   568         -} {}
   569         -do_test trigger-10.11 {
   570         -  execsql {
   571         -    SELECT * FROM insert_log;
   572         -  }
   573         -} {main 21 22 23 temp 24 25 26 aux 27 28 29}
          501  +ifcapable tempdb {
          502  +  do_test trigger1-10.0 {
          503  +    file delete -force test2.db
          504  +    file delete -force test2.db-journal
          505  +    execsql {
          506  +      ATTACH 'test2.db' AS aux;
          507  +    }
          508  +  } {}
          509  +  do_test trigger1-10.1 {
          510  +    execsql {
          511  +      CREATE TABLE main.t4(a, b, c);
          512  +      CREATE TABLE temp.t4(a, b, c);
          513  +      CREATE TABLE aux.t4(a, b, c);
          514  +      CREATE TABLE insert_log(db, a, b, c);
          515  +    }
          516  +  } {}
          517  +  do_test trigger1-10.2 {
          518  +    execsql {
          519  +      CREATE TEMP TRIGGER trig1 AFTER INSERT ON main.t4 BEGIN 
          520  +        INSERT INTO insert_log VALUES('main', new.a, new.b, new.c);
          521  +      END;
          522  +      CREATE TEMP TRIGGER trig2 AFTER INSERT ON temp.t4 BEGIN 
          523  +        INSERT INTO insert_log VALUES('temp', new.a, new.b, new.c);
          524  +      END;
          525  +      CREATE TEMP TRIGGER trig3 AFTER INSERT ON aux.t4 BEGIN 
          526  +        INSERT INTO insert_log VALUES('aux', new.a, new.b, new.c);
          527  +      END;
          528  +    }
          529  +  } {}
          530  +  do_test trigger1-10.3 {
          531  +    execsql {
          532  +      INSERT INTO main.t4 VALUES(1, 2, 3);
          533  +      INSERT INTO temp.t4 VALUES(4, 5, 6);
          534  +      INSERT INTO aux.t4  VALUES(7, 8, 9);
          535  +    }
          536  +  } {}
          537  +  do_test trigger1-10.4 {
          538  +    execsql {
          539  +      SELECT * FROM insert_log;
          540  +    }
          541  +  } {main 1 2 3 temp 4 5 6 aux 7 8 9}
          542  +  do_test trigger1-10.5 {
          543  +    execsql {
          544  +      BEGIN;
          545  +      INSERT INTO main.t4 VALUES(1, 2, 3);
          546  +      INSERT INTO temp.t4 VALUES(4, 5, 6);
          547  +      INSERT INTO aux.t4  VALUES(7, 8, 9);
          548  +      ROLLBACK;
          549  +    }
          550  +  } {}
          551  +  do_test trigger1-10.6 {
          552  +    execsql {
          553  +      SELECT * FROM insert_log;
          554  +    }
          555  +  } {main 1 2 3 temp 4 5 6 aux 7 8 9}
          556  +  do_test trigger1-10.7 {
          557  +    execsql {
          558  +      DELETE FROM insert_log;
          559  +      INSERT INTO main.t4 VALUES(11, 12, 13);
          560  +      INSERT INTO temp.t4 VALUES(14, 15, 16);
          561  +      INSERT INTO aux.t4  VALUES(17, 18, 19);
          562  +    }
          563  +  } {}
          564  +  do_test trigger1-10.8 {
          565  +    execsql {
          566  +      SELECT * FROM insert_log;
          567  +    }
          568  +  } {main 11 12 13 temp 14 15 16 aux 17 18 19}
          569  +  do_test trigger1-10.8 {
          570  +  # Drop and re-create the insert_log table in a different database. Note
          571  +  # that we can change the column names because the trigger programs don't
          572  +  # use them explicitly.
          573  +    execsql {
          574  +      DROP TABLE insert_log;
          575  +      CREATE TABLE aux.insert_log(db, d, e, f);
          576  +    }
          577  +  } {}
          578  +  do_test trigger1-10.10 {
          579  +    execsql {
          580  +      INSERT INTO main.t4 VALUES(21, 22, 23);
          581  +      INSERT INTO temp.t4 VALUES(24, 25, 26);
          582  +      INSERT INTO aux.t4  VALUES(27, 28, 29);
          583  +    }
          584  +  } {}
          585  +  do_test trigger1-10.11 {
          586  +    execsql {
          587  +      SELECT * FROM insert_log;
          588  +    }
          589  +  } {main 21 22 23 temp 24 25 26 aux 27 28 29}
          590  +}
   574    591   
   575    592   finish_test

Changes to test/trigger2.test.

    53     53     finish_test
    54     54     return
    55     55   }
    56     56   
    57     57   # 1.
    58     58   ifcapable subquery {
    59     59     set ii 0
    60         -  foreach tbl_defn {
    61         -  	{CREATE TEMP TABLE tbl (a, b);} 
    62         -  	{CREATE TABLE tbl (a, b);} 
    63         -  	{CREATE TABLE tbl (a INTEGER PRIMARY KEY, b);} 
    64         -  	{CREATE TEMPORARY TABLE tbl (a INTEGER PRIMARY KEY, b);} 
    65         -          {CREATE TABLE tbl (a, b PRIMARY KEY);} 
    66         -  	{CREATE TABLE tbl (a, b); CREATE INDEX tbl_idx ON tbl(b);} 
    67         -  	{CREATE TEMP TABLE tbl (a, b); CREATE INDEX tbl_idx ON tbl(b);} 
    68         -  } {
           60  +  set tbl_definitions [list \
           61  +  	{CREATE TABLE tbl (a, b);}                                      \
           62  +  	{CREATE TABLE tbl (a INTEGER PRIMARY KEY, b);}                  \
           63  +        {CREATE TABLE tbl (a, b PRIMARY KEY);}                          \
           64  +  	{CREATE TABLE tbl (a, b); CREATE INDEX tbl_idx ON tbl(b);}      \
           65  +  ]
           66  +  ifcapable tempdb {
           67  +    lappend tbl_definitions \
           68  +        {CREATE TEMP TABLE tbl (a, b); CREATE INDEX tbl_idx ON tbl(b);} 
           69  +    lappend tbl_definitions {CREATE TEMP TABLE tbl (a, b);}
           70  +    lappend tbl_definitions \
           71  +        {CREATE TEMPORARY TABLE tbl (a INTEGER PRIMARY KEY, b);}
           72  +  }
           73  +  foreach tbl_defn $tbl_definitions {
    69     74       incr ii
    70     75       catchsql { DROP INDEX tbl_idx; }
    71     76       catchsql {
    72     77         DROP TABLE rlog;
    73     78         DROP TABLE clog;
    74     79         DROP TABLE tbl;
    75     80         DROP TABLE other_tbl;

Changes to test/vacuum.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this file is testing the VACUUM statement.
    13     13   #
    14         -# $Id: vacuum.test,v 1.34 2005/02/12 00:19:30 drh Exp $
           14  +# $Id: vacuum.test,v 1.35 2005/03/29 03:11:00 danielk1977 Exp $
    15     15   
    16     16   set testdir [file dirname $argv0]
    17     17   source $testdir/tester.tcl
    18     18   
    19     19   # If the VACUUM statement is disabled in the current build, skip all
    20     20   # the tests in this file.
    21     21   #
................................................................................
   235    235     sqlite3 db test.db
   236    236     catchsql {
   237    237       CREATE TABLE Test (TestID int primary key);
   238    238       INSERT INTO Test VALUES (NULL);
   239    239       CREATE VIEW viewTest AS SELECT * FROM Test;
   240    240   
   241    241       BEGIN;
   242         -    CREATE TEMP TABLE tempTest (TestID int primary key, Test2 int NULL);
          242  +    CREATE TABLE tempTest (TestID int primary key, Test2 int NULL);
   243    243       INSERT INTO tempTest SELECT TestID, 1 FROM Test;
   244    244       DROP TABLE Test;
   245    245       CREATE TABLE Test(TestID int primary key, Test2 int NULL);
   246    246       INSERT INTO Test SELECT * FROM tempTest;
          247  +    DROP TABLE tempTest;
   247    248       COMMIT;
   248    249       VACUUM;
   249    250     }
   250    251   } {0 {}}
   251    252   do_test vacuum-5.2 {
   252    253     catchsql {
   253    254       VACUUM;