diff --git a/manifest b/manifest index 39f44b3661..a4c9500cc0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\swindows\sDLL\ssection\sof\sMakefile.in\sfor\suse\swith\sbuild\sdir.\s(CVS\s1301) -D 2004-03-26T23:16:32 +C Get\sthe\stemp_store\sand\sdefault_temp_store\spragmas\sworking.\s\sUpdate\sthe\ndocumentation.\s\sAlso\sfix\sa\smalloc\sproblem\sthat\spopped\sup\sduring\sthe\sregression\ntesting.\s(CVS\s1302) +D 2004-04-23T17:04:44 F Makefile.in ab7b0d5118e2da97bac66be8684a1034e3500f5a F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd @@ -26,24 +26,24 @@ F src/auth.c 4fa3b05bd19445d1c474d6751c4a508d6ea0abe1 F src/btree.c 08a05b925b348c05d79b9b062b79e50d565678de F src/btree.h 41cb3ff6ebc3f6da2d0a074e39ff8c7a2287469f F src/btree_rb.c 99feb3ff835106d018a483a1ce403e5cf9c718bc -F src/build.c c8ab8b467d9a64254b0d4d42083f6313b3a980d1 +F src/build.c 76fbca30081decd6615dee34b48c927ed5063752 F src/copy.c 750e13828c3e4a293123e36aaa7cf0f22466248a F src/date.c f055419d602bde622c70f831350b6b52f2235de0 F src/delete.c 82001c74882319f94dab5f6b92a27311b31092ae F src/encode.c fc8c51f0b61bc803ccdec092e130bebe762b0a2f -F src/expr.c 938e4d341ce6766a5ee14b31d119ce1f99f478b6 +F src/expr.c 8c3f5603c3e98b1c146d18076ba3e82cdbb59c11 F src/func.c 34fead7a33e82095f6412d3fafd379d47864b3be F src/hash.c 9b56ef3b291e25168f630d5643a4264ec011c70e F src/hash.h 3247573ab95b9dd90bcca0307a75d9a16da1ccc7 F src/insert.c c0485ee2d1b99322894e2d1e0b576fd05ed75616 -F src/main.c 89a18cfb2a6a832a03fff10b2515da4bbe8f83ef +F src/main.c 94dd355768e2a389e184a069b6880f4bac100307 F src/md5.c fe4f9c9c6f71dfc26af8da63e4d04489b1430565 F src/os.c 5f11382733805d4529ec2a30800e117f30995ea8 F src/os.h 250a3789be609adfee5c5aa20137ce8683276f24 F src/pager.c b246986e5ba31b15aa3cf91d3b9ec2e608aceb8e F src/pager.h 82332878799280145639a48d88cdb4058925e3f6 F src/parse.y 023720cb8c3bef74e51738bca78335d0dc6d2cfd -F src/pragma.c 621d319580e9e23712ec232e8be1786cdae06b36 +F src/pragma.c f9c157b0591419d2d3407dac90222020d2a6d822 F src/printf.c 8c58b7b6d4069eec6ebe2d46bdbc3a89a367bf95 F src/random.c 775913e0b7fbd6295d21f12a7bd35b46387c44b2 F src/select.c 3833e2b64cc6d249385ee44e13bf49c9ae5b903d @@ -55,7 +55,7 @@ F src/tclsqlite.c 819d92d305756c4ea57de023c387d2fa8a256aff F src/test1.c 9aa62b89d420e6763b5e7ae89a47f6cf87370477 F src/test2.c 75819b0f2c63c6a0fd6995445881f2eb94036996 F src/test3.c 30985ebdfaf3ee1462a9b0652d3efbdc8d9798f5 -F src/test4.c dcbbbb382626fd466a7c46907f74db35fc8bad64 +F src/test4.c 6e3e31acfaf21d66420fc35fda5b17dc0000cc8d F src/tokenize.c 6676b946fd8825b67ab52140af4fdc57a70bda48 F src/trigger.c a9927b57c865b6f3df3fb5e40c9824d722660ded F src/update.c 4c50328ebc127852bde8e2950eb8933234802c21 @@ -115,7 +115,7 @@ F test/misuse.test 1095f26d1aed406c65e1d2eba651c4bb7c38cbff F test/notnull.test 7a08117a71e74b0321aaa937dbeb41a09d6eb1d0 F test/null.test c14d0f4739f21e929b8115b72bf0c765b6bb1721 F test/pager.test 331519008889d45f6df6697395e5bce6ee602fd9 -F test/pragma.test 33011f5741cc4952ff8306ead8a1aeb003fb0786 +F test/pragma.test 24a3f7a697b45cb90d664ebce5566bec7ac41571 F test/printf.test 46b3d07d59d871d0831b4a657f6dfcafe0574850 F test/progress.test 701b6115c2613128ececdfe1398a1bd0e1a4cfb3 x F test/quick.test 5a6bccf5c02f16841a79fbac7409a02138880c10 @@ -176,8 +176,8 @@ F www/dynload.tcl 02eb8273aa78cfa9070dd4501dca937fb22b466c F www/faq.tcl 88d3b95d9cd8e374772daa3a646c4d107e7f3e9b F www/fileformat.tcl 56f77e435a6306b337b20b416e3b89500ba2d029 F www/formatchng.tcl ca6cc1cb1bef9bc36f0619049d3c95e749bc6983 -F www/index.tcl b31c15e1b8bffea9a16793bc88d712a9dbbf3d8e -F www/lang.tcl 6cb027f5483aa831752daeef0c946111af303713 +F www/index.tcl bacb2a0d052845bbe3bf078765cce907ed7080a4 +F www/lang.tcl 17954f37c8bb1d25e026d97041ff6459fb89ac95 F www/mingw.tcl d96b451568c5d28545fefe0c80bee3431c73f69c F www/nulls.tcl 38117d24afb81efd079b59723b985a6d654cc2e8 F www/omitted.tcl 11037a1b557bd01405092d93dfa08898a4c26cd7 @@ -188,7 +188,7 @@ F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604 F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1 F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4 -P 85238f06902851dd5085395501a0ab2d6a2b9814 -R 21ef3c09e06057b93271ec18ed7b08b6 -U rdc -Z a0f2c4708b5ae5e7ecb38e2aaf58c2f0 +P 1e84f70fb98755651e0c04dc2cf0114e2e6fe39c +R 49661129e558c10c6a80ceab2ff48aff +U drh +Z 3af77926e38ece4579fe3c33c425d46c diff --git a/manifest.uuid b/manifest.uuid index 42058492e2..c4d6387c73 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1e84f70fb98755651e0c04dc2cf0114e2e6fe39c \ No newline at end of file +7ace576215367101904677bd69951755ee9cb1a1 \ No newline at end of file diff --git a/src/build.c b/src/build.c index 87c88346be..3d74322b31 100644 --- a/src/build.c +++ b/src/build.c @@ -23,7 +23,7 @@ ** ROLLBACK ** PRAGMA ** -** $Id: build.c,v 1.175 2004/02/24 01:04:12 drh Exp $ +** $Id: build.c,v 1.176 2004/04/23 17:04:44 drh Exp $ */ #include "sqliteInt.h" #include @@ -484,7 +484,6 @@ void sqliteStartTable( if( rc!=SQLITE_OK ){ sqliteErrorMsg(pParse, "unable to get a write lock on " "the temporary database file"); - pParse->nErr++; return; } } diff --git a/src/expr.c b/src/expr.c index eafc50ce82..f92dbc078d 100644 --- a/src/expr.c +++ b/src/expr.c @@ -12,7 +12,7 @@ ** This file contains routines used for analyzing expressions and ** for generating VDBE code that evaluates expressions in SQLite. ** -** $Id: expr.c,v 1.113 2004/03/17 23:32:08 drh Exp $ +** $Id: expr.c,v 1.114 2004/04/23 17:04:45 drh Exp $ */ #include "sqliteInt.h" #include @@ -155,7 +155,8 @@ ExprList *sqliteExprListDup(ExprList *p){ if( pNew==0 ) return 0; pNew->nExpr = pNew->nAlloc = p->nExpr; pNew->a = pItem = sqliteMalloc( p->nExpr*sizeof(p->a[0]) ); - for(i=0; pItem && inExpr; i++, pItem++){ + if( pItem==0 ) return 0; /* Leaks memory after a malloc failure */ + for(i=0; inExpr; i++, pItem++){ Expr *pNewExpr, *pOldExpr; pItem->pExpr = pNewExpr = sqliteExprDup(pOldExpr = p->a[i].pExpr); if( pOldExpr->span.z!=0 && pNewExpr ){ @@ -278,6 +279,8 @@ ExprList *sqliteExprListAppend(ExprList *pList, Expr *pExpr, Token *pName){ void sqliteExprListDelete(ExprList *pList){ int i; if( pList==0 ) return; + assert( pList->a!=0 || (pList->nExpr==0 && pList->nAlloc==0) ); + assert( pList->nExpr<=pList->nAlloc ); for(i=0; inExpr; i++){ sqliteExprDelete(pList->a[i].pExpr); sqliteFree(pList->a[i].zName); diff --git a/src/main.c b/src/main.c index bf8b666735..27f237f7c1 100644 --- a/src/main.c +++ b/src/main.c @@ -14,7 +14,7 @@ ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** -** $Id: main.c,v 1.163 2004/03/17 18:44:47 drh Exp $ +** $Id: main.c,v 1.164 2004/04/23 17:04:45 drh Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -300,6 +300,9 @@ static int sqliteInitOne(sqlite *db, int iDb, char **pzErrMsg){ if( size==0 ){ size = MAX_PAGES; } db->cache_size = size; db->safety_level = meta[4]; + if( meta[6]>0 && meta[6]<=2 && db->temp_store==0 ){ + db->temp_store = meta[6]; + } if( db->safety_level==0 ) db->safety_level = 2; /* diff --git a/src/pragma.c b/src/pragma.c index d9cf6354ae..a002c7dc21 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -11,7 +11,7 @@ ************************************************************************* ** This file contains code used to implement the PRAGMA command. ** -** $Id: pragma.c,v 1.18 2004/02/22 20:05:01 drh Exp $ +** $Id: pragma.c,v 1.19 2004/04/23 17:04:45 drh Exp $ */ #include "sqliteInt.h" #include @@ -71,8 +71,8 @@ static int getSafetyLevel(char *z){ ** backed temporary databases, 2 for the Red-Black tree in memory database ** and 0 to use the compile-time default. */ -static int getTempStore(char *z){ - if( z[0]>='0' || z[0]<='2' ){ +static int getTempStore(const char *z){ + if( z[0]>='0' && z[0]<='2' ){ return z[0] - '0'; }else if( sqliteStrICmp(z, "file")==0 ){ return 1; @@ -83,6 +83,29 @@ static int getTempStore(char *z){ } } +/* +** If the TEMP database is open, close it and mark the database schema +** as needing reloading. This must be done when using the TEMP_STORE +** or DEFAULT_TEMP_STORE pragmas. +*/ +static int changeTempStorage(Parse *pParse, const char *zStorageType){ + int ts = getTempStore(zStorageType); + sqlite *db = pParse->db; + if( db->temp_store==ts ) return SQLITE_OK; + if( db->aDb[1].pBt!=0 ){ + if( db->flags & SQLITE_InTrans ){ + sqliteErrorMsg(pParse, "temporary storage cannot be changed " + "from within a transaction"); + return SQLITE_ERROR; + } + sqliteBtreeClose(db->aDb[1].pBt); + db->aDb[1].pBt = 0; + sqliteResetInternalSchema(db, 0); + } + db->temp_store = ts; + return SQLITE_OK; +} + /* ** Check to see if zRight and zLeft refer to a pragma that queries ** or changes one of the flags in db->flags. Return 1 if so and 0 if not. @@ -498,12 +521,7 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){ sqliteVdbeAddOp(v, OP_Integer, db->temp_store, 0); sqliteVdbeAddOpList(v, ArraySize(getTmpDbLoc), getTmpDbLoc); }else{ - if (&db->aDb[1].pBt != 0) { - sqliteErrorMsg(pParse, "The temporary database already exists - " - "its location cannot now be changed"); - } else { - db->temp_store = getTempStore(zRight); - } + changeTempStorage(pParse, zRight); } }else @@ -511,8 +529,9 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){ ** PRAGMA default_temp_store ** PRAGMA default_temp_store = "default"|"memory"|"file" ** - ** Return or set the value of the persistent temp_store flag (as - ** well as the value currently in force). + ** Return or set the value of the persistent temp_store flag. Any + ** change does not take effect until the next time the database is + ** opened. ** ** Note that it is possible for the library compile-time options to ** override this setting @@ -525,16 +544,10 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){ if( pRight->z==pLeft->z ){ sqliteVdbeAddOpList(v, ArraySize(getTmpDbLoc), getTmpDbLoc); }else{ - if (&db->aDb[1].pBt != 0) { - sqliteErrorMsg(pParse, "The temporary database already exists - " - "its location cannot now be changed"); - } else { - sqliteBeginWriteOperation(pParse, 0, 0); - db->temp_store = getTempStore(zRight); - sqliteVdbeAddOp(v, OP_Integer, db->temp_store, 0); - sqliteVdbeAddOp(v, OP_SetCookie, 0, 5); - sqliteEndWriteOperation(pParse); - } + sqliteBeginWriteOperation(pParse, 0, 0); + sqliteVdbeAddOp(v, OP_Integer, getTempStore(zRight), 0); + sqliteVdbeAddOp(v, OP_SetCookie, 0, 5); + sqliteEndWriteOperation(pParse); } }else diff --git a/src/test4.c b/src/test4.c index 3389f3eae6..2966a67566 100644 --- a/src/test4.c +++ b/src/test4.c @@ -11,7 +11,7 @@ ************************************************************************* ** Code for testing the the SQLite library in a multithreaded environment. ** -** $Id: test4.c,v 1.2 2003/12/20 04:00:53 drh Exp $ +** $Id: test4.c,v 1.3 2004/04/23 17:04:45 drh Exp $ */ #include "sqliteInt.h" #include "tcl.h" @@ -563,6 +563,44 @@ static int tcl_thread_finalize( return TCL_OK; } +/* +** Usage: thread_swap ID ID +** +** Interchange the sqlite* pointer between two threads. +*/ +static int tcl_thread_swap( + void *NotUsed, + Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ + int argc, /* Number of arguments */ + const char **argv /* Text of each argument */ +){ + int i, j; + sqlite *temp; + if( argc!=3 ){ + Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], + " ID1 ID2", 0); + return TCL_ERROR; + } + i = parse_thread_id(interp, argv[1]); + if( i<0 ) return TCL_ERROR; + if( !threadset[i].busy ){ + Tcl_AppendResult(interp, "no such thread", 0); + return TCL_ERROR; + } + thread_wait(&threadset[i]); + j = parse_thread_id(interp, argv[2]); + if( j<0 ) return TCL_ERROR; + if( !threadset[j].busy ){ + Tcl_AppendResult(interp, "no such thread", 0); + return TCL_ERROR; + } + thread_wait(&threadset[j]); + temp = threadset[i].db; + threadset[i].db = threadset[j].db; + threadset[j].db = temp; + return TCL_OK; +} + /* ** Register commands with the TCL interpreter. */ @@ -582,6 +620,7 @@ int Sqlitetest4_Init(Tcl_Interp *interp){ { "thread_compile", (Tcl_CmdProc*)tcl_thread_compile }, { "thread_step", (Tcl_CmdProc*)tcl_thread_step }, { "thread_finalize", (Tcl_CmdProc*)tcl_thread_finalize }, + { "thread_swap", (Tcl_CmdProc*)tcl_thread_swap }, }; int i; diff --git a/test/pragma.test b/test/pragma.test index c3b42055dd..0b764a9914 100644 --- a/test/pragma.test +++ b/test/pragma.test @@ -12,7 +12,7 @@ # # This file implements tests for the PRAGMA command. # -# $Id: pragma.test,v 1.8 2004/02/11 02:18:07 drh Exp $ +# $Id: pragma.test,v 1.9 2004/04/23 17:04:45 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -268,4 +268,150 @@ do_test pragma-3.2 { } {{rowid 1 missing from index i2} {wrong # of entries in index i2}} }; # endif has-codec +# Test the temp_store and default_temp_store pragmas +# +do_test pragma-4.2 { + execsql { + PRAGMA temp_store='default'; + PRAGMA temp_store; + } +} {0} +do_test pragma-4.3 { + execsql { + PRAGMA temp_store='file'; + PRAGMA temp_store; + } +} {1} +do_test pragma-4.4 { + execsql { + PRAGMA temp_store='memory'; + PRAGMA temp_store; + } +} {2} +do_test pragma-4.5 { + execsql { + PRAGMA default_temp_store='default'; + PRAGMA default_temp_store; + } +} {0} +do_test pragma-4.6 { + execsql { + PRAGMA temp_store; + } +} {2} +do_test pragma-4.7 { + db close + sqlite db test.db + execsql { + PRAGMA temp_store; + } +} {0} +do_test pragma-4.8 { + execsql { + PRAGMA default_temp_store; + } +} {0} +do_test pragma-4.9 { + execsql { + PRAGMA default_temp_store='file'; + PRAGMA default_temp_store; + } +} {1} +do_test pragma-4.10 { + execsql { + PRAGMA temp_store; + } +} {0} +do_test pragma-4.11 { + db close + sqlite db test.db + execsql { + PRAGMA temp_store; + } +} {1} +do_test pragma-4.12 { + execsql { + PRAGMA default_temp_store; + } +} {1} +do_test pragma-4.13 { + execsql { + PRAGMA default_temp_store='memory'; + PRAGMA default_temp_store; + } +} {2} +do_test pragma-4.14 { + execsql { + PRAGMA temp_store; + } +} {1} +do_test pragma-4.15 { + db close + sqlite db test.db + execsql { + PRAGMA temp_store; + } +} {2} +do_test pragma-4.16 { + execsql { + PRAGMA default_temp_store; + } +} {2} +do_test pragma-4.17 { + execsql { + PRAGMA temp_store='file'; + PRAGMA temp_store + } +} {1} +do_test pragma-4.18 { + execsql { + PRAGMA default_temp_store + } +} {2} +do_test pragma-4.19 { + db close + sqlite db test.db + execsql { + PRAGMA temp_store + } +} {2} + +# Changing the TEMP_STORE deletes any existing temporary tables +# +do_test pragma-4.20 { + execsql {SELECT name FROM sqlite_temp_master} +} {} +do_test pragma-4.21 { + execsql { + CREATE TEMP TABLE test1(a,b,c); + SELECT name FROM sqlite_temp_master; + } +} {test1} +do_test pragma-4.22 { + execsql { + PRAGMA temp_store='file'; + SELECT name FROM sqlite_temp_master; + } +} {} +do_test pragma-4.23 { + execsql { + CREATE TEMP TABLE test1(a,b,c); + SELECT name FROM sqlite_temp_master; + } +} {test1} +do_test pragma-4.24 { + execsql { + PRAGMA temp_store='memory'; + SELECT name FROM sqlite_temp_master; + } +} {} +do_test pragma-4.25 { + catchsql { + BEGIN; + PRAGMA temp_store='default'; + COMMIT; + } +} {1 {temporary storage cannot be changed from within a transaction}} +catchsql {COMMIT} + finish_test diff --git a/www/index.tcl b/www/index.tcl index e438156f4c..49ea7befad 100644 --- a/www/index.tcl +++ b/www/index.tcl @@ -1,7 +1,7 @@ # # Run this TCL script to generate HTML for the index.html file. # -set rcsid {$Id: index.tcl,v 1.81 2004/01/22 23:38:22 drh Exp $} +set rcsid {$Id: index.tcl,v 1.82 2004/04/23 17:04:45 drh Exp $} puts { SQLite: An Embeddable SQL Database Engine @@ -56,7 +56,8 @@ puts {

