mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-08 14:02:16 +03:00
Reorganize and cleanup the prepared statement object. Remove code that has
been commented out for ages and is no longer relevant to anything. (CVS 6786) FossilOrigin-Name: 37ae5f5e8feb34a8e6e8b34aa18df1e9a1ce55cb
This commit is contained in:
28
manifest
28
manifest
@@ -1,5 +1,5 @@
|
||||
C Fix\sa\spossible\ssegfault\swhen\sbacking\sup\san\sencrypted\sdatabase.\s(CVS\s6785)
|
||||
D 2009-06-19T02:25:49
|
||||
C Reorganize\sand\scleanup\sthe\sprepared\sstatement\sobject.\s\sRemove\scode\sthat\shas\nbeen\scommented\sout\sfor\sages\sand\sis\sno\slonger\srelevant\sto\sanything.\s(CVS\s6786)
|
||||
D 2009-06-19T14:06:03
|
||||
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
|
||||
F Makefile.in 8b8fb7823264331210cddf103831816c286ba446
|
||||
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
|
||||
@@ -116,7 +116,7 @@ F src/date.c ab5f7137656652a48434d64f96bdcdc823bb23b3
|
||||
F src/delete.c cb791855c7948cecc96def9d97989879ca26f257
|
||||
F src/expr.c 1d580a7b2e51092785cbbc1fb8d2ff84e93c76dc
|
||||
F src/fault.c dc88c821842157460750d2d61a8a8b4197d047ff
|
||||
F src/func.c 006875b8e94c5ee9a41915f197797703e3867365
|
||||
F src/func.c d108b0028050ecd0fd9508268995892937d577ae
|
||||
F src/global.c 448419c44ce0701104c2121b0e06919b44514c0c
|
||||
F src/hash.c ebcaa921ffd9d86f7ea5ae16a0a29d1c871130a7
|
||||
F src/hash.h 35b216c13343d0b4f87d9f21969ac55ad72174e1
|
||||
@@ -125,7 +125,7 @@ F src/insert.c 69ef88ce30d1f65315b57aba63b2d4e9bdca1090
|
||||
F src/journal.c e00df0c0da8413ab6e1bb7d7cab5665d4a9000d0
|
||||
F src/legacy.c 9a56cf126ceee332b56061bf16bd0fb4ff9e26c0
|
||||
F src/loadext.c 0e88a335665db0b2fb4cece3e49dcb65d832635a
|
||||
F src/main.c a30a4a7faaefb3dbceee60f80caf985f2f38b3ea
|
||||
F src/main.c 120d65f0c2d011b0d7f373680a913b84819b2f92
|
||||
F src/malloc.c 7b3b6423f5b355e5d649b91e16ef252d610bcf19
|
||||
F src/mem0.c f2f84062d1f35814d6535c9f9e33de3bfb3b132c
|
||||
F src/mem1.c e6d5c23941288df8191b8a98c28e3f57771e2270
|
||||
@@ -148,11 +148,11 @@ F src/os_unix.c b64129c296e480c2827606e206ea51bb30904626
|
||||
F src/os_win.c 725c38a524d168ce280446ad8761d731bc516405
|
||||
F src/pager.c afe8e53fef52725e05b32ca6e2cfef04b933ca48
|
||||
F src/pager.h 5aec418bf99f568b92ae82816a1463400513726d
|
||||
F src/parse.y bab89225c2543a350ef96995926520bbbd781aba
|
||||
F src/parse.y b6e99f4208a34eb83c62f20dd67f8d9058e86768
|
||||
F src/pcache.c 395f752a13574120bd7513a400ba02a265aaa76d
|
||||
F src/pcache.h 9b927ccc5a538e31b4c3bc7eec4f976db42a1324
|
||||
F src/pcache1.c 97e7e8e6e34026fb43b47d08532b0c02e959c26c
|
||||
F src/pragma.c 06b3a4b93a5e587f1c04b4a40016eb360792cdf3
|
||||
F src/pragma.c 1774ff8e2f167368225108489b1c9d123aa13257
|
||||
F src/prepare.c aba6954623ad10e94c3eb30e6c2db5d709852bfc
|
||||
F src/printf.c 508a1c59433353552b6553cba175eaa7331f8fc1
|
||||
F src/random.c 676b9d7ac820fe81e6fb2394ac8c10cff7f38628
|
||||
@@ -162,7 +162,7 @@ F src/select.c 71748b8e244112cf73df9446c4246c192276c30d
|
||||
F src/shell.c db2643650b9268df89a4bedca3f1c6d9e786f1bb
|
||||
F src/sqlite.h.in 9fe53ec7a8310d7d18d482b85e46f5556abfd1de
|
||||
F src/sqlite3ext.h 1db7d63ab5de4b3e6b83dd03d1a4e64fef6d2a17
|
||||
F src/sqliteInt.h ad6f72619f491cc1732e7b83cc5acea621edabd7
|
||||
F src/sqliteInt.h 9fd22fed12cbb0eccfe14108796ae05fa473786e
|
||||
F src/sqliteLimit.h ffe93f5a0c4e7bd13e70cd7bf84cfb5c3465f45d
|
||||
F src/status.c 237b193efae0cf6ac3f0817a208de6c6c6ef6d76
|
||||
F src/table.c cc86ad3d6ad54df7c63a3e807b5783c90411a08d
|
||||
@@ -180,7 +180,7 @@ F src/test_async.c 731d23f953ece5bf40ce87810cfb7607218953c5
|
||||
F src/test_autoext.c f53b0cdf7bf5f08100009572a5d65cdb540bd0ad
|
||||
F src/test_backup.c 1384a18985a5a2d275c2662e48473bf1542ebd08
|
||||
F src/test_btree.c d7b8716544611c323860370ee364e897c861f1b0
|
||||
F src/test_config.c f947e2899812144c4c089083ed1554a97cd5f4b0
|
||||
F src/test_config.c 63d1b08809ca182ee75429573111b44735861c64
|
||||
F src/test_devsym.c 9f4bc2551e267ce7aeda195f3897d0f30c5228f4
|
||||
F src/test_func.c b8140bc4ed0d290d5e22972eb2a3bfd40aa798dc
|
||||
F src/test_hexio.c 2f1122aa3f012fa0142ee3c36ce5c902a70cd12f
|
||||
@@ -203,10 +203,10 @@ F src/update.c 6ae6c26adff8dc34532d578f66e6cfde04b5d177
|
||||
F src/utf.c 9541d28f40441812c0b40f00334372a0542c00ff
|
||||
F src/util.c a7e981e032c3c9c0887d50d7e658a33cb355b43d
|
||||
F src/vacuum.c 0e14f371ea3326c6b8cfba257286d798cd20db59
|
||||
F src/vdbe.c 09925c462891da6d2efdd68e657f3e072620177e
|
||||
F src/vdbe.c ad47fc3df73544d25e47ebb116b6d4777306256c
|
||||
F src/vdbe.h 35a648bc3279a120da24f34d9a25213ec15daf8a
|
||||
F src/vdbeInt.h 3727128255a93d116e454f67d4559700f7ae4d6f
|
||||
F src/vdbeapi.c 619992b16821b989050e8a12e259d795d30731a9
|
||||
F src/vdbeInt.h f5147efa8ead0ae78496487a83c7e87c54ffa405
|
||||
F src/vdbeapi.c 73bd1d2c57b953bc688d1d8c84b24c2084c2aec7
|
||||
F src/vdbeaux.c 77b6734303c58e36db65f6e63795425546905059
|
||||
F src/vdbeblob.c c25d7e7bc6d5917feeb17270bd275fa771f26e5c
|
||||
F src/vdbemem.c ba39c0afa609595c7c23dfc2ac929d9414faa59f
|
||||
@@ -736,7 +736,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
||||
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
||||
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
||||
F tool/vdbe-compress.tcl 672f81d693a03f80f5ae60bfefacd8a349e76746
|
||||
P 1c8ec2a6e4efbb3fdc58f999b7b725fa5dc4d0e9
|
||||
R 3d7c0621c5ac9f2c379cadce398f647c
|
||||
P 7d8f178c8145b90da31f6557f7cd99d154eb676e
|
||||
R b3e036533bac5a29d77c23602f39da64
|
||||
U drh
|
||||
Z 575e2486b6c7837b5553271f9ae077bd
|
||||
Z f2670ca2615f8f31d0717b2c5d58ef64
|
||||
|
@@ -1 +1 @@
|
||||
7d8f178c8145b90da31f6557f7cd99d154eb676e
|
||||
37ae5f5e8feb34a8e6e8b34aa18df1e9a1ce55cb
|
@@ -16,7 +16,7 @@
|
||||
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
|
||||
** All other code has file scope.
|
||||
**
|
||||
** $Id: func.c,v 1.237 2009/06/03 01:24:54 drh Exp $
|
||||
** $Id: func.c,v 1.238 2009/06/19 14:06:03 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <stdlib.h>
|
||||
@@ -1319,9 +1319,6 @@ void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
|
||||
db->mallocFailed = 1;
|
||||
}
|
||||
}
|
||||
#ifdef SQLITE_SSE
|
||||
(void)sqlite3SseFunctions(db);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -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.557 2009/06/09 19:53:58 drh Exp $
|
||||
** $Id: main.c,v 1.558 2009/06/19 14:06:03 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -583,13 +583,6 @@ int sqlite3_close(sqlite3 *db){
|
||||
}
|
||||
sqlite3_mutex_enter(db->mutex);
|
||||
|
||||
#ifdef SQLITE_SSE
|
||||
{
|
||||
extern void sqlite3SseCleanup(sqlite3*);
|
||||
sqlite3SseCleanup(db);
|
||||
}
|
||||
#endif
|
||||
|
||||
sqlite3ResetInternalSchema(db, 0);
|
||||
|
||||
/* If a transaction is open, the ResetInternalSchema() call above
|
||||
|
@@ -14,7 +14,7 @@
|
||||
** the parser. Lemon will also generate a header file containing
|
||||
** numeric codes for all of the tokens.
|
||||
**
|
||||
** @(#) $Id: parse.y,v 1.282 2009/06/12 13:53:52 drh Exp $
|
||||
** @(#) $Id: parse.y,v 1.283 2009/06/19 14:06:03 drh Exp $
|
||||
*/
|
||||
|
||||
// All token codes are small integers with #defines that begin with "TK_"
|
||||
@@ -1108,7 +1108,6 @@ cmd ::= VACUUM nm. {sqlite3Vacuum(pParse);}
|
||||
|
||||
///////////////////////////// The PRAGMA command /////////////////////////////
|
||||
//
|
||||
%ifndef SQLITE_OMIT_PARSER
|
||||
%ifndef SQLITE_OMIT_PRAGMA
|
||||
cmd ::= PRAGMA nm(X) dbnm(Z). {sqlite3Pragma(pParse,&X,&Z,0,0);}
|
||||
cmd ::= PRAGMA nm(X) dbnm(Z) EQ nmnum(Y). {sqlite3Pragma(pParse,&X,&Z,&Y,0);}
|
||||
@@ -1124,7 +1123,6 @@ nmnum(A) ::= ON(X). {A = X;}
|
||||
nmnum(A) ::= DELETE(X). {A = X;}
|
||||
nmnum(A) ::= DEFAULT(X). {A = X;}
|
||||
%endif SQLITE_OMIT_PRAGMA
|
||||
%endif SQLITE_OMIT_PARSER
|
||||
plus_num(A) ::= plus_opt number(X). {A = X;}
|
||||
minus_num(A) ::= MINUS number(X). {A = X;}
|
||||
number(A) ::= INTEGER|FLOAT(X). {A = X;}
|
||||
|
17
src/pragma.c
17
src/pragma.c
@@ -11,13 +11,13 @@
|
||||
*************************************************************************
|
||||
** This file contains code used to implement the PRAGMA command.
|
||||
**
|
||||
** $Id: pragma.c,v 1.212 2009/06/03 11:25:07 danielk1977 Exp $
|
||||
** $Id: pragma.c,v 1.213 2009/06/19 14:06:03 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
/* Ignore this whole file if pragmas are disabled
|
||||
*/
|
||||
#if !defined(SQLITE_OMIT_PRAGMA) && !defined(SQLITE_OMIT_PARSER)
|
||||
#if !defined(SQLITE_OMIT_PRAGMA)
|
||||
|
||||
/*
|
||||
** Interpret the given string as a safety level. Return 0 for OFF,
|
||||
@@ -1348,17 +1348,6 @@ void sqlite3Pragma(
|
||||
}else
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_SSE
|
||||
/*
|
||||
** Check to see if the sqlite_statements table exists. Create it
|
||||
** if it does not.
|
||||
*/
|
||||
if( sqlite3StrICmp(zLeft, "create_sqlite_statement_table")==0 ){
|
||||
extern int sqlite3CreateStatementsTable(Parse*);
|
||||
sqlite3CreateStatementsTable(pParse);
|
||||
}else
|
||||
#endif
|
||||
|
||||
#if SQLITE_HAS_CODEC
|
||||
if( sqlite3StrICmp(zLeft, "key")==0 && zRight ){
|
||||
sqlite3_key(db, zRight, sqlite3Strlen30(zRight));
|
||||
@@ -1423,4 +1412,4 @@ pragma_out:
|
||||
sqlite3DbFree(db, zRight);
|
||||
}
|
||||
|
||||
#endif /* SQLITE_OMIT_PRAGMA || SQLITE_OMIT_PARSER */
|
||||
#endif /* SQLITE_OMIT_PRAGMA */
|
||||
|
@@ -11,7 +11,7 @@
|
||||
*************************************************************************
|
||||
** Internal interface definitions for SQLite.
|
||||
**
|
||||
** @(#) $Id: sqliteInt.h,v 1.885 2009/06/18 17:22:39 drh Exp $
|
||||
** @(#) $Id: sqliteInt.h,v 1.886 2009/06/19 14:06:03 drh Exp $
|
||||
*/
|
||||
#ifndef _SQLITEINT_H_
|
||||
#define _SQLITEINT_H_
|
||||
@@ -848,9 +848,6 @@ struct sqlite3 {
|
||||
BusyHandler busyHandler; /* Busy callback */
|
||||
int busyTimeout; /* Busy handler timeout, in msec */
|
||||
Db aDbStatic[2]; /* Static space for the 2 default backends */
|
||||
#ifdef SQLITE_SSE
|
||||
sqlite3_stmt *pFetch; /* Used by SSE to fetch stored statements */
|
||||
#endif
|
||||
Savepoint *pSavepoint; /* List of active savepoints */
|
||||
int nSavepoint; /* Number of non-transaction savepoints */
|
||||
int nStatement; /* Number of nested statement-transactions */
|
||||
@@ -2890,11 +2887,6 @@ void sqlite3Put4byte(u8*, u32);
|
||||
#define sqlite3ConnectionClosed(x)
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef SQLITE_SSE
|
||||
#include "sseInt.h"
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_DEBUG
|
||||
void sqlite3ParserTrace(FILE*, char *);
|
||||
#endif
|
||||
|
@@ -16,7 +16,7 @@
|
||||
** The focus of this file is providing the TCL testing layer
|
||||
** access to compile-time constants.
|
||||
**
|
||||
** $Id: test_config.c,v 1.49 2009/06/09 13:42:25 drh Exp $
|
||||
** $Id: test_config.c,v 1.50 2009/06/19 14:06:03 drh Exp $
|
||||
*/
|
||||
|
||||
#include "sqliteLimit.h"
|
||||
@@ -359,12 +359,6 @@ Tcl_SetVar2(interp, "sqlite_options", "long_double",
|
||||
Tcl_SetVar2(interp, "sqlite_options", "pager_pragmas", "1", TCL_GLOBAL_ONLY);
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_OMIT_PARSER
|
||||
Tcl_SetVar2(interp, "sqlite_options", "parser", "0", TCL_GLOBAL_ONLY);
|
||||
#else
|
||||
Tcl_SetVar2(interp, "sqlite_options", "parser", "1", TCL_GLOBAL_ONLY);
|
||||
#endif
|
||||
|
||||
#if defined(SQLITE_OMIT_PRAGMA) || defined(SQLITE_OMIT_FLAG_PRAGMAS)
|
||||
Tcl_SetVar2(interp, "sqlite_options", "pragma", "0", TCL_GLOBAL_ONLY);
|
||||
Tcl_SetVar2(interp, "sqlite_options", "integrityck", "0", TCL_GLOBAL_ONLY);
|
||||
|
@@ -43,7 +43,7 @@
|
||||
** in this file for details. If in doubt, do not deviate from existing
|
||||
** commenting and indentation practices when changing or adding code.
|
||||
**
|
||||
** $Id: vdbe.c,v 1.855 2009/06/18 00:41:56 drh Exp $
|
||||
** $Id: vdbe.c,v 1.856 2009/06/19 14:06:03 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "vdbeInt.h"
|
||||
@@ -4560,7 +4560,7 @@ case OP_ParseSchema: {
|
||||
break;
|
||||
}
|
||||
|
||||
#if !defined(SQLITE_OMIT_ANALYZE) && !defined(SQLITE_OMIT_PARSER)
|
||||
#if !defined(SQLITE_OMIT_ANALYZE)
|
||||
/* Opcode: LoadAnalysis P1 * * * *
|
||||
**
|
||||
** Read the sqlite_stat1 table for database P1 and load the content
|
||||
@@ -4572,7 +4572,7 @@ case OP_LoadAnalysis: {
|
||||
rc = sqlite3AnalysisLoad(db, pOp->p1);
|
||||
break;
|
||||
}
|
||||
#endif /* !defined(SQLITE_OMIT_ANALYZE) && !defined(SQLITE_OMIT_PARSER) */
|
||||
#endif /* !defined(SQLITE_OMIT_ANALYZE) */
|
||||
|
||||
/* Opcode: DropTable P1 * * P4 *
|
||||
**
|
||||
|
@@ -15,7 +15,7 @@
|
||||
** 6000 lines long) it was split up into several smaller files and
|
||||
** this header information was factored out.
|
||||
**
|
||||
** $Id: vdbeInt.h,v 1.171 2009/06/05 14:17:25 drh Exp $
|
||||
** $Id: vdbeInt.h,v 1.172 2009/06/19 14:06:03 drh Exp $
|
||||
*/
|
||||
#ifndef _VDBEINT_H_
|
||||
#define _VDBEINT_H_
|
||||
@@ -262,7 +262,7 @@ struct Context {
|
||||
** method function.
|
||||
*/
|
||||
struct Vdbe {
|
||||
sqlite3 *db; /* The whole database */
|
||||
sqlite3 *db; /* The database connection that owns this statement */
|
||||
Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
|
||||
int nOp; /* Number of instructions in the program */
|
||||
int nOpAlloc; /* Number of slots allocated for aOp[] */
|
||||
@@ -272,12 +272,15 @@ struct Vdbe {
|
||||
int *aLabel; /* Space to hold the labels */
|
||||
Mem **apArg; /* Arguments to currently executing user function */
|
||||
Mem *aColName; /* Column names to return */
|
||||
int nCursor; /* Number of slots in apCsr[] */
|
||||
Mem *pResultSet; /* Pointer to an array of results */
|
||||
u16 nResColumn; /* Number of columns in one row of the result set */
|
||||
u16 nCursor; /* Number of slots in apCsr[] */
|
||||
VdbeCursor **apCsr; /* One element of this array for each open cursor */
|
||||
int nVar; /* Number of entries in aVar[] */
|
||||
u8 errorAction; /* Recovery action to do in case of an error */
|
||||
u8 okVar; /* True if azVar[] has been initialized */
|
||||
u16 nVar; /* Number of entries in aVar[] */
|
||||
Mem *aVar; /* Values for the OP_Variable opcode. */
|
||||
char **azVar; /* Name of variables */
|
||||
int okVar; /* True if azVar[] has been initialized */
|
||||
u32 magic; /* Magic number for sanity checking */
|
||||
int nMem; /* Number of memory locations currently allocated */
|
||||
Mem *aMem; /* The memory locations */
|
||||
@@ -287,11 +290,7 @@ struct Vdbe {
|
||||
Context *contextStack; /* Stack used by opcodes ContextPush & ContextPop*/
|
||||
int pc; /* The program counter */
|
||||
int rc; /* Value to return */
|
||||
int errorAction; /* Recovery action to do in case of an error */
|
||||
int nResColumn; /* Number of columns in one row of the result set */
|
||||
char **azResColumn; /* Values for one row of result */
|
||||
char *zErrMsg; /* Error message written here */
|
||||
Mem *pResultSet; /* Pointer to an array of results */
|
||||
u8 explain; /* True if EXPLAIN present on SQL command */
|
||||
u8 changeCntOn; /* True to update the change-counter */
|
||||
u8 expired; /* True if the VM needs to be recompiled */
|
||||
@@ -301,23 +300,15 @@ struct Vdbe {
|
||||
u8 readOnly; /* True for read-only statements */
|
||||
u8 isPrepareV2; /* True if prepared with prepare_v2() */
|
||||
int nChange; /* Number of db changes made since last reset */
|
||||
i64 startTime; /* Time when query started - used for profiling */
|
||||
int btreeMask; /* Bitmask of db->aDb[] entries referenced */
|
||||
i64 startTime; /* Time when query started - used for profiling */
|
||||
BtreeMutexArray aMutex; /* An array of Btree used here and needing locks */
|
||||
int aCounter[2]; /* Counters used by sqlite3_stmt_status() */
|
||||
char *zSql; /* Text of the SQL statement that generated this */
|
||||
void *pFree; /* Free this when deleting the vdbe */
|
||||
int iStatement; /* Statement number (or 0 if has not opened stmt) */
|
||||
#ifdef SQLITE_DEBUG
|
||||
FILE *trace; /* Write an execution trace here, if not NULL */
|
||||
#endif
|
||||
int iStatement; /* Statement number (or 0 if has not opened stmt) */
|
||||
#ifdef SQLITE_SSE
|
||||
int fetchId; /* Statement number used by sqlite3_fetch_statement */
|
||||
int lru; /* Counter used for LRU cache replacement */
|
||||
#endif
|
||||
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
|
||||
Vdbe *pLruPrev;
|
||||
Vdbe *pLruNext;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
177
src/vdbeapi.c
177
src/vdbeapi.c
@@ -13,167 +13,11 @@
|
||||
** This file contains code use to implement APIs that are part of the
|
||||
** VDBE.
|
||||
**
|
||||
** $Id: vdbeapi.c,v 1.165 2009/06/06 14:13:27 danielk1977 Exp $
|
||||
** $Id: vdbeapi.c,v 1.166 2009/06/19 14:06:03 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "vdbeInt.h"
|
||||
|
||||
#if 0 && defined(SQLITE_ENABLE_MEMORY_MANAGEMENT)
|
||||
/*
|
||||
** The following structure contains pointers to the end points of a
|
||||
** doubly-linked list of all compiled SQL statements that may be holding
|
||||
** buffers eligible for release when the sqlite3_release_memory() interface is
|
||||
** invoked. Access to this list is protected by the SQLITE_MUTEX_STATIC_LRU2
|
||||
** mutex.
|
||||
**
|
||||
** Statements are added to the end of this list when sqlite3_reset() is
|
||||
** called. They are removed either when sqlite3_step() or sqlite3_finalize()
|
||||
** is called. When statements are added to this list, the associated
|
||||
** register array (p->aMem[1..p->nMem]) may contain dynamic buffers that
|
||||
** can be freed using sqlite3VdbeReleaseMemory().
|
||||
**
|
||||
** When statements are added or removed from this list, the mutex
|
||||
** associated with the Vdbe being added or removed (Vdbe.db->mutex) is
|
||||
** already held. The LRU2 mutex is then obtained, blocking if necessary,
|
||||
** the linked-list pointers manipulated and the LRU2 mutex relinquished.
|
||||
*/
|
||||
struct StatementLruList {
|
||||
Vdbe *pFirst;
|
||||
Vdbe *pLast;
|
||||
};
|
||||
static struct StatementLruList sqlite3LruStatements;
|
||||
|
||||
/*
|
||||
** Check that the list looks to be internally consistent. This is used
|
||||
** as part of an assert() statement as follows:
|
||||
**
|
||||
** assert( stmtLruCheck() );
|
||||
*/
|
||||
#ifndef NDEBUG
|
||||
static int stmtLruCheck(){
|
||||
Vdbe *p;
|
||||
for(p=sqlite3LruStatements.pFirst; p; p=p->pLruNext){
|
||||
assert(p->pLruNext || p==sqlite3LruStatements.pLast);
|
||||
assert(!p->pLruNext || p->pLruNext->pLruPrev==p);
|
||||
assert(p->pLruPrev || p==sqlite3LruStatements.pFirst);
|
||||
assert(!p->pLruPrev || p->pLruPrev->pLruNext==p);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Add vdbe p to the end of the statement lru list. It is assumed that
|
||||
** p is not already part of the list when this is called. The lru list
|
||||
** is protected by the SQLITE_MUTEX_STATIC_LRU mutex.
|
||||
*/
|
||||
static void stmtLruAdd(Vdbe *p){
|
||||
sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_LRU2));
|
||||
|
||||
if( p->pLruPrev || p->pLruNext || sqlite3LruStatements.pFirst==p ){
|
||||
sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_LRU2));
|
||||
return;
|
||||
}
|
||||
|
||||
assert( stmtLruCheck() );
|
||||
|
||||
if( !sqlite3LruStatements.pFirst ){
|
||||
assert( !sqlite3LruStatements.pLast );
|
||||
sqlite3LruStatements.pFirst = p;
|
||||
sqlite3LruStatements.pLast = p;
|
||||
}else{
|
||||
assert( !sqlite3LruStatements.pLast->pLruNext );
|
||||
p->pLruPrev = sqlite3LruStatements.pLast;
|
||||
sqlite3LruStatements.pLast->pLruNext = p;
|
||||
sqlite3LruStatements.pLast = p;
|
||||
}
|
||||
|
||||
assert( stmtLruCheck() );
|
||||
|
||||
sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_LRU2));
|
||||
}
|
||||
|
||||
/*
|
||||
** Assuming the SQLITE_MUTEX_STATIC_LRU2 mutext is already held, remove
|
||||
** statement p from the least-recently-used statement list. If the
|
||||
** statement is not currently part of the list, this call is a no-op.
|
||||
*/
|
||||
static void stmtLruRemoveNomutex(Vdbe *p){
|
||||
if( p->pLruPrev || p->pLruNext || p==sqlite3LruStatements.pFirst ){
|
||||
assert( stmtLruCheck() );
|
||||
if( p->pLruNext ){
|
||||
p->pLruNext->pLruPrev = p->pLruPrev;
|
||||
}else{
|
||||
sqlite3LruStatements.pLast = p->pLruPrev;
|
||||
}
|
||||
if( p->pLruPrev ){
|
||||
p->pLruPrev->pLruNext = p->pLruNext;
|
||||
}else{
|
||||
sqlite3LruStatements.pFirst = p->pLruNext;
|
||||
}
|
||||
p->pLruNext = 0;
|
||||
p->pLruPrev = 0;
|
||||
assert( stmtLruCheck() );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Assuming the SQLITE_MUTEX_STATIC_LRU2 mutext is not held, remove
|
||||
** statement p from the least-recently-used statement list. If the
|
||||
** statement is not currently part of the list, this call is a no-op.
|
||||
*/
|
||||
static void stmtLruRemove(Vdbe *p){
|
||||
sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_LRU2));
|
||||
stmtLruRemoveNomutex(p);
|
||||
sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_LRU2));
|
||||
}
|
||||
|
||||
/*
|
||||
** Try to release n bytes of memory by freeing buffers associated
|
||||
** with the memory registers of currently unused vdbes.
|
||||
*/
|
||||
int sqlite3VdbeReleaseMemory(int n){
|
||||
Vdbe *p;
|
||||
Vdbe *pNext;
|
||||
int nFree = 0;
|
||||
|
||||
sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_LRU2));
|
||||
for(p=sqlite3LruStatements.pFirst; p && nFree<n; p=pNext){
|
||||
pNext = p->pLruNext;
|
||||
|
||||
/* For each statement handle in the lru list, attempt to obtain the
|
||||
** associated database mutex. If it cannot be obtained, continue
|
||||
** to the next statement handle. It is not possible to block on
|
||||
** the database mutex - that could cause deadlock.
|
||||
*/
|
||||
if( SQLITE_OK==sqlite3_mutex_try(p->db->mutex) ){
|
||||
nFree += sqlite3VdbeReleaseBuffers(p);
|
||||
stmtLruRemoveNomutex(p);
|
||||
sqlite3_mutex_leave(p->db->mutex);
|
||||
}
|
||||
}
|
||||
sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_LRU2));
|
||||
|
||||
return nFree;
|
||||
}
|
||||
|
||||
/*
|
||||
** Call sqlite3Reprepare() on the statement. Remove it from the
|
||||
** lru list before doing so, as Reprepare() will free all the
|
||||
** memory register buffers anyway.
|
||||
*/
|
||||
int vdbeReprepare(Vdbe *p){
|
||||
stmtLruRemove(p);
|
||||
return sqlite3Reprepare(p);
|
||||
}
|
||||
|
||||
#else /* !SQLITE_ENABLE_MEMORY_MANAGEMENT */
|
||||
#define stmtLruRemove(x)
|
||||
#define stmtLruAdd(x)
|
||||
#define vdbeReprepare(x) sqlite3Reprepare(x)
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef SQLITE_OMIT_DEPRECATED
|
||||
/*
|
||||
** Return TRUE (non-zero) of the statement supplied as an argument needs
|
||||
@@ -209,7 +53,6 @@ int sqlite3_finalize(sqlite3_stmt *pStmt){
|
||||
sqlite3_mutex *mutex = v->db->mutex;
|
||||
#endif
|
||||
sqlite3_mutex_enter(mutex);
|
||||
stmtLruRemove(v);
|
||||
rc = sqlite3VdbeFinalize(v);
|
||||
rc = sqlite3ApiExit(db, rc);
|
||||
sqlite3_mutex_leave(mutex);
|
||||
@@ -233,7 +76,6 @@ int sqlite3_reset(sqlite3_stmt *pStmt){
|
||||
Vdbe *v = (Vdbe*)pStmt;
|
||||
sqlite3_mutex_enter(v->db->mutex);
|
||||
rc = sqlite3VdbeReset(v);
|
||||
stmtLruAdd(v);
|
||||
sqlite3VdbeMakeReady(v, -1, 0, 0, 0);
|
||||
assert( (rc & (v->db->errMask))==rc );
|
||||
rc = sqlite3ApiExit(v->db, rc);
|
||||
@@ -477,7 +319,6 @@ static int sqlite3Step(Vdbe *p){
|
||||
db->activeVdbeCnt++;
|
||||
if( p->readOnly==0 ) db->writeVdbeCnt++;
|
||||
p->pc = 0;
|
||||
stmtLruRemove(p);
|
||||
}
|
||||
#ifndef SQLITE_OMIT_EXPLAIN
|
||||
if( p->explain ){
|
||||
@@ -537,19 +378,6 @@ end_of_step:
|
||||
** sqlite3Step() to do most of the work. If a schema error occurs,
|
||||
** call sqlite3Reprepare() and try again.
|
||||
*/
|
||||
#ifdef SQLITE_OMIT_PARSER
|
||||
int sqlite3_step(sqlite3_stmt *pStmt){
|
||||
int rc = SQLITE_MISUSE;
|
||||
if( pStmt ){
|
||||
Vdbe *v;
|
||||
v = (Vdbe*)pStmt;
|
||||
sqlite3_mutex_enter(v->db->mutex);
|
||||
rc = sqlite3Step(v);
|
||||
sqlite3_mutex_leave(v->db->mutex);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
#else
|
||||
int sqlite3_step(sqlite3_stmt *pStmt){
|
||||
int rc = SQLITE_MISUSE;
|
||||
if( pStmt ){
|
||||
@@ -559,7 +387,7 @@ int sqlite3_step(sqlite3_stmt *pStmt){
|
||||
sqlite3_mutex_enter(db->mutex);
|
||||
while( (rc = sqlite3Step(v))==SQLITE_SCHEMA
|
||||
&& cnt++ < 5
|
||||
&& (rc = vdbeReprepare(v))==SQLITE_OK ){
|
||||
&& (rc = sqlite3Reprepare(v))==SQLITE_OK ){
|
||||
sqlite3_reset(pStmt);
|
||||
v->expired = 0;
|
||||
}
|
||||
@@ -586,7 +414,6 @@ int sqlite3_step(sqlite3_stmt *pStmt){
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Extract the user data from a sqlite3_context structure and return a
|
||||
|
Reference in New Issue
Block a user