-C Add\sa\scomment\sto\sprepare.c\sexplaining\swhy\sthe\slookaside\sbuffer\sis\sdisabled\sbefore\ssqlite3_exec()\sis\scalled\sto\sparse\sa\sschema\sstatement.\sNo\scode\schanges.\s(CVS\s6376)
-D 2009-03-24T04:46:08
+C Changes\sto\sinsure\sthat\slookaside\smemory\sallocations\sare\snever\sused\sto\shold\r\nschema\scontent.\r\nTicket\s#3743.\s(CVS\s6377)
+D 2009-03-24T15:08:10
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in 583e87706abc3026960ed759aff6371faf84c211
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b
F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc
F sqlite3.pc.in ae6f59a76e862f5c561eb32a380228a02afc3cad
-F src/alter.c b95815ccc92477b1b5874fb0fe20f65c867e9cc8
+F src/alter.c 472c0a4733de40f1d997ff4fd746042b707faf7b
F src/analyze.c 3585d1a4c480ee85b65cf0a676e05d2c29eb6bdb
F src/attach.c d34589d5c85d81e755e4a8fc946d313915a6fa6d
F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627
F src/btree.c 1a709b6aac17e520de49b6cbad5cc14000910d8b
F src/btree.h e302c5747494067cd4f5763000fbe7bca767d816
F src/btreeInt.h df64030d632f8c8ac217ed52e8b6b3eacacb33a5
-F src/build.c f217f9ce2528c5b968f77a11998948466ea81bc9
-F src/callback.c 09c6fedc77a45db99ba25a75d61382830314b357
+F src/build.c be2bdaf2a3f6b24ef08dc14b9fd33aa84c689908
+F src/callback.c 73016376d6848ba987709e8c9048d4f0e0776036
F src/complete.c cb14e06dbe79dee031031f0d9e686ff306afe07c
F src/date.c 0d804df3bbda46329946a01ff5c75c3f4f135218
F src/delete.c eb1066b2f35489fee46ad765d2b66386fc7d8adf
-F src/expr.c ca5d176acc69497401cc5c376a91f785159b83a4
+F src/expr.c 614a60615fd4bd186459c0c1fa87fdefedb76c26
F src/fault.c dc88c821842157460750d2d61a8a8b4197d047ff
F src/func.c de2eed7d96365210faecda877c5a12cf440bdf42
F src/global.c 448419c44ce0701104c2121b0e06919b44514c0c
F src/legacy.c 2ad5b52df322d0f132f66817095e0e79c8942611
F src/loadext.c 3f96631089fc4f3871a67f02f2e4fc7ea4d51edc
F src/main.c 95e13cd23b7a88e33c1acfe233c748fd9dd7e467
-F src/malloc.c 1d862da7eb382d4b79b55436b04278fedec288e7
+F src/malloc.c a1f0f8ae110abb8eb546e259ab0eaea7e0f9b588
F src/mem0.c f2f84062d1f35814d6535c9f9e33de3bfb3b132c
F src/mem1.c e6d5c23941288df8191b8a98c28e3f57771e2270
F src/mem2.c d02bd6a5b34f2d59012a852615621939d9c09548
F src/os_win.c 40636702058ed4dcd35d68151bfab56d4997cdc1
F src/pager.c da7ffd068347cdc88b477875585d53dcf2bdc4a7
F src/pager.h 0c9f3520c00d8a3b8e792ca56c9a11b6b02b4b0f
-F src/parse.y 30ae25cd9ce8002527fca3011052a7fba0aff349
+F src/parse.y b9ba0946a13e9f32a96044e64a3e8780269b08b0
F src/pcache.c fcf7738c83c4d3e9d45836b2334c8a368cc41274
F src/pcache.h 9b927ccc5a538e31b4c3bc7eec4f976db42a1324
F src/pcache1.c f587565f4ba0fd1772067eaa96814dce761b7a4c
F src/pragma.c 22ed04836aab8ce134c53be1ca896f3ad20fabdb
-F src/prepare.c 662b7d30574558822ca6f0621cbb7aef7e87cee3
+F src/prepare.c 157a7528ba686964ab0e0687749ca30adb9ab614
F src/printf.c 9866a9a9c4a90f6d4147407f373df3fd5d5f9b6f
F src/random.c 676b9d7ac820fe81e6fb2394ac8c10cff7f38628
F src/resolve.c 094e44450371fb27869eb8bf679aacbe51fdc56d
F src/rowset.c ba9375f37053d422dd76965a9c370a13b6e1aac4
-F src/select.c 4d0b77fd76ff80f09a798ee98953e344c9de8fbb
+F src/select.c 607e5b2d3be379781e5be3ac0854f5c237152d26
F src/shell.c 0a11f831603f17fea20ca97133c0f64e716af4a7
F src/sqlite.h.in 0db1e59d89aeacb8fe64a19fd14c13a796060ccb
F src/sqlite3ext.h 1db7d63ab5de4b3e6b83dd03d1a4e64fef6d2a17
-F src/sqliteInt.h b6858d742b30d556886cca16437fb0a4aad2e065
+F src/sqliteInt.h ddaadadd35b07e468b0a07a5575c796a71e89dc1
F src/sqliteLimit.h ffe93f5a0c4e7bd13e70cd7bf84cfb5c3465f45d
F src/status.c 237b193efae0cf6ac3f0817a208de6c6c6ef6d76
F src/table.c 332ab0ea691e63862e2a8bdfe2c0617ee61062a3
-F src/tclsqlite.c 8a472804b901d4559213eeda538c2eadb2ad7f2a
+F src/tclsqlite.c 3d64c59fa441c4b6d550cb97b03c91693b87bbd1
F src/test1.c 17300af44640eea439778f5b5e03e0d68a6f00a2
F src/test2.c 71c22e2974f8094fe0fd1eba8f27872dde9b2a39
F src/test3.c d3115b301c6ee761b102f315fe24125f3d6c3a4d
F src/test_tclvar.c 9e42fa59d3d2f064b7ab8628e7ab2dc8a9fe93d4
F src/test_thread.c 1c7a895dbc469d87d22c1b36f269a6f799fc47a8
F src/test_wsd.c 3ae5101de6cbfda2720152ab659ea84079719241
-F src/tokenize.c 6987fb7f0d6a87ac53499aee568cabb05eb4bea8
+F src/tokenize.c fff72a9bc0af326583e5966daecebeb5ed9b9614
F src/trigger.c 21f39db410cdc32166a94900ac1b3df98ea560e6
F src/update.c 8ededddcde6f7b6da981dd0429a5d34518a475b7
F src/utf.c 1da9c832dba0fa8f865b5b902d93f420a1ee4245
F src/vdbeInt.h 53a2f4696871712646c77351904576cca6ad9752
F src/vdbeapi.c 025d83f51f5e0a6e0fb55d603103d24825577967
F src/vdbeaux.c be958dfe3a476ccb58dbc0d5786d58717f40f4b0
-F src/vdbeblob.c 3408f5e1ab62627300b9c9c3168cff1de65e1658
+F src/vdbeblob.c e67757450ae8581a8b354d9d7e467e41502dfe38
F src/vdbemem.c 38615b5d4b1b3b5a1221a5623578e5e3864e4888
-F src/vtab.c 18d671f0a45d0159088070bc6b219a3105034c87
+F src/vtab.c f1aba5a6dc1f83b97a39fbbc58ff8cbc76311347
F src/walker.c 42bd3f00ca2ef5ae842304ec0d59903ef051412d
F src/where.c 55b13048fd0f82b330511e37766208b96fd764df
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
F test/alias.test 597662c5d777a122f9a3df0047ea5c5bd383a911
F test/all.test 14165b3e32715b700b5f0cbf8f6e3833dda0be45
-F test/alter.test 958b36b7e9752e8a4ed03ba34690b06e48b0e3e0
+F test/alter.test 645b2e8d23c9936f9494af9d2fa7f8351a248c6e
F test/alter2.test dd55146e812622c8fc51fd2216bcd8dca8880752
F test/alter3.test 25b95a136708f22b87184fa6a4309eea03d65153
F test/alter4.test 9386ffd1e9c7245f43eca412b2058d747509cc1f
F test/capi3c.test ce0fcbbaccfc9703fb247ea9ac5ada96dc9ca047
F test/capi3d.test 57d83b690d7364bde02cddbf8339a4b50d80ce23
F test/cast.test 166951664a0b0a2e0f8fb5997a152490c6363932
-F test/check.test 024ed399600b799160378cf9d9f436bdf5dfd184
+F test/check.test 4f245970b4583555a349dceacdae7976222d834a
F test/collate1.test e3eaa48c21e150814be1a7b852d2a8af24458d04
F test/collate2.test 04cebe4a033be319d6ddbb3bbc69464e01700b49
F test/collate3.test d28d2cfab2c3a3d4628ae4b2b7afc9965daa3b4c
F test/lock4.test 991b57669a868bbfd39fe0c0df0d493985829105
F test/lock5.test 6b1f78f09ad1522843dad571b76b321e6f439bf7
F test/lock6.test 862aa71e97b288d6b3f92ba3313f51bd0b003776
-F test/lookaside.test e69f822f13745f1d5c445c6e30e30f059f30c8e5
+F test/lookaside.test b3e928efeb9a31147bb72350462831e104ec2c1e
F test/main.test 187a9a1b5248ed74a83838c581c15ec6023b555b
F test/make-where7.tcl 40bb740b37eead343eaf57b74ab72d2a5a304745
F test/malloc.test 7388109bccc42888ad4e2cb01b2169eb98d4d283
F test/misc6.test 953cc693924d88e6117aeba16f46f0bf5abede91
F test/misc7.test debcd7dbfd847ae97b16ceb7fec6f567902874a6
F test/misuse.test 30b3a458e5a70c31e74c291937b6c82204c59f33
-F test/mutex1.test ace3ba551ef0cd864df2b820b5dbe18d28b4db6c
+F test/mutex1.test ebd54720401fafe854799dc86b7bf60b75631935
F test/mutex2.test bfeaeac2e73095b2ac32285d2756e3a65e681660
F test/nan.test c627d79b3d36ea892563fd67584b3e8a18f0618a
F test/notify1.test 9a985a94f34de1b24daf25fd86b6d5033ba532d0
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
-P 7c2df04b52a40d5d1b744ad1097f7c12143d8c2c
-R 703f5e83ff72a6ceec997ed32c6b6e4e
-U danielk1977
-Z 3f57c912d20fa971468a1ff4756c679d
+P 8ca6a665650c9683a202f3ced17b14f7c85624bf
+R 8c93b31b69e1e1ff0ee86ef0261f4c0c
+U drh
+Z 226c5008143d3b67d9a3ebdf1903227a
-8ca6a665650c9683a202f3ced17b14f7c85624bf
\ No newline at end of file
+ea74d8dc62f5784089aa8ef098e97c505a79b176
\ No newline at end of file
** This file contains C code routines that used to generate VDBE code
** that implements the ALTER TABLE command.
**
-** $Id: alter.c,v 1.54 2009/02/28 10:47:42 danielk1977 Exp $
+** $Id: alter.c,v 1.55 2009/03/24 15:08:10 drh Exp $
*/
#include "sqliteInt.h"
if( !pNew ) goto exit_begin_add_column;
pParse->pNewTable = pNew;
pNew->nRef = 1;
- pNew->db = db;
+ pNew->dbMem = pTab->dbMem;
pNew->nCol = pTab->nCol;
assert( pNew->nCol>0 );
nAlloc = (((pNew->nCol-1)/8)*8)+8;
** COMMIT
** ROLLBACK
**
-** $Id: build.c,v 1.525 2009/03/21 16:19:26 drh Exp $
+** $Id: build.c,v 1.526 2009/03/24 15:08:10 drh Exp $
*/
#include "sqliteInt.h"
** Reclaim the memory used by an index
*/
static void freeIndex(Index *p){
- sqlite3 *db = p->pTable->db;
+ sqlite3 *db = p->pTable->dbMem;
sqlite3DbFree(db, p->zColAff);
sqlite3DbFree(db, p);
}
static void sqliteResetColumnNames(Table *pTable){
int i;
Column *pCol;
- sqlite3 *db = pTable->db;
+ sqlite3 *db = pTable->dbMem;
assert( pTable!=0 );
if( (pCol = pTable->aCol)!=0 ){
for(i=0; i<pTable->nCol; i++, pCol++){
sqlite3 *db;
if( pTable==0 ) return;
- db = pTable->db;
+ db = pTable->dbMem;
/* Do not delete the table until the reference count reaches zero. */
pTable->nRef--;
pTable->iPKey = -1;
pTable->pSchema = db->aDb[iDb].pSchema;
pTable->nRef = 1;
- pTable->db = db;
+ pTable->dbMem = db->lookaside.bEnabled ? db : 0;
if( pParse->pNewTable ) sqlite3DeleteTable(pParse->pNewTable);
pParse->pNewTable = pTable;
assert( pTable->pSelect );
pSel = sqlite3SelectDup(db, pTable->pSelect, 0);
if( pSel ){
+ int enableLookaside = db->lookaside.bEnabled;
n = pParse->nTab;
sqlite3SrcListAssignCursors(pParse, pSel->pSrc);
pTable->nCol = -1;
+ db->lookaside.bEnabled = 0;
#ifndef SQLITE_OMIT_AUTHORIZATION
xAuth = db->xAuth;
db->xAuth = 0;
#else
pSelTab = sqlite3ResultSetOfSelect(pParse, pSel);
#endif
+ db->lookaside.bEnabled = enableLookaside;
pParse->nTab = n;
if( pSelTab ){
assert( pTable->aCol==0 );
** This file contains functions used to access the internal hash tables
** of user defined functions and collation sequences.
**
-** $Id: callback.c,v 1.36 2009/03/05 04:20:32 shane Exp $
+** $Id: callback.c,v 1.37 2009/03/24 15:08:10 drh Exp $
*/
#include "sqliteInt.h"
sqlite3HashInit(&pSchema->tblHash, 0);
for(pElem=sqliteHashFirst(&temp1); pElem; pElem=sqliteHashNext(pElem)){
Table *pTab = sqliteHashData(pElem);
+ assert( pTab->dbMem==0 );
sqlite3DeleteTable(pTab);
}
sqlite3HashClear(&temp1);
** This file contains routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite.
**
-** $Id: expr.c,v 1.421 2009/03/23 04:33:32 danielk1977 Exp $
+** $Id: expr.c,v 1.422 2009/03/24 15:08:10 drh Exp $
*/
#include "sqliteInt.h"
pNew->iAgg = -1;
pNew->span.z = (u8*)"";
if( pToken ){
+ int c;
assert( pToken->dyn==0 );
- pNew->span = pNew->token = *pToken;
+ pNew->span = *pToken;
+
+ /* The pToken->z value is constant and must not change. But
+ ** this expression might be passed to sqlite3DequoteExpr() which
+ ** will attempt to modify pNew->token.z. Hence, if the token
+ ** is quoted, make a copy now so that DequoteExpr() will change
+ ** the copy rather than the original (read-only) text.
+ */
+ if( pToken->n>=2
+ && ((c = pToken->z[0])=='\'' || c=='"' || c=='[' || c=='`') ){
+ sqlite3TokenCopy(db, &pNew->token, pToken);
+ }else{
+ pNew->token = *pToken;
+ }
}else if( pLeft ){
if( pRight ){
if( pRight->span.dyn==0 && pLeft->span.dyn==0 ){
assert( pToken );
pNew = sqlite3DbMallocZero(db, sizeof(Expr) );
if( pNew==0 ){
- sqlite3ExprListDelete(db, pList); /* Avoid leaking memory when malloc fails */
+ sqlite3ExprListDelete(db, pList); /* Avoid memory leak when malloc fails */
return 0;
}
pNew->op = TK_FUNCTION;
pNew->x.pList = pList;
assert( !ExprHasProperty(pNew, EP_xIsSelect) );
assert( pToken->dyn==0 );
- pNew->token = *pToken;
- pNew->span = pNew->token;
-
+ pNew->span = *pToken;
+ sqlite3TokenCopy(db, &pNew->token, pToken);
sqlite3ExprSetHeight(pParse, pNew);
return pNew;
}
** If so, remove the quotation marks.
*/
void sqlite3DequoteExpr(sqlite3 *db, Expr *p){
- if( ExprHasAnyProperty(p, EP_Dequoted) ){
- return;
+ if( !ExprHasAnyProperty(p, EP_Dequoted) ){
+ ExprSetProperty(p, EP_Dequoted);
+ sqlite3Dequote((char*)p->token.z);
}
- ExprSetProperty(p, EP_Dequoted);
-
- /* If p->token.dyn==0 and none of EP_Reduced, EP_TokenOnly, or
- ** EP_SpanOnly are set, that means that the p->token.z string points
- ** back to the original SQL statement text. In that case, we need
- ** to make a copy before modifying the string, otherwise we would
- ** corrupt the original SQL statement text.
- */
- testcase( p->token.dyn==0 && ExprHasProperty(p, EP_Reduced) );
- testcase( p->token.dyn==0 && ExprHasProperty(p, EP_TokenOnly) );
- testcase( p->token.dyn==0 && ExprHasProperty(p, EP_SpanOnly) );
- if( p->token.dyn==0
- && !ExprHasAnyProperty(p, EP_Reduced|EP_TokenOnly|EP_SpanOnly)
- ){
- sqlite3TokenCopy(db, &p->token, &p->token);
- }
-
- sqlite3Dequote((char*)p->token.z);
}
/*
Expr *sqlite3ExprDup(sqlite3 *db, Expr *p, int flags){
return exprDup(db, p, flags, 0);
}
-void sqlite3TokenCopy(sqlite3 *db, Token *pTo, Token *pFrom){
+void sqlite3TokenCopy(sqlite3 *db, Token *pTo, const Token *pFrom){
if( pTo->dyn ) sqlite3DbFree(db, (char*)pTo->z);
if( pFrom->z ){
pTo->n = pFrom->n;
**
** Memory allocation functions used throughout sqlite.
**
-** $Id: malloc.c,v 1.60 2009/03/23 17:49:15 drh Exp $
+** $Id: malloc.c,v 1.61 2009/03/24 15:08:10 drh Exp $
*/
#include "sqliteInt.h"
#include <stdarg.h>
*/
void *sqlite3DbMallocRaw(sqlite3 *db, int n){
void *p;
+ assert( db==0 || sqlite3_mutex_held(db->mutex) );
#ifndef SQLITE_OMIT_LOOKASIDE
if( db ){
LookasideSlot *pBuf;
- assert( sqlite3_mutex_held(db->mutex) );
if( db->mallocFailed ){
return 0;
}
*/
void *sqlite3DbRealloc(sqlite3 *db, void *p, int n){
void *pNew = 0;
+ assert( db!=0 );
assert( sqlite3_mutex_held(db->mutex) );
if( db->mallocFailed==0 ){
if( p==0 ){
** the parser. Lemon will also generate a header file containing
** numeric codes for all of the tokens.
**
-** @(#) $Id: parse.y,v 1.271 2009/03/22 20:36:19 drh Exp $
+** @(#) $Id: parse.y,v 1.272 2009/03/24 15:08:10 drh Exp $
*/
// All token codes are small integers with #defines that begin with "TK_"
///////////////////// The CREATE TABLE statement ////////////////////////////
//
cmd ::= create_table create_table_args.
-create_table ::= CREATE temp(T) TABLE ifnotexists(E) nm(Y) dbnm(Z). {
+create_table ::= createkw temp(T) TABLE ifnotexists(E) nm(Y) dbnm(Z). {
sqlite3StartTable(pParse,&Y,&Z,T,0,0,E);
}
+createkw(A) ::= CREATE(X). {
+ pParse->db->lookaside.bEnabled = 0;
+ A = X;
+}
%type ifnotexists {int}
ifnotexists(A) ::= . {A = 0;}
ifnotexists(A) ::= IF NOT EXISTS. {A = 1;}
///////////////////// The CREATE VIEW statement /////////////////////////////
//
%ifndef SQLITE_OMIT_VIEW
-cmd ::= CREATE(X) temp(T) VIEW ifnotexists(E) nm(Y) dbnm(Z) AS select(S). {
+cmd ::= createkw(X) temp(T) VIEW ifnotexists(E) nm(Y) dbnm(Z) AS select(S). {
sqlite3CreateView(pParse, &X, &Y, &Z, S, T, E);
}
cmd ::= DROP VIEW ifexists(E) fullname(X). {
///////////////////////////// The CREATE INDEX command ///////////////////////
//
-cmd ::= CREATE(S) uniqueflag(U) INDEX ifnotexists(NE) nm(X) dbnm(D)
+cmd ::= createkw(S) uniqueflag(U) INDEX ifnotexists(NE) nm(X) dbnm(D)
ON nm(Y) LP idxlist(Z) RP(E). {
sqlite3CreateIndex(pParse, &X, &D,
sqlite3SrcListAppend(pParse->db,0,&Y,0), Z, U,
%ifndef SQLITE_OMIT_TRIGGER
-cmd ::= CREATE trigger_decl(A) BEGIN trigger_cmd_list(S) END(Z). {
+cmd ::= createkw trigger_decl(A) BEGIN trigger_cmd_list(S) END(Z). {
Token all;
all.z = A.z;
all.n = (int)(Z.z - A.z) + Z.n;
sqlite3AlterFinishAddColumn(pParse, &Y);
}
add_column_fullname ::= fullname(X). {
+ pParse->db->lookaside.bEnabled = 0;
sqlite3AlterBeginAddColumn(pParse, X);
}
kwcolumn_opt ::= .
%ifndef SQLITE_OMIT_VIRTUALTABLE
cmd ::= create_vtab. {sqlite3VtabFinishParse(pParse,0);}
cmd ::= create_vtab LP vtabarglist RP(X). {sqlite3VtabFinishParse(pParse,&X);}
-create_vtab ::= CREATE VIRTUAL TABLE nm(X) dbnm(Y) USING nm(Z). {
+create_vtab ::= createkw VIRTUAL TABLE nm(X) dbnm(Y) USING nm(Z). {
sqlite3VtabBeginParse(pParse, &X, &Y, &Z);
}
vtabarglist ::= vtabarg.
** interface, and routines that contribute to loading the database schema
** from disk.
**
-** $Id: prepare.c,v 1.113 2009/03/24 04:46:08 danielk1977 Exp $
+** $Id: prepare.c,v 1.114 2009/03/24 15:08:10 drh Exp $
*/
#include "sqliteInt.h"
** But because db->init.busy is set to 1, no VDBE code is generated
** or executed. All the parser does is build the internal data
** structures that describe the table, index, or view.
- **
- ** While the CREATE XXX statement is being processed, the lookaside
- ** buffer is disabled. One reason for this is that when running in
- ** shared cache mode, the objects allocated for the in-memory schema
- ** might be freed from within a call made on a different database
- ** connection to db (e.g. if the second connection executes a DROP
- ** TABLE statement). If the objects that make up the Table structure
- ** are allocated from within db's lookaside buffer, then db->mutex
- ** would have to be obtained before they could be freed. This would
- ** open the door to deadlock in a multi-threaded application.
- **
- ** Another reason to disable the lookaside buffer is that lookaside
- ** gives the greatest performance boost when it is used to allocate
- ** and free small transient objects. The schema objects, which tend
- ** to have long lifetimes, are better allocated from the heap.
*/
char *zErr;
int rc;
- u8 lookasideEnabled;
assert( db->init.busy );
db->init.iDb = iDb;
db->init.newTnum = atoi(argv[1]);
- lookasideEnabled = db->lookaside.bEnabled;
- db->lookaside.bEnabled = 0;
rc = sqlite3_exec(db, argv[2], 0, 0, &zErr);
db->init.iDb = 0;
- db->lookaside.bEnabled = lookasideEnabled;
assert( rc!=SQLITE_OK || zErr==0 );
if( SQLITE_OK!=rc ){
pData->rc = rc;
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
-** $Id: select.c,v 1.504 2009/02/25 08:56:47 danielk1977 Exp $
+** $Id: select.c,v 1.505 2009/03/24 15:08:10 drh Exp $
*/
#include "sqliteInt.h"
if( pTab==0 ){
return 0;
}
- pTab->db = db;
+ pTab->dbMem = db->lookaside.bEnabled ? db : 0;
pTab->nRef = 1;
pTab->zName = 0;
selectColumnsFromExprList(pParse, pSelect->pEList, &pTab->nCol, &pTab->aCol);
sqlite3WalkSelect(pWalker, pSel);
pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
if( pTab==0 ) return WRC_Abort;
- pTab->db = db;
+ pTab->dbMem = db->lookaside.bEnabled ? db : 0;
pTab->nRef = 1;
pTab->zName = sqlite3MPrintf(db, "sqlite_subquery_%p_", (void*)pTab);
while( pSel->pPrior ){ pSel = pSel->pPrior; }
*************************************************************************
** Internal interface definitions for SQLite.
**
-** @(#) $Id: sqliteInt.h,v 1.845 2009/03/23 04:33:33 danielk1977 Exp $
+** @(#) $Id: sqliteInt.h,v 1.846 2009/03/24 15:08:10 drh Exp $
*/
#ifndef _SQLITEINT_H_
#define _SQLITEINT_H_
** lookaside malloc subsystem. Each available memory allocation in
** the lookaside subsystem is stored on a linked list of LookasideSlot
** objects.
+**
+** Lookaside allocations are only allowed for objects that are associated
+** with a particular database connection. Hence, schema information cannot
+** be stored in lookaside because in shared cache mode the schema information
+** is shared by multiple database connections. Therefore, while parsing
+** schema information, the Lookaside.bEnabled flag is cleared so that
+** lookaside allocations are not used to construct the schema objects.
*/
struct Lookaside {
u16 sz; /* Size of each buffer in bytes */
- u8 bEnabled; /* True if use lookaside. False to ignore it */
+ u8 bEnabled; /* False to disable new lookaside allocations */
u8 bMalloced; /* True if pStart obtained from sqlite3_malloc() */
int nOut; /* Number of buffers currently checked out */
int mxOut; /* Highwater mark for nOut */
** of a SELECT statement.
*/
struct Table {
- sqlite3 *db; /* Associated database connection. Might be NULL. */
+ sqlite3 *dbMem; /* DB connection used for lookaside allocations. */
char *zName; /* Name of the table or view */
int iPKey; /* If not negative, use aCol[iPKey] as the primary key */
int nCol; /* Number of columns in this table */
int sqlite3OpenTableAndIndices(Parse*, Table*, int, int);
void sqlite3BeginWriteOperation(Parse*, int, int);
Expr *sqlite3ExprDup(sqlite3*,Expr*,int);
-void sqlite3TokenCopy(sqlite3*,Token*, Token*);
+void sqlite3TokenCopy(sqlite3*,Token*,const Token*);
ExprList *sqlite3ExprListDup(sqlite3*,ExprList*,int);
SrcList *sqlite3SrcListDup(sqlite3*,SrcList*,int);
IdList *sqlite3IdListDup(sqlite3*,IdList*);
** A TCL Interface to SQLite. Append this file to sqlite3.c and
** compile the whole thing to build a TCL-enabled version of SQLite.
**
-** $Id: tclsqlite.c,v 1.238 2009/03/16 13:19:36 danielk1977 Exp $
+** $Id: tclsqlite.c,v 1.239 2009/03/24 15:08:10 drh Exp $
*/
#include "tcl.h"
#include <errno.h>
int i;
const char *zFile;
const char *zVfs = 0;
- int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_NOMUTEX;
+ int flags;
Tcl_DString translatedFilename;
+
+ /* In normal use, each TCL interpreter runs in a single thread. So
+ ** by default, we can turn of mutexing on SQLite database connections.
+ ** However, for testing purposes it is useful to have mutexes turned
+ ** on. So, by default, mutexes default off. But if compiled with
+ ** SQLITE_TCL_DEFAULT_FULLMUTEX then mutexes default on.
+ */
+#ifdef SQLITE_TCL_DEFAULT_FULLMUTEX
+ flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX;
+#else
+ flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_NOMUTEX;
+#endif
+
if( objc==2 ){
zArg = Tcl_GetStringFromObj(objv[1], 0);
if( strcmp(zArg,"-version")==0 ){
** individual tokens and sends those tokens one-by-one over to the
** parser for analysis.
**
-** $Id: tokenize.c,v 1.153 2009/01/20 16:53:41 danielk1977 Exp $
+** $Id: tokenize.c,v 1.154 2009/03/24 15:08:10 drh Exp $
*/
#include "sqliteInt.h"
#include <stdlib.h>
** error message.
*/
int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
- int nErr = 0;
- int i;
- void *pEngine;
- int tokenType;
- int lastTokenParsed = -1;
- sqlite3 *db = pParse->db;
- int mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
+ int nErr = 0; /* Number of errors encountered */
+ int i; /* Loop counter */
+ void *pEngine; /* The LEMON-generated LALR(1) parser */
+ int tokenType; /* type of the next token */
+ int lastTokenParsed = -1; /* type of the previous token */
+ int enableLookaside; /* Saved value of db->lookaside.bEnabled */
+ sqlite3 *db = pParse->db; /* The database connection */
+ int mxSqlLen; /* Max length of an SQL string */
+
+ mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
if( db->activeVdbeCnt==0 ){
db->u1.isInterrupted = 0;
}
assert( pParse->nVarExpr==0 );
assert( pParse->nVarExprAlloc==0 );
assert( pParse->apVarExpr==0 );
+ enableLookaside = db->lookaside.bEnabled;
+ if( db->lookaside.pStart ) db->lookaside.bEnabled = 1;
while( !db->mallocFailed && zSql[i]!=0 ){
assert( i>=0 );
pParse->sLastToken.z = (u8*)&zSql[i];
);
#endif /* YYDEBUG */
sqlite3ParserFree(pEngine, sqlite3_free);
+ db->lookaside.bEnabled = enableLookaside;
if( db->mallocFailed ){
pParse->rc = SQLITE_NOMEM;
}
**
** This file contains code used to implement incremental BLOB I/O.
**
-** $Id: vdbeblob.c,v 1.30 2009/03/19 18:51:07 danielk1977 Exp $
+** $Id: vdbeblob.c,v 1.31 2009/03/24 15:08:10 drh Exp $
*/
#include "sqliteInt.h"
int sqlite3_blob_close(sqlite3_blob *pBlob){
Incrblob *p = (Incrblob *)pBlob;
int rc;
+ sqlite3 *db;
+ db = p->db;
+ sqlite3_mutex_enter(db->mutex);
rc = sqlite3_finalize(p->pStmt);
- sqlite3DbFree(p->db, p);
+ sqlite3DbFree(db, p);
+ sqlite3_mutex_leave(db->mutex);
return rc;
}
*************************************************************************
** This file contains code used to help implement virtual tables.
**
-** $Id: vtab.c,v 1.83 2009/03/19 18:51:07 danielk1977 Exp $
+** $Id: vtab.c,v 1.84 2009/03/24 15:08:10 drh Exp $
*/
#ifndef SQLITE_OMIT_VIRTUALTABLE
#include "sqliteInt.h"
*/
void sqlite3VtabClear(Table *p){
sqlite3_vtab *pVtab = p->pVtab;
- sqlite3 *db = p->db;
+ Schema *pSchema = p->pSchema;
+ sqlite3 *db = pSchema ? pSchema->db : 0;
if( pVtab ){
assert( p->pMod && p->pMod->pModule );
sqlite3VtabUnlock(db, pVtab);
# This file implements regression tests for SQLite library. The
# focus of this script is testing the ALTER TABLE statement.
#
-# $Id: alter.test,v 1.31 2009/02/13 03:43:32 drh Exp $
+# $Id: alter.test,v 1.32 2009/03/24 15:08:10 drh Exp $
#
set testdir [file dirname $argv0]
execsql {
SELECT SQLITE_RENAME_TABLE(0,0);
SELECT SQLITE_RENAME_TABLE(10,20);
- SELECT SQLITE_RENAME_TABLE("foo", "foo");
+ SELECT SQLITE_RENAME_TABLE('foo', 'foo');
}
} {{} {} {}}
# This file implements regression tests for SQLite library. The
# focus of this file is testing CHECK constraints
#
-# $Id: check.test,v 1.11 2007/07/23 19:39:47 drh Exp $
+# $Id: check.test,v 1.12 2009/03/24 15:08:10 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
} {4 11.0}
do_test check-2.1 {
+breakpoint
execsql {
CREATE TABLE t2(
x INTEGER CHECK( typeof(coalesce(x,0))=="integer" ),
- y REAL CHECK( typeof(coalesce(y,0.1))=="real" ),
- z TEXT CHECK( typeof(coalesce(z,''))=="text" )
+ y REAL CHECK( typeof(coalesce(y,0.1))=='real' ),
+ z TEXT CHECK( typeof(coalesce(z,''))=='text' )
);
}
} {}
SELECT * FROM t2;
}
} {1 2.2 three}
+db close
+sqlite3 db test.db
do_test check-2.3 {
execsql {
INSERT INTO t2 VALUES(NULL, NULL, NULL);
#
# Tests for the lookaside memory allocator.
#
-# $Id: lookaside.test,v 1.8 2008/10/11 17:06:04 drh Exp $
+# $Id: lookaside.test,v 1.9 2009/03/24 15:08:10 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
db eval {CREATE TABLE t1(w,x,y,z);}
foreach {x y z} [sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 0] break
expr {$x==0 && $y<$z && $z==18}
-} {1}
+} {0}
do_test lookaside-1.5 {
foreach {x y z} [sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 1] break
expr {$x==0 && $y<$z && $z==18}
-} {1}
+} {0}
do_test lookaside-1.6 {
foreach {x y z} [sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 0] break
expr {$x==0 && $y==$z && $y<18}
#
#***********************************************************************
#
-# $Id: mutex1.test,v 1.18 2009/03/20 13:15:31 drh Exp $
+# $Id: mutex1.test,v 1.19 2009/03/24 15:08:10 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
do_test mutex1.2.$mode.2 {
sqlite3_initialize
clear_mutex_counters
- sqlite3 db test.db -nomutex 0
+ sqlite3 db test.db -nomutex 0 -fullmutex 0
catchsql { CREATE TABLE abc(a, b, c) }
db eval {
INSERT INTO abc VALUES(1, 2, 3);