Features

  • Database files can be freely shared between machines with different byte orders.
  • Supports databases up to 2 terabytes (2^41 bytes) in size.
  • -
  • Small memory footprint: less than 25K lines of C code.
  • +
  • A zero-configuration database engine - no DBA needed.
  • +
  • Small memory footprint: less than 30K lines of C code.
  • Two times faster than PostgreSQL and MySQL for many common operations.
  • Very simple diff --git a/www/lang.tcl b/www/lang.tcl index e472d6e34b..074e45b845 100644 --- a/www/lang.tcl +++ b/www/lang.tcl @@ -1,7 +1,7 @@ # # Run this Tcl script to generate the sqlite.html file. # -set rcsid {$Id: lang.tcl,v 1.66 2004/01/19 05:09:24 jplyon Exp $} +set rcsid {$Id: lang.tcl,v 1.67 2004/04/23 17:04:45 drh Exp $} puts { @@ -1323,8 +1323,7 @@ is returned it is as an integer.

    the database. When temp_store is DEFAULT (0), the compile-time value of the symbol TEMP_STORE is used for the temporary database. When temp_store is MEMORY (2), an in-memory database is used. - When temp_store is FILE (1), a temporary database file on disk will be used. - Once the temporary database is in use, its location cannot be changed. + When temp_store is FILE (1), a temporary database file on disk will be used. It is possible for the library compile-time symbol TEMP_STORE to override this setting. The following table summarizes this:

    @@ -1340,10 +1339,11 @@ is returned it is as an integer.

    3anymemory -

    This pragma changes the temp_store mode persistently. Once changed, - the mode stays set even if the database is closed and reopened. The - temp_store pragma does the same - thing but only applies the setting to the current session.

  • +

    This pragma changes the temp_store mode for whenever the database + is opened in the future. The temp_store mode for the current session + is unchanged. Use the + temp_store pragma to change the + temp_store mode for the current session.

  • PRAGMA empty_result_callbacks = ON; (1) @@ -1460,6 +1460,10 @@ is returned it is as an integer.

    flag, see the description of the default_temp_store pragma. Note that it is possible for the library compile-time options to override this setting.

    + +

    When the temp_store setting is changed, all existing temporary + tables, indices, triggers, and viewers are immediately deleted. +