├── .gitignore ├── alter.c ├── analyze.c ├── attach.c ├── auth.c ├── backup.c ├── bitvec.c ├── btmutex.c ├── btree.c ├── btree.h ├── btreeint.h ├── build.c ├── callback.c ├── complete.c ├── ctime.c ├── date.c ├── delete.c ├── descrip.mms ├── expr.c ├── fault.c ├── fkey.c ├── fts1.c ├── fts1.h ├── fts1_hash.c ├── fts1_hash.h ├── fts1_porter.c ├── fts1_tokenizer.h ├── fts1_tokenizer1.c ├── fts2.c ├── fts2.h ├── fts2_hash.c ├── fts2_hash.h ├── fts2_icu.c ├── fts2_porter.c ├── fts2_tokenizer.c ├── fts2_tokenizer.h ├── fts2_tokenizer1.c ├── fts3.c ├── fts3.h ├── fts3_aux.c ├── fts3_expr.c ├── fts3_hash.c ├── fts3_hash.h ├── fts3_icu.c ├── fts3_porter.c ├── fts3_snippet.c ├── fts3_tokenize_vtab.c ├── fts3_tokenizer.c ├── fts3_tokenizer.h ├── fts3_tokenizer1.c ├── fts3_unicode.c ├── fts3_unicode2.c ├── fts3_write.c ├── fts3int.h ├── func.c ├── global.c ├── hash.c ├── hash.h ├── hwtime.h ├── icu.c ├── insert.c ├── journal.c ├── keywordhash.h ├── legacy.c ├── loadext.c ├── main.c ├── make_linker_vector.tec ├── make_linker_vector.tes ├── make_symbol_vector.tec ├── make_symbol_vector.tes ├── make_vax_vector.tec ├── make_vax_vector.tes ├── make_version.com ├── malloc.c ├── mem0.c ├── mem1.c ├── mem2.c ├── mem3.c ├── mem5.c ├── memjournal.c ├── memvms.c ├── mutex.c ├── mutex.h ├── mutex_noop.c ├── mutex_unix.c ├── mutex_vms.c ├── mutex_w32.c ├── notify.c ├── opcodes.c ├── opcodes.h ├── os.c ├── os.h ├── os_common.h ├── os_unix.c ├── os_vms.c ├── os_win.c ├── pager.c ├── pager.h ├── parse.c ├── parse.h ├── pcache.c ├── pcache.h ├── pcache1.c ├── pragma.c ├── prepare.c ├── printf.c ├── random.c ├── readme.txt ├── release_notes.sdml ├── resolve.c ├── rowset.c ├── rtree.c ├── rtree.h ├── select.c ├── shell.c ├── sqlite3.axp_opt ├── sqlite3.h ├── sqlite3.i64_opt ├── sqlite3.vax_opt ├── sqlite3_aliases.s ├── sqlite3_shr.axp_opt ├── sqlite3_shr.i64_opt ├── sqlite3_shr.vax_opt ├── sqlite3_vector.axp_opt ├── sqlite3_vector.i64_opt ├── sqlite3_vector.mar ├── sqlite3_vector.vax_opt ├── sqlite3ext.h ├── sqlite3rtree.h ├── sqliteicu.h ├── sqliteint.h ├── sqlitelimit.h ├── squ.tec ├── status.c ├── symbol_vector.txt ├── table.c ├── tclsqlite.c ├── tokenize.c ├── trigger.c ├── update.c ├── utf.c ├── util.c ├── vacuum.c ├── vdbe.c ├── vdbe.h ├── vdbeapi.c ├── vdbeaux.c ├── vdbeblob.c ├── vdbeint.h ├── vdbemem.c ├── vdbesort.c ├── vdbetrace.c ├── vmsshell.c ├── vtab.c ├── wal.c ├── wal.h ├── walker.c └── where.c /.gitignore: -------------------------------------------------------------------------------- 1 | .\$ADF\$* 2 | .\$NFS\$* 3 | *\;* 4 | *-*/* 5 | *.jou 6 | *.tex 7 | *.dvi_* 8 | *.int_* 9 | *.tc[befi] 10 | -------------------------------------------------------------------------------- /fault.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2008 Jan 22 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ************************************************************************* 12 | ** 13 | ** This file contains code to support the concept of "benign" 14 | ** malloc failures (when the xMalloc() or xRealloc() method of the 15 | ** sqlite3_mem_methods structure fails to allocate a block of memory 16 | ** and returns 0). 17 | ** 18 | ** Most malloc failures are non-benign. After they occur, SQLite 19 | ** abandons the current operation and returns an error code (usually 20 | ** SQLITE_NOMEM) to the user. However, sometimes a fault is not necessarily 21 | ** fatal. For example, if a malloc fails while resizing a hash table, this 22 | ** is completely recoverable simply by not carrying out the resize. The 23 | ** hash table will continue to function normally. So a malloc failure 24 | ** during a hash table resize is a benign fault. 25 | */ 26 | 27 | #include "sqliteInt.h" 28 | 29 | #ifndef SQLITE_OMIT_BUILTIN_TEST 30 | 31 | /* 32 | ** Global variables. 33 | */ 34 | typedef struct BenignMallocHooks BenignMallocHooks; 35 | static SQLITE_WSD struct BenignMallocHooks { 36 | void (*xBenignBegin)(void); 37 | void (*xBenignEnd)(void); 38 | } sqlite3Hooks = { 0, 0 }; 39 | 40 | /* The "wsdHooks" macro will resolve to the appropriate BenignMallocHooks 41 | ** structure. If writable static data is unsupported on the target, 42 | ** we have to locate the state vector at run-time. In the more common 43 | ** case where writable static data is supported, wsdHooks can refer directly 44 | ** to the "sqlite3Hooks" state vector declared above. 45 | */ 46 | #ifdef SQLITE_OMIT_WSD 47 | # define wsdHooksInit \ 48 | BenignMallocHooks *x = &GLOBAL(BenignMallocHooks,sqlite3Hooks) 49 | # define wsdHooks x[0] 50 | #else 51 | # define wsdHooksInit 52 | # define wsdHooks sqlite3Hooks 53 | #endif 54 | 55 | 56 | /* 57 | ** Register hooks to call when sqlite3BeginBenignMalloc() and 58 | ** sqlite3EndBenignMalloc() are called, respectively. 59 | */ 60 | void sqlite3BenignMallocHooks( 61 | void (*xBenignBegin)(void), 62 | void (*xBenignEnd)(void) 63 | ){ 64 | wsdHooksInit; 65 | wsdHooks.xBenignBegin = xBenignBegin; 66 | wsdHooks.xBenignEnd = xBenignEnd; 67 | } 68 | 69 | /* 70 | ** This (sqlite3EndBenignMalloc()) is called by SQLite code to indicate that 71 | ** subsequent malloc failures are benign. A call to sqlite3EndBenignMalloc() 72 | ** indicates that subsequent malloc failures are non-benign. 73 | */ 74 | void sqlite3BeginBenignMalloc(void){ 75 | wsdHooksInit; 76 | if( wsdHooks.xBenignBegin ){ 77 | wsdHooks.xBenignBegin(); 78 | } 79 | } 80 | void sqlite3EndBenignMalloc(void){ 81 | wsdHooksInit; 82 | if( wsdHooks.xBenignEnd ){ 83 | wsdHooks.xBenignEnd(); 84 | } 85 | } 86 | 87 | #endif /* #ifndef SQLITE_OMIT_BUILTIN_TEST */ 88 | -------------------------------------------------------------------------------- /fts1.h: -------------------------------------------------------------------------------- 1 | #include "sqlite3.h" 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif /* __cplusplus */ 6 | 7 | int sqlite3Fts1Init(sqlite3 *db); 8 | 9 | #ifdef __cplusplus 10 | } /* extern "C" */ 11 | #endif /* __cplusplus */ 12 | -------------------------------------------------------------------------------- /fts1_hash.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2001 September 22 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ************************************************************************* 12 | ** This is the header file for the generic hash-table implementation 13 | ** used in SQLite. We've modified it slightly to serve as a standalone 14 | ** hash table implementation for the full-text indexing module. 15 | ** 16 | */ 17 | #ifndef _FTS1_HASH_H_ 18 | #define _FTS1_HASH_H_ 19 | 20 | /* Forward declarations of structures. */ 21 | typedef struct fts1Hash fts1Hash; 22 | typedef struct fts1HashElem fts1HashElem; 23 | 24 | /* A complete hash table is an instance of the following structure. 25 | ** The internals of this structure are intended to be opaque -- client 26 | ** code should not attempt to access or modify the fields of this structure 27 | ** directly. Change this structure only by using the routines below. 28 | ** However, many of the "procedures" and "functions" for modifying and 29 | ** accessing this structure are really macros, so we can't really make 30 | ** this structure opaque. 31 | */ 32 | struct fts1Hash { 33 | char keyClass; /* HASH_INT, _POINTER, _STRING, _BINARY */ 34 | char copyKey; /* True if copy of key made on insert */ 35 | int count; /* Number of entries in this table */ 36 | fts1HashElem *first; /* The first element of the array */ 37 | void *(*xMalloc)(int); /* malloc() function to use */ 38 | void (*xFree)(void *); /* free() function to use */ 39 | int htsize; /* Number of buckets in the hash table */ 40 | struct _fts1ht { /* the hash table */ 41 | int count; /* Number of entries with this hash */ 42 | fts1HashElem *chain; /* Pointer to first entry with this hash */ 43 | } *ht; 44 | }; 45 | 46 | /* Each element in the hash table is an instance of the following 47 | ** structure. All elements are stored on a single doubly-linked list. 48 | ** 49 | ** Again, this structure is intended to be opaque, but it can't really 50 | ** be opaque because it is used by macros. 51 | */ 52 | struct fts1HashElem { 53 | fts1HashElem *next, *prev; /* Next and previous elements in the table */ 54 | void *data; /* Data associated with this element */ 55 | void *pKey; int nKey; /* Key associated with this element */ 56 | }; 57 | 58 | /* 59 | ** There are 2 different modes of operation for a hash table: 60 | ** 61 | ** FTS1_HASH_STRING pKey points to a string that is nKey bytes long 62 | ** (including the null-terminator, if any). Case 63 | ** is respected in comparisons. 64 | ** 65 | ** FTS1_HASH_BINARY pKey points to binary data nKey bytes long. 66 | ** memcmp() is used to compare keys. 67 | ** 68 | ** A copy of the key is made if the copyKey parameter to fts1HashInit is 1. 69 | */ 70 | #define FTS1_HASH_STRING 1 71 | #define FTS1_HASH_BINARY 2 72 | 73 | /* 74 | ** Access routines. To delete, insert a NULL pointer. 75 | */ 76 | void sqlite3Fts1HashInit(fts1Hash*, int keytype, int copyKey); 77 | void *sqlite3Fts1HashInsert(fts1Hash*, const void *pKey, int nKey, void *pData); 78 | void *sqlite3Fts1HashFind(const fts1Hash*, const void *pKey, int nKey); 79 | void sqlite3Fts1HashClear(fts1Hash*); 80 | 81 | /* 82 | ** Shorthand for the functions above 83 | */ 84 | #define fts1HashInit sqlite3Fts1HashInit 85 | #define fts1HashInsert sqlite3Fts1HashInsert 86 | #define fts1HashFind sqlite3Fts1HashFind 87 | #define fts1HashClear sqlite3Fts1HashClear 88 | 89 | /* 90 | ** Macros for looping over all elements of a hash table. The idiom is 91 | ** like this: 92 | ** 93 | ** fts1Hash h; 94 | ** fts1HashElem *p; 95 | ** ... 96 | ** for(p=fts1HashFirst(&h); p; p=fts1HashNext(p)){ 97 | ** SomeStructure *pData = fts1HashData(p); 98 | ** // do something with pData 99 | ** } 100 | */ 101 | #define fts1HashFirst(H) ((H)->first) 102 | #define fts1HashNext(E) ((E)->next) 103 | #define fts1HashData(E) ((E)->data) 104 | #define fts1HashKey(E) ((E)->pKey) 105 | #define fts1HashKeysize(E) ((E)->nKey) 106 | 107 | /* 108 | ** Number of entries in a hash table 109 | */ 110 | #define fts1HashCount(H) ((H)->count) 111 | 112 | #endif /* _FTS1_HASH_H_ */ 113 | -------------------------------------------------------------------------------- /fts1_tokenizer.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2006 July 10 3 | ** 4 | ** The author disclaims copyright to this source code. 5 | ** 6 | ************************************************************************* 7 | ** Defines the interface to tokenizers used by fulltext-search. There 8 | ** are three basic components: 9 | ** 10 | ** sqlite3_tokenizer_module is a singleton defining the tokenizer 11 | ** interface functions. This is essentially the class structure for 12 | ** tokenizers. 13 | ** 14 | ** sqlite3_tokenizer is used to define a particular tokenizer, perhaps 15 | ** including customization information defined at creation time. 16 | ** 17 | ** sqlite3_tokenizer_cursor is generated by a tokenizer to generate 18 | ** tokens from a particular input. 19 | */ 20 | #ifndef _FTS1_TOKENIZER_H_ 21 | #define _FTS1_TOKENIZER_H_ 22 | 23 | /* TODO(shess) Only used for SQLITE_OK and SQLITE_DONE at this time. 24 | ** If tokenizers are to be allowed to call sqlite3_*() functions, then 25 | ** we will need a way to register the API consistently. 26 | */ 27 | #include "sqlite3.h" 28 | 29 | /* 30 | ** Structures used by the tokenizer interface. 31 | */ 32 | typedef struct sqlite3_tokenizer sqlite3_tokenizer; 33 | typedef struct sqlite3_tokenizer_cursor sqlite3_tokenizer_cursor; 34 | typedef struct sqlite3_tokenizer_module sqlite3_tokenizer_module; 35 | 36 | struct sqlite3_tokenizer_module { 37 | int iVersion; /* currently 0 */ 38 | 39 | /* 40 | ** Create and destroy a tokenizer. argc/argv are passed down from 41 | ** the fulltext virtual table creation to allow customization. 42 | */ 43 | int (*xCreate)(int argc, const char *const*argv, 44 | sqlite3_tokenizer **ppTokenizer); 45 | int (*xDestroy)(sqlite3_tokenizer *pTokenizer); 46 | 47 | /* 48 | ** Tokenize a particular input. Call xOpen() to prepare to 49 | ** tokenize, xNext() repeatedly until it returns SQLITE_DONE, then 50 | ** xClose() to free any internal state. The pInput passed to 51 | ** xOpen() must exist until the cursor is closed. The ppToken 52 | ** result from xNext() is only valid until the next call to xNext() 53 | ** or until xClose() is called. 54 | */ 55 | /* TODO(shess) current implementation requires pInput to be 56 | ** nul-terminated. This should either be fixed, or pInput/nBytes 57 | ** should be converted to zInput. 58 | */ 59 | int (*xOpen)(sqlite3_tokenizer *pTokenizer, 60 | const char *pInput, int nBytes, 61 | sqlite3_tokenizer_cursor **ppCursor); 62 | int (*xClose)(sqlite3_tokenizer_cursor *pCursor); 63 | int (*xNext)(sqlite3_tokenizer_cursor *pCursor, 64 | const char **ppToken, int *pnBytes, 65 | int *piStartOffset, int *piEndOffset, int *piPosition); 66 | }; 67 | 68 | struct sqlite3_tokenizer { 69 | const sqlite3_tokenizer_module *pModule; /* The module for this tokenizer */ 70 | /* Tokenizer implementations will typically add additional fields */ 71 | }; 72 | 73 | struct sqlite3_tokenizer_cursor { 74 | sqlite3_tokenizer *pTokenizer; /* Tokenizer for this cursor. */ 75 | /* Tokenizer implementations will typically add additional fields */ 76 | }; 77 | 78 | /* 79 | ** Get the module for a tokenizer which generates tokens based on a 80 | ** set of non-token characters. The default is to break tokens at any 81 | ** non-alnum character, though the set of delimiters can also be 82 | ** specified by the first argv argument to xCreate(). 83 | */ 84 | /* TODO(shess) This doesn't belong here. Need some sort of 85 | ** registration process. 86 | */ 87 | void sqlite3Fts1SimpleTokenizerModule(sqlite3_tokenizer_module const**ppModule); 88 | void sqlite3Fts1PorterTokenizerModule(sqlite3_tokenizer_module const**ppModule); 89 | 90 | #endif /* _FTS1_TOKENIZER_H_ */ 91 | -------------------------------------------------------------------------------- /fts1_tokenizer1.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** The author disclaims copyright to this source code. 3 | ** 4 | ************************************************************************* 5 | ** Implementation of the "simple" full-text-search tokenizer. 6 | */ 7 | 8 | /* 9 | ** The code in this file is only compiled if: 10 | ** 11 | ** * The FTS1 module is being built as an extension 12 | ** (in which case SQLITE_CORE is not defined), or 13 | ** 14 | ** * The FTS1 module is being built into the core of 15 | ** SQLite (in which case SQLITE_ENABLE_FTS1 is defined). 16 | */ 17 | #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS1) 18 | 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "fts1_tokenizer.h" 27 | 28 | typedef struct simple_tokenizer { 29 | sqlite3_tokenizer base; 30 | char delim[128]; /* flag ASCII delimiters */ 31 | } simple_tokenizer; 32 | 33 | typedef struct simple_tokenizer_cursor { 34 | sqlite3_tokenizer_cursor base; 35 | const char *pInput; /* input we are tokenizing */ 36 | int nBytes; /* size of the input */ 37 | int iOffset; /* current position in pInput */ 38 | int iToken; /* index of next token to be returned */ 39 | char *pToken; /* storage for current token */ 40 | int nTokenAllocated; /* space allocated to zToken buffer */ 41 | } simple_tokenizer_cursor; 42 | 43 | 44 | /* Forward declaration */ 45 | static const sqlite3_tokenizer_module simpleTokenizerModule; 46 | 47 | static int isDelim(simple_tokenizer *t, unsigned char c){ 48 | return c<0x80 && t->delim[c]; 49 | } 50 | 51 | /* 52 | ** Create a new tokenizer instance. 53 | */ 54 | static int simpleCreate( 55 | int argc, const char * const *argv, 56 | sqlite3_tokenizer **ppTokenizer 57 | ){ 58 | simple_tokenizer *t; 59 | 60 | t = (simple_tokenizer *) calloc(sizeof(*t), 1); 61 | if( t==NULL ) return SQLITE_NOMEM; 62 | 63 | /* TODO(shess) Delimiters need to remain the same from run to run, 64 | ** else we need to reindex. One solution would be a meta-table to 65 | ** track such information in the database, then we'd only want this 66 | ** information on the initial create. 67 | */ 68 | if( argc>1 ){ 69 | int i, n = strlen(argv[1]); 70 | for(i=0; i=0x80 ){ 74 | free(t); 75 | return SQLITE_ERROR; 76 | } 77 | t->delim[ch] = 1; 78 | } 79 | } else { 80 | /* Mark non-alphanumeric ASCII characters as delimiters */ 81 | int i; 82 | for(i=1; i<0x80; i++){ 83 | t->delim[i] = !isalnum(i); 84 | } 85 | } 86 | 87 | *ppTokenizer = &t->base; 88 | return SQLITE_OK; 89 | } 90 | 91 | /* 92 | ** Destroy a tokenizer 93 | */ 94 | static int simpleDestroy(sqlite3_tokenizer *pTokenizer){ 95 | free(pTokenizer); 96 | return SQLITE_OK; 97 | } 98 | 99 | /* 100 | ** Prepare to begin tokenizing a particular string. The input 101 | ** string to be tokenized is pInput[0..nBytes-1]. A cursor 102 | ** used to incrementally tokenize this string is returned in 103 | ** *ppCursor. 104 | */ 105 | static int simpleOpen( 106 | sqlite3_tokenizer *pTokenizer, /* The tokenizer */ 107 | const char *pInput, int nBytes, /* String to be tokenized */ 108 | sqlite3_tokenizer_cursor **ppCursor /* OUT: Tokenization cursor */ 109 | ){ 110 | simple_tokenizer_cursor *c; 111 | 112 | c = (simple_tokenizer_cursor *) malloc(sizeof(*c)); 113 | if( c==NULL ) return SQLITE_NOMEM; 114 | 115 | c->pInput = pInput; 116 | if( pInput==0 ){ 117 | c->nBytes = 0; 118 | }else if( nBytes<0 ){ 119 | c->nBytes = (int)strlen(pInput); 120 | }else{ 121 | c->nBytes = nBytes; 122 | } 123 | c->iOffset = 0; /* start tokenizing at the beginning */ 124 | c->iToken = 0; 125 | c->pToken = NULL; /* no space allocated, yet. */ 126 | c->nTokenAllocated = 0; 127 | 128 | *ppCursor = &c->base; 129 | return SQLITE_OK; 130 | } 131 | 132 | /* 133 | ** Close a tokenization cursor previously opened by a call to 134 | ** simpleOpen() above. 135 | */ 136 | static int simpleClose(sqlite3_tokenizer_cursor *pCursor){ 137 | simple_tokenizer_cursor *c = (simple_tokenizer_cursor *) pCursor; 138 | free(c->pToken); 139 | free(c); 140 | return SQLITE_OK; 141 | } 142 | 143 | /* 144 | ** Extract the next token from a tokenization cursor. The cursor must 145 | ** have been opened by a prior call to simpleOpen(). 146 | */ 147 | static int simpleNext( 148 | sqlite3_tokenizer_cursor *pCursor, /* Cursor returned by simpleOpen */ 149 | const char **ppToken, /* OUT: *ppToken is the token text */ 150 | int *pnBytes, /* OUT: Number of bytes in token */ 151 | int *piStartOffset, /* OUT: Starting offset of token */ 152 | int *piEndOffset, /* OUT: Ending offset of token */ 153 | int *piPosition /* OUT: Position integer of token */ 154 | ){ 155 | simple_tokenizer_cursor *c = (simple_tokenizer_cursor *) pCursor; 156 | simple_tokenizer *t = (simple_tokenizer *) pCursor->pTokenizer; 157 | unsigned char *p = (unsigned char *)c->pInput; 158 | 159 | while( c->iOffsetnBytes ){ 160 | int iStartOffset; 161 | 162 | /* Scan past delimiter characters */ 163 | while( c->iOffsetnBytes && isDelim(t, p[c->iOffset]) ){ 164 | c->iOffset++; 165 | } 166 | 167 | /* Count non-delimiter characters. */ 168 | iStartOffset = c->iOffset; 169 | while( c->iOffsetnBytes && !isDelim(t, p[c->iOffset]) ){ 170 | c->iOffset++; 171 | } 172 | 173 | if( c->iOffset>iStartOffset ){ 174 | int i, n = c->iOffset-iStartOffset; 175 | if( n>c->nTokenAllocated ){ 176 | c->nTokenAllocated = n+20; 177 | c->pToken = realloc(c->pToken, c->nTokenAllocated); 178 | if( c->pToken==NULL ) return SQLITE_NOMEM; 179 | } 180 | for(i=0; ipToken[i] = ch<0x80 ? tolower(ch) : ch; 186 | } 187 | *ppToken = c->pToken; 188 | *pnBytes = n; 189 | *piStartOffset = iStartOffset; 190 | *piEndOffset = c->iOffset; 191 | *piPosition = c->iToken++; 192 | 193 | return SQLITE_OK; 194 | } 195 | } 196 | return SQLITE_DONE; 197 | } 198 | 199 | /* 200 | ** The set of routines that implement the simple tokenizer 201 | */ 202 | static const sqlite3_tokenizer_module simpleTokenizerModule = { 203 | 0, 204 | simpleCreate, 205 | simpleDestroy, 206 | simpleOpen, 207 | simpleClose, 208 | simpleNext, 209 | }; 210 | 211 | /* 212 | ** Allocate a new simple tokenizer. Return a pointer to the new 213 | ** tokenizer in *ppModule 214 | */ 215 | void sqlite3Fts1SimpleTokenizerModule( 216 | sqlite3_tokenizer_module const**ppModule 217 | ){ 218 | *ppModule = &simpleTokenizerModule; 219 | } 220 | 221 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS1) */ 222 | -------------------------------------------------------------------------------- /fts2.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2006 Oct 10 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ****************************************************************************** 12 | ** 13 | ** This header file is used by programs that want to link against the 14 | ** FTS2 library. All it does is declare the sqlite3Fts2Init() interface. 15 | */ 16 | #include "sqlite3.h" 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif /* __cplusplus */ 21 | 22 | int sqlite3Fts2Init(sqlite3 *db); 23 | 24 | #ifdef __cplusplus 25 | } /* extern "C" */ 26 | #endif /* __cplusplus */ 27 | -------------------------------------------------------------------------------- /fts2_hash.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2001 September 22 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ************************************************************************* 12 | ** This is the header file for the generic hash-table implementation 13 | ** used in SQLite. We've modified it slightly to serve as a standalone 14 | ** hash table implementation for the full-text indexing module. 15 | ** 16 | */ 17 | #ifndef _FTS2_HASH_H_ 18 | #define _FTS2_HASH_H_ 19 | 20 | /* Forward declarations of structures. */ 21 | typedef struct fts2Hash fts2Hash; 22 | typedef struct fts2HashElem fts2HashElem; 23 | 24 | /* A complete hash table is an instance of the following structure. 25 | ** The internals of this structure are intended to be opaque -- client 26 | ** code should not attempt to access or modify the fields of this structure 27 | ** directly. Change this structure only by using the routines below. 28 | ** However, many of the "procedures" and "functions" for modifying and 29 | ** accessing this structure are really macros, so we can't really make 30 | ** this structure opaque. 31 | */ 32 | struct fts2Hash { 33 | char keyClass; /* HASH_INT, _POINTER, _STRING, _BINARY */ 34 | char copyKey; /* True if copy of key made on insert */ 35 | int count; /* Number of entries in this table */ 36 | fts2HashElem *first; /* The first element of the array */ 37 | int htsize; /* Number of buckets in the hash table */ 38 | struct _fts2ht { /* the hash table */ 39 | int count; /* Number of entries with this hash */ 40 | fts2HashElem *chain; /* Pointer to first entry with this hash */ 41 | } *ht; 42 | }; 43 | 44 | /* Each element in the hash table is an instance of the following 45 | ** structure. All elements are stored on a single doubly-linked list. 46 | ** 47 | ** Again, this structure is intended to be opaque, but it can't really 48 | ** be opaque because it is used by macros. 49 | */ 50 | struct fts2HashElem { 51 | fts2HashElem *next, *prev; /* Next and previous elements in the table */ 52 | void *data; /* Data associated with this element */ 53 | void *pKey; int nKey; /* Key associated with this element */ 54 | }; 55 | 56 | /* 57 | ** There are 2 different modes of operation for a hash table: 58 | ** 59 | ** FTS2_HASH_STRING pKey points to a string that is nKey bytes long 60 | ** (including the null-terminator, if any). Case 61 | ** is respected in comparisons. 62 | ** 63 | ** FTS2_HASH_BINARY pKey points to binary data nKey bytes long. 64 | ** memcmp() is used to compare keys. 65 | ** 66 | ** A copy of the key is made if the copyKey parameter to fts2HashInit is 1. 67 | */ 68 | #define FTS2_HASH_STRING 1 69 | #define FTS2_HASH_BINARY 2 70 | 71 | /* 72 | ** Access routines. To delete, insert a NULL pointer. 73 | */ 74 | void sqlite3Fts2HashInit(fts2Hash*, int keytype, int copyKey); 75 | void *sqlite3Fts2HashInsert(fts2Hash*, const void *pKey, int nKey, void *pData); 76 | void *sqlite3Fts2HashFind(const fts2Hash*, const void *pKey, int nKey); 77 | void sqlite3Fts2HashClear(fts2Hash*); 78 | 79 | /* 80 | ** Shorthand for the functions above 81 | */ 82 | #define fts2HashInit sqlite3Fts2HashInit 83 | #define fts2HashInsert sqlite3Fts2HashInsert 84 | #define fts2HashFind sqlite3Fts2HashFind 85 | #define fts2HashClear sqlite3Fts2HashClear 86 | 87 | /* 88 | ** Macros for looping over all elements of a hash table. The idiom is 89 | ** like this: 90 | ** 91 | ** fts2Hash h; 92 | ** fts2HashElem *p; 93 | ** ... 94 | ** for(p=fts2HashFirst(&h); p; p=fts2HashNext(p)){ 95 | ** SomeStructure *pData = fts2HashData(p); 96 | ** // do something with pData 97 | ** } 98 | */ 99 | #define fts2HashFirst(H) ((H)->first) 100 | #define fts2HashNext(E) ((E)->next) 101 | #define fts2HashData(E) ((E)->data) 102 | #define fts2HashKey(E) ((E)->pKey) 103 | #define fts2HashKeysize(E) ((E)->nKey) 104 | 105 | /* 106 | ** Number of entries in a hash table 107 | */ 108 | #define fts2HashCount(H) ((H)->count) 109 | 110 | #endif /* _FTS2_HASH_H_ */ 111 | -------------------------------------------------------------------------------- /fts2_icu.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2007 June 22 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ************************************************************************* 12 | ** This file implements a tokenizer for fts2 based on the ICU library. 13 | ** 14 | ** $Id: fts2_icu.c,v 1.3 2008/12/18 05:30:26 danielk1977 Exp $ 15 | */ 16 | 17 | #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS2) 18 | #ifdef SQLITE_ENABLE_ICU 19 | 20 | #include 21 | #include 22 | #include "fts2_tokenizer.h" 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | typedef struct IcuTokenizer IcuTokenizer; 30 | typedef struct IcuCursor IcuCursor; 31 | 32 | struct IcuTokenizer { 33 | sqlite3_tokenizer base; 34 | char *zLocale; 35 | }; 36 | 37 | struct IcuCursor { 38 | sqlite3_tokenizer_cursor base; 39 | 40 | UBreakIterator *pIter; /* ICU break-iterator object */ 41 | int nChar; /* Number of UChar elements in pInput */ 42 | UChar *aChar; /* Copy of input using utf-16 encoding */ 43 | int *aOffset; /* Offsets of each character in utf-8 input */ 44 | 45 | int nBuffer; 46 | char *zBuffer; 47 | 48 | int iToken; 49 | }; 50 | 51 | /* 52 | ** Create a new tokenizer instance. 53 | */ 54 | static int icuCreate( 55 | int argc, /* Number of entries in argv[] */ 56 | const char * const *argv, /* Tokenizer creation arguments */ 57 | sqlite3_tokenizer **ppTokenizer /* OUT: Created tokenizer */ 58 | ){ 59 | IcuTokenizer *p; 60 | int n = 0; 61 | 62 | if( argc>0 ){ 63 | n = strlen(argv[0])+1; 64 | } 65 | p = (IcuTokenizer *)sqlite3_malloc(sizeof(IcuTokenizer)+n); 66 | if( !p ){ 67 | return SQLITE_NOMEM; 68 | } 69 | memset(p, 0, sizeof(IcuTokenizer)); 70 | 71 | if( n ){ 72 | p->zLocale = (char *)&p[1]; 73 | memcpy(p->zLocale, argv[0], n); 74 | } 75 | 76 | *ppTokenizer = (sqlite3_tokenizer *)p; 77 | 78 | return SQLITE_OK; 79 | } 80 | 81 | /* 82 | ** Destroy a tokenizer 83 | */ 84 | static int icuDestroy(sqlite3_tokenizer *pTokenizer){ 85 | IcuTokenizer *p = (IcuTokenizer *)pTokenizer; 86 | sqlite3_free(p); 87 | return SQLITE_OK; 88 | } 89 | 90 | /* 91 | ** Prepare to begin tokenizing a particular string. The input 92 | ** string to be tokenized is pInput[0..nBytes-1]. A cursor 93 | ** used to incrementally tokenize this string is returned in 94 | ** *ppCursor. 95 | */ 96 | static int icuOpen( 97 | sqlite3_tokenizer *pTokenizer, /* The tokenizer */ 98 | const char *zInput, /* Input string */ 99 | int nInput, /* Length of zInput in bytes */ 100 | sqlite3_tokenizer_cursor **ppCursor /* OUT: Tokenization cursor */ 101 | ){ 102 | IcuTokenizer *p = (IcuTokenizer *)pTokenizer; 103 | IcuCursor *pCsr; 104 | 105 | const int32_t opt = U_FOLD_CASE_DEFAULT; 106 | UErrorCode status = U_ZERO_ERROR; 107 | int nChar; 108 | 109 | UChar32 c; 110 | int iInput = 0; 111 | int iOut = 0; 112 | 113 | *ppCursor = 0; 114 | 115 | if( nInput<0 ){ 116 | nInput = strlen(zInput); 117 | } 118 | nChar = nInput+1; 119 | pCsr = (IcuCursor *)sqlite3_malloc( 120 | sizeof(IcuCursor) + /* IcuCursor */ 121 | ((nChar+3)&~3) * sizeof(UChar) + /* IcuCursor.aChar[] */ 122 | (nChar+1) * sizeof(int) /* IcuCursor.aOffset[] */ 123 | ); 124 | if( !pCsr ){ 125 | return SQLITE_NOMEM; 126 | } 127 | memset(pCsr, 0, sizeof(IcuCursor)); 128 | pCsr->aChar = (UChar *)&pCsr[1]; 129 | pCsr->aOffset = (int *)&pCsr->aChar[(nChar+3)&~3]; 130 | 131 | pCsr->aOffset[iOut] = iInput; 132 | U8_NEXT(zInput, iInput, nInput, c); 133 | while( c>0 ){ 134 | int isError = 0; 135 | c = u_foldCase(c, opt); 136 | U16_APPEND(pCsr->aChar, iOut, nChar, c, isError); 137 | if( isError ){ 138 | sqlite3_free(pCsr); 139 | return SQLITE_ERROR; 140 | } 141 | pCsr->aOffset[iOut] = iInput; 142 | 143 | if( iInputpIter = ubrk_open(UBRK_WORD, p->zLocale, pCsr->aChar, iOut, &status); 151 | if( !U_SUCCESS(status) ){ 152 | sqlite3_free(pCsr); 153 | return SQLITE_ERROR; 154 | } 155 | pCsr->nChar = iOut; 156 | 157 | ubrk_first(pCsr->pIter); 158 | *ppCursor = (sqlite3_tokenizer_cursor *)pCsr; 159 | return SQLITE_OK; 160 | } 161 | 162 | /* 163 | ** Close a tokenization cursor previously opened by a call to icuOpen(). 164 | */ 165 | static int icuClose(sqlite3_tokenizer_cursor *pCursor){ 166 | IcuCursor *pCsr = (IcuCursor *)pCursor; 167 | ubrk_close(pCsr->pIter); 168 | sqlite3_free(pCsr->zBuffer); 169 | sqlite3_free(pCsr); 170 | return SQLITE_OK; 171 | } 172 | 173 | /* 174 | ** Extract the next token from a tokenization cursor. 175 | */ 176 | static int icuNext( 177 | sqlite3_tokenizer_cursor *pCursor, /* Cursor returned by simpleOpen */ 178 | const char **ppToken, /* OUT: *ppToken is the token text */ 179 | int *pnBytes, /* OUT: Number of bytes in token */ 180 | int *piStartOffset, /* OUT: Starting offset of token */ 181 | int *piEndOffset, /* OUT: Ending offset of token */ 182 | int *piPosition /* OUT: Position integer of token */ 183 | ){ 184 | IcuCursor *pCsr = (IcuCursor *)pCursor; 185 | 186 | int iStart = 0; 187 | int iEnd = 0; 188 | int nByte = 0; 189 | 190 | while( iStart==iEnd ){ 191 | UChar32 c; 192 | 193 | iStart = ubrk_current(pCsr->pIter); 194 | iEnd = ubrk_next(pCsr->pIter); 195 | if( iEnd==UBRK_DONE ){ 196 | return SQLITE_DONE; 197 | } 198 | 199 | while( iStartaChar, iWhite, pCsr->nChar, c); 202 | if( u_isspace(c) ){ 203 | iStart = iWhite; 204 | }else{ 205 | break; 206 | } 207 | } 208 | assert(iStart<=iEnd); 209 | } 210 | 211 | do { 212 | UErrorCode status = U_ZERO_ERROR; 213 | if( nByte ){ 214 | char *zNew = sqlite3_realloc(pCsr->zBuffer, nByte); 215 | if( !zNew ){ 216 | return SQLITE_NOMEM; 217 | } 218 | pCsr->zBuffer = zNew; 219 | pCsr->nBuffer = nByte; 220 | } 221 | 222 | u_strToUTF8( 223 | pCsr->zBuffer, pCsr->nBuffer, &nByte, /* Output vars */ 224 | &pCsr->aChar[iStart], iEnd-iStart, /* Input vars */ 225 | &status /* Output success/failure */ 226 | ); 227 | } while( nByte>pCsr->nBuffer ); 228 | 229 | *ppToken = pCsr->zBuffer; 230 | *pnBytes = nByte; 231 | *piStartOffset = pCsr->aOffset[iStart]; 232 | *piEndOffset = pCsr->aOffset[iEnd]; 233 | *piPosition = pCsr->iToken++; 234 | 235 | return SQLITE_OK; 236 | } 237 | 238 | /* 239 | ** The set of routines that implement the simple tokenizer 240 | */ 241 | static const sqlite3_tokenizer_module icuTokenizerModule = { 242 | 0, /* iVersion */ 243 | icuCreate, /* xCreate */ 244 | icuDestroy, /* xCreate */ 245 | icuOpen, /* xOpen */ 246 | icuClose, /* xClose */ 247 | icuNext, /* xNext */ 248 | }; 249 | 250 | /* 251 | ** Set *ppModule to point at the implementation of the ICU tokenizer. 252 | */ 253 | void sqlite3Fts2IcuTokenizerModule( 254 | sqlite3_tokenizer_module const**ppModule 255 | ){ 256 | *ppModule = &icuTokenizerModule; 257 | } 258 | 259 | #endif /* defined(SQLITE_ENABLE_ICU) */ 260 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS2) */ 261 | -------------------------------------------------------------------------------- /fts2_tokenizer.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2006 July 10 3 | ** 4 | ** The author disclaims copyright to this source code. 5 | ** 6 | ************************************************************************* 7 | ** Defines the interface to tokenizers used by fulltext-search. There 8 | ** are three basic components: 9 | ** 10 | ** sqlite3_tokenizer_module is a singleton defining the tokenizer 11 | ** interface functions. This is essentially the class structure for 12 | ** tokenizers. 13 | ** 14 | ** sqlite3_tokenizer is used to define a particular tokenizer, perhaps 15 | ** including customization information defined at creation time. 16 | ** 17 | ** sqlite3_tokenizer_cursor is generated by a tokenizer to generate 18 | ** tokens from a particular input. 19 | */ 20 | #ifndef _FTS2_TOKENIZER_H_ 21 | #define _FTS2_TOKENIZER_H_ 22 | 23 | /* TODO(shess) Only used for SQLITE_OK and SQLITE_DONE at this time. 24 | ** If tokenizers are to be allowed to call sqlite3_*() functions, then 25 | ** we will need a way to register the API consistently. 26 | */ 27 | #include "sqlite3.h" 28 | 29 | /* 30 | ** Structures used by the tokenizer interface. When a new tokenizer 31 | ** implementation is registered, the caller provides a pointer to 32 | ** an sqlite3_tokenizer_module containing pointers to the callback 33 | ** functions that make up an implementation. 34 | ** 35 | ** When an fts2 table is created, it passes any arguments passed to 36 | ** the tokenizer clause of the CREATE VIRTUAL TABLE statement to the 37 | ** sqlite3_tokenizer_module.xCreate() function of the requested tokenizer 38 | ** implementation. The xCreate() function in turn returns an 39 | ** sqlite3_tokenizer structure representing the specific tokenizer to 40 | ** be used for the fts2 table (customized by the tokenizer clause arguments). 41 | ** 42 | ** To tokenize an input buffer, the sqlite3_tokenizer_module.xOpen() 43 | ** method is called. It returns an sqlite3_tokenizer_cursor object 44 | ** that may be used to tokenize a specific input buffer based on 45 | ** the tokenization rules supplied by a specific sqlite3_tokenizer 46 | ** object. 47 | */ 48 | typedef struct sqlite3_tokenizer_module sqlite3_tokenizer_module; 49 | typedef struct sqlite3_tokenizer sqlite3_tokenizer; 50 | typedef struct sqlite3_tokenizer_cursor sqlite3_tokenizer_cursor; 51 | 52 | struct sqlite3_tokenizer_module { 53 | 54 | /* 55 | ** Structure version. Should always be set to 0. 56 | */ 57 | int iVersion; 58 | 59 | /* 60 | ** Create a new tokenizer. The values in the argv[] array are the 61 | ** arguments passed to the "tokenizer" clause of the CREATE VIRTUAL 62 | ** TABLE statement that created the fts2 table. For example, if 63 | ** the following SQL is executed: 64 | ** 65 | ** CREATE .. USING fts2( ... , tokenizer arg1 arg2) 66 | ** 67 | ** then argc is set to 2, and the argv[] array contains pointers 68 | ** to the strings "arg1" and "arg2". 69 | ** 70 | ** This method should return either SQLITE_OK (0), or an SQLite error 71 | ** code. If SQLITE_OK is returned, then *ppTokenizer should be set 72 | ** to point at the newly created tokenizer structure. The generic 73 | ** sqlite3_tokenizer.pModule variable should not be initialized by 74 | ** this callback. The caller will do so. 75 | */ 76 | int (*xCreate)( 77 | int argc, /* Size of argv array */ 78 | const char *const*argv, /* Tokenizer argument strings */ 79 | sqlite3_tokenizer **ppTokenizer /* OUT: Created tokenizer */ 80 | ); 81 | 82 | /* 83 | ** Destroy an existing tokenizer. The fts2 module calls this method 84 | ** exactly once for each successful call to xCreate(). 85 | */ 86 | int (*xDestroy)(sqlite3_tokenizer *pTokenizer); 87 | 88 | /* 89 | ** Create a tokenizer cursor to tokenize an input buffer. The caller 90 | ** is responsible for ensuring that the input buffer remains valid 91 | ** until the cursor is closed (using the xClose() method). 92 | */ 93 | int (*xOpen)( 94 | sqlite3_tokenizer *pTokenizer, /* Tokenizer object */ 95 | const char *pInput, int nBytes, /* Input buffer */ 96 | sqlite3_tokenizer_cursor **ppCursor /* OUT: Created tokenizer cursor */ 97 | ); 98 | 99 | /* 100 | ** Destroy an existing tokenizer cursor. The fts2 module calls this 101 | ** method exactly once for each successful call to xOpen(). 102 | */ 103 | int (*xClose)(sqlite3_tokenizer_cursor *pCursor); 104 | 105 | /* 106 | ** Retrieve the next token from the tokenizer cursor pCursor. This 107 | ** method should either return SQLITE_OK and set the values of the 108 | ** "OUT" variables identified below, or SQLITE_DONE to indicate that 109 | ** the end of the buffer has been reached, or an SQLite error code. 110 | ** 111 | ** *ppToken should be set to point at a buffer containing the 112 | ** normalized version of the token (i.e. after any case-folding and/or 113 | ** stemming has been performed). *pnBytes should be set to the length 114 | ** of this buffer in bytes. The input text that generated the token is 115 | ** identified by the byte offsets returned in *piStartOffset and 116 | ** *piEndOffset. 117 | ** 118 | ** The buffer *ppToken is set to point at is managed by the tokenizer 119 | ** implementation. It is only required to be valid until the next call 120 | ** to xNext() or xClose(). 121 | */ 122 | /* TODO(shess) current implementation requires pInput to be 123 | ** nul-terminated. This should either be fixed, or pInput/nBytes 124 | ** should be converted to zInput. 125 | */ 126 | int (*xNext)( 127 | sqlite3_tokenizer_cursor *pCursor, /* Tokenizer cursor */ 128 | const char **ppToken, int *pnBytes, /* OUT: Normalized text for token */ 129 | int *piStartOffset, /* OUT: Byte offset of token in input buffer */ 130 | int *piEndOffset, /* OUT: Byte offset of end of token in input buffer */ 131 | int *piPosition /* OUT: Number of tokens returned before this one */ 132 | ); 133 | }; 134 | 135 | struct sqlite3_tokenizer { 136 | const sqlite3_tokenizer_module *pModule; /* The module for this tokenizer */ 137 | /* Tokenizer implementations will typically add additional fields */ 138 | }; 139 | 140 | struct sqlite3_tokenizer_cursor { 141 | sqlite3_tokenizer *pTokenizer; /* Tokenizer for this cursor. */ 142 | /* Tokenizer implementations will typically add additional fields */ 143 | }; 144 | 145 | #endif /* _FTS2_TOKENIZER_H_ */ 146 | -------------------------------------------------------------------------------- /fts2_tokenizer1.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2006 Oct 10 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ****************************************************************************** 12 | ** 13 | ** Implementation of the "simple" full-text-search tokenizer. 14 | */ 15 | 16 | /* 17 | ** The code in this file is only compiled if: 18 | ** 19 | ** * The FTS2 module is being built as an extension 20 | ** (in which case SQLITE_CORE is not defined), or 21 | ** 22 | ** * The FTS2 module is being built into the core of 23 | ** SQLite (in which case SQLITE_ENABLE_FTS2 is defined). 24 | */ 25 | #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS2) 26 | 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include "fts2_tokenizer.h" 34 | 35 | typedef struct simple_tokenizer { 36 | sqlite3_tokenizer base; 37 | char delim[128]; /* flag ASCII delimiters */ 38 | } simple_tokenizer; 39 | 40 | typedef struct simple_tokenizer_cursor { 41 | sqlite3_tokenizer_cursor base; 42 | const char *pInput; /* input we are tokenizing */ 43 | int nBytes; /* size of the input */ 44 | int iOffset; /* current position in pInput */ 45 | int iToken; /* index of next token to be returned */ 46 | char *pToken; /* storage for current token */ 47 | int nTokenAllocated; /* space allocated to zToken buffer */ 48 | } simple_tokenizer_cursor; 49 | 50 | 51 | /* Forward declaration */ 52 | static const sqlite3_tokenizer_module simpleTokenizerModule; 53 | 54 | static int simpleDelim(simple_tokenizer *t, unsigned char c){ 55 | return c<0x80 && t->delim[c]; 56 | } 57 | 58 | /* 59 | ** Create a new tokenizer instance. 60 | */ 61 | static int simpleCreate( 62 | int argc, const char * const *argv, 63 | sqlite3_tokenizer **ppTokenizer 64 | ){ 65 | simple_tokenizer *t; 66 | 67 | t = (simple_tokenizer *) sqlite3_malloc(sizeof(*t)); 68 | if( t==NULL ) return SQLITE_NOMEM; 69 | memset(t, 0, sizeof(*t)); 70 | 71 | /* TODO(shess) Delimiters need to remain the same from run to run, 72 | ** else we need to reindex. One solution would be a meta-table to 73 | ** track such information in the database, then we'd only want this 74 | ** information on the initial create. 75 | */ 76 | if( argc>1 ){ 77 | int i, n = strlen(argv[1]); 78 | for(i=0; i=0x80 ){ 82 | sqlite3_free(t); 83 | return SQLITE_ERROR; 84 | } 85 | t->delim[ch] = 1; 86 | } 87 | } else { 88 | /* Mark non-alphanumeric ASCII characters as delimiters */ 89 | int i; 90 | for(i=1; i<0x80; i++){ 91 | t->delim[i] = !((i>='0' && i<='9') || (i>='A' && i<='Z') || 92 | (i>='a' && i<='z')); 93 | } 94 | } 95 | 96 | *ppTokenizer = &t->base; 97 | return SQLITE_OK; 98 | } 99 | 100 | /* 101 | ** Destroy a tokenizer 102 | */ 103 | static int simpleDestroy(sqlite3_tokenizer *pTokenizer){ 104 | sqlite3_free(pTokenizer); 105 | return SQLITE_OK; 106 | } 107 | 108 | /* 109 | ** Prepare to begin tokenizing a particular string. The input 110 | ** string to be tokenized is pInput[0..nBytes-1]. A cursor 111 | ** used to incrementally tokenize this string is returned in 112 | ** *ppCursor. 113 | */ 114 | static int simpleOpen( 115 | sqlite3_tokenizer *pTokenizer, /* The tokenizer */ 116 | const char *pInput, int nBytes, /* String to be tokenized */ 117 | sqlite3_tokenizer_cursor **ppCursor /* OUT: Tokenization cursor */ 118 | ){ 119 | simple_tokenizer_cursor *c; 120 | 121 | c = (simple_tokenizer_cursor *) sqlite3_malloc(sizeof(*c)); 122 | if( c==NULL ) return SQLITE_NOMEM; 123 | 124 | c->pInput = pInput; 125 | if( pInput==0 ){ 126 | c->nBytes = 0; 127 | }else if( nBytes<0 ){ 128 | c->nBytes = (int)strlen(pInput); 129 | }else{ 130 | c->nBytes = nBytes; 131 | } 132 | c->iOffset = 0; /* start tokenizing at the beginning */ 133 | c->iToken = 0; 134 | c->pToken = NULL; /* no space allocated, yet. */ 135 | c->nTokenAllocated = 0; 136 | 137 | *ppCursor = &c->base; 138 | return SQLITE_OK; 139 | } 140 | 141 | /* 142 | ** Close a tokenization cursor previously opened by a call to 143 | ** simpleOpen() above. 144 | */ 145 | static int simpleClose(sqlite3_tokenizer_cursor *pCursor){ 146 | simple_tokenizer_cursor *c = (simple_tokenizer_cursor *) pCursor; 147 | sqlite3_free(c->pToken); 148 | sqlite3_free(c); 149 | return SQLITE_OK; 150 | } 151 | 152 | /* 153 | ** Extract the next token from a tokenization cursor. The cursor must 154 | ** have been opened by a prior call to simpleOpen(). 155 | */ 156 | static int simpleNext( 157 | sqlite3_tokenizer_cursor *pCursor, /* Cursor returned by simpleOpen */ 158 | const char **ppToken, /* OUT: *ppToken is the token text */ 159 | int *pnBytes, /* OUT: Number of bytes in token */ 160 | int *piStartOffset, /* OUT: Starting offset of token */ 161 | int *piEndOffset, /* OUT: Ending offset of token */ 162 | int *piPosition /* OUT: Position integer of token */ 163 | ){ 164 | simple_tokenizer_cursor *c = (simple_tokenizer_cursor *) pCursor; 165 | simple_tokenizer *t = (simple_tokenizer *) pCursor->pTokenizer; 166 | unsigned char *p = (unsigned char *)c->pInput; 167 | 168 | while( c->iOffsetnBytes ){ 169 | int iStartOffset; 170 | 171 | /* Scan past delimiter characters */ 172 | while( c->iOffsetnBytes && simpleDelim(t, p[c->iOffset]) ){ 173 | c->iOffset++; 174 | } 175 | 176 | /* Count non-delimiter characters. */ 177 | iStartOffset = c->iOffset; 178 | while( c->iOffsetnBytes && !simpleDelim(t, p[c->iOffset]) ){ 179 | c->iOffset++; 180 | } 181 | 182 | if( c->iOffset>iStartOffset ){ 183 | int i, n = c->iOffset-iStartOffset; 184 | if( n>c->nTokenAllocated ){ 185 | c->nTokenAllocated = n+20; 186 | c->pToken = sqlite3_realloc(c->pToken, c->nTokenAllocated); 187 | if( c->pToken==NULL ) return SQLITE_NOMEM; 188 | } 189 | for(i=0; ipToken[i] = (ch>='A' && ch<='Z') ? (ch - 'A' + 'a') : ch; 195 | } 196 | *ppToken = c->pToken; 197 | *pnBytes = n; 198 | *piStartOffset = iStartOffset; 199 | *piEndOffset = c->iOffset; 200 | *piPosition = c->iToken++; 201 | 202 | return SQLITE_OK; 203 | } 204 | } 205 | return SQLITE_DONE; 206 | } 207 | 208 | /* 209 | ** The set of routines that implement the simple tokenizer 210 | */ 211 | static const sqlite3_tokenizer_module simpleTokenizerModule = { 212 | 0, 213 | simpleCreate, 214 | simpleDestroy, 215 | simpleOpen, 216 | simpleClose, 217 | simpleNext, 218 | }; 219 | 220 | /* 221 | ** Allocate a new simple tokenizer. Return a pointer to the new 222 | ** tokenizer in *ppModule 223 | */ 224 | void sqlite3Fts2SimpleTokenizerModule( 225 | sqlite3_tokenizer_module const**ppModule 226 | ){ 227 | *ppModule = &simpleTokenizerModule; 228 | } 229 | 230 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS2) */ 231 | -------------------------------------------------------------------------------- /fts3.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2006 Oct 10 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ****************************************************************************** 12 | ** 13 | ** This header file is used by programs that want to link against the 14 | ** FTS3 library. All it does is declare the sqlite3Fts3Init() interface. 15 | */ 16 | #include "sqlite3.h" 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif /* __cplusplus */ 21 | 22 | int sqlite3Fts3Init(sqlite3 *db); 23 | 24 | #ifdef __cplusplus 25 | } /* extern "C" */ 26 | #endif /* __cplusplus */ 27 | -------------------------------------------------------------------------------- /fts3_hash.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2001 September 22 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ************************************************************************* 12 | ** This is the header file for the generic hash-table implementation 13 | ** used in SQLite. We've modified it slightly to serve as a standalone 14 | ** hash table implementation for the full-text indexing module. 15 | ** 16 | */ 17 | #ifndef _FTS3_HASH_H_ 18 | #define _FTS3_HASH_H_ 19 | 20 | /* Forward declarations of structures. */ 21 | typedef struct Fts3Hash Fts3Hash; 22 | typedef struct Fts3HashElem Fts3HashElem; 23 | 24 | /* A complete hash table is an instance of the following structure. 25 | ** The internals of this structure are intended to be opaque -- client 26 | ** code should not attempt to access or modify the fields of this structure 27 | ** directly. Change this structure only by using the routines below. 28 | ** However, many of the "procedures" and "functions" for modifying and 29 | ** accessing this structure are really macros, so we can't really make 30 | ** this structure opaque. 31 | */ 32 | struct Fts3Hash { 33 | char keyClass; /* HASH_INT, _POINTER, _STRING, _BINARY */ 34 | char copyKey; /* True if copy of key made on insert */ 35 | int count; /* Number of entries in this table */ 36 | Fts3HashElem *first; /* The first element of the array */ 37 | int htsize; /* Number of buckets in the hash table */ 38 | struct _fts3ht { /* the hash table */ 39 | int count; /* Number of entries with this hash */ 40 | Fts3HashElem *chain; /* Pointer to first entry with this hash */ 41 | } *ht; 42 | }; 43 | 44 | /* Each element in the hash table is an instance of the following 45 | ** structure. All elements are stored on a single doubly-linked list. 46 | ** 47 | ** Again, this structure is intended to be opaque, but it can't really 48 | ** be opaque because it is used by macros. 49 | */ 50 | struct Fts3HashElem { 51 | Fts3HashElem *next, *prev; /* Next and previous elements in the table */ 52 | void *data; /* Data associated with this element */ 53 | void *pKey; int nKey; /* Key associated with this element */ 54 | }; 55 | 56 | /* 57 | ** There are 2 different modes of operation for a hash table: 58 | ** 59 | ** FTS3_HASH_STRING pKey points to a string that is nKey bytes long 60 | ** (including the null-terminator, if any). Case 61 | ** is respected in comparisons. 62 | ** 63 | ** FTS3_HASH_BINARY pKey points to binary data nKey bytes long. 64 | ** memcmp() is used to compare keys. 65 | ** 66 | ** A copy of the key is made if the copyKey parameter to fts3HashInit is 1. 67 | */ 68 | #define FTS3_HASH_STRING 1 69 | #define FTS3_HASH_BINARY 2 70 | 71 | /* 72 | ** Access routines. To delete, insert a NULL pointer. 73 | */ 74 | void sqlite3Fts3HashInit(Fts3Hash *pNew, char keyClass, char copyKey); 75 | void *sqlite3Fts3HashInsert(Fts3Hash*, const void *pKey, int nKey, void *pData); 76 | void *sqlite3Fts3HashFind(const Fts3Hash*, const void *pKey, int nKey); 77 | void sqlite3Fts3HashClear(Fts3Hash*); 78 | Fts3HashElem *sqlite3Fts3HashFindElem(const Fts3Hash *, const void *, int); 79 | 80 | /* 81 | ** Shorthand for the functions above 82 | */ 83 | #define fts3HashInit sqlite3Fts3HashInit 84 | #define fts3HashInsert sqlite3Fts3HashInsert 85 | #define fts3HashFind sqlite3Fts3HashFind 86 | #define fts3HashClear sqlite3Fts3HashClear 87 | #define fts3HashFindElem sqlite3Fts3HashFindElem 88 | 89 | /* 90 | ** Macros for looping over all elements of a hash table. The idiom is 91 | ** like this: 92 | ** 93 | ** Fts3Hash h; 94 | ** Fts3HashElem *p; 95 | ** ... 96 | ** for(p=fts3HashFirst(&h); p; p=fts3HashNext(p)){ 97 | ** SomeStructure *pData = fts3HashData(p); 98 | ** // do something with pData 99 | ** } 100 | */ 101 | #define fts3HashFirst(H) ((H)->first) 102 | #define fts3HashNext(E) ((E)->next) 103 | #define fts3HashData(E) ((E)->data) 104 | #define fts3HashKey(E) ((E)->pKey) 105 | #define fts3HashKeysize(E) ((E)->nKey) 106 | 107 | /* 108 | ** Number of entries in a hash table 109 | */ 110 | #define fts3HashCount(H) ((H)->count) 111 | 112 | #endif /* _FTS3_HASH_H_ */ 113 | -------------------------------------------------------------------------------- /fts3_icu.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2007 June 22 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ************************************************************************* 12 | ** This file implements a tokenizer for fts3 based on the ICU library. 13 | */ 14 | #include "fts3Int.h" 15 | #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) 16 | #ifdef SQLITE_ENABLE_ICU 17 | 18 | #include 19 | #include 20 | #include "fts3_tokenizer.h" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | typedef struct IcuTokenizer IcuTokenizer; 28 | typedef struct IcuCursor IcuCursor; 29 | 30 | struct IcuTokenizer { 31 | sqlite3_tokenizer base; 32 | char *zLocale; 33 | }; 34 | 35 | struct IcuCursor { 36 | sqlite3_tokenizer_cursor base; 37 | 38 | UBreakIterator *pIter; /* ICU break-iterator object */ 39 | int nChar; /* Number of UChar elements in pInput */ 40 | UChar *aChar; /* Copy of input using utf-16 encoding */ 41 | int *aOffset; /* Offsets of each character in utf-8 input */ 42 | 43 | int nBuffer; 44 | char *zBuffer; 45 | 46 | int iToken; 47 | }; 48 | 49 | /* 50 | ** Create a new tokenizer instance. 51 | */ 52 | static int icuCreate( 53 | int argc, /* Number of entries in argv[] */ 54 | const char * const *argv, /* Tokenizer creation arguments */ 55 | sqlite3_tokenizer **ppTokenizer /* OUT: Created tokenizer */ 56 | ){ 57 | IcuTokenizer *p; 58 | int n = 0; 59 | 60 | if( argc>0 ){ 61 | n = strlen(argv[0])+1; 62 | } 63 | p = (IcuTokenizer *)sqlite3_malloc(sizeof(IcuTokenizer)+n); 64 | if( !p ){ 65 | return SQLITE_NOMEM; 66 | } 67 | memset(p, 0, sizeof(IcuTokenizer)); 68 | 69 | if( n ){ 70 | p->zLocale = (char *)&p[1]; 71 | memcpy(p->zLocale, argv[0], n); 72 | } 73 | 74 | *ppTokenizer = (sqlite3_tokenizer *)p; 75 | 76 | return SQLITE_OK; 77 | } 78 | 79 | /* 80 | ** Destroy a tokenizer 81 | */ 82 | static int icuDestroy(sqlite3_tokenizer *pTokenizer){ 83 | IcuTokenizer *p = (IcuTokenizer *)pTokenizer; 84 | sqlite3_free(p); 85 | return SQLITE_OK; 86 | } 87 | 88 | /* 89 | ** Prepare to begin tokenizing a particular string. The input 90 | ** string to be tokenized is pInput[0..nBytes-1]. A cursor 91 | ** used to incrementally tokenize this string is returned in 92 | ** *ppCursor. 93 | */ 94 | static int icuOpen( 95 | sqlite3_tokenizer *pTokenizer, /* The tokenizer */ 96 | const char *zInput, /* Input string */ 97 | int nInput, /* Length of zInput in bytes */ 98 | sqlite3_tokenizer_cursor **ppCursor /* OUT: Tokenization cursor */ 99 | ){ 100 | IcuTokenizer *p = (IcuTokenizer *)pTokenizer; 101 | IcuCursor *pCsr; 102 | 103 | const int32_t opt = U_FOLD_CASE_DEFAULT; 104 | UErrorCode status = U_ZERO_ERROR; 105 | int nChar; 106 | 107 | UChar32 c; 108 | int iInput = 0; 109 | int iOut = 0; 110 | 111 | *ppCursor = 0; 112 | 113 | if( zInput==0 ){ 114 | nInput = 0; 115 | zInput = ""; 116 | }else if( nInput<0 ){ 117 | nInput = strlen(zInput); 118 | } 119 | nChar = nInput+1; 120 | pCsr = (IcuCursor *)sqlite3_malloc( 121 | sizeof(IcuCursor) + /* IcuCursor */ 122 | ((nChar+3)&~3) * sizeof(UChar) + /* IcuCursor.aChar[] */ 123 | (nChar+1) * sizeof(int) /* IcuCursor.aOffset[] */ 124 | ); 125 | if( !pCsr ){ 126 | return SQLITE_NOMEM; 127 | } 128 | memset(pCsr, 0, sizeof(IcuCursor)); 129 | pCsr->aChar = (UChar *)&pCsr[1]; 130 | pCsr->aOffset = (int *)&pCsr->aChar[(nChar+3)&~3]; 131 | 132 | pCsr->aOffset[iOut] = iInput; 133 | U8_NEXT(zInput, iInput, nInput, c); 134 | while( c>0 ){ 135 | int isError = 0; 136 | c = u_foldCase(c, opt); 137 | U16_APPEND(pCsr->aChar, iOut, nChar, c, isError); 138 | if( isError ){ 139 | sqlite3_free(pCsr); 140 | return SQLITE_ERROR; 141 | } 142 | pCsr->aOffset[iOut] = iInput; 143 | 144 | if( iInputpIter = ubrk_open(UBRK_WORD, p->zLocale, pCsr->aChar, iOut, &status); 152 | if( !U_SUCCESS(status) ){ 153 | sqlite3_free(pCsr); 154 | return SQLITE_ERROR; 155 | } 156 | pCsr->nChar = iOut; 157 | 158 | ubrk_first(pCsr->pIter); 159 | *ppCursor = (sqlite3_tokenizer_cursor *)pCsr; 160 | return SQLITE_OK; 161 | } 162 | 163 | /* 164 | ** Close a tokenization cursor previously opened by a call to icuOpen(). 165 | */ 166 | static int icuClose(sqlite3_tokenizer_cursor *pCursor){ 167 | IcuCursor *pCsr = (IcuCursor *)pCursor; 168 | ubrk_close(pCsr->pIter); 169 | sqlite3_free(pCsr->zBuffer); 170 | sqlite3_free(pCsr); 171 | return SQLITE_OK; 172 | } 173 | 174 | /* 175 | ** Extract the next token from a tokenization cursor. 176 | */ 177 | static int icuNext( 178 | sqlite3_tokenizer_cursor *pCursor, /* Cursor returned by simpleOpen */ 179 | const char **ppToken, /* OUT: *ppToken is the token text */ 180 | int *pnBytes, /* OUT: Number of bytes in token */ 181 | int *piStartOffset, /* OUT: Starting offset of token */ 182 | int *piEndOffset, /* OUT: Ending offset of token */ 183 | int *piPosition /* OUT: Position integer of token */ 184 | ){ 185 | IcuCursor *pCsr = (IcuCursor *)pCursor; 186 | 187 | int iStart = 0; 188 | int iEnd = 0; 189 | int nByte = 0; 190 | 191 | while( iStart==iEnd ){ 192 | UChar32 c; 193 | 194 | iStart = ubrk_current(pCsr->pIter); 195 | iEnd = ubrk_next(pCsr->pIter); 196 | if( iEnd==UBRK_DONE ){ 197 | return SQLITE_DONE; 198 | } 199 | 200 | while( iStartaChar, iWhite, pCsr->nChar, c); 203 | if( u_isspace(c) ){ 204 | iStart = iWhite; 205 | }else{ 206 | break; 207 | } 208 | } 209 | assert(iStart<=iEnd); 210 | } 211 | 212 | do { 213 | UErrorCode status = U_ZERO_ERROR; 214 | if( nByte ){ 215 | char *zNew = sqlite3_realloc(pCsr->zBuffer, nByte); 216 | if( !zNew ){ 217 | return SQLITE_NOMEM; 218 | } 219 | pCsr->zBuffer = zNew; 220 | pCsr->nBuffer = nByte; 221 | } 222 | 223 | u_strToUTF8( 224 | pCsr->zBuffer, pCsr->nBuffer, &nByte, /* Output vars */ 225 | &pCsr->aChar[iStart], iEnd-iStart, /* Input vars */ 226 | &status /* Output success/failure */ 227 | ); 228 | } while( nByte>pCsr->nBuffer ); 229 | 230 | *ppToken = pCsr->zBuffer; 231 | *pnBytes = nByte; 232 | *piStartOffset = pCsr->aOffset[iStart]; 233 | *piEndOffset = pCsr->aOffset[iEnd]; 234 | *piPosition = pCsr->iToken++; 235 | 236 | return SQLITE_OK; 237 | } 238 | 239 | /* 240 | ** The set of routines that implement the simple tokenizer 241 | */ 242 | static const sqlite3_tokenizer_module icuTokenizerModule = { 243 | 0, /* iVersion */ 244 | icuCreate, /* xCreate */ 245 | icuDestroy, /* xCreate */ 246 | icuOpen, /* xOpen */ 247 | icuClose, /* xClose */ 248 | icuNext, /* xNext */ 249 | }; 250 | 251 | /* 252 | ** Set *ppModule to point at the implementation of the ICU tokenizer. 253 | */ 254 | void sqlite3Fts3IcuTokenizerModule( 255 | sqlite3_tokenizer_module const**ppModule 256 | ){ 257 | *ppModule = &icuTokenizerModule; 258 | } 259 | 260 | #endif /* defined(SQLITE_ENABLE_ICU) */ 261 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */ 262 | -------------------------------------------------------------------------------- /fts3_tokenizer.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2006 July 10 3 | ** 4 | ** The author disclaims copyright to this source code. 5 | ** 6 | ************************************************************************* 7 | ** Defines the interface to tokenizers used by fulltext-search. There 8 | ** are three basic components: 9 | ** 10 | ** sqlite3_tokenizer_module is a singleton defining the tokenizer 11 | ** interface functions. This is essentially the class structure for 12 | ** tokenizers. 13 | ** 14 | ** sqlite3_tokenizer is used to define a particular tokenizer, perhaps 15 | ** including customization information defined at creation time. 16 | ** 17 | ** sqlite3_tokenizer_cursor is generated by a tokenizer to generate 18 | ** tokens from a particular input. 19 | */ 20 | #ifndef _FTS3_TOKENIZER_H_ 21 | #define _FTS3_TOKENIZER_H_ 22 | 23 | /* TODO(shess) Only used for SQLITE_OK and SQLITE_DONE at this time. 24 | ** If tokenizers are to be allowed to call sqlite3_*() functions, then 25 | ** we will need a way to register the API consistently. 26 | */ 27 | #include "sqlite3.h" 28 | 29 | /* 30 | ** Structures used by the tokenizer interface. When a new tokenizer 31 | ** implementation is registered, the caller provides a pointer to 32 | ** an sqlite3_tokenizer_module containing pointers to the callback 33 | ** functions that make up an implementation. 34 | ** 35 | ** When an fts3 table is created, it passes any arguments passed to 36 | ** the tokenizer clause of the CREATE VIRTUAL TABLE statement to the 37 | ** sqlite3_tokenizer_module.xCreate() function of the requested tokenizer 38 | ** implementation. The xCreate() function in turn returns an 39 | ** sqlite3_tokenizer structure representing the specific tokenizer to 40 | ** be used for the fts3 table (customized by the tokenizer clause arguments). 41 | ** 42 | ** To tokenize an input buffer, the sqlite3_tokenizer_module.xOpen() 43 | ** method is called. It returns an sqlite3_tokenizer_cursor object 44 | ** that may be used to tokenize a specific input buffer based on 45 | ** the tokenization rules supplied by a specific sqlite3_tokenizer 46 | ** object. 47 | */ 48 | typedef struct sqlite3_tokenizer_module sqlite3_tokenizer_module; 49 | typedef struct sqlite3_tokenizer sqlite3_tokenizer; 50 | typedef struct sqlite3_tokenizer_cursor sqlite3_tokenizer_cursor; 51 | 52 | struct sqlite3_tokenizer_module { 53 | 54 | /* 55 | ** Structure version. Should always be set to 0 or 1. 56 | */ 57 | int iVersion; 58 | 59 | /* 60 | ** Create a new tokenizer. The values in the argv[] array are the 61 | ** arguments passed to the "tokenizer" clause of the CREATE VIRTUAL 62 | ** TABLE statement that created the fts3 table. For example, if 63 | ** the following SQL is executed: 64 | ** 65 | ** CREATE .. USING fts3( ... , tokenizer arg1 arg2) 66 | ** 67 | ** then argc is set to 2, and the argv[] array contains pointers 68 | ** to the strings "arg1" and "arg2". 69 | ** 70 | ** This method should return either SQLITE_OK (0), or an SQLite error 71 | ** code. If SQLITE_OK is returned, then *ppTokenizer should be set 72 | ** to point at the newly created tokenizer structure. The generic 73 | ** sqlite3_tokenizer.pModule variable should not be initialized by 74 | ** this callback. The caller will do so. 75 | */ 76 | int (*xCreate)( 77 | int argc, /* Size of argv array */ 78 | const char *const*argv, /* Tokenizer argument strings */ 79 | sqlite3_tokenizer **ppTokenizer /* OUT: Created tokenizer */ 80 | ); 81 | 82 | /* 83 | ** Destroy an existing tokenizer. The fts3 module calls this method 84 | ** exactly once for each successful call to xCreate(). 85 | */ 86 | int (*xDestroy)(sqlite3_tokenizer *pTokenizer); 87 | 88 | /* 89 | ** Create a tokenizer cursor to tokenize an input buffer. The caller 90 | ** is responsible for ensuring that the input buffer remains valid 91 | ** until the cursor is closed (using the xClose() method). 92 | */ 93 | int (*xOpen)( 94 | sqlite3_tokenizer *pTokenizer, /* Tokenizer object */ 95 | const char *pInput, int nBytes, /* Input buffer */ 96 | sqlite3_tokenizer_cursor **ppCursor /* OUT: Created tokenizer cursor */ 97 | ); 98 | 99 | /* 100 | ** Destroy an existing tokenizer cursor. The fts3 module calls this 101 | ** method exactly once for each successful call to xOpen(). 102 | */ 103 | int (*xClose)(sqlite3_tokenizer_cursor *pCursor); 104 | 105 | /* 106 | ** Retrieve the next token from the tokenizer cursor pCursor. This 107 | ** method should either return SQLITE_OK and set the values of the 108 | ** "OUT" variables identified below, or SQLITE_DONE to indicate that 109 | ** the end of the buffer has been reached, or an SQLite error code. 110 | ** 111 | ** *ppToken should be set to point at a buffer containing the 112 | ** normalized version of the token (i.e. after any case-folding and/or 113 | ** stemming has been performed). *pnBytes should be set to the length 114 | ** of this buffer in bytes. The input text that generated the token is 115 | ** identified by the byte offsets returned in *piStartOffset and 116 | ** *piEndOffset. *piStartOffset should be set to the index of the first 117 | ** byte of the token in the input buffer. *piEndOffset should be set 118 | ** to the index of the first byte just past the end of the token in 119 | ** the input buffer. 120 | ** 121 | ** The buffer *ppToken is set to point at is managed by the tokenizer 122 | ** implementation. It is only required to be valid until the next call 123 | ** to xNext() or xClose(). 124 | */ 125 | /* TODO(shess) current implementation requires pInput to be 126 | ** nul-terminated. This should either be fixed, or pInput/nBytes 127 | ** should be converted to zInput. 128 | */ 129 | int (*xNext)( 130 | sqlite3_tokenizer_cursor *pCursor, /* Tokenizer cursor */ 131 | const char **ppToken, int *pnBytes, /* OUT: Normalized text for token */ 132 | int *piStartOffset, /* OUT: Byte offset of token in input buffer */ 133 | int *piEndOffset, /* OUT: Byte offset of end of token in input buffer */ 134 | int *piPosition /* OUT: Number of tokens returned before this one */ 135 | ); 136 | 137 | /*********************************************************************** 138 | ** Methods below this point are only available if iVersion>=1. 139 | */ 140 | 141 | /* 142 | ** Configure the language id of a tokenizer cursor. 143 | */ 144 | int (*xLanguageid)(sqlite3_tokenizer_cursor *pCsr, int iLangid); 145 | }; 146 | 147 | struct sqlite3_tokenizer { 148 | const sqlite3_tokenizer_module *pModule; /* The module for this tokenizer */ 149 | /* Tokenizer implementations will typically add additional fields */ 150 | }; 151 | 152 | struct sqlite3_tokenizer_cursor { 153 | sqlite3_tokenizer *pTokenizer; /* Tokenizer for this cursor. */ 154 | /* Tokenizer implementations will typically add additional fields */ 155 | }; 156 | 157 | int fts3_global_term_cnt(int iTerm, int iCol); 158 | int fts3_term_cnt(int iTerm, int iCol); 159 | 160 | 161 | #endif /* _FTS3_TOKENIZER_H_ */ 162 | -------------------------------------------------------------------------------- /fts3_tokenizer1.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2006 Oct 10 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ****************************************************************************** 12 | ** 13 | ** Implementation of the "simple" full-text-search tokenizer. 14 | */ 15 | 16 | /* 17 | ** The code in this file is only compiled if: 18 | ** 19 | ** * The FTS3 module is being built as an extension 20 | ** (in which case SQLITE_CORE is not defined), or 21 | ** 22 | ** * The FTS3 module is being built into the core of 23 | ** SQLite (in which case SQLITE_ENABLE_FTS3 is defined). 24 | */ 25 | #include "fts3Int.h" 26 | #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include "fts3_tokenizer.h" 34 | 35 | typedef struct simple_tokenizer { 36 | sqlite3_tokenizer base; 37 | char delim[128]; /* flag ASCII delimiters */ 38 | } simple_tokenizer; 39 | 40 | typedef struct simple_tokenizer_cursor { 41 | sqlite3_tokenizer_cursor base; 42 | const char *pInput; /* input we are tokenizing */ 43 | int nBytes; /* size of the input */ 44 | int iOffset; /* current position in pInput */ 45 | int iToken; /* index of next token to be returned */ 46 | char *pToken; /* storage for current token */ 47 | int nTokenAllocated; /* space allocated to zToken buffer */ 48 | } simple_tokenizer_cursor; 49 | 50 | 51 | static int simpleDelim(simple_tokenizer *t, unsigned char c){ 52 | return c<0x80 && t->delim[c]; 53 | } 54 | static int fts3_isalnum(int x){ 55 | return (x>='0' && x<='9') || (x>='A' && x<='Z') || (x>='a' && x<='z'); 56 | } 57 | 58 | /* 59 | ** Create a new tokenizer instance. 60 | */ 61 | static int simpleCreate( 62 | int argc, const char * const *argv, 63 | sqlite3_tokenizer **ppTokenizer 64 | ){ 65 | simple_tokenizer *t; 66 | 67 | t = (simple_tokenizer *) sqlite3_malloc(sizeof(*t)); 68 | if( t==NULL ) return SQLITE_NOMEM; 69 | memset(t, 0, sizeof(*t)); 70 | 71 | /* TODO(shess) Delimiters need to remain the same from run to run, 72 | ** else we need to reindex. One solution would be a meta-table to 73 | ** track such information in the database, then we'd only want this 74 | ** information on the initial create. 75 | */ 76 | if( argc>1 ){ 77 | int i, n = (int)strlen(argv[1]); 78 | for(i=0; i=0x80 ){ 82 | sqlite3_free(t); 83 | return SQLITE_ERROR; 84 | } 85 | t->delim[ch] = 1; 86 | } 87 | } else { 88 | /* Mark non-alphanumeric ASCII characters as delimiters */ 89 | int i; 90 | for(i=1; i<0x80; i++){ 91 | t->delim[i] = !fts3_isalnum(i) ? -1 : 0; 92 | } 93 | } 94 | 95 | *ppTokenizer = &t->base; 96 | return SQLITE_OK; 97 | } 98 | 99 | /* 100 | ** Destroy a tokenizer 101 | */ 102 | static int simpleDestroy(sqlite3_tokenizer *pTokenizer){ 103 | sqlite3_free(pTokenizer); 104 | return SQLITE_OK; 105 | } 106 | 107 | /* 108 | ** Prepare to begin tokenizing a particular string. The input 109 | ** string to be tokenized is pInput[0..nBytes-1]. A cursor 110 | ** used to incrementally tokenize this string is returned in 111 | ** *ppCursor. 112 | */ 113 | static int simpleOpen( 114 | sqlite3_tokenizer *pTokenizer, /* The tokenizer */ 115 | const char *pInput, int nBytes, /* String to be tokenized */ 116 | sqlite3_tokenizer_cursor **ppCursor /* OUT: Tokenization cursor */ 117 | ){ 118 | simple_tokenizer_cursor *c; 119 | 120 | UNUSED_PARAMETER(pTokenizer); 121 | 122 | c = (simple_tokenizer_cursor *) sqlite3_malloc(sizeof(*c)); 123 | if( c==NULL ) return SQLITE_NOMEM; 124 | 125 | c->pInput = pInput; 126 | if( pInput==0 ){ 127 | c->nBytes = 0; 128 | }else if( nBytes<0 ){ 129 | c->nBytes = (int)strlen(pInput); 130 | }else{ 131 | c->nBytes = nBytes; 132 | } 133 | c->iOffset = 0; /* start tokenizing at the beginning */ 134 | c->iToken = 0; 135 | c->pToken = NULL; /* no space allocated, yet. */ 136 | c->nTokenAllocated = 0; 137 | 138 | *ppCursor = &c->base; 139 | return SQLITE_OK; 140 | } 141 | 142 | /* 143 | ** Close a tokenization cursor previously opened by a call to 144 | ** simpleOpen() above. 145 | */ 146 | static int simpleClose(sqlite3_tokenizer_cursor *pCursor){ 147 | simple_tokenizer_cursor *c = (simple_tokenizer_cursor *) pCursor; 148 | sqlite3_free(c->pToken); 149 | sqlite3_free(c); 150 | return SQLITE_OK; 151 | } 152 | 153 | /* 154 | ** Extract the next token from a tokenization cursor. The cursor must 155 | ** have been opened by a prior call to simpleOpen(). 156 | */ 157 | static int simpleNext( 158 | sqlite3_tokenizer_cursor *pCursor, /* Cursor returned by simpleOpen */ 159 | const char **ppToken, /* OUT: *ppToken is the token text */ 160 | int *pnBytes, /* OUT: Number of bytes in token */ 161 | int *piStartOffset, /* OUT: Starting offset of token */ 162 | int *piEndOffset, /* OUT: Ending offset of token */ 163 | int *piPosition /* OUT: Position integer of token */ 164 | ){ 165 | simple_tokenizer_cursor *c = (simple_tokenizer_cursor *) pCursor; 166 | simple_tokenizer *t = (simple_tokenizer *) pCursor->pTokenizer; 167 | unsigned char *p = (unsigned char *)c->pInput; 168 | 169 | while( c->iOffsetnBytes ){ 170 | int iStartOffset; 171 | 172 | /* Scan past delimiter characters */ 173 | while( c->iOffsetnBytes && simpleDelim(t, p[c->iOffset]) ){ 174 | c->iOffset++; 175 | } 176 | 177 | /* Count non-delimiter characters. */ 178 | iStartOffset = c->iOffset; 179 | while( c->iOffsetnBytes && !simpleDelim(t, p[c->iOffset]) ){ 180 | c->iOffset++; 181 | } 182 | 183 | if( c->iOffset>iStartOffset ){ 184 | int i, n = c->iOffset-iStartOffset; 185 | if( n>c->nTokenAllocated ){ 186 | char *pNew; 187 | c->nTokenAllocated = n+20; 188 | pNew = sqlite3_realloc(c->pToken, c->nTokenAllocated); 189 | if( !pNew ) return SQLITE_NOMEM; 190 | c->pToken = pNew; 191 | } 192 | for(i=0; ipToken[i] = (char)((ch>='A' && ch<='Z') ? ch-'A'+'a' : ch); 198 | } 199 | *ppToken = c->pToken; 200 | *pnBytes = n; 201 | *piStartOffset = iStartOffset; 202 | *piEndOffset = c->iOffset; 203 | *piPosition = c->iToken++; 204 | 205 | return SQLITE_OK; 206 | } 207 | } 208 | return SQLITE_DONE; 209 | } 210 | 211 | /* 212 | ** The set of routines that implement the simple tokenizer 213 | */ 214 | static const sqlite3_tokenizer_module simpleTokenizerModule = { 215 | 0, 216 | simpleCreate, 217 | simpleDestroy, 218 | simpleOpen, 219 | simpleClose, 220 | simpleNext, 221 | 0, 222 | }; 223 | 224 | /* 225 | ** Allocate a new simple tokenizer. Return a pointer to the new 226 | ** tokenizer in *ppModule 227 | */ 228 | void sqlite3Fts3SimpleTokenizerModule( 229 | sqlite3_tokenizer_module const**ppModule 230 | ){ 231 | *ppModule = &simpleTokenizerModule; 232 | } 233 | 234 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */ 235 | -------------------------------------------------------------------------------- /hash.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2001 September 22 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ************************************************************************* 12 | ** This is the header file for the generic hash-table implementation 13 | ** used in SQLite. 14 | */ 15 | #ifndef _SQLITE_HASH_H_ 16 | #define _SQLITE_HASH_H_ 17 | 18 | /* Forward declarations of structures. */ 19 | typedef struct Hash Hash; 20 | typedef struct HashElem HashElem; 21 | 22 | /* A complete hash table is an instance of the following structure. 23 | ** The internals of this structure are intended to be opaque -- client 24 | ** code should not attempt to access or modify the fields of this structure 25 | ** directly. Change this structure only by using the routines below. 26 | ** However, some of the "procedures" and "functions" for modifying and 27 | ** accessing this structure are really macros, so we can't really make 28 | ** this structure opaque. 29 | ** 30 | ** All elements of the hash table are on a single doubly-linked list. 31 | ** Hash.first points to the head of this list. 32 | ** 33 | ** There are Hash.htsize buckets. Each bucket points to a spot in 34 | ** the global doubly-linked list. The contents of the bucket are the 35 | ** element pointed to plus the next _ht.count-1 elements in the list. 36 | ** 37 | ** Hash.htsize and Hash.ht may be zero. In that case lookup is done 38 | ** by a linear search of the global list. For small tables, the 39 | ** Hash.ht table is never allocated because if there are few elements 40 | ** in the table, it is faster to do a linear search than to manage 41 | ** the hash table. 42 | */ 43 | struct Hash { 44 | unsigned int htsize; /* Number of buckets in the hash table */ 45 | unsigned int count; /* Number of entries in this table */ 46 | HashElem *first; /* The first element of the array */ 47 | struct _ht { /* the hash table */ 48 | int count; /* Number of entries with this hash */ 49 | HashElem *chain; /* Pointer to first entry with this hash */ 50 | } *ht; 51 | }; 52 | 53 | /* Each element in the hash table is an instance of the following 54 | ** structure. All elements are stored on a single doubly-linked list. 55 | ** 56 | ** Again, this structure is intended to be opaque, but it can't really 57 | ** be opaque because it is used by macros. 58 | */ 59 | struct HashElem { 60 | HashElem *next, *prev; /* Next and previous elements in the table */ 61 | void *data; /* Data associated with this element */ 62 | const char *pKey; int nKey; /* Key associated with this element */ 63 | }; 64 | 65 | /* 66 | ** Access routines. To delete, insert a NULL pointer. 67 | */ 68 | void sqlite3HashInit(Hash*); 69 | void *sqlite3HashInsert(Hash*, const char *pKey, int nKey, void *pData); 70 | void *sqlite3HashFind(const Hash*, const char *pKey, int nKey); 71 | void sqlite3HashClear(Hash*); 72 | 73 | /* 74 | ** Macros for looping over all elements of a hash table. The idiom is 75 | ** like this: 76 | ** 77 | ** Hash h; 78 | ** HashElem *p; 79 | ** ... 80 | ** for(p=sqliteHashFirst(&h); p; p=sqliteHashNext(p)){ 81 | ** SomeStructure *pData = sqliteHashData(p); 82 | ** // do something with pData 83 | ** } 84 | */ 85 | #define sqliteHashFirst(H) ((H)->first) 86 | #define sqliteHashNext(E) ((E)->next) 87 | #define sqliteHashData(E) ((E)->data) 88 | /* #define sqliteHashKey(E) ((E)->pKey) // NOT USED */ 89 | /* #define sqliteHashKeysize(E) ((E)->nKey) // NOT USED */ 90 | 91 | /* 92 | ** Number of entries in a hash table 93 | */ 94 | /* #define sqliteHashCount(H) ((H)->count) // NOT USED */ 95 | 96 | #endif /* _SQLITE_HASH_H_ */ 97 | -------------------------------------------------------------------------------- /hwtime.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2008 May 27 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ****************************************************************************** 12 | ** 13 | ** This file contains inline asm code for retrieving "high-performance" 14 | ** counters for x86 class CPUs. 15 | */ 16 | #ifndef _HWTIME_H_ 17 | #define _HWTIME_H_ 18 | 19 | /* 20 | ** The following routine only works on pentium-class (or newer) processors. 21 | ** It uses the RDTSC opcode to read the cycle count value out of the 22 | ** processor and returns that value. This can be used for high-res 23 | ** profiling. 24 | */ 25 | #if (defined(__GNUC__) || defined(_MSC_VER)) && \ 26 | (defined(i386) || defined(__i386__) || defined(_M_IX86)) 27 | 28 | #if defined(__GNUC__) 29 | 30 | __inline__ sqlite_uint64 sqlite3Hwtime(void){ 31 | unsigned int lo, hi; 32 | __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi)); 33 | return (sqlite_uint64)hi << 32 | lo; 34 | } 35 | 36 | #elif defined(_MSC_VER) 37 | 38 | __declspec(naked) __inline sqlite_uint64 __cdecl sqlite3Hwtime(void){ 39 | __asm { 40 | rdtsc 41 | ret ; return value at EDX:EAX 42 | } 43 | } 44 | 45 | #endif 46 | 47 | #elif (defined(__GNUC__) && defined(__x86_64__)) 48 | 49 | __inline__ sqlite_uint64 sqlite3Hwtime(void){ 50 | unsigned long val; 51 | __asm__ __volatile__ ("rdtsc" : "=A" (val)); 52 | return val; 53 | } 54 | 55 | #elif (defined(__GNUC__) && defined(__ppc__)) 56 | 57 | __inline__ sqlite_uint64 sqlite3Hwtime(void){ 58 | unsigned long long retval; 59 | unsigned long junk; 60 | __asm__ __volatile__ ("\n\ 61 | 1: mftbu %1\n\ 62 | mftb %L0\n\ 63 | mftbu %0\n\ 64 | cmpw %0,%1\n\ 65 | bne 1b" 66 | : "=r" (retval), "=r" (junk)); 67 | return retval; 68 | } 69 | 70 | #else 71 | 72 | #error Need implementation of sqlite3Hwtime() for your platform. 73 | 74 | /* 75 | ** To compile without implementing sqlite3Hwtime() for your platform, 76 | ** you can remove the above #error and use the following 77 | ** stub function. You will lose timing support for many 78 | ** of the debugging and testing utilities, but it should at 79 | ** least compile and run. 80 | */ 81 | sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); } 82 | 83 | #endif 84 | 85 | #endif /* !defined(_HWTIME_H_) */ 86 | -------------------------------------------------------------------------------- /legacy.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2001 September 15 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ************************************************************************* 12 | ** Main file for the SQLite library. The routines in this file 13 | ** implement the programmer interface to the library. Routines in 14 | ** other files are for internal use by SQLite and should not be 15 | ** accessed by users of the library. 16 | */ 17 | 18 | #include "sqliteInt.h" 19 | 20 | /* 21 | ** Execute SQL code. Return one of the SQLITE_ success/failure 22 | ** codes. Also write an error message into memory obtained from 23 | ** malloc() and make *pzErrMsg point to that message. 24 | ** 25 | ** If the SQL is a query, then for each row in the query result 26 | ** the xCallback() function is called. pArg becomes the first 27 | ** argument to xCallback(). If xCallback=NULL then no callback 28 | ** is invoked, even for queries. 29 | */ 30 | int sqlite3_exec( 31 | sqlite3 *db, /* The database on which the SQL executes */ 32 | const char *zSql, /* The SQL to be executed */ 33 | sqlite3_callback xCallback, /* Invoke this callback routine */ 34 | void *pArg, /* First argument to xCallback() */ 35 | char **pzErrMsg /* Write error messages here */ 36 | ){ 37 | int rc = SQLITE_OK; /* Return code */ 38 | const char *zLeftover; /* Tail of unprocessed SQL */ 39 | sqlite3_stmt *pStmt = 0; /* The current SQL statement */ 40 | char **azCols = 0; /* Names of result columns */ 41 | int callbackIsInit; /* True if callback data is initialized */ 42 | 43 | if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; 44 | if( zSql==0 ) zSql = ""; 45 | 46 | sqlite3_mutex_enter(db->mutex); 47 | sqlite3Error(db, SQLITE_OK, 0); 48 | while( rc==SQLITE_OK && zSql[0] ){ 49 | int nCol; 50 | char **azVals = 0; 51 | 52 | pStmt = 0; 53 | rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover); 54 | assert( rc==SQLITE_OK || pStmt==0 ); 55 | if( rc!=SQLITE_OK ){ 56 | continue; 57 | } 58 | if( !pStmt ){ 59 | /* this happens for a comment or white-space */ 60 | zSql = zLeftover; 61 | continue; 62 | } 63 | 64 | callbackIsInit = 0; 65 | nCol = sqlite3_column_count(pStmt); 66 | 67 | while( 1 ){ 68 | int i; 69 | rc = sqlite3_step(pStmt); 70 | 71 | /* Invoke the callback function if required */ 72 | if( xCallback && (SQLITE_ROW==rc || 73 | (SQLITE_DONE==rc && !callbackIsInit 74 | && db->flags&SQLITE_NullCallback)) ){ 75 | if( !callbackIsInit ){ 76 | azCols = sqlite3DbMallocZero(db, 2*nCol*sizeof(const char*) + 1); 77 | if( azCols==0 ){ 78 | goto exec_out; 79 | } 80 | for(i=0; imallocFailed = 1; 94 | goto exec_out; 95 | } 96 | } 97 | } 98 | if( xCallback(pArg, nCol, azVals, azCols) ){ 99 | rc = SQLITE_ABORT; 100 | sqlite3VdbeFinalize((Vdbe *)pStmt); 101 | pStmt = 0; 102 | sqlite3Error(db, SQLITE_ABORT, 0); 103 | goto exec_out; 104 | } 105 | } 106 | 107 | if( rc!=SQLITE_ROW ){ 108 | rc = sqlite3VdbeFinalize((Vdbe *)pStmt); 109 | pStmt = 0; 110 | zSql = zLeftover; 111 | while( sqlite3Isspace(zSql[0]) ) zSql++; 112 | break; 113 | } 114 | } 115 | 116 | sqlite3DbFree(db, azCols); 117 | azCols = 0; 118 | } 119 | 120 | exec_out: 121 | if( pStmt ) sqlite3VdbeFinalize((Vdbe *)pStmt); 122 | sqlite3DbFree(db, azCols); 123 | 124 | rc = sqlite3ApiExit(db, rc); 125 | if( rc!=SQLITE_OK && ALWAYS(rc==sqlite3_errcode(db)) && pzErrMsg ){ 126 | int nErrMsg = 1 + sqlite3Strlen30(sqlite3_errmsg(db)); 127 | *pzErrMsg = sqlite3Malloc(nErrMsg); 128 | if( *pzErrMsg ){ 129 | memcpy(*pzErrMsg, sqlite3_errmsg(db), nErrMsg); 130 | }else{ 131 | rc = SQLITE_NOMEM; 132 | sqlite3Error(db, SQLITE_NOMEM, 0); 133 | } 134 | }else if( pzErrMsg ){ 135 | *pzErrMsg = 0; 136 | } 137 | 138 | assert( (rc&db->errMask)==rc ); 139 | sqlite3_mutex_leave(db->mutex); 140 | return rc; 141 | } 142 | -------------------------------------------------------------------------------- /make_linker_vector.tec: -------------------------------------------------------------------------------- 1 | !***********************************************************************! 2 | MAKE_LINKER_VECTOR V1.013100JZ"N0J0A-32"ED'ZJ-1A-32"E 3 | -D''HXZHK[SUS[SEDUS[SEHUS[SESUS[SEVUS[SETUS[SEUUS[S00ED2EH0ES0EV 4 | 2#16#128#512#8192ET-1EUEI 5 | @D$.U.PZJ.U.Z/32/16+1900\I /32&15U.M-1%.M"EIJanuaryOGOTMON' 6 | -1%.M"EIFebruaryOGOTMON'-1%.M"EIMarchOGOTMON'-1%.M"EIApril 7 | OGOTMON'-1%.M"EIMayOGOTMON'-1%.M"EIJuneOGOTMON'-1%.M"EIJuly 8 | OGOTMON'-1%.M"EIAugustOGOTMON'-1%.M"EISeptemberOGOTMON'-1%.M"E 9 | IOctoberOGOTMON'-1%.M"EINovemberOGOTMON'IDecember!GOTMON!I  10 | &31+100\3RDZJQ.Z,.X0Q.Z,.KQ.PJ$ 11 | GZ0JZ"NXYZ0J0A-32"ED'ZJ-1A-32"E-D'0J<0A:YC0A-="E 12 | C0;'>.,ZXX'...Loading existing symbol vector table...:QX"NHK 13 | :ER^EQX"S:EY'0JHXTHKdone...1310|unable to open :GX...1310' 14 | :QT"N...Generating Linker Options Symbol Vector...I!13I10IMDI!  15 | G013I10II! 16 | ! The author disclaims copyright to this source code. In place of 17 | ! a legal notice, here is a blessing: 18 | ! 19 | ! May you do good and not evil. 20 | ! May you find forgiveness for yourself and forgive others. 21 | ! May you share freely, never taking more than you give. 22 | ! 23 | !*********************************************************************** 24 | ! This is automatically generated by MAKE_SYMBOL_VECTOR. DO NOT EDIT!!! 25 | ! 26 | CASE_SENSITIVE=YES 27 | 0U.P%.P0;'>:QT-Q.P"E0;'>-DI)13I10I:QT-Q.P"E0;'> 32 | ICASE_SENSITIVE=NO 33 | :EW^EQY/STM"SHPEFdone...1310|Could not open vector file :GY13 34 | 10'' 35 | ]SQSEU]SQSET]SQSEV]SQSES]SQSEH]SQSED]SQS]S 36 | -------------------------------------------------------------------------------- /make_linker_vector.tes: -------------------------------------------------------------------------------- 1 | ! ! 2 | ! 2013 April 17 ! 3 | ! ! 4 | ! The author disclaims copyright to this source code. In place of ! 5 | ! a legal notice, here is a blessing: ! 6 | ! ! 7 | ! May you do good and not evil. ! 8 | ! May you find forgiveness for yourself and forgive others. ! 9 | ! May you share freely, never taking more than you give. ! 10 | ! ! 11 | !***********************************************************************! 12 | ! This module builds a linker options file that contains the ! 13 | ! definition of the SQLite 3 symbol vector for either Alpha or Itanium. ! 14 | ! ! 15 | 16 | @^A%MAKE_LINKER_VECTOR V1.0% ! Identify myself... ! 17 | 13^T 10^T 18 | 19 | 0J Z"N <@FS%^ES% %;> ! Clean up the buffer, if it's there ! 20 | 0J 0A-32"E D ' ! strip leading spaces ! 21 | ZJ -1A-32"E -D ' ! and trailing spaces ! 22 | ' ! endif buffer there ! 23 | HXZ HK ! Save possible command ! 24 | 25 | ! Set flags for our use, and close this file ! 26 | 27 | [S ^XUS [S EDUS [S EHUS [S ! Save all the existing flags ! 28 | ESUS [S EVUS [S ETUS [S EUUS [S ! so we can restore the user to ! 29 | ! his original state on exit ! 30 | 31 | ^D ! Set Radix to 10 ! 32 | 0^X ! Case-sensitive search ! 33 | 0ED ! ^ in search means ConTRL ! 34 | ! Disable Y or _ if data loss ! 35 | 2EH ! Full error messages ! 36 | 0ES 0EV ! No typeout after search ! 37 | 2#16#128#512#8192ET 38 | ! Set ET flag as follows - ! 39 | ! 1 rw typeout in image mode ! 40 | ! 2 rw terminal is a scope ! 41 | ! 4 rw read lower case ! 42 | ! 8 rw ^T reads with no echo ! 43 | ! 16 rw cancel ^O on typeout ! 44 | ! 32 rw read with no wait, returns -1 if no input ! 45 | ! 64 rw detach flag ! 46 | ! 128 rw abort on error ! 47 | ! 256 rw truncate to set width ! 48 | ! 512 ro terminal is scope and watch is present ! 49 | ! 1024 ro terminal is refresh and watch is present ! 50 | ! 2048 xx not used ! 51 | ! 4096 rw 1 => 8bit, 0 => 7bit ! 52 | ! 8192 rw Surrogate escape on ! 53 | ! 16384 xx not used ! 54 | ! 32768 rw trap ^C and reset ! 55 | -1EU ! No case flagging on output ! 56 | ! EO is Teco's Version Number ! 57 | ! 0EJ is Job Number ! 58 | ! 1EJ is KB Number ! 59 | ! 2EJ is PPN ! 60 | @EI%% ! Close this file ! 61 | 62 | ! --------------------------------------------------------------------- ! 63 | ! * Load the date routine ! 64 | ! ! 65 | ! Executed from D$ ! 66 | ! Value returned in 0$ ! 67 | ! --------------------------------------------------------------------- ! 68 | @^UD$^[ 69 | .U.P ZJ .U.Z 70 | ^B/32/16+1900\ @I% % 71 | ^B/32&15U.M 72 | -1%.M"E @I%January% @O!GOTMON! ' 73 | -1%.M"E @I%February% @O!GOTMON! ' 74 | -1%.M"E @I%March% @O!GOTMON! ' 75 | -1%.M"E @I%April% @O!GOTMON! ' 76 | -1%.M"E @I%May% @O!GOTMON! ' 77 | -1%.M"E @I%June% @O!GOTMON! ' 78 | -1%.M"E @I%July% @O!GOTMON! ' 79 | -1%.M"E @I%August% @O!GOTMON! ' 80 | -1%.M"E @I%September% @O!GOTMON! ' 81 | -1%.M"E @I%October% @O!GOTMON! ' 82 | -1%.M"E @I%November% @O!GOTMON! ' 83 | @I%December% 84 | !GOTMON! @I% % 85 | ^B&31+100\ 3R D ZJ 86 | Q.Z,.X0 Q.Z,.K 87 | Q.PJ ^[$ 88 | 89 | ! --------------------------------------------------------------------- ! 90 | ! * Load symbol vector generation for Alpha and I64 ! 91 | ! --------------------------------------------------------------------- ! 92 | 93 | GZ ! Dump command line into buffer ! 94 | 0J Z"N <@FS%^ES% %;> ! Clean up the buffer, if there ! 95 | @^UX%% @^UY%% @^UZ%% ! init filename buffers ! 96 | 0J 0A-32"E D ' ! strip leading spaces ! 97 | ZJ -1A-32"E -D ' ! and trailing spaces ! 98 | 0J 99 | < 0A:@^UY%% C 0A-^^="E C0;' > 100 | .,ZXX 101 | ' 102 | 103 | @^A%...Loading existing symbol vector table...% 104 | :QX"N 105 | HK ! Clear text buffer ! 106 | :@ER%^EQX%"S ! If can open existing vector ! 107 | :EY ! then load it into buffer ! 108 | ' ! endif ! 109 | 0J HXT HK 110 | @^A%done...% 13^T 10^T 111 | | 112 | @^A%unable to open % :GX @^A%...% 13^T 10^T 113 | ' 114 | 115 | :QT"N 116 | @^A%...Generating Linker Options Symbol Vector...% 117 | 118 | @I%!% 13@I%% 10@I%% 119 | MD @I%! % G0 13@I%% 10@I%% 120 | @I%! 121 | ! The author disclaims copyright to this source code. In place of 122 | ! a legal notice, here is a blessing: 123 | ! 124 | ! May you do good and not evil. 125 | ! May you find forgiveness for yourself and forgive others. 126 | ! May you share freely, never taking more than you give. 127 | ! 128 | !*********************************************************************** 129 | ! This is automatically generated by MAKE_SYMBOL_VECTOR. DO NOT EDIT!!! 130 | ! 131 | CASE_SENSITIVE=YES 132 | % 133 | 0U.P < ! Init pointer ! 134 | @I%SYMBOL_VECTOR = (% 135 | 32 < 136 | @^U.L%% @^U.U%% ! Init symbol and alias ! 137 | < 138 | Q.PQT:@^U.L%% 139 | Q.PQT"V 140 | Q.PQT-^^ :@^U.U%% 141 | | 142 | Q.PQT:@^U.U%% 143 | ' 144 | %.PQT-^^,"E 145 | @I%-% 13@I%% 10@I%% 146 | 3%.P^[ 147 | Q.PQT-^^S"E 148 | @I% SPARE,- ! % G.L 13@I%% 10@I%% 149 | @I% SPARE,% 150 | | Q.PQT-^^D"E 151 | @I% % G.L @I%=DATA,-% 13@I%% 10@I%% 152 | @I% % G.U @I%/% G.L @I%=DATA,% 153 | | 154 | @I% % G.L @I%=PROCEDURE,-% 13@I%% 10@I%% 155 | @I% % G.U @I%/% G.L @I%=PROCEDURE,% 156 | ' ' 157 | < %.PQT-10"E 0;' > 158 | %.P^[ 159 | 0; 160 | ' 161 | > 162 | :QT-Q.P"E 0;' > 163 | -D @I%)% 13@I%% 10@I%% 164 | :QT-Q.P"E 0;' > 165 | 166 | @I%CASE_SENSITIVE=NO 167 | % 168 | 169 | :@EW%^EQY/STM%"S ! If open vector file ! 170 | HP ! then dump out to file ! 171 | EF ! close vector file ! 172 | @^A%done...% 13^T 10^T 173 | | ! else ! 174 | @^A%Could not open vector file % :GY 13^T 10^T 175 | ' ! end if ! 176 | ' 177 | 178 | ! --------------------------------------------------------------------- ! 179 | ! * Now restore all the flags and exit ! 180 | ! --------------------------------------------------------------------- ! 181 | 182 | ]S QSEU ]S QSET ]S QSEV ]S QSES ]S ! Restore all the flags we ! 183 | QSEH ]S QSED ]S QS^X ]S ! saved at the start ! 184 | 185 | ^C 186 |  187 | -------------------------------------------------------------------------------- /make_symbol_vector.tec: -------------------------------------------------------------------------------- 1 | !***********************************************************************! 2 | MAKE_SYMBOL_VECTOR V2.013100JZ"N0J0A-32"ED'ZJ-1A-32"E 3 | -D''HXZHK[SUS[SEDUS[SEHUS[SESUS[SEVUS[SETUS[SEUUS[S00ED2EH0ES0EV 4 | 2#16#128#512#8192ET-1EUEI 5 | !!GZ0JZ"NXYZ0J0A-32"ED'ZJ-1A-32"E-D'0J<0A:YC0A-="E 6 | C0;'>.,ZXX'...Reading symbol vector table from library listing...HK 7 | N:ER^EQX"FCan't find file ":G.I"...132<10>|0U.F<:EY;< 8 | ::SModule "S-1U.F|Q.F"S::S^X^EL"SC0U.F|<<0A- "N0;'C><0A"C0A:NC| 9 | 0;'>,:N0A-13"E0;'>'''L.-Z;>>HKdone...1310':QN"N 10 | ...Loading public header file for comparison...H 11 | :ERSRC_DIR:SQLITE3.H"S<:EY;<:S^ELSQLITE_API^ES;:FB^Xsqlite3_"S+1C 12 | :XH'>>sorting...HKGH0J<0U.F0J<0LX.A7U.AL.-Z"E0;'8C:Q.A-(Q.A+1)< 13 | %.AQ.A"C(Q.AQ.A#32)-(0A#32)"L0;|(Q.AQ.A#32)-(0A#32)"G-1U.F0LX.AK-LG.A 14 | 0;|C''|0;'>>Q.F;>HXHdone...1310|unable to open SRC_DIR:SQLITE3.H 15 | 1310'':QN+:QH"N...Loading existing symbol vector table...HK 16 | :ER^EQY"S:EY'0Jdone...1310 17 | ...Building new symbol vector table...0U.P<.S0J:S^EQ.S,^ED,^EA^X^EL"FHX2.U2HKGH0J:S^EQ.SU3Q3"S::S^ES  19 | 0AU3'HKG2Q2JQ3"NZJG.SI,2,Q3-("EIP|ID'13I10I'|-2S,CDI1' 20 | :QN-Q.P"E0;'>...done...1310 21 | ...Checking for changes in symbol vector table...-1UTHXT0J<..S< 22 | 0A:.SC0A-,"E0;'>S,\U.S-DI0Q.S-1"LS,0A-S"N1310 ...:G.S 23 |  is missingDIS0UT'|Q.S-1"G1310 ...:G.S is new0UT''L.-Z;>13 24 | 10QT"F...symbol table has changed:EW^EQY/STM"SHPEF| 25 | Could not open :GY for output1310'| 26 | ...symbol table has not changed'...done...1310' 27 | ]SQSEU]SQSET]SQSEV]SQSES]SQSEH]SQSED]SQS]S 28 | -------------------------------------------------------------------------------- /make_vax_vector.tec: -------------------------------------------------------------------------------- 1 | !***********************************************************************! 2 | MAKE_VAX_VECTOR V1.013100JZ"N0J0A-32"ED'ZJ-1A-32"E-D'' 3 | HXZHK[SUS[SEDUS[SEHUS[SESUS[SEVUS[SETUS[SEUUS[S00ED2EH0ES0EV 4 | 2#16#128#512#8192ET-1EUEI 5 | @D$.U.PZJ.U.Z/32/16+1900\I /32&15U.M-1%.M"EIJanuaryOGOTMON' 6 | -1%.M"EIFebruaryOGOTMON'-1%.M"EIMarchOGOTMON'-1%.M"EIApril 7 | OGOTMON'-1%.M"EIMayOGOTMON'-1%.M"EIJuneOGOTMON'-1%.M"EIJuly 8 | OGOTMON'-1%.M"EIAugustOGOTMON'-1%.M"EISeptemberOGOTMON'-1%.M"E 9 | IOctoberOGOTMON'-1%.M"EINovemberOGOTMON'IDecember!GOTMON!I  10 | &31+100\3RDZJQ.Z,.X0Q.Z,.KQ.PJ$ 11 | GZ0JZ"NXYZ0J0A-32"ED'ZJ-1A-32"E-D'0J<0A:YC0A-="E 12 | C0;'><0A:XC0A- "EC0;'>.,ZXZ' 13 | ...Loading existing symbol vector table...:QX"NHK:ER^EQX"S:EY'0JHXT 14 | HKdone...1310|unable to open :GX...1310':QT"N 15 | ...Generating VAX MACRO-32 Transfer Vector...MDHKI;13I10II; G0 16 | 13I10II; 17 | ; The author disclaims copyright to this source code. In place of 18 | ; a legal notice, here is a blessing: 19 | ; 20 | ; May you do good and not evil. 21 | ; May you find forgiveness for yourself and forgive others. 22 | ; May you share freely, never taking more than you give. 23 | ; 24 | ;*********************************************************************** 25 | ; This is automatically generated by MAKE_SYMBOL_VECTOR. DO NOT EDIT!!! 26 | ; 27 | 28 | .TITLE SQLITE3_VECTOR 29 | 30 | .MACRO ROUTINE NAME 31 | .EXTRN NAME 32 | .ALIGN QUAD 33 | .TRANSFER NAME 34 | .MASK NAME 35 | JMP NAME+2 36 | .ENDM 37 | 38 | .MACRO SPARE ?L1 39 | .EXTRN LIB$NOT_IMPLEMENTED 40 | .ALIGN QUAD 41 | BSBB L1 42 | L1: JMP LIB$NOT_IMPLEMENTED 43 | .ENDM 44 | 45 | .PSECT ___SQLITE3_VECTOR - 46 | PIC,USR,CON,REL,LCL,SHR,EXE,RD,NOWRT,QUAD 47 | 48 | 0U.P<.S%.P0;'>:QT-Q.P"E0;' 50 | >I 51 | .END 52 | :EW^EQY/STM"SHPEFdone...1310|Could not open vector file :GY13 53 | 10'...Generating VAX UPPER CASE aliases...HKI#13I10II# G013I 54 | 10II# 55 | # The author disclaims copyright to this source code. In place of 56 | # a legal notice, here is a blessing: 57 | # 58 | # May you do good and not evil. 59 | # May you find forgiveness for yourself and forgive others. 60 | # May you share freely, never taking more than you give. 61 | # 62 | #*********************************************************************** 63 | # This is automatically generated by MAKE_SYMBOL_VECTOR. DO NOT EDIT!!! 64 | # 65 | .text 66 | .align 8 67 | 68 | .macro routine uc,lc 69 | .align 8 70 | .extern _\lc 71 | .global _\uc 72 | _\uc: 73 | .word 0xff 74 | jmp _\lc+2 75 | .endm 76 | 77 | 0U.P<.L.U%.P0;'> 79 | :QT-Q.P"E0;'>I .end 80 | :EW^EQZ/STM"SHPEFdone...1310|Could not open alias file :GZ13 81 | 10'' 82 | ]SQSEU]SQSET]SQSEV]SQSES]SQSEH]SQSED]SQS]S 83 | -------------------------------------------------------------------------------- /make_version.com: -------------------------------------------------------------------------------- 1 | $! 2 | $! 2013 March 9 3 | $! 4 | $! The author disclaims copyright to this source code. In place of 5 | $! a legal notice, here is a blessing: 6 | $! 7 | $! May you do good and not evil. 8 | $! May you find forgiveness for yourself and forgive others. 9 | $! May you share freely, never taking more than you give. 10 | $! 11 | $!*********************************************************************** 12 | $! This procedure generates a linker IDENT string from sqlite3.h. 13 | $! 14 | $ set noon 15 | $ pipe search 'p1' "#define SQLITE_VERSION" | - 16 | ( read sys$pipe v ; - 17 | v = f$element(2, " ", f$edit(v, "COMPRESS") - """" - """") ; - 18 | define/job/nolog SQLITE_VERSION &v ) 19 | $ version = f$trnlnm("SQLITE_VERSION") 20 | $ major = f$element(1, ".", version) 21 | $ minor = f$element(2, ".", version) 22 | $ edit = f$element(3, ".", version) 23 | $ if (edit .eqs. ".") then edit = "" 24 | $ if (edit .nes. "") then edit = "-" + edit 25 | $ close/nolog opt 26 | $ open/write opt 'p2' 27 | $ write opt "IDENT=""V''major'.''minor'''edit'"""" 28 | $ close/nolog opt 29 | $ exit 1 30 | -------------------------------------------------------------------------------- /mem0.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2008 October 28 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ************************************************************************* 12 | ** 13 | ** This file contains a no-op memory allocation drivers for use when 14 | ** SQLITE_ZERO_MALLOC is defined. The allocation drivers implemented 15 | ** here always fail. SQLite will not operate with these drivers. These 16 | ** are merely placeholders. Real drivers must be substituted using 17 | ** sqlite3_config() before SQLite will operate. 18 | */ 19 | #include "sqliteInt.h" 20 | 21 | /* 22 | ** This version of the memory allocator is the default. It is 23 | ** used when no other memory allocator is specified using compile-time 24 | ** macros. 25 | */ 26 | #ifdef SQLITE_ZERO_MALLOC 27 | 28 | /* 29 | ** No-op versions of all memory allocation routines 30 | */ 31 | static void *sqlite3MemMalloc(int nByte){ return 0; } 32 | static void sqlite3MemFree(void *pPrior){ return; } 33 | static void *sqlite3MemRealloc(void *pPrior, int nByte){ return 0; } 34 | static int sqlite3MemSize(void *pPrior){ return 0; } 35 | static int sqlite3MemRoundup(int n){ return n; } 36 | static int sqlite3MemInit(void *NotUsed){ return SQLITE_OK; } 37 | static void sqlite3MemShutdown(void *NotUsed){ return; } 38 | 39 | /* 40 | ** This routine is the only routine in this file with external linkage. 41 | ** 42 | ** Populate the low-level memory allocation function pointers in 43 | ** sqlite3GlobalConfig.m with pointers to the routines in this file. 44 | */ 45 | void sqlite3MemSetDefault(void){ 46 | static const sqlite3_mem_methods defaultMethods = { 47 | sqlite3MemMalloc, 48 | sqlite3MemFree, 49 | sqlite3MemRealloc, 50 | sqlite3MemSize, 51 | sqlite3MemRoundup, 52 | sqlite3MemInit, 53 | sqlite3MemShutdown, 54 | 0 55 | }; 56 | sqlite3_config(SQLITE_CONFIG_MALLOC, &defaultMethods); 57 | } 58 | 59 | #endif /* SQLITE_ZERO_MALLOC */ 60 | -------------------------------------------------------------------------------- /memvms.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2013 March 8 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ************************************************************************* 12 | ** 13 | ** This file contains the memory allocation drivers for use when running 14 | ** under OpenVMS. 15 | */ 16 | #include "sqliteInt.h" 17 | 18 | /* 19 | ** This version of the memory allocator is the only one supported on 20 | ** OpenVMS, although the others do work. 21 | */ 22 | #ifdef VMS 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #if !defined(VAX) 31 | # include 32 | #endif 33 | 34 | static long _sqliteZone_ = 0; 35 | 36 | static void *sqlite3MemMalloc(int nByte){ 37 | long *pNew, szNew = nByte + sizeof(int); 38 | if( $VMS_STATUS_SUCCESS(lib$get_vm(&szNew, &pNew, &_sqliteZone_)) ){ 39 | *pNew = nByte; 40 | return ++pNew; 41 | } 42 | return 0; 43 | } 44 | 45 | static void sqlite3MemFree(void *pPrior){ 46 | long *pOld = ((long *)pPrior) - 1, szOld = *pOld + sizeof(int); 47 | 48 | lib$free_vm(&szOld, &pOld, &_sqliteZone_); 49 | } 50 | 51 | static void *sqlite3MemRealloc(void *pPrior, int nByte){ 52 | int *pOld = ((int *)pPrior) - 1, szOld = *pOld; 53 | void *pNew; 54 | 55 | if( nByte <= szOld ){ 56 | return pPrior; 57 | } else { 58 | pNew = sqlite3MemMalloc(nByte); 59 | if (!pNew) return 0; 60 | memcpy(pNew, pPrior, szOld); 61 | sqlite3MemFree(pPrior); 62 | return pNew; 63 | } 64 | } 65 | 66 | static int sqlite3MemSize(void *pPrior){ 67 | if (!pPrior) return 0; 68 | return *((int *)pPrior - 1); 69 | } 70 | 71 | static int sqlite3MemRoundup(int n){ 72 | return ROUND8(n); 73 | } 74 | 75 | static int sqlite3MemInit(void *NotUsed){ 76 | const int alg = LIB$K_VM_QUICK_FIT, arg = 16, extent = 128; 77 | const int blocksize = 512, smallest = 8; 78 | const int flags = LIB$M_VM_BOUNDARY_TAGS | LIB$M_VM_EXTEND_AREA 79 | | LIB$M_VM_TAIL_LARGE; 80 | int rc = SQLITE_OK, status; 81 | 82 | $DESCRIPTOR(name, "Sqlite_heap"); 83 | 84 | if( _sqliteZone_ == 0){ 85 | status = lib$create_vm_zone(&_sqliteZone_, &alg, &arg, &flags, &extent, 86 | &extent, &blocksize, 0, 0, &smallest, &name); 87 | if( !$VMS_STATUS_SUCCESS(status) ){ 88 | rc = SQLITE_ERROR; 89 | } 90 | } 91 | 92 | return rc; 93 | } 94 | 95 | static void sqlite3MemShutdown(void *NotUsed){ 96 | lib$delete_vm_zone(&_sqliteZone_); 97 | } 98 | 99 | /* 100 | ** This routine is the only routine in this file with external linkage. 101 | ** 102 | ** Populate the low-level memory allocation function pointers in 103 | ** sqlite3GlobalConfig.m with pointers to the routines in this file. 104 | */ 105 | void sqlite3MemSetDefault(void){ 106 | static const sqlite3_mem_methods defaultMethods = { 107 | sqlite3MemMalloc, 108 | sqlite3MemFree, 109 | sqlite3MemRealloc, 110 | sqlite3MemSize, 111 | sqlite3MemRoundup, 112 | sqlite3MemInit, 113 | sqlite3MemShutdown, 114 | 0 115 | }; 116 | sqlite3_config(SQLITE_CONFIG_MALLOC, &defaultMethods); 117 | } 118 | 119 | #endif /* VMS */ 120 | -------------------------------------------------------------------------------- /mutex.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2007 August 14 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ************************************************************************* 12 | ** This file contains the C functions that implement mutexes. 13 | ** 14 | ** This file contains code that is common across all mutex implementations. 15 | */ 16 | #include "sqliteInt.h" 17 | 18 | #if defined(SQLITE_DEBUG) && !defined(SQLITE_MUTEX_OMIT) 19 | /* 20 | ** For debugging purposes, record when the mutex subsystem is initialized 21 | ** and uninitialized so that we can assert() if there is an attempt to 22 | ** allocate a mutex while the system is uninitialized. 23 | */ 24 | static SQLITE_WSD int mutexIsInit = 0; 25 | #endif /* SQLITE_DEBUG */ 26 | 27 | 28 | #ifndef SQLITE_MUTEX_OMIT 29 | /* 30 | ** Initialize the mutex system. 31 | */ 32 | int sqlite3MutexInit(void){ 33 | int rc = SQLITE_OK; 34 | if( !sqlite3GlobalConfig.mutex.xMutexAlloc ){ 35 | /* If the xMutexAlloc method has not been set, then the user did not 36 | ** install a mutex implementation via sqlite3_config() prior to 37 | ** sqlite3_initialize() being called. This block copies pointers to 38 | ** the default implementation into the sqlite3GlobalConfig structure. 39 | */ 40 | sqlite3_mutex_methods const *pFrom; 41 | sqlite3_mutex_methods *pTo = &sqlite3GlobalConfig.mutex; 42 | 43 | if( sqlite3GlobalConfig.bCoreMutex ){ 44 | pFrom = sqlite3DefaultMutex(); 45 | }else{ 46 | pFrom = sqlite3NoopMutex(); 47 | } 48 | memcpy(pTo, pFrom, offsetof(sqlite3_mutex_methods, xMutexAlloc)); 49 | memcpy(&pTo->xMutexFree, &pFrom->xMutexFree, 50 | sizeof(*pTo) - offsetof(sqlite3_mutex_methods, xMutexFree)); 51 | pTo->xMutexAlloc = pFrom->xMutexAlloc; 52 | } 53 | rc = sqlite3GlobalConfig.mutex.xMutexInit(); 54 | 55 | #ifdef SQLITE_DEBUG 56 | GLOBAL(int, mutexIsInit) = 1; 57 | #endif 58 | 59 | return rc; 60 | } 61 | 62 | /* 63 | ** Shutdown the mutex system. This call frees resources allocated by 64 | ** sqlite3MutexInit(). 65 | */ 66 | int sqlite3MutexEnd(void){ 67 | int rc = SQLITE_OK; 68 | if( sqlite3GlobalConfig.mutex.xMutexEnd ){ 69 | rc = sqlite3GlobalConfig.mutex.xMutexEnd(); 70 | } 71 | 72 | #ifdef SQLITE_DEBUG 73 | GLOBAL(int, mutexIsInit) = 0; 74 | #endif 75 | 76 | return rc; 77 | } 78 | 79 | /* 80 | ** Retrieve a pointer to a static mutex or allocate a new dynamic one. 81 | */ 82 | sqlite3_mutex *sqlite3_mutex_alloc(int id){ 83 | #ifndef SQLITE_OMIT_AUTOINIT 84 | if( sqlite3_initialize() ) return 0; 85 | #endif 86 | return sqlite3GlobalConfig.mutex.xMutexAlloc(id); 87 | } 88 | 89 | sqlite3_mutex *sqlite3MutexAlloc(int id){ 90 | if( !sqlite3GlobalConfig.bCoreMutex ){ 91 | return 0; 92 | } 93 | assert( GLOBAL(int, mutexIsInit) ); 94 | return sqlite3GlobalConfig.mutex.xMutexAlloc(id); 95 | } 96 | 97 | /* 98 | ** Free a dynamic mutex. 99 | */ 100 | void sqlite3_mutex_free(sqlite3_mutex *p){ 101 | if( p ){ 102 | sqlite3GlobalConfig.mutex.xMutexFree(p); 103 | } 104 | } 105 | 106 | /* 107 | ** Obtain the mutex p. If some other thread already has the mutex, block 108 | ** until it can be obtained. 109 | */ 110 | void sqlite3_mutex_enter(sqlite3_mutex *p){ 111 | if( p ){ 112 | sqlite3GlobalConfig.mutex.xMutexEnter(p); 113 | } 114 | } 115 | 116 | /* 117 | ** Obtain the mutex p. If successful, return SQLITE_OK. Otherwise, if another 118 | ** thread holds the mutex and it cannot be obtained, return SQLITE_BUSY. 119 | */ 120 | int sqlite3_mutex_try(sqlite3_mutex *p){ 121 | int rc = SQLITE_OK; 122 | if( p ){ 123 | return sqlite3GlobalConfig.mutex.xMutexTry(p); 124 | } 125 | return rc; 126 | } 127 | 128 | /* 129 | ** The sqlite3_mutex_leave() routine exits a mutex that was previously 130 | ** entered by the same thread. The behavior is undefined if the mutex 131 | ** is not currently entered. If a NULL pointer is passed as an argument 132 | ** this function is a no-op. 133 | */ 134 | void sqlite3_mutex_leave(sqlite3_mutex *p){ 135 | if( p ){ 136 | sqlite3GlobalConfig.mutex.xMutexLeave(p); 137 | } 138 | } 139 | 140 | #ifndef NDEBUG 141 | /* 142 | ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are 143 | ** intended for use inside assert() statements. 144 | */ 145 | int sqlite3_mutex_held(sqlite3_mutex *p){ 146 | return p==0 || sqlite3GlobalConfig.mutex.xMutexHeld(p); 147 | } 148 | int sqlite3_mutex_notheld(sqlite3_mutex *p){ 149 | return p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld(p); 150 | } 151 | #endif 152 | 153 | #endif /* !defined(SQLITE_MUTEX_OMIT) */ 154 | -------------------------------------------------------------------------------- /mutex.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2007 August 28 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ************************************************************************* 12 | ** 13 | ** This file contains the common header for all mutex implementations. 14 | ** The sqliteInt.h header #includes this file so that it is available 15 | ** to all source files. We break it out in an effort to keep the code 16 | ** better organized. 17 | ** 18 | ** NOTE: source files should *not* #include this header file directly. 19 | ** Source files should #include the sqliteInt.h file and let that file 20 | ** include this one indirectly. 21 | */ 22 | 23 | 24 | /* 25 | ** Figure out what version of the code to use. The choices are 26 | ** 27 | ** SQLITE_MUTEX_OMIT No mutex logic. Not even stubs. The 28 | ** mutexes implemention cannot be overridden 29 | ** at start-time. 30 | ** 31 | ** SQLITE_MUTEX_NOOP For single-threaded applications. No 32 | ** mutual exclusion is provided. But this 33 | ** implementation can be overridden at 34 | ** start-time. 35 | ** 36 | ** SQLITE_MUTEX_PTHREADS For multi-threaded applications on Unix. 37 | ** 38 | ** SQLITE_MUTEX_W32 For multi-threaded applications on Win32. 39 | ** 40 | ** SQLITE_MUTEX_VMS For multi-threaded applications on OpenVMS. 41 | */ 42 | #if !SQLITE_THREADSAFE 43 | # define SQLITE_MUTEX_OMIT 44 | #endif 45 | #if SQLITE_THREADSAFE && !defined(SQLITE_MUTEX_NOOP) 46 | # if SQLITE_OS_UNIX 47 | # define SQLITE_MUTEX_PTHREADS 48 | # elif SQLITE_OS_WIN 49 | # define SQLITE_MUTEX_W32 50 | # elif SQLITE_OS_VMS 51 | # define SQLITE_MUTEX_VMS 52 | # else 53 | # define SQLITE_MUTEX_NOOP 54 | # endif 55 | #endif 56 | 57 | #ifdef SQLITE_MUTEX_OMIT 58 | /* 59 | ** If this is a no-op implementation, implement everything as macros. 60 | */ 61 | #define sqlite3_mutex_alloc(X) ((sqlite3_mutex*)8) 62 | #define sqlite3_mutex_free(X) 63 | #define sqlite3_mutex_enter(X) 64 | #define sqlite3_mutex_try(X) SQLITE_OK 65 | #define sqlite3_mutex_leave(X) 66 | #define sqlite3_mutex_held(X) ((void)(X),1) 67 | #define sqlite3_mutex_notheld(X) ((void)(X),1) 68 | #define sqlite3MutexAlloc(X) ((sqlite3_mutex*)8) 69 | #define sqlite3MutexInit() SQLITE_OK 70 | #define sqlite3MutexEnd() 71 | #define MUTEX_LOGIC(X) 72 | #else 73 | #define MUTEX_LOGIC(X) X 74 | #endif /* defined(SQLITE_MUTEX_OMIT) */ 75 | -------------------------------------------------------------------------------- /mutex_noop.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2008 October 07 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ************************************************************************* 12 | ** This file contains the C functions that implement mutexes. 13 | ** 14 | ** This implementation in this file does not provide any mutual 15 | ** exclusion and is thus suitable for use only in applications 16 | ** that use SQLite in a single thread. The routines defined 17 | ** here are place-holders. Applications can substitute working 18 | ** mutex routines at start-time using the 19 | ** 20 | ** sqlite3_config(SQLITE_CONFIG_MUTEX,...) 21 | ** 22 | ** interface. 23 | ** 24 | ** If compiled with SQLITE_DEBUG, then additional logic is inserted 25 | ** that does error checking on mutexes to make sure they are being 26 | ** called correctly. 27 | */ 28 | #include "sqliteInt.h" 29 | 30 | #ifndef SQLITE_MUTEX_OMIT 31 | 32 | #ifndef SQLITE_DEBUG 33 | /* 34 | ** Stub routines for all mutex methods. 35 | ** 36 | ** This routines provide no mutual exclusion or error checking. 37 | */ 38 | static int noopMutexInit(void){ return SQLITE_OK; } 39 | static int noopMutexEnd(void){ return SQLITE_OK; } 40 | static sqlite3_mutex *noopMutexAlloc(int id){ 41 | UNUSED_PARAMETER(id); 42 | return (sqlite3_mutex*)8; 43 | } 44 | static void noopMutexFree(sqlite3_mutex *p){ UNUSED_PARAMETER(p); return; } 45 | static void noopMutexEnter(sqlite3_mutex *p){ UNUSED_PARAMETER(p); return; } 46 | static int noopMutexTry(sqlite3_mutex *p){ 47 | UNUSED_PARAMETER(p); 48 | return SQLITE_OK; 49 | } 50 | static void noopMutexLeave(sqlite3_mutex *p){ UNUSED_PARAMETER(p); return; } 51 | 52 | sqlite3_mutex_methods const *sqlite3NoopMutex(void){ 53 | static const sqlite3_mutex_methods sMutex = { 54 | noopMutexInit, 55 | noopMutexEnd, 56 | noopMutexAlloc, 57 | noopMutexFree, 58 | noopMutexEnter, 59 | noopMutexTry, 60 | noopMutexLeave, 61 | 62 | 0, 63 | 0, 64 | }; 65 | 66 | return &sMutex; 67 | } 68 | #endif /* !SQLITE_DEBUG */ 69 | 70 | #ifdef SQLITE_DEBUG 71 | /* 72 | ** In this implementation, error checking is provided for testing 73 | ** and debugging purposes. The mutexes still do not provide any 74 | ** mutual exclusion. 75 | */ 76 | 77 | /* 78 | ** The mutex object 79 | */ 80 | typedef struct sqlite3_debug_mutex { 81 | int id; /* The mutex type */ 82 | int cnt; /* Number of entries without a matching leave */ 83 | } sqlite3_debug_mutex; 84 | 85 | /* 86 | ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are 87 | ** intended for use inside assert() statements. 88 | */ 89 | static int debugMutexHeld(sqlite3_mutex *pX){ 90 | sqlite3_debug_mutex *p = (sqlite3_debug_mutex*)pX; 91 | return p==0 || p->cnt>0; 92 | } 93 | static int debugMutexNotheld(sqlite3_mutex *pX){ 94 | sqlite3_debug_mutex *p = (sqlite3_debug_mutex*)pX; 95 | return p==0 || p->cnt==0; 96 | } 97 | 98 | /* 99 | ** Initialize and deinitialize the mutex subsystem. 100 | */ 101 | static int debugMutexInit(void){ return SQLITE_OK; } 102 | static int debugMutexEnd(void){ return SQLITE_OK; } 103 | 104 | /* 105 | ** The sqlite3_mutex_alloc() routine allocates a new 106 | ** mutex and returns a pointer to it. If it returns NULL 107 | ** that means that a mutex could not be allocated. 108 | */ 109 | static sqlite3_mutex *debugMutexAlloc(int id){ 110 | static sqlite3_debug_mutex aStatic[6]; 111 | sqlite3_debug_mutex *pNew = 0; 112 | switch( id ){ 113 | case SQLITE_MUTEX_FAST: 114 | case SQLITE_MUTEX_RECURSIVE: { 115 | pNew = sqlite3Malloc(sizeof(*pNew)); 116 | if( pNew ){ 117 | pNew->id = id; 118 | pNew->cnt = 0; 119 | } 120 | break; 121 | } 122 | default: { 123 | assert( id-2 >= 0 ); 124 | assert( id-2 < (int)(sizeof(aStatic)/sizeof(aStatic[0])) ); 125 | pNew = &aStatic[id-2]; 126 | pNew->id = id; 127 | break; 128 | } 129 | } 130 | return (sqlite3_mutex*)pNew; 131 | } 132 | 133 | /* 134 | ** This routine deallocates a previously allocated mutex. 135 | */ 136 | static void debugMutexFree(sqlite3_mutex *pX){ 137 | sqlite3_debug_mutex *p = (sqlite3_debug_mutex*)pX; 138 | assert( p->cnt==0 ); 139 | assert( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE ); 140 | sqlite3_free(p); 141 | } 142 | 143 | /* 144 | ** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt 145 | ** to enter a mutex. If another thread is already within the mutex, 146 | ** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return 147 | ** SQLITE_BUSY. The sqlite3_mutex_try() interface returns SQLITE_OK 148 | ** upon successful entry. Mutexes created using SQLITE_MUTEX_RECURSIVE can 149 | ** be entered multiple times by the same thread. In such cases the, 150 | ** mutex must be exited an equal number of times before another thread 151 | ** can enter. If the same thread tries to enter any other kind of mutex 152 | ** more than once, the behavior is undefined. 153 | */ 154 | static void debugMutexEnter(sqlite3_mutex *pX){ 155 | sqlite3_debug_mutex *p = (sqlite3_debug_mutex*)pX; 156 | assert( p->id==SQLITE_MUTEX_RECURSIVE || debugMutexNotheld(pX) ); 157 | p->cnt++; 158 | } 159 | static int debugMutexTry(sqlite3_mutex *pX){ 160 | sqlite3_debug_mutex *p = (sqlite3_debug_mutex*)pX; 161 | assert( p->id==SQLITE_MUTEX_RECURSIVE || debugMutexNotheld(pX) ); 162 | p->cnt++; 163 | return SQLITE_OK; 164 | } 165 | 166 | /* 167 | ** The sqlite3_mutex_leave() routine exits a mutex that was 168 | ** previously entered by the same thread. The behavior 169 | ** is undefined if the mutex is not currently entered or 170 | ** is not currently allocated. SQLite will never do either. 171 | */ 172 | static void debugMutexLeave(sqlite3_mutex *pX){ 173 | sqlite3_debug_mutex *p = (sqlite3_debug_mutex*)pX; 174 | assert( debugMutexHeld(pX) ); 175 | p->cnt--; 176 | assert( p->id==SQLITE_MUTEX_RECURSIVE || debugMutexNotheld(pX) ); 177 | } 178 | 179 | sqlite3_mutex_methods const *sqlite3NoopMutex(void){ 180 | static const sqlite3_mutex_methods sMutex = { 181 | debugMutexInit, 182 | debugMutexEnd, 183 | debugMutexAlloc, 184 | debugMutexFree, 185 | debugMutexEnter, 186 | debugMutexTry, 187 | debugMutexLeave, 188 | 189 | debugMutexHeld, 190 | debugMutexNotheld 191 | }; 192 | 193 | return &sMutex; 194 | } 195 | #endif /* SQLITE_DEBUG */ 196 | 197 | /* 198 | ** If compiled with SQLITE_MUTEX_NOOP, then the no-op mutex implementation 199 | ** is used regardless of the run-time threadsafety setting. 200 | */ 201 | #ifdef SQLITE_MUTEX_NOOP 202 | sqlite3_mutex_methods const *sqlite3DefaultMutex(void){ 203 | return sqlite3NoopMutex(); 204 | } 205 | #endif /* defined(SQLITE_MUTEX_NOOP) */ 206 | #endif /* !defined(SQLITE_MUTEX_OMIT) */ 207 | -------------------------------------------------------------------------------- /mutex_vms.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2013 March 8 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ************************************************************************* 12 | ** 13 | ** This file contains the C functions that implement mutexes for OpenVMS 14 | */ 15 | #include "sqliteInt.h" 16 | 17 | /* 18 | ** The code in this file is only used if we are compiling threadsafe 19 | ** under OpenVMS. It uses the tis library. 20 | */ 21 | #ifdef SQLITE_MUTEX_VMS 22 | 23 | #include 24 | 25 | /* 26 | ** Each recursive mutex is an instance of the following structure. 27 | */ 28 | struct sqlite3_mutex { 29 | pthread_mutex_t mutex; /* Mutex controlling the lock */ 30 | }; 31 | 32 | #define SQLITE3_MUTEX_INITIALIZER(n) { PTHREAD_MUTEX_INITWITHNAME_NP(n, 0) } 33 | 34 | /* 35 | ** Initialize and deinitialize the mutex subsystem. 36 | */ 37 | static int vmsMutexInit(void){ return SQLITE_OK; } 38 | static int vmsMutexEnd(void){ return SQLITE_OK; } 39 | 40 | /* 41 | ** The sqlite3_mutex_alloc() routine allocates a new 42 | ** mutex and returns a pointer to it. If it returns NULL 43 | ** that means that a mutex could not be allocated. SQLite 44 | ** will unwind its stack and return an error. The argument 45 | ** to sqlite3_mutex_alloc() is one of these integer constants: 46 | ** 47 | **
    48 | **
  • SQLITE_MUTEX_FAST 49 | **
  • SQLITE_MUTEX_RECURSIVE 50 | **
  • SQLITE_MUTEX_STATIC_MASTER 51 | **
  • SQLITE_MUTEX_STATIC_MEM 52 | **
  • SQLITE_MUTEX_STATIC_MEM2 53 | **
  • SQLITE_MUTEX_STATIC_PRNG 54 | **
  • SQLITE_MUTEX_STATIC_LRU 55 | **
  • SQLITE_MUTEX_STATIC_PMEM 56 | **
57 | ** 58 | ** The first two constants cause sqlite3_mutex_alloc() to create 59 | ** a new mutex. The new mutex is recursive when SQLITE_MUTEX_RECURSIVE 60 | ** is used but not necessarily so when SQLITE_MUTEX_FAST is used. 61 | ** The mutex implementation does not need to make a distinction 62 | ** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does 63 | ** not want to. But SQLite will only request a recursive mutex in 64 | ** cases where it really needs one. If a faster non-recursive mutex 65 | ** implementation is available on the host platform, the mutex subsystem 66 | ** might return such a mutex in response to SQLITE_MUTEX_FAST. 67 | ** 68 | ** The other allowed parameters to sqlite3_mutex_alloc() each return 69 | ** a pointer to a static preexisting mutex. Six static mutexes are 70 | ** used by the current version of SQLite. Future versions of SQLite 71 | ** may add additional static mutexes. Static mutexes are for internal 72 | ** use by SQLite only. Applications that use SQLite mutexes should 73 | ** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or 74 | ** SQLITE_MUTEX_RECURSIVE. 75 | ** 76 | ** Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST 77 | ** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc() 78 | ** returns a different mutex on every call. But for the static 79 | ** mutex types, the same mutex is returned on every call that has 80 | ** the same type number. 81 | */ 82 | static sqlite3_mutex *vmsMutexAlloc(int iType){ 83 | static sqlite3_mutex staticMutexes[] = { 84 | SQLITE3_MUTEX_INITIALIZER("SQLITE3_MUTEX_STATIC_MASTER"), 85 | SQLITE3_MUTEX_INITIALIZER("SQLITE3_MUTEX_STATIC_MEM"), 86 | SQLITE3_MUTEX_INITIALIZER("SQLITE3_MUTEX_STATIC_MEM2"), 87 | SQLITE3_MUTEX_INITIALIZER("SQLITE3_MUTEX_STATIC_PRNG"), 88 | SQLITE3_MUTEX_INITIALIZER("SQLITE3_MUTEX_STATIC_LRU"), 89 | SQLITE3_MUTEX_INITIALIZER("SQLITE3_MUTEX_STATIC_PMEM") 90 | }; 91 | sqlite3_mutex *p; 92 | switch( iType ){ 93 | case SQLITE_MUTEX_RECURSIVE: { 94 | p = sqlite3MallocZero( sizeof(*p) ); 95 | if( p ){ 96 | #ifdef vax 97 | /* 98 | ** On OpenVMS VAX there is no way to create a recursive mutex in 99 | ** the tis interface. The routine tis_mutex_initwithname is in 100 | ** the header file and claims to enable this. However, it does 101 | ** not actually exist in the CMA$TIS_SHR RTL. So, while the 102 | ** jiggery-pokery of the lock field in pthread_mutex_t below is 103 | ** completely unsupported it does, in fact, seem to work. 104 | */ 105 | tis_mutex_init(&p->mutex); 106 | p->mutex.lock &= ~_PTHREAD_MSTATE_TYPE; /* Clear mutex type */ 107 | p->mutex.lock |= _PTHREAD_MTYPE_RECURS; /* Set mutex type to recursive */ 108 | #else 109 | /* 110 | ** Although not documented, this is the routine used by the 111 | ** CRTL on Alpha and I64 to implement the flock() routine. 112 | */ 113 | tis_mutex_init_type(&p->mutex, PTHREAD_MUTEX_RECURSIVE, 0); 114 | #endif 115 | } 116 | break; 117 | } 118 | case SQLITE_MUTEX_FAST: { 119 | p = sqlite3MallocZero( sizeof(*p) ); 120 | if( p ){ 121 | tis_mutex_init(&p->mutex); 122 | } 123 | break; 124 | } 125 | default: { 126 | assert( iType-2 >= 0 ); 127 | assert( iType-2 < ArraySize(staticMutexes) ); 128 | p = &staticMutexes[iType-2]; 129 | break; 130 | } 131 | } 132 | return p; 133 | } 134 | 135 | 136 | /* 137 | ** This routine deallocates a previously 138 | ** allocated mutex. SQLite is careful to deallocate every 139 | ** mutex that it allocates. 140 | */ 141 | static void vmsMutexFree(sqlite3_mutex *p){ 142 | tis_mutex_destroy(&p->mutex); 143 | sqlite3_free(p); 144 | } 145 | 146 | /* 147 | ** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt 148 | ** to enter a mutex. If another thread is already within the mutex, 149 | ** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return 150 | ** SQLITE_BUSY. The sqlite3_mutex_try() interface returns SQLITE_OK 151 | ** upon successful entry. Mutexes created using SQLITE_MUTEX_RECURSIVE can 152 | ** be entered multiple times by the same thread. In such cases the, 153 | ** mutex must be exited an equal number of times before another thread 154 | ** can enter. If the same thread tries to enter any other kind of mutex 155 | ** more than once, the behavior is undefined. 156 | */ 157 | static void vmsMutexEnter(sqlite3_mutex *p){ 158 | tis_mutex_lock(&p->mutex); 159 | } 160 | 161 | static int vmsMutexTry(sqlite3_mutex *p){ 162 | if( tis_mutex_trylock(&p->mutex)==0 ){ 163 | return SQLITE_OK; 164 | } 165 | 166 | return SQLITE_BUSY; 167 | } 168 | 169 | /* 170 | ** The sqlite3_mutex_leave() routine exits a mutex that was 171 | ** previously entered by the same thread. The behavior 172 | ** is undefined if the mutex is not currently entered or 173 | ** is not currently allocated. SQLite will never do either. 174 | */ 175 | static void vmsMutexLeave(sqlite3_mutex *p){ 176 | tis_mutex_unlock(&p->mutex); 177 | } 178 | 179 | sqlite3_mutex_methods const *sqlite3DefaultMutex(void){ 180 | static const sqlite3_mutex_methods sMutex = { 181 | vmsMutexInit, 182 | vmsMutexEnd, 183 | vmsMutexAlloc, 184 | vmsMutexFree, 185 | vmsMutexEnter, 186 | vmsMutexTry, 187 | vmsMutexLeave, 188 | 0, 189 | 0 190 | }; 191 | 192 | return &sMutex; 193 | } 194 | 195 | #endif /* SQLITE_MUTEX_VMS */ 196 | -------------------------------------------------------------------------------- /opcodes.c: -------------------------------------------------------------------------------- 1 | /* Automatically generated. Do not edit */ 2 | /* See the mkopcodec.awk script for details. */ 3 | #if !defined(SQLITE_OMIT_EXPLAIN) || !defined(NDEBUG) || defined(VDBE_PROFILE) || defined(SQLITE_DEBUG) 4 | const char *sqlite3OpcodeName(int i){ 5 | static const char *const azName[] = { "?", 6 | /* 1 */ "Goto", 7 | /* 2 */ "Gosub", 8 | /* 3 */ "Return", 9 | /* 4 */ "Yield", 10 | /* 5 */ "HaltIfNull", 11 | /* 6 */ "Halt", 12 | /* 7 */ "Integer", 13 | /* 8 */ "Int64", 14 | /* 9 */ "String", 15 | /* 10 */ "Null", 16 | /* 11 */ "Blob", 17 | /* 12 */ "Variable", 18 | /* 13 */ "Move", 19 | /* 14 */ "Copy", 20 | /* 15 */ "SCopy", 21 | /* 16 */ "ResultRow", 22 | /* 17 */ "CollSeq", 23 | /* 18 */ "Function", 24 | /* 19 */ "Not", 25 | /* 20 */ "AddImm", 26 | /* 21 */ "MustBeInt", 27 | /* 22 */ "RealAffinity", 28 | /* 23 */ "Permutation", 29 | /* 24 */ "Compare", 30 | /* 25 */ "Jump", 31 | /* 26 */ "Once", 32 | /* 27 */ "If", 33 | /* 28 */ "IfNot", 34 | /* 29 */ "Column", 35 | /* 30 */ "Affinity", 36 | /* 31 */ "MakeRecord", 37 | /* 32 */ "Count", 38 | /* 33 */ "Savepoint", 39 | /* 34 */ "AutoCommit", 40 | /* 35 */ "Transaction", 41 | /* 36 */ "ReadCookie", 42 | /* 37 */ "SetCookie", 43 | /* 38 */ "VerifyCookie", 44 | /* 39 */ "OpenRead", 45 | /* 40 */ "OpenWrite", 46 | /* 41 */ "OpenAutoindex", 47 | /* 42 */ "OpenEphemeral", 48 | /* 43 */ "SorterOpen", 49 | /* 44 */ "OpenPseudo", 50 | /* 45 */ "Close", 51 | /* 46 */ "SeekLt", 52 | /* 47 */ "SeekLe", 53 | /* 48 */ "SeekGe", 54 | /* 49 */ "SeekGt", 55 | /* 50 */ "Seek", 56 | /* 51 */ "NotFound", 57 | /* 52 */ "Found", 58 | /* 53 */ "IsUnique", 59 | /* 54 */ "NotExists", 60 | /* 55 */ "Sequence", 61 | /* 56 */ "NewRowid", 62 | /* 57 */ "Insert", 63 | /* 58 */ "InsertInt", 64 | /* 59 */ "Delete", 65 | /* 60 */ "ResetCount", 66 | /* 61 */ "SorterCompare", 67 | /* 62 */ "SorterData", 68 | /* 63 */ "RowKey", 69 | /* 64 */ "RowData", 70 | /* 65 */ "Rowid", 71 | /* 66 */ "NullRow", 72 | /* 67 */ "Last", 73 | /* 68 */ "Or", 74 | /* 69 */ "And", 75 | /* 70 */ "SorterSort", 76 | /* 71 */ "Sort", 77 | /* 72 */ "Rewind", 78 | /* 73 */ "IsNull", 79 | /* 74 */ "NotNull", 80 | /* 75 */ "Ne", 81 | /* 76 */ "Eq", 82 | /* 77 */ "Gt", 83 | /* 78 */ "Le", 84 | /* 79 */ "Lt", 85 | /* 80 */ "Ge", 86 | /* 81 */ "SorterNext", 87 | /* 82 */ "BitAnd", 88 | /* 83 */ "BitOr", 89 | /* 84 */ "ShiftLeft", 90 | /* 85 */ "ShiftRight", 91 | /* 86 */ "Add", 92 | /* 87 */ "Subtract", 93 | /* 88 */ "Multiply", 94 | /* 89 */ "Divide", 95 | /* 90 */ "Remainder", 96 | /* 91 */ "Concat", 97 | /* 92 */ "Prev", 98 | /* 93 */ "BitNot", 99 | /* 94 */ "String8", 100 | /* 95 */ "Next", 101 | /* 96 */ "SorterInsert", 102 | /* 97 */ "IdxInsert", 103 | /* 98 */ "IdxDelete", 104 | /* 99 */ "IdxRowid", 105 | /* 100 */ "IdxLT", 106 | /* 101 */ "IdxGE", 107 | /* 102 */ "Destroy", 108 | /* 103 */ "Clear", 109 | /* 104 */ "CreateIndex", 110 | /* 105 */ "CreateTable", 111 | /* 106 */ "ParseSchema", 112 | /* 107 */ "LoadAnalysis", 113 | /* 108 */ "DropTable", 114 | /* 109 */ "DropIndex", 115 | /* 110 */ "DropTrigger", 116 | /* 111 */ "IntegrityCk", 117 | /* 112 */ "RowSetAdd", 118 | /* 113 */ "RowSetRead", 119 | /* 114 */ "RowSetTest", 120 | /* 115 */ "Program", 121 | /* 116 */ "Param", 122 | /* 117 */ "FkCounter", 123 | /* 118 */ "FkIfZero", 124 | /* 119 */ "MemMax", 125 | /* 120 */ "IfPos", 126 | /* 121 */ "IfNeg", 127 | /* 122 */ "IfZero", 128 | /* 123 */ "AggStep", 129 | /* 124 */ "AggFinal", 130 | /* 125 */ "Checkpoint", 131 | /* 126 */ "JournalMode", 132 | /* 127 */ "Vacuum", 133 | /* 128 */ "IncrVacuum", 134 | /* 129 */ "Expire", 135 | /* 130 */ "Real", 136 | /* 131 */ "TableLock", 137 | /* 132 */ "VBegin", 138 | /* 133 */ "VCreate", 139 | /* 134 */ "VDestroy", 140 | /* 135 */ "VOpen", 141 | /* 136 */ "VFilter", 142 | /* 137 */ "VColumn", 143 | /* 138 */ "VNext", 144 | /* 139 */ "VRename", 145 | /* 140 */ "VUpdate", 146 | /* 141 */ "ToText", 147 | /* 142 */ "ToBlob", 148 | /* 143 */ "ToNumeric", 149 | /* 144 */ "ToInt", 150 | /* 145 */ "ToReal", 151 | /* 146 */ "Pagecount", 152 | /* 147 */ "MaxPgcnt", 153 | /* 148 */ "Trace", 154 | /* 149 */ "Noop", 155 | /* 150 */ "Explain", 156 | }; 157 | return azName[i]; 158 | } 159 | #endif 160 | -------------------------------------------------------------------------------- /os_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2004 May 22 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ****************************************************************************** 12 | ** 13 | ** This file contains macros and a little bit of code that is common to 14 | ** all of the platform-specific files (os_*.c) and is #included into those 15 | ** files. 16 | ** 17 | ** This file should be #included by the os_*.c files only. It is not a 18 | ** general purpose header file. 19 | */ 20 | #ifndef _OS_COMMON_H_ 21 | #define _OS_COMMON_H_ 22 | 23 | /* 24 | ** At least two bugs have slipped in because we changed the MEMORY_DEBUG 25 | ** macro to SQLITE_DEBUG and some older makefiles have not yet made the 26 | ** switch. The following code should catch this problem at compile-time. 27 | */ 28 | #ifdef MEMORY_DEBUG 29 | # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead." 30 | #endif 31 | 32 | #if defined(SQLITE_TEST) && defined(SQLITE_DEBUG) 33 | # ifndef SQLITE_DEBUG_OS_TRACE 34 | # define SQLITE_DEBUG_OS_TRACE 0 35 | # endif 36 | int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE; 37 | # define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X 38 | #else 39 | # define OSTRACE(X) 40 | #endif 41 | 42 | /* 43 | ** Macros for performance tracing. Normally turned off. Only works 44 | ** on i486 hardware. 45 | */ 46 | #ifdef SQLITE_PERFORMANCE_TRACE 47 | 48 | /* 49 | ** hwtime.h contains inline assembler code for implementing 50 | ** high-performance timing routines. 51 | */ 52 | #include "hwtime.h" 53 | 54 | static sqlite_uint64 g_start; 55 | static sqlite_uint64 g_elapsed; 56 | #define TIMER_START g_start=sqlite3Hwtime() 57 | #define TIMER_END g_elapsed=sqlite3Hwtime()-g_start 58 | #define TIMER_ELAPSED g_elapsed 59 | #else 60 | #define TIMER_START 61 | #define TIMER_END 62 | #define TIMER_ELAPSED ((sqlite_uint64)0) 63 | #endif 64 | 65 | /* 66 | ** If we compile with the SQLITE_TEST macro set, then the following block 67 | ** of code will give us the ability to simulate a disk I/O error. This 68 | ** is used for testing the I/O recovery logic. 69 | */ 70 | #ifdef SQLITE_TEST 71 | int sqlite3_io_error_hit = 0; /* Total number of I/O Errors */ 72 | int sqlite3_io_error_hardhit = 0; /* Number of non-benign errors */ 73 | int sqlite3_io_error_pending = 0; /* Count down to first I/O error */ 74 | int sqlite3_io_error_persist = 0; /* True if I/O errors persist */ 75 | int sqlite3_io_error_benign = 0; /* True if errors are benign */ 76 | int sqlite3_diskfull_pending = 0; 77 | int sqlite3_diskfull = 0; 78 | #define SimulateIOErrorBenign(X) sqlite3_io_error_benign=(X) 79 | #define SimulateIOError(CODE) \ 80 | if( (sqlite3_io_error_persist && sqlite3_io_error_hit) \ 81 | || sqlite3_io_error_pending-- == 1 ) \ 82 | { local_ioerr(); CODE; } 83 | static void local_ioerr(){ 84 | IOTRACE(("IOERR\n")); 85 | sqlite3_io_error_hit++; 86 | if( !sqlite3_io_error_benign ) sqlite3_io_error_hardhit++; 87 | } 88 | #define SimulateDiskfullError(CODE) \ 89 | if( sqlite3_diskfull_pending ){ \ 90 | if( sqlite3_diskfull_pending == 1 ){ \ 91 | local_ioerr(); \ 92 | sqlite3_diskfull = 1; \ 93 | sqlite3_io_error_hit = 1; \ 94 | CODE; \ 95 | }else{ \ 96 | sqlite3_diskfull_pending--; \ 97 | } \ 98 | } 99 | #else 100 | #define SimulateIOErrorBenign(X) 101 | #define SimulateIOError(A) 102 | #define SimulateDiskfullError(A) 103 | #endif 104 | 105 | /* 106 | ** When testing, keep a count of the number of open files. 107 | */ 108 | #ifdef SQLITE_TEST 109 | int sqlite3_open_file_count = 0; 110 | #define OpenCounter(X) sqlite3_open_file_count+=(X) 111 | #else 112 | #define OpenCounter(X) 113 | #endif 114 | 115 | #endif /* !defined(_OS_COMMON_H_) */ 116 | -------------------------------------------------------------------------------- /pager.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2001 September 15 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ************************************************************************* 12 | ** This header file defines the interface that the sqlite page cache 13 | ** subsystem. The page cache subsystem reads and writes a file a page 14 | ** at a time and provides a journal for rollback. 15 | */ 16 | 17 | #ifndef _PAGER_H_ 18 | #define _PAGER_H_ 19 | 20 | /* 21 | ** Default maximum size for persistent journal files. A negative 22 | ** value means no limit. This value may be overridden using the 23 | ** sqlite3PagerJournalSizeLimit() API. See also "PRAGMA journal_size_limit". 24 | */ 25 | #ifndef SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT 26 | #define SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT -1 27 | #endif 28 | 29 | /* 30 | ** The type used to represent a page number. The first page in a file 31 | ** is called page 1. 0 is used to represent "not a page". 32 | */ 33 | typedef u32 Pgno; 34 | 35 | /* 36 | ** Each open file is managed by a separate instance of the "Pager" structure. 37 | */ 38 | typedef struct Pager Pager; 39 | 40 | /* 41 | ** Handle type for pages. 42 | */ 43 | typedef struct PgHdr DbPage; 44 | 45 | /* 46 | ** Page number PAGER_MJ_PGNO is never used in an SQLite database (it is 47 | ** reserved for working around a windows/posix incompatibility). It is 48 | ** used in the journal to signify that the remainder of the journal file 49 | ** is devoted to storing a master journal name - there are no more pages to 50 | ** roll back. See comments for function writeMasterJournal() in pager.c 51 | ** for details. 52 | */ 53 | #define PAGER_MJ_PGNO(x) ((Pgno)((PENDING_BYTE/((x)->pageSize))+1)) 54 | 55 | /* 56 | ** Allowed values for the flags parameter to sqlite3PagerOpen(). 57 | ** 58 | ** NOTE: These values must match the corresponding BTREE_ values in btree.h. 59 | */ 60 | #define PAGER_OMIT_JOURNAL 0x0001 /* Do not use a rollback journal */ 61 | #define PAGER_MEMORY 0x0002 /* In-memory database */ 62 | 63 | /* 64 | ** Valid values for the second argument to sqlite3PagerLockingMode(). 65 | */ 66 | #define PAGER_LOCKINGMODE_QUERY -1 67 | #define PAGER_LOCKINGMODE_NORMAL 0 68 | #define PAGER_LOCKINGMODE_EXCLUSIVE 1 69 | 70 | /* 71 | ** Numeric constants that encode the journalmode. 72 | */ 73 | #define PAGER_JOURNALMODE_QUERY (-1) /* Query the value of journalmode */ 74 | #define PAGER_JOURNALMODE_DELETE 0 /* Commit by deleting journal file */ 75 | #define PAGER_JOURNALMODE_PERSIST 1 /* Commit by zeroing journal header */ 76 | #define PAGER_JOURNALMODE_OFF 2 /* Journal omitted. */ 77 | #define PAGER_JOURNALMODE_TRUNCATE 3 /* Commit by truncating journal */ 78 | #define PAGER_JOURNALMODE_MEMORY 4 /* In-memory journal file */ 79 | #define PAGER_JOURNALMODE_WAL 5 /* Use write-ahead logging */ 80 | 81 | /* 82 | ** Flags that make up the mask passed to sqlite3PagerAcquire(). 83 | */ 84 | #define PAGER_ACQUIRE_NOCONTENT 0x01 /* Do not load data from disk */ 85 | #define PAGER_ACQUIRE_READONLY 0x02 /* Read-only page is acceptable */ 86 | 87 | /* 88 | ** The remainder of this file contains the declarations of the functions 89 | ** that make up the Pager sub-system API. See source code comments for 90 | ** a detailed description of each routine. 91 | */ 92 | 93 | /* Open and close a Pager connection. */ 94 | int sqlite3PagerOpen( 95 | sqlite3_vfs*, 96 | Pager **ppPager, 97 | const char*, 98 | int, 99 | int, 100 | int, 101 | void(*)(DbPage*) 102 | ); 103 | int sqlite3PagerClose(Pager *pPager); 104 | int sqlite3PagerReadFileheader(Pager*, int, unsigned char*); 105 | 106 | /* Functions used to configure a Pager object. */ 107 | void sqlite3PagerSetBusyhandler(Pager*, int(*)(void *), void *); 108 | int sqlite3PagerSetPagesize(Pager*, u32*, int); 109 | int sqlite3PagerMaxPageCount(Pager*, int); 110 | void sqlite3PagerSetCachesize(Pager*, int); 111 | void sqlite3PagerSetMmapLimit(Pager *, sqlite3_int64); 112 | void sqlite3PagerShrink(Pager*); 113 | void sqlite3PagerSetSafetyLevel(Pager*,int,int,int); 114 | int sqlite3PagerLockingMode(Pager *, int); 115 | int sqlite3PagerSetJournalMode(Pager *, int); 116 | int sqlite3PagerGetJournalMode(Pager*); 117 | int sqlite3PagerOkToChangeJournalMode(Pager*); 118 | i64 sqlite3PagerJournalSizeLimit(Pager *, i64); 119 | sqlite3_backup **sqlite3PagerBackupPtr(Pager*); 120 | 121 | /* Functions used to obtain and release page references. */ 122 | int sqlite3PagerAcquire(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag); 123 | #define sqlite3PagerGet(A,B,C) sqlite3PagerAcquire(A,B,C,0) 124 | DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno); 125 | void sqlite3PagerRef(DbPage*); 126 | void sqlite3PagerUnref(DbPage*); 127 | 128 | /* Operations on page references. */ 129 | int sqlite3PagerWrite(DbPage*); 130 | void sqlite3PagerDontWrite(DbPage*); 131 | int sqlite3PagerMovepage(Pager*,DbPage*,Pgno,int); 132 | int sqlite3PagerPageRefcount(DbPage*); 133 | void *sqlite3PagerGetData(DbPage *); 134 | void *sqlite3PagerGetExtra(DbPage *); 135 | 136 | /* Functions used to manage pager transactions and savepoints. */ 137 | void sqlite3PagerPagecount(Pager*, int*); 138 | int sqlite3PagerBegin(Pager*, int exFlag, int); 139 | int sqlite3PagerCommitPhaseOne(Pager*,const char *zMaster, int); 140 | int sqlite3PagerExclusiveLock(Pager*); 141 | int sqlite3PagerSync(Pager *pPager); 142 | int sqlite3PagerCommitPhaseTwo(Pager*); 143 | int sqlite3PagerRollback(Pager*); 144 | int sqlite3PagerOpenSavepoint(Pager *pPager, int n); 145 | int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint); 146 | int sqlite3PagerSharedLock(Pager *pPager); 147 | 148 | #ifndef SQLITE_OMIT_WAL 149 | int sqlite3PagerCheckpoint(Pager *pPager, int, int*, int*); 150 | int sqlite3PagerWalSupported(Pager *pPager); 151 | int sqlite3PagerWalCallback(Pager *pPager); 152 | int sqlite3PagerOpenWal(Pager *pPager, int *pisOpen); 153 | int sqlite3PagerCloseWal(Pager *pPager); 154 | #endif 155 | 156 | #ifdef SQLITE_ENABLE_ZIPVFS 157 | int sqlite3PagerWalFramesize(Pager *pPager); 158 | #endif 159 | 160 | /* Functions used to query pager state and configuration. */ 161 | u8 sqlite3PagerIsreadonly(Pager*); 162 | int sqlite3PagerRefcount(Pager*); 163 | int sqlite3PagerMemUsed(Pager*); 164 | const char *sqlite3PagerFilename(Pager*, int); 165 | const sqlite3_vfs *sqlite3PagerVfs(Pager*); 166 | sqlite3_file *sqlite3PagerFile(Pager*); 167 | const char *sqlite3PagerJournalname(Pager*); 168 | int sqlite3PagerNosync(Pager*); 169 | void *sqlite3PagerTempSpace(Pager*); 170 | int sqlite3PagerIsMemdb(Pager*); 171 | void sqlite3PagerCacheStat(Pager *, int, int, int *); 172 | void sqlite3PagerClearCache(Pager *); 173 | int sqlite3SectorSize(sqlite3_file *); 174 | 175 | /* Functions used to truncate the database file. */ 176 | void sqlite3PagerTruncateImage(Pager*,Pgno); 177 | 178 | #if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_WAL) 179 | void *sqlite3PagerCodec(DbPage *); 180 | #endif 181 | 182 | /* Functions to support testing and debugging. */ 183 | #if !defined(NDEBUG) || defined(SQLITE_TEST) 184 | Pgno sqlite3PagerPagenumber(DbPage*); 185 | int sqlite3PagerIswriteable(DbPage*); 186 | #endif 187 | #ifdef SQLITE_TEST 188 | int *sqlite3PagerStats(Pager*); 189 | void sqlite3PagerRefdump(Pager*); 190 | void disable_simulated_io_errors(void); 191 | void enable_simulated_io_errors(void); 192 | #else 193 | # define disable_simulated_io_errors() 194 | # define enable_simulated_io_errors() 195 | #endif 196 | 197 | #endif /* _PAGER_H_ */ 198 | -------------------------------------------------------------------------------- /parse.h: -------------------------------------------------------------------------------- 1 | #define TK_SEMI 1 2 | #define TK_EXPLAIN 2 3 | #define TK_QUERY 3 4 | #define TK_PLAN 4 5 | #define TK_BEGIN 5 6 | #define TK_TRANSACTION 6 7 | #define TK_DEFERRED 7 8 | #define TK_IMMEDIATE 8 9 | #define TK_EXCLUSIVE 9 10 | #define TK_COMMIT 10 11 | #define TK_END 11 12 | #define TK_ROLLBACK 12 13 | #define TK_SAVEPOINT 13 14 | #define TK_RELEASE 14 15 | #define TK_TO 15 16 | #define TK_TABLE 16 17 | #define TK_CREATE 17 18 | #define TK_IF 18 19 | #define TK_NOT 19 20 | #define TK_EXISTS 20 21 | #define TK_TEMP 21 22 | #define TK_LP 22 23 | #define TK_RP 23 24 | #define TK_AS 24 25 | #define TK_COMMA 25 26 | #define TK_ID 26 27 | #define TK_INDEXED 27 28 | #define TK_ABORT 28 29 | #define TK_ACTION 29 30 | #define TK_AFTER 30 31 | #define TK_ANALYZE 31 32 | #define TK_ASC 32 33 | #define TK_ATTACH 33 34 | #define TK_BEFORE 34 35 | #define TK_BY 35 36 | #define TK_CASCADE 36 37 | #define TK_CAST 37 38 | #define TK_COLUMNKW 38 39 | #define TK_CONFLICT 39 40 | #define TK_DATABASE 40 41 | #define TK_DESC 41 42 | #define TK_DETACH 42 43 | #define TK_EACH 43 44 | #define TK_FAIL 44 45 | #define TK_FOR 45 46 | #define TK_IGNORE 46 47 | #define TK_INITIALLY 47 48 | #define TK_INSTEAD 48 49 | #define TK_LIKE_KW 49 50 | #define TK_MATCH 50 51 | #define TK_NO 51 52 | #define TK_KEY 52 53 | #define TK_OF 53 54 | #define TK_OFFSET 54 55 | #define TK_PRAGMA 55 56 | #define TK_RAISE 56 57 | #define TK_REPLACE 57 58 | #define TK_RESTRICT 58 59 | #define TK_ROW 59 60 | #define TK_TRIGGER 60 61 | #define TK_VACUUM 61 62 | #define TK_VIEW 62 63 | #define TK_VIRTUAL 63 64 | #define TK_REINDEX 64 65 | #define TK_RENAME 65 66 | #define TK_CTIME_KW 66 67 | #define TK_ANY 67 68 | #define TK_OR 68 69 | #define TK_AND 69 70 | #define TK_IS 70 71 | #define TK_BETWEEN 71 72 | #define TK_IN 72 73 | #define TK_ISNULL 73 74 | #define TK_NOTNULL 74 75 | #define TK_NE 75 76 | #define TK_EQ 76 77 | #define TK_GT 77 78 | #define TK_LE 78 79 | #define TK_LT 79 80 | #define TK_GE 80 81 | #define TK_ESCAPE 81 82 | #define TK_BITAND 82 83 | #define TK_BITOR 83 84 | #define TK_LSHIFT 84 85 | #define TK_RSHIFT 85 86 | #define TK_PLUS 86 87 | #define TK_MINUS 87 88 | #define TK_STAR 88 89 | #define TK_SLASH 89 90 | #define TK_REM 90 91 | #define TK_CONCAT 91 92 | #define TK_COLLATE 92 93 | #define TK_BITNOT 93 94 | #define TK_STRING 94 95 | #define TK_JOIN_KW 95 96 | #define TK_CONSTRAINT 96 97 | #define TK_DEFAULT 97 98 | #define TK_NULL 98 99 | #define TK_PRIMARY 99 100 | #define TK_UNIQUE 100 101 | #define TK_CHECK 101 102 | #define TK_REFERENCES 102 103 | #define TK_AUTOINCR 103 104 | #define TK_ON 104 105 | #define TK_INSERT 105 106 | #define TK_DELETE 106 107 | #define TK_UPDATE 107 108 | #define TK_SET 108 109 | #define TK_DEFERRABLE 109 110 | #define TK_FOREIGN 110 111 | #define TK_DROP 111 112 | #define TK_UNION 112 113 | #define TK_ALL 113 114 | #define TK_EXCEPT 114 115 | #define TK_INTERSECT 115 116 | #define TK_SELECT 116 117 | #define TK_DISTINCT 117 118 | #define TK_DOT 118 119 | #define TK_FROM 119 120 | #define TK_JOIN 120 121 | #define TK_USING 121 122 | #define TK_ORDER 122 123 | #define TK_GROUP 123 124 | #define TK_HAVING 124 125 | #define TK_LIMIT 125 126 | #define TK_WHERE 126 127 | #define TK_INTO 127 128 | #define TK_VALUES 128 129 | #define TK_INTEGER 129 130 | #define TK_FLOAT 130 131 | #define TK_BLOB 131 132 | #define TK_REGISTER 132 133 | #define TK_VARIABLE 133 134 | #define TK_CASE 134 135 | #define TK_WHEN 135 136 | #define TK_THEN 136 137 | #define TK_ELSE 137 138 | #define TK_INDEX 138 139 | #define TK_ALTER 139 140 | #define TK_ADD 140 141 | #define TK_TO_TEXT 141 142 | #define TK_TO_BLOB 142 143 | #define TK_TO_NUMERIC 143 144 | #define TK_TO_INT 144 145 | #define TK_TO_REAL 145 146 | #define TK_ISNOT 146 147 | #define TK_END_OF_FILE 147 148 | #define TK_ILLEGAL 148 149 | #define TK_SPACE 149 150 | #define TK_UNCLOSED_STRING 150 151 | #define TK_FUNCTION 151 152 | #define TK_COLUMN 152 153 | #define TK_AGG_FUNCTION 153 154 | #define TK_AGG_COLUMN 154 155 | #define TK_CONST_FUNC 155 156 | #define TK_UMINUS 156 157 | #define TK_UPLUS 157 158 | -------------------------------------------------------------------------------- /pcache.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2008 August 05 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ************************************************************************* 12 | ** This header file defines the interface that the sqlite page cache 13 | ** subsystem. 14 | */ 15 | 16 | #ifndef _PCACHE_H_ 17 | 18 | typedef struct PgHdr PgHdr; 19 | typedef struct PCache PCache; 20 | 21 | /* 22 | ** Every page in the cache is controlled by an instance of the following 23 | ** structure. 24 | */ 25 | struct PgHdr { 26 | sqlite3_pcache_page *pPage; /* Pcache object page handle */ 27 | void *pData; /* Page data */ 28 | void *pExtra; /* Extra content */ 29 | PgHdr *pDirty; /* Transient list of dirty pages */ 30 | Pager *pPager; /* The pager this page is part of */ 31 | Pgno pgno; /* Page number for this page */ 32 | #ifdef SQLITE_CHECK_PAGES 33 | u32 pageHash; /* Hash of page content */ 34 | #endif 35 | u16 flags; /* PGHDR flags defined below */ 36 | 37 | /********************************************************************** 38 | ** Elements above are public. All that follows is private to pcache.c 39 | ** and should not be accessed by other modules. 40 | */ 41 | i16 nRef; /* Number of users of this page */ 42 | PCache *pCache; /* Cache that owns this page */ 43 | 44 | PgHdr *pDirtyNext; /* Next element in list of dirty pages */ 45 | PgHdr *pDirtyPrev; /* Previous element in list of dirty pages */ 46 | }; 47 | 48 | /* Bit values for PgHdr.flags */ 49 | #define PGHDR_DIRTY 0x002 /* Page has changed */ 50 | #define PGHDR_NEED_SYNC 0x004 /* Fsync the rollback journal before 51 | ** writing this page to the database */ 52 | #define PGHDR_NEED_READ 0x008 /* Content is unread */ 53 | #define PGHDR_REUSE_UNLIKELY 0x010 /* A hint that reuse is unlikely */ 54 | #define PGHDR_DONT_WRITE 0x020 /* Do not write content to disk */ 55 | 56 | #define PGHDR_MMAP 0x040 /* This is an mmap page object */ 57 | 58 | /* Initialize and shutdown the page cache subsystem */ 59 | int sqlite3PcacheInitialize(void); 60 | void sqlite3PcacheShutdown(void); 61 | 62 | /* Page cache buffer management: 63 | ** These routines implement SQLITE_CONFIG_PAGECACHE. 64 | */ 65 | void sqlite3PCacheBufferSetup(void *, int sz, int n); 66 | 67 | /* Create a new pager cache. 68 | ** Under memory stress, invoke xStress to try to make pages clean. 69 | ** Only clean and unpinned pages can be reclaimed. 70 | */ 71 | void sqlite3PcacheOpen( 72 | int szPage, /* Size of every page */ 73 | int szExtra, /* Extra space associated with each page */ 74 | int bPurgeable, /* True if pages are on backing store */ 75 | int (*xStress)(void*, PgHdr*), /* Call to try to make pages clean */ 76 | void *pStress, /* Argument to xStress */ 77 | PCache *pToInit /* Preallocated space for the PCache */ 78 | ); 79 | 80 | /* Modify the page-size after the cache has been created. */ 81 | void sqlite3PcacheSetPageSize(PCache *, int); 82 | 83 | /* Return the size in bytes of a PCache object. Used to preallocate 84 | ** storage space. 85 | */ 86 | int sqlite3PcacheSize(void); 87 | 88 | /* One release per successful fetch. Page is pinned until released. 89 | ** Reference counted. 90 | */ 91 | int sqlite3PcacheFetch(PCache*, Pgno, int createFlag, PgHdr**); 92 | void sqlite3PcacheRelease(PgHdr*); 93 | 94 | void sqlite3PcacheDrop(PgHdr*); /* Remove page from cache */ 95 | void sqlite3PcacheMakeDirty(PgHdr*); /* Make sure page is marked dirty */ 96 | void sqlite3PcacheMakeClean(PgHdr*); /* Mark a single page as clean */ 97 | void sqlite3PcacheCleanAll(PCache*); /* Mark all dirty list pages as clean */ 98 | 99 | /* Change a page number. Used by incr-vacuum. */ 100 | void sqlite3PcacheMove(PgHdr*, Pgno); 101 | 102 | /* Remove all pages with pgno>x. Reset the cache if x==0 */ 103 | void sqlite3PcacheTruncate(PCache*, Pgno x); 104 | 105 | /* Get a list of all dirty pages in the cache, sorted by page number */ 106 | PgHdr *sqlite3PcacheDirtyList(PCache*); 107 | 108 | /* Reset and close the cache object */ 109 | void sqlite3PcacheClose(PCache*); 110 | 111 | /* Clear flags from pages of the page cache */ 112 | void sqlite3PcacheClearSyncFlags(PCache *); 113 | 114 | /* Discard the contents of the cache */ 115 | void sqlite3PcacheClear(PCache*); 116 | 117 | /* Return the total number of outstanding page references */ 118 | int sqlite3PcacheRefCount(PCache*); 119 | 120 | /* Increment the reference count of an existing page */ 121 | void sqlite3PcacheRef(PgHdr*); 122 | 123 | int sqlite3PcachePageRefcount(PgHdr*); 124 | 125 | /* Return the total number of pages stored in the cache */ 126 | int sqlite3PcachePagecount(PCache*); 127 | 128 | #if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG) 129 | /* Iterate through all dirty pages currently stored in the cache. This 130 | ** interface is only available if SQLITE_CHECK_PAGES is defined when the 131 | ** library is built. 132 | */ 133 | void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *)); 134 | #endif 135 | 136 | /* Set and get the suggested cache-size for the specified pager-cache. 137 | ** 138 | ** If no global maximum is configured, then the system attempts to limit 139 | ** the total number of pages cached by purgeable pager-caches to the sum 140 | ** of the suggested cache-sizes. 141 | */ 142 | void sqlite3PcacheSetCachesize(PCache *, int); 143 | #ifdef SQLITE_TEST 144 | int sqlite3PcacheGetCachesize(PCache *); 145 | #endif 146 | 147 | /* Free up as much memory as possible from the page cache */ 148 | void sqlite3PcacheShrink(PCache*); 149 | 150 | #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT 151 | /* Try to return memory used by the pcache module to the main memory heap */ 152 | int sqlite3PcacheReleaseMemory(int); 153 | #endif 154 | 155 | #ifdef SQLITE_TEST 156 | void sqlite3PcacheStats(int*,int*,int*,int*); 157 | #endif 158 | 159 | void sqlite3PCacheSetDefault(void); 160 | 161 | #endif /* _PCACHE_H_ */ 162 | -------------------------------------------------------------------------------- /random.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2001 September 15 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ************************************************************************* 12 | ** This file contains code to implement a pseudo-random number 13 | ** generator (PRNG) for SQLite. 14 | ** 15 | ** Random numbers are used by some of the database backends in order 16 | ** to generate random integer keys for tables or random filenames. 17 | */ 18 | #include "sqliteInt.h" 19 | 20 | 21 | /* All threads share a single random number generator. 22 | ** This structure is the current state of the generator. 23 | */ 24 | static SQLITE_WSD struct sqlite3PrngType { 25 | unsigned char isInit; /* True if initialized */ 26 | unsigned char i, j; /* State variables */ 27 | unsigned char s[256]; /* State variables */ 28 | } sqlite3Prng; 29 | 30 | /* 31 | ** Get a single 8-bit random value from the RC4 PRNG. The Mutex 32 | ** must be held while executing this routine. 33 | ** 34 | ** Why not just use a library random generator like lrand48() for this? 35 | ** Because the OP_NewRowid opcode in the VDBE depends on having a very 36 | ** good source of random numbers. The lrand48() library function may 37 | ** well be good enough. But maybe not. Or maybe lrand48() has some 38 | ** subtle problems on some systems that could cause problems. It is hard 39 | ** to know. To minimize the risk of problems due to bad lrand48() 40 | ** implementations, SQLite uses this random number generator based 41 | ** on RC4, which we know works very well. 42 | ** 43 | ** (Later): Actually, OP_NewRowid does not depend on a good source of 44 | ** randomness any more. But we will leave this code in all the same. 45 | */ 46 | static u8 randomByte(void){ 47 | unsigned char t; 48 | 49 | 50 | /* The "wsdPrng" macro will resolve to the pseudo-random number generator 51 | ** state vector. If writable static data is unsupported on the target, 52 | ** we have to locate the state vector at run-time. In the more common 53 | ** case where writable static data is supported, wsdPrng can refer directly 54 | ** to the "sqlite3Prng" state vector declared above. 55 | */ 56 | #ifdef SQLITE_OMIT_WSD 57 | struct sqlite3PrngType *p = &GLOBAL(struct sqlite3PrngType, sqlite3Prng); 58 | # define wsdPrng p[0] 59 | #else 60 | # define wsdPrng sqlite3Prng 61 | #endif 62 | 63 | 64 | /* Initialize the state of the random number generator once, 65 | ** the first time this routine is called. The seed value does 66 | ** not need to contain a lot of randomness since we are not 67 | ** trying to do secure encryption or anything like that... 68 | ** 69 | ** Nothing in this file or anywhere else in SQLite does any kind of 70 | ** encryption. The RC4 algorithm is being used as a PRNG (pseudo-random 71 | ** number generator) not as an encryption device. 72 | */ 73 | if( !wsdPrng.isInit ){ 74 | int i; 75 | char k[256]; 76 | wsdPrng.j = 0; 77 | wsdPrng.i = 0; 78 | sqlite3OsRandomness(sqlite3_vfs_find(0), 256, k); 79 | for(i=0; i<256; i++){ 80 | wsdPrng.s[i] = (u8)i; 81 | } 82 | for(i=0; i<256; i++){ 83 | wsdPrng.j += wsdPrng.s[i] + k[i]; 84 | t = wsdPrng.s[wsdPrng.j]; 85 | wsdPrng.s[wsdPrng.j] = wsdPrng.s[i]; 86 | wsdPrng.s[i] = t; 87 | } 88 | wsdPrng.isInit = 1; 89 | } 90 | 91 | /* Generate and return single random byte 92 | */ 93 | wsdPrng.i++; 94 | t = wsdPrng.s[wsdPrng.i]; 95 | wsdPrng.j += t; 96 | wsdPrng.s[wsdPrng.i] = wsdPrng.s[wsdPrng.j]; 97 | wsdPrng.s[wsdPrng.j] = t; 98 | t += wsdPrng.s[wsdPrng.i]; 99 | return wsdPrng.s[t]; 100 | } 101 | 102 | /* 103 | ** Return N random bytes. 104 | */ 105 | void sqlite3_randomness(int N, void *pBuf){ 106 | unsigned char *zBuf = pBuf; 107 | #if SQLITE_THREADSAFE 108 | sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG); 109 | #endif 110 | sqlite3_mutex_enter(mutex); 111 | while( N-- ){ 112 | *(zBuf++) = randomByte(); 113 | } 114 | sqlite3_mutex_leave(mutex); 115 | } 116 | 117 | #ifndef SQLITE_OMIT_BUILTIN_TEST 118 | /* 119 | ** For testing purposes, we sometimes want to preserve the state of 120 | ** PRNG and restore the PRNG to its saved state at a later time, or 121 | ** to reset the PRNG to its initial state. These routines accomplish 122 | ** those tasks. 123 | ** 124 | ** The sqlite3_test_control() interface calls these routines to 125 | ** control the PRNG. 126 | */ 127 | static SQLITE_WSD struct sqlite3PrngType sqlite3SavedPrng; 128 | void sqlite3PrngSaveState(void){ 129 | memcpy( 130 | &GLOBAL(struct sqlite3PrngType, sqlite3SavedPrng), 131 | &GLOBAL(struct sqlite3PrngType, sqlite3Prng), 132 | sizeof(sqlite3Prng) 133 | ); 134 | } 135 | void sqlite3PrngRestoreState(void){ 136 | memcpy( 137 | &GLOBAL(struct sqlite3PrngType, sqlite3Prng), 138 | &GLOBAL(struct sqlite3PrngType, sqlite3SavedPrng), 139 | sizeof(sqlite3Prng) 140 | ); 141 | } 142 | void sqlite3PrngResetState(void){ 143 | GLOBAL(struct sqlite3PrngType, sqlite3Prng).isInit = 0; 144 | } 145 | #endif /* SQLITE_OMIT_BUILTIN_TEST */ 146 | -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | SQLite for OpenVMS 2 | 3 | This is a native port of the SQLite database package to OpenVMS. It delivers 4 | the SQLite database to OpenVMS using the following native features: 5 | 6 | * Thread support using the tis library. This allows support for 7 | multi-threading without having to link against the pthreads RTL. 8 | 9 | * Direct file access. All files access is performed using the $QIO 10 | system services, rather than the C RTL or even RMS. 11 | 12 | * Native locking. All locking is handled using the OpenVMS distributed 13 | lock manager, allowing database access to be coordinated across 14 | cluster nodes (of all architectures). 15 | 16 | Despite these OpenVMS-specific improvements the database file maintained 17 | by SQLite is still portable to other SQLite-based applications running on 18 | other systems. 19 | -------------------------------------------------------------------------------- /release_notes.sdml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 2013 March 31 4 | 5 | The author disclaims copyright to this source code. In place of 6 | a legal notice, here is a blessing: 7 | 8 | May you do good and not evil. 9 | May you find forgiveness for yourself and forgive others. 10 | May you share freely, never taking more than you give. 11 | 12 | ************************************************************************ 13 | This is the OpenVMS-specific user guide and release notes documentation. 14 | 15 | 16 | (ETC_DIR:DYNAMIC_SYMBOLS.SDML) 17 | 18 | 19 | (SQLite3 for OpenVMS User's Guide and Release Notes) 20 | <ABSTRACT>(<REFERENCE>(RELMONTH)) 21 | <P> 22 | This document contains the release notes and user's guide for 23 | SQLite3 for OpenVMS. It describes any OpenVMS-specific features, 24 | restrictions, changes or additions made to SQLite3 in this release. It 25 | also describes how to install and use the SQLite3 utilities and run-time 26 | library. 27 | <ENDABSTRACT> 28 | <REVISION_INFO>(This is a new manual.) 29 | <REVISION_INFO>(Operating System and Version:\OpenVMS VAX V7.3 or later) 30 | <REVISION_INFO>(\OpenVMS Alpha V7.3 or later) 31 | <REVISION_INFO>(\OpenVMS I64 V8.2 or later) 32 | <REVISION_INFO>(Software Version:\SQLite3 <REFERENCE(VER)) 33 | <ENDTITLE_PAGE>(Endless Software Solutions<LINE>Perth, Western Australia) 34 | <COPYRIGHT_PAGE> 35 | <PRINT_DATE>(<REFERENCE>(PRTDATE)) 36 | <COPYRIGHT_DATE>(<REFERENCE>(CPYDATE)) 37 | <P> 38 | The author disclaims copyright to this source code. In place of 39 | a legal notice, here is a blessing: 40 | 41 | <LIST>(UNNUMBERED) 42 | <LE>May you do good and not evil. 43 | <LE>May you find forgiveness for yourself and forgive others. 44 | <LE>May you share freely, never taking more than you give. 45 | <ENDLIST> 46 | <ENDCOPYRIGHT_PAGE> 47 | <CONTENTS_FILE> 48 | <ENDFRONT_MATTER> 49 | 50 | <CHAPTER>(Installation Guide\install) 51 | 52 | <HEAD1>(Installation) 53 | 54 | <P>Only comes in a PCSI kit...no VMSINSTAL. 55 | 56 | <HEAD1>(Post-Installation Tasks) 57 | 58 | <CHAPTER>(User's Guide) 59 | 60 | <HEAD1>(Version Numbering) 61 | <P>Describe how it works and were to get version information from... 62 | 63 | <HEAD1>(Client Utility) 64 | 65 | <HEAD2>(History File) 66 | 67 | If you don't want it then define SQLITE_HISTORY to NLA0: or 68 | SYS$LOGIN:SQLITE_HISTORY.DAT by default. 69 | 70 | <HEAD2>(Initialization file) 71 | 72 | <P>Define SQLITE_INIT to ... otherwise SYS$LOGIN:SQLITE_INIT.DAT is init file. 73 | 74 | <HEAD1>(Linking) 75 | 76 | <HEAD1>(Thread Safety) 77 | 78 | <P> 79 | Describe how we use the tis interface and that you enable by linking with 80 | the pthread RTL and using the right calls to switch it on. 81 | 82 | <HEAD1>(Locking) 83 | 84 | <P> 85 | Describe cluster locking mechanism. For this reason we have to install the 86 | RTL with SYSLCK privs. 87 | 88 | <HEAD1>(Shared Memory) 89 | <P> 90 | Describe the shared memory mechanism and hwo that all hangs together. 91 | 92 | <HEAD1>(API Reference) 93 | <p>include links back to SQLite3 website and it's documentation, etc... 94 | 95 | <CHAPTER>(Release Notes\relnote) 96 | 97 | <HEAD1>(New Features and Changes in SQLite3 V7. 98 | 99 | ...nothing here as this is a new manual... 100 | 101 | <HEAD1>(Known Restrictions> 102 | <P>The following section details known restrictions to the 103 | 104 | -- related to creating temporary files, with out names... 105 | 106 | NFS and identified with the VACUUM command.... 107 | -------------------------------------------------------------------------------- /rtree.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2008 May 26 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ****************************************************************************** 12 | ** 13 | ** This header file is used by programs that want to link against the 14 | ** RTREE library. All it does is declare the sqlite3RtreeInit() interface. 15 | */ 16 | #include "sqlite3.h" 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif /* __cplusplus */ 21 | 22 | int sqlite3RtreeInit(sqlite3 *db); 23 | 24 | #ifdef __cplusplus 25 | } /* extern "C" */ 26 | #endif /* __cplusplus */ 27 | -------------------------------------------------------------------------------- /sqlite3.axp_opt: -------------------------------------------------------------------------------- 1 | ! 2 | ! 2013 April 18 3 | ! 4 | ! The author disclaims copyright to this source code. In place of 5 | ! a legal notice, here is a blessing: 6 | ! 7 | ! May you do good and not evil. 8 | ! May you find forgiveness for yourself and forgive others. 9 | ! May you share freely, never taking more than you give. 10 | ! 11 | !*********************************************************************** 12 | ! This file contains the linker options file for the Alpha command line 13 | ! utility. 14 | ! 15 | BIN_DIR:SHELL.OBJ 16 | BIN_DIR:VMSSHELL.OBJ 17 | SQLITE3_SHR/SHARE 18 | -------------------------------------------------------------------------------- /sqlite3.i64_opt: -------------------------------------------------------------------------------- 1 | ! 2 | ! 2013 April 1 3 | ! 4 | ! The author disclaims copyright to this source code. In place of 5 | ! a legal notice, here is a blessing: 6 | ! 7 | ! May you do good and not evil. 8 | ! May you find forgiveness for yourself and forgive others. 9 | ! May you share freely, never taking more than you give. 10 | ! 11 | !*********************************************************************** 12 | ! This file contains the linker options file for the I64 command line 13 | ! utility. 14 | ! 15 | BIN_DIR:SHELL.OBJ 16 | BIN_DIR:VMSSHELL.OBJ 17 | SQLITE3_SHR/SHARE 18 | -------------------------------------------------------------------------------- /sqlite3.vax_opt: -------------------------------------------------------------------------------- 1 | ! 2 | ! 2013 March 21 3 | ! 4 | ! The author disclaims copyright to this source code. In place of 5 | ! a legal notice, here is a blessing: 6 | ! 7 | ! May you do good and not evil. 8 | ! May you find forgiveness for yourself and forgive others. 9 | ! May you share freely, never taking more than you give. 10 | ! 11 | !*********************************************************************** 12 | ! This file contains the linker options file for the VAX command line 13 | ! utility. 14 | ! 15 | BIN_DIR:SHELL.OBJ 16 | BIN_DIR:VMSSHELL.OBJ 17 | GNU_CC_LIBRARY:LIBGCC/LIB 18 | SYS$LIBRARY:VAXCRTL/LIB 19 | SYS$LIBRARY:DECCRTL/LIB/INCLUDE=(C$TRUNCATEVECTORS,C$POPENVECTORS) 20 | SQLITE3_SHR/SHARE 21 | SYS$LIBRARY:SMGSHR/SHARE 22 | SYS$LIBRARY:STARLET/LIB 23 | -------------------------------------------------------------------------------- /sqlite3_shr.axp_opt: -------------------------------------------------------------------------------- 1 | ! 2 | ! 2013 March 30 3 | ! 4 | ! The author disclaims copyright to this source code. In place of 5 | ! a legal notice, here is a blessing: 6 | ! 7 | ! May you do good and not evil. 8 | ! May you find forgiveness for yourself and forgive others. 9 | ! May you share freely, never taking more than you give. 10 | ! 11 | !*********************************************************************** 12 | ! This file contains the linker options file for the Alpha shareable 13 | ! image. 14 | ! 15 | GSMATCH=LEQUAL,8,0 16 | CLUSTER = CLUSTER1 17 | PSECT_ATTR=$CODE$,SHR 18 | COLLECT = CLUSTER1,$CODE$,$CODE 19 | BIN_DIR:SQLITE3.OLB/LIB 20 | -------------------------------------------------------------------------------- /sqlite3_shr.i64_opt: -------------------------------------------------------------------------------- 1 | ! 2 | ! 2013 March 30 3 | ! 4 | ! The author disclaims copyright to this source code. In place of 5 | ! a legal notice, here is a blessing: 6 | ! 7 | ! May you do good and not evil. 8 | ! May you find forgiveness for yourself and forgive others. 9 | ! May you share freely, never taking more than you give. 10 | ! 11 | !*********************************************************************** 12 | ! This file contains the linker options file for the Itanium shareable 13 | ! image. 14 | ! 15 | GSMATCH=LEQUAL,8,0 16 | CLUSTER = CLUSTER1 17 | PSECT_ATTR=$CODE$,SHR 18 | COLLECT = CLUSTER1,$CODE$,$CODE 19 | BIN_DIR:SQLITE3.OLB/LIB 20 | -------------------------------------------------------------------------------- /sqlite3_shr.vax_opt: -------------------------------------------------------------------------------- 1 | ! 2 | ! 2013 March 9 3 | ! 4 | ! The author disclaims copyright to this source code. In place of 5 | ! a legal notice, here is a blessing: 6 | ! 7 | ! May you do good and not evil. 8 | ! May you find forgiveness for yourself and forgive others. 9 | ! May you share freely, never taking more than you give. 10 | ! 11 | !*********************************************************************** 12 | ! This file contains the linker options file for the VAX shareable 13 | ! image. 14 | ! 15 | GSMATCH=LEQUAL,8,0 16 | 17 | CASE_SENSITIVE=YES 18 | 19 | CLUSTER=___SQLITE3_VECTOR,,,BIN_DIR:SQLITE3_VECTOR.OBJ 20 | CLUSTER=CLUSTER1 21 | COLLECT=CLUSTER1,$CODE$,$CODE,$code 22 | 23 | ! 24 | ! These PSECT definitions are here to counter-act the fact 25 | ! that GCC insists on marking these WRT,SHR. This ensures 26 | ! we don't create a shareable image that must be INSTALL'd 27 | ! /WRITE. 28 | ! 29 | PSECT_ATTR=sqlite3Config,NOSHR,WRT,NOEXE,RD,NOVEC 30 | PSECT_ATTR=sqlite3GlobalFunctions,NOSHR,WRT,NOEXE,RD,NOVEC 31 | PSECT_ATTR=sqlite3PendingByte,NOSHR,WRT,NOEXE,RD,NOVEC 32 | PSECT_ATTR=sqlite3_data_directory,NOSHR,WRT,NOEXE,RD,NOVEC 33 | PSECT_ATTR=sqlite3_temp_directory,NOSHR,WRT,NOEXE,RD,NOVEC 34 | 35 | CASE_SENSITIVE=NO 36 | 37 | BIN_DIR:SQLITE3_ALIASES.OBJ 38 | BIN_DIR:SQLITE3.OLB/LIB 39 | GNU_CC_LIBRARY:LIBGCC/LIB 40 | SYS$LIBRARY:VAXC2DECC/SHARE 41 | -------------------------------------------------------------------------------- /sqlite3_vector.mar: -------------------------------------------------------------------------------- 1 | ; 2 | ; 2013 September 19 3 | ; 4 | ; The author disclaims copyright to this source code. In place of 5 | ; a legal notice, here is a blessing: 6 | ; 7 | ; May you do good and not evil. 8 | ; May you find forgiveness for yourself and forgive others. 9 | ; May you share freely, never taking more than you give. 10 | ; 11 | ;*********************************************************************** 12 | ; This is automatically generated by MAKE_SYMBOL_VECTOR. DO NOT EDIT!!! 13 | ; 14 | 15 | .TITLE SQLITE3_VECTOR 16 | 17 | .MACRO ROUTINE NAME 18 | .EXTRN NAME 19 | .ALIGN QUAD 20 | .TRANSFER NAME 21 | .MASK NAME 22 | JMP NAME+2 23 | .ENDM 24 | 25 | .MACRO SPARE ?L1 26 | .EXTRN LIB$NOT_IMPLEMENTED 27 | .ALIGN QUAD 28 | BSBB L1 29 | L1: JMP LIB$NOT_IMPLEMENTED 30 | .ENDM 31 | 32 | .PSECT ___SQLITE3_VECTOR - 33 | PIC,USR,CON,REL,LCL,SHR,EXE,RD,NOWRT,QUAD 34 | 35 | ROUTINE sqlite3_set_authorizer 36 | ROUTINE sqlite3_backup_finish 37 | ROUTINE sqlite3_backup_init 38 | ROUTINE sqlite3_backup_pagecount 39 | ROUTINE sqlite3_backup_remaining 40 | ROUTINE sqlite3_backup_step 41 | ROUTINE sqlite3_enable_shared_cache 42 | ROUTINE sqlite3_complete 43 | ROUTINE sqlite3_compileoption_get 44 | ROUTINE sqlite3_compileoption_used 45 | ROUTINE sqlite3_exec 46 | ROUTINE sqlite3_auto_extension 47 | ROUTINE sqlite3_enable_load_extension 48 | ROUTINE sqlite3_load_extension 49 | ROUTINE sqlite3_reset_auto_extension 50 | ROUTINE sqlite3_busy_handler 51 | ROUTINE sqlite3_busy_timeout 52 | ROUTINE sqlite3_changes 53 | ROUTINE sqlite3_close 54 | ROUTINE sqlite3_close_v2 55 | ROUTINE sqlite3_collation_needed 56 | ROUTINE sqlite3_commit_hook 57 | ROUTINE sqlite3_config 58 | ROUTINE sqlite3_create_collation 59 | ROUTINE sqlite3_create_collation_v2 60 | ROUTINE sqlite3_create_function 61 | ROUTINE sqlite3_create_function_v2 62 | ROUTINE sqlite3_db_config 63 | ROUTINE sqlite3_db_filename 64 | ROUTINE sqlite3_db_mutex 65 | ROUTINE sqlite3_db_readonly 66 | ROUTINE sqlite3_db_release_memory 67 | ROUTINE sqlite3_errcode 68 | ROUTINE sqlite3_errmsg 69 | ROUTINE sqlite3_errstr 70 | ROUTINE sqlite3_extended_errcode 71 | ROUTINE sqlite3_extended_result_codes 72 | ROUTINE sqlite3_file_control 73 | ROUTINE sqlite3_get_autocommit 74 | ROUTINE sqlite3_global_recover 75 | ROUTINE sqlite3_initialize 76 | ROUTINE sqlite3_interrupt 77 | ROUTINE sqlite3_last_insert_rowid 78 | ROUTINE sqlite3_libversion 79 | ROUTINE sqlite3_libversion_number 80 | ROUTINE sqlite3_limit 81 | ROUTINE sqlite3_open 82 | ROUTINE sqlite3_open_v2 83 | ROUTINE sqlite3_overload_function 84 | ROUTINE sqlite3_profile 85 | ROUTINE sqlite3_progress_handler 86 | ROUTINE sqlite3_rollback_hook 87 | ROUTINE sqlite3_shutdown 88 | ROUTINE sqlite3_sleep 89 | ROUTINE sqlite3_sourceid 90 | ROUTINE sqlite3_table_column_metadata 91 | ROUTINE sqlite3_test_control 92 | ROUTINE sqlite3_thread_cleanup 93 | ROUTINE sqlite3_threadsafe 94 | ROUTINE sqlite3_total_changes 95 | ROUTINE sqlite3_trace 96 | ROUTINE sqlite3_update_hook 97 | ROUTINE sqlite3_uri_boolean 98 | ROUTINE sqlite3_uri_int64 99 | ROUTINE sqlite3_uri_parameter 100 | ROUTINE sqlite3_wal_autocheckpoint 101 | ROUTINE sqlite3_wal_checkpoint 102 | ROUTINE sqlite3_wal_checkpoint_v2 103 | ROUTINE sqlite3_wal_hook 104 | ROUTINE sqlite3_free 105 | ROUTINE sqlite3_malloc 106 | ROUTINE sqlite3_memory_alarm 107 | ROUTINE sqlite3_memory_highwater 108 | ROUTINE sqlite3_memory_used 109 | ROUTINE sqlite3_realloc 110 | ROUTINE sqlite3_release_memory 111 | ROUTINE sqlite3_soft_heap_limit 112 | ROUTINE sqlite3_soft_heap_limit64 113 | ROUTINE sqlite3_mutex_alloc 114 | ROUTINE sqlite3_mutex_enter 115 | ROUTINE sqlite3_mutex_free 116 | ROUTINE sqlite3_mutex_leave 117 | ROUTINE sqlite3_mutex_try 118 | ROUTINE sqlite3_vfs_find 119 | ROUTINE sqlite3_vfs_register 120 | ROUTINE sqlite3_vfs_unregister 121 | ROUTINE sqlite3_os_end 122 | ROUTINE sqlite3_os_init 123 | ROUTINE sqlite3_prepare 124 | ROUTINE sqlite3_prepare_v2 125 | ROUTINE sqlite3_log 126 | ROUTINE sqlite3_mprintf 127 | ROUTINE sqlite3_snprintf 128 | ROUTINE sqlite3_vmprintf 129 | ROUTINE sqlite3_vsnprintf 130 | ROUTINE sqlite3_randomness 131 | ROUTINE sqlite3_db_status 132 | ROUTINE sqlite3_status 133 | ROUTINE sqlite3_free_table 134 | ROUTINE sqlite3_get_table 135 | ROUTINE sqlite3_stricmp 136 | ROUTINE sqlite3_strnicmp 137 | ROUTINE sqlite3_value_numeric_type 138 | ROUTINE sqlite3_aggregate_context 139 | ROUTINE sqlite3_aggregate_count 140 | ROUTINE sqlite3_bind_blob 141 | ROUTINE sqlite3_bind_double 142 | ROUTINE sqlite3_bind_int 143 | ROUTINE sqlite3_bind_int64 144 | ROUTINE sqlite3_bind_null 145 | ROUTINE sqlite3_bind_parameter_count 146 | ROUTINE sqlite3_bind_parameter_index 147 | ROUTINE sqlite3_bind_parameter_name 148 | ROUTINE sqlite3_bind_text 149 | ROUTINE sqlite3_bind_value 150 | ROUTINE sqlite3_bind_zeroblob 151 | ROUTINE sqlite3_clear_bindings 152 | ROUTINE sqlite3_column_blob 153 | ROUTINE sqlite3_column_bytes 154 | ROUTINE sqlite3_column_bytes16 155 | ROUTINE sqlite3_column_count 156 | ROUTINE sqlite3_column_database_name 157 | ROUTINE sqlite3_column_decltype 158 | ROUTINE sqlite3_column_double 159 | ROUTINE sqlite3_column_int 160 | ROUTINE sqlite3_column_int64 161 | ROUTINE sqlite3_column_name 162 | ROUTINE sqlite3_column_origin_name 163 | ROUTINE sqlite3_column_table_name 164 | ROUTINE sqlite3_column_text 165 | ROUTINE sqlite3_column_type 166 | ROUTINE sqlite3_column_value 167 | ROUTINE sqlite3_context_db_handle 168 | ROUTINE sqlite3_data_count 169 | ROUTINE sqlite3_db_handle 170 | ROUTINE sqlite3_expired 171 | ROUTINE sqlite3_finalize 172 | ROUTINE sqlite3_get_auxdata 173 | ROUTINE sqlite3_next_stmt 174 | ROUTINE sqlite3_reset 175 | ROUTINE sqlite3_result_blob 176 | ROUTINE sqlite3_result_double 177 | ROUTINE sqlite3_result_error 178 | ROUTINE sqlite3_result_error_code 179 | ROUTINE sqlite3_result_error_nomem 180 | ROUTINE sqlite3_result_error_toobig 181 | ROUTINE sqlite3_result_int 182 | ROUTINE sqlite3_result_int64 183 | ROUTINE sqlite3_result_null 184 | ROUTINE sqlite3_result_text 185 | ROUTINE sqlite3_result_value 186 | ROUTINE sqlite3_result_zeroblob 187 | ROUTINE sqlite3_set_auxdata 188 | ROUTINE sqlite3_step 189 | ROUTINE sqlite3_stmt_busy 190 | ROUTINE sqlite3_stmt_readonly 191 | ROUTINE sqlite3_stmt_status 192 | ROUTINE sqlite3_transfer_bindings 193 | ROUTINE sqlite3_user_data 194 | ROUTINE sqlite3_value_blob 195 | ROUTINE sqlite3_value_bytes 196 | ROUTINE sqlite3_value_bytes16 197 | ROUTINE sqlite3_value_double 198 | ROUTINE sqlite3_value_int 199 | ROUTINE sqlite3_value_int64 200 | ROUTINE sqlite3_value_text 201 | ROUTINE sqlite3_value_type 202 | ROUTINE sqlite3_sql 203 | ROUTINE sqlite3_blob_bytes 204 | ROUTINE sqlite3_blob_close 205 | ROUTINE sqlite3_blob_open 206 | ROUTINE sqlite3_blob_read 207 | ROUTINE sqlite3_blob_reopen 208 | ROUTINE sqlite3_blob_write 209 | ROUTINE sqlite3_create_module 210 | ROUTINE sqlite3_create_module_v2 211 | ROUTINE sqlite3_declare_vtab 212 | ROUTINE sqlite3_vtab_config 213 | ROUTINE sqlite3_vtab_on_conflict 214 | 215 | .END 216 | -------------------------------------------------------------------------------- /sqlite3_vector.vax_opt: -------------------------------------------------------------------------------- 1 | ! 2 | ! 2013 March 31 3 | ! 4 | ! The author disclaims copyright to this source code. In place of 5 | ! a legal notice, here is a blessing: 6 | ! 7 | ! May you do good and not evil. 8 | ! May you find forgiveness for yourself and forgive others. 9 | ! May you share freely, never taking more than you give. 10 | ! 11 | !*********************************************************************** 12 | ! This is a dummy file that make our description file. It doesn't actually 13 | ! do anything. 14 | ! 15 | -------------------------------------------------------------------------------- /sqlite3rtree.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2010 August 30 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ************************************************************************* 12 | */ 13 | 14 | #ifndef _SQLITE3RTREE_H_ 15 | #define _SQLITE3RTREE_H_ 16 | 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | typedef struct sqlite3_rtree_geometry sqlite3_rtree_geometry; 23 | 24 | /* 25 | ** Register a geometry callback named zGeom that can be used as part of an 26 | ** R-Tree geometry query as follows: 27 | ** 28 | ** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...) 29 | */ 30 | SQLITE_API int sqlite3_rtree_geometry_callback( 31 | sqlite3 *db, 32 | const char *zGeom, 33 | #ifdef SQLITE_RTREE_INT_ONLY 34 | int (*xGeom)(sqlite3_rtree_geometry*, int n, sqlite3_int64 *a, int *pRes), 35 | #else 36 | int (*xGeom)(sqlite3_rtree_geometry*, int n, double *a, int *pRes), 37 | #endif 38 | void *pContext 39 | ); 40 | 41 | /* 42 | ** A pointer to a structure of the following type is passed as the first 43 | ** argument to callbacks registered using rtree_geometry_callback(). 44 | */ 45 | struct sqlite3_rtree_geometry { 46 | void *pContext; /* Copy of pContext passed to s_r_g_c() */ 47 | int nParam; /* Size of array aParam[] */ 48 | double *aParam; /* Parameters passed to SQL geom function */ 49 | void *pUser; /* Callback implementation user data */ 50 | void (*xDelUser)(void *); /* Called by SQLite to clean up pUser */ 51 | }; 52 | 53 | 54 | #ifdef __cplusplus 55 | } /* end of the 'extern "C"' block */ 56 | #endif 57 | 58 | #endif /* ifndef _SQLITE3RTREE_H_ */ 59 | -------------------------------------------------------------------------------- /sqliteicu.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2008 May 26 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ****************************************************************************** 12 | ** 13 | ** This header file is used by programs that want to link against the 14 | ** ICU extension. All it does is declare the sqlite3IcuInit() interface. 15 | */ 16 | #include "sqlite3.h" 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif /* __cplusplus */ 21 | 22 | int sqlite3IcuInit(sqlite3 *db); 23 | 24 | #ifdef __cplusplus 25 | } /* extern "C" */ 26 | #endif /* __cplusplus */ 27 | 28 | -------------------------------------------------------------------------------- /sqlitelimit.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2007 May 7 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ************************************************************************* 12 | ** 13 | ** This file defines various limits of what SQLite can process. 14 | */ 15 | 16 | /* 17 | ** The maximum length of a TEXT or BLOB in bytes. This also 18 | ** limits the size of a row in a table or index. 19 | ** 20 | ** The hard limit is the ability of a 32-bit signed integer 21 | ** to count the size: 2^31-1 or 2147483647. 22 | */ 23 | #ifndef SQLITE_MAX_LENGTH 24 | # define SQLITE_MAX_LENGTH 1000000000 25 | #endif 26 | 27 | /* 28 | ** This is the maximum number of 29 | ** 30 | ** * Columns in a table 31 | ** * Columns in an index 32 | ** * Columns in a view 33 | ** * Terms in the SET clause of an UPDATE statement 34 | ** * Terms in the result set of a SELECT statement 35 | ** * Terms in the GROUP BY or ORDER BY clauses of a SELECT statement. 36 | ** * Terms in the VALUES clause of an INSERT statement 37 | ** 38 | ** The hard upper limit here is 32676. Most database people will 39 | ** tell you that in a well-normalized database, you usually should 40 | ** not have more than a dozen or so columns in any table. And if 41 | ** that is the case, there is no point in having more than a few 42 | ** dozen values in any of the other situations described above. 43 | */ 44 | #ifndef SQLITE_MAX_COLUMN 45 | # define SQLITE_MAX_COLUMN 2000 46 | #endif 47 | 48 | /* 49 | ** The maximum length of a single SQL statement in bytes. 50 | ** 51 | ** It used to be the case that setting this value to zero would 52 | ** turn the limit off. That is no longer true. It is not possible 53 | ** to turn this limit off. 54 | */ 55 | #ifndef SQLITE_MAX_SQL_LENGTH 56 | # define SQLITE_MAX_SQL_LENGTH 1000000000 57 | #endif 58 | 59 | /* 60 | ** The maximum depth of an expression tree. This is limited to 61 | ** some extent by SQLITE_MAX_SQL_LENGTH. But sometime you might 62 | ** want to place more severe limits on the complexity of an 63 | ** expression. 64 | ** 65 | ** A value of 0 used to mean that the limit was not enforced. 66 | ** But that is no longer true. The limit is now strictly enforced 67 | ** at all times. 68 | */ 69 | #ifndef SQLITE_MAX_EXPR_DEPTH 70 | # define SQLITE_MAX_EXPR_DEPTH 1000 71 | #endif 72 | 73 | /* 74 | ** The maximum number of terms in a compound SELECT statement. 75 | ** The code generator for compound SELECT statements does one 76 | ** level of recursion for each term. A stack overflow can result 77 | ** if the number of terms is too large. In practice, most SQL 78 | ** never has more than 3 or 4 terms. Use a value of 0 to disable 79 | ** any limit on the number of terms in a compount SELECT. 80 | */ 81 | #ifndef SQLITE_MAX_COMPOUND_SELECT 82 | # define SQLITE_MAX_COMPOUND_SELECT 500 83 | #endif 84 | 85 | /* 86 | ** The maximum number of opcodes in a VDBE program. 87 | ** Not currently enforced. 88 | */ 89 | #ifndef SQLITE_MAX_VDBE_OP 90 | # define SQLITE_MAX_VDBE_OP 25000 91 | #endif 92 | 93 | /* 94 | ** The maximum number of arguments to an SQL function. 95 | */ 96 | #ifndef SQLITE_MAX_FUNCTION_ARG 97 | # define SQLITE_MAX_FUNCTION_ARG 127 98 | #endif 99 | 100 | /* 101 | ** The maximum number of in-memory pages to use for the main database 102 | ** table and for temporary tables. The SQLITE_DEFAULT_CACHE_SIZE 103 | */ 104 | #ifndef SQLITE_DEFAULT_CACHE_SIZE 105 | # define SQLITE_DEFAULT_CACHE_SIZE 2000 106 | #endif 107 | #ifndef SQLITE_DEFAULT_TEMP_CACHE_SIZE 108 | # define SQLITE_DEFAULT_TEMP_CACHE_SIZE 500 109 | #endif 110 | 111 | /* 112 | ** The default number of frames to accumulate in the log file before 113 | ** checkpointing the database in WAL mode. 114 | */ 115 | #ifndef SQLITE_DEFAULT_WAL_AUTOCHECKPOINT 116 | # define SQLITE_DEFAULT_WAL_AUTOCHECKPOINT 1000 117 | #endif 118 | 119 | /* 120 | ** The maximum number of attached databases. This must be between 0 121 | ** and 62. The upper bound on 62 is because a 64-bit integer bitmap 122 | ** is used internally to track attached databases. 123 | */ 124 | #ifndef SQLITE_MAX_ATTACHED 125 | # define SQLITE_MAX_ATTACHED 10 126 | #endif 127 | 128 | 129 | /* 130 | ** The maximum value of a ?nnn wildcard that the parser will accept. 131 | */ 132 | #ifndef SQLITE_MAX_VARIABLE_NUMBER 133 | # define SQLITE_MAX_VARIABLE_NUMBER 999 134 | #endif 135 | 136 | /* Maximum page size. The upper bound on this value is 65536. This a limit 137 | ** imposed by the use of 16-bit offsets within each page. 138 | ** 139 | ** Earlier versions of SQLite allowed the user to change this value at 140 | ** compile time. This is no longer permitted, on the grounds that it creates 141 | ** a library that is technically incompatible with an SQLite library 142 | ** compiled with a different limit. If a process operating on a database 143 | ** with a page-size of 65536 bytes crashes, then an instance of SQLite 144 | ** compiled with the default page-size limit will not be able to rollback 145 | ** the aborted transaction. This could lead to database corruption. 146 | */ 147 | #ifdef SQLITE_MAX_PAGE_SIZE 148 | # undef SQLITE_MAX_PAGE_SIZE 149 | #endif 150 | #define SQLITE_MAX_PAGE_SIZE 65536 151 | 152 | 153 | /* 154 | ** The default size of a database page. 155 | */ 156 | #ifndef SQLITE_DEFAULT_PAGE_SIZE 157 | # define SQLITE_DEFAULT_PAGE_SIZE 1024 158 | #endif 159 | #if SQLITE_DEFAULT_PAGE_SIZE>SQLITE_MAX_PAGE_SIZE 160 | # undef SQLITE_DEFAULT_PAGE_SIZE 161 | # define SQLITE_DEFAULT_PAGE_SIZE SQLITE_MAX_PAGE_SIZE 162 | #endif 163 | 164 | /* 165 | ** Ordinarily, if no value is explicitly provided, SQLite creates databases 166 | ** with page size SQLITE_DEFAULT_PAGE_SIZE. However, based on certain 167 | ** device characteristics (sector-size and atomic write() support), 168 | ** SQLite may choose a larger value. This constant is the maximum value 169 | ** SQLite will choose on its own. 170 | */ 171 | #ifndef SQLITE_MAX_DEFAULT_PAGE_SIZE 172 | # define SQLITE_MAX_DEFAULT_PAGE_SIZE 8192 173 | #endif 174 | #if SQLITE_MAX_DEFAULT_PAGE_SIZE>SQLITE_MAX_PAGE_SIZE 175 | # undef SQLITE_MAX_DEFAULT_PAGE_SIZE 176 | # define SQLITE_MAX_DEFAULT_PAGE_SIZE SQLITE_MAX_PAGE_SIZE 177 | #endif 178 | 179 | 180 | /* 181 | ** Maximum number of pages in one database file. 182 | ** 183 | ** This is really just the default value for the max_page_count pragma. 184 | ** This value can be lowered (or raised) at run-time using that the 185 | ** max_page_count macro. 186 | */ 187 | #ifndef SQLITE_MAX_PAGE_COUNT 188 | # define SQLITE_MAX_PAGE_COUNT 1073741823 189 | #endif 190 | 191 | /* 192 | ** Maximum length (in bytes) of the pattern in a LIKE or GLOB 193 | ** operator. 194 | */ 195 | #ifndef SQLITE_MAX_LIKE_PATTERN_LENGTH 196 | # define SQLITE_MAX_LIKE_PATTERN_LENGTH 50000 197 | #endif 198 | 199 | /* 200 | ** Maximum depth of recursion for triggers. 201 | ** 202 | ** A value of 1 means that a trigger program will not be able to itself 203 | ** fire any triggers. A value of 0 means that no trigger programs at all 204 | ** may be executed. 205 | */ 206 | #ifndef SQLITE_MAX_TRIGGER_DEPTH 207 | # define SQLITE_MAX_TRIGGER_DEPTH 1000 208 | #endif 209 | -------------------------------------------------------------------------------- /squ.tec: -------------------------------------------------------------------------------- 1 | !SQU.TEC V4-001!@F0ED0ET&128"N0,0XP'0,128ETJ<@FS%^ES%%;>J:S/UB 2 | QB"TET&64"E 3 | ''@R\[0[1[2[3+0U3X0K.U1ZJ.U2Q3&127"R| 4 | ?Invalid Q-register in INPLIN 5 | OEXIT'IQ2,.XQ3&127IQ2,.X1Q2,.K!PROMPT!13ET&512"N0,1ET271,0ET 6 | 0:W-4"E['J|10'.-Q2+(0)"G0T|:G0Q2,ZT'!GETCH!U0Q0-127"EZ-Q2"N-D' 7 | OPROMPT'Q0-21"EQ2,ZKOPROMPT'Q0-18"E1310:G0Q2,ZTOGETCH'Q0-26"E 8 | Q2,ZK%0'Q0-27"E1310ODONE'Q3&128"EQ0-10"E13ODONE'Q0-13"EODONE' 9 | 'Q0IOGETCH!DONE!M1Q2,.K!EXIT!Q1J]3]2]1]0\0,0X9J:@FS%/D%%"S 10 | ::@FS%:%%"S0AQD|QY'|QB"TQ|IDelete CR/LF (Y/N) <N>? QMR''0QQ"A 11 | 0QQ&95-Y"E9DA.......TD..D.......U....Z...V.D''!BADNUM!0UO:Q9"NJ 12 | :@FS%/L%%"S%/L specified with /D, /L ignored 13 | ::@FS%:%%"S0A"D<D.-Z;0A"D>'|D'''|J:@FS%/L%%"S::@FS%:%%"S0AQ0A"D<D 14 | .-Z;0A"D0A:Q>'|D'|QY'|QB"TQ| 15 | ISet line lengths (Y for 70, N, or length) <N>? QMR''0QQ"A 16 | 0QQ&95-Y"E9DA.......TO..O.......U....Z...V.O70UO''0QQ"D.UQZJGQC\UO 17 | D.-Z"NZKQQJOBADNUM'QQJQO"EOBADNUM' 18 | 9DA.......TO..O.......U....Z...V.O'':Q9"NJ:@FS%/B%%"S::@FS%:%%"S 19 | 0A-N"E%/B:N specified with /D or /L, /B:N ignored 20 | 'D''|J:@FS%/B%%"S::@FS%:%%"S0AQD|QY'|QB"TQ| 21 | IDelete blank lines (Y/N) <N>? QMR''0QQ"A0QQ&95-Y"E 22 | 9DA.......TB..........U....Z...V.D''':Q9"E 23 | 9DA.......T...........U....Z...V.D'J:@FS%/T%%"S::@FS%:%%"S0AQD| 24 | QY'|QB"TQ|IDelete lexical TABs and FORM FEEDs (Y/N) <N>? QMR'' 25 | 0QQ"A0QQ&95Q'0QQ-Y"EJG99JDIO12JDIOJ0,33X90,33K'CJ:@FS%/C%%"S 26 | ::@FS%:%%"S0AQD|QY'|QB"TQ| 27 | IDelete comments (Y for SP/TAB, N, or set) <N>? QMR'':QQ"EQN'0QQUQ 28 | QQ"VQQ-32UQ'QQ-N"E:9A|:9CQQ-Y"E32C9:C|GQXCK'' 29 | :91..1..........................:9@....EF1.$...1$$.1.$.1..1..1.1^$ 30 | :9.LLLLLLLLLLLLLLLLLLLLLLLLLL....D8/#*&\?()$!@1U8126<Q8:8%8>W 31 | ET&512"EJ:@FS%/W%%"S::@FS%:%%"SD''|J:@FS%/W%%"S::@FS%:%%"S0AQD|QY' 32 | |QB"TQ|IWatch progress (Y/N) <N>? QMR''0QQ"A0QQ&95-Y"E0:W-2"E 33 | 4,0:W'W-1W'''KJ:@FS%/A%%"S::@FS%:%%"S0AQD|QY'|QB"TQY| 34 | IAutomatic mode (Y for %, N, or set) <N>? QMR'':QQ"N0QQUQQQ"VQQ-32UQ 35 | 'QQ-N"NQQ-Y"E%K|GQXKK'''0UHJ:@FS%/E%%"S::@FS%:%%"S0AQD|QY'| 36 | QB"TQ|IAllow adjacent ESCapes (Y/N) <N>? QMR''0QQ"A0QQ&95-Y"E-1UH 37 | ''@Z*[10U1:QW"N-1,3:W0,4:W0,5:W'<!..!MW!.!ME;0AU0Q0"LOOFFEND'C 38 | Q0&128"NQ0&127U0-DQ0I'!DISP!Q0Q90O^EQ0!L!Q0-32U0-DQ0IODISP!^! 39 | 0A&31U0C-2DQH"FQ0-27"E0A-27"EI^[CO..'.US0UT<-.;R0AUTQT&128"EQT-10"N 40 | 0;|-.;-1A-128-13"N0;'''>QSJQT-27"EI '''Q0IODISP!B!-1+2"E-2D'O.. 41 | !O!-D."N-1A&128"N-D'.-1"G-1A-10"E-2A-128-13"EQ0-13"E-2D|O..'''' 42 | Q0#128IQ0-13"E.-Z"E10IR'0A&127-10"ED'10I''O..!U!271.UC0AU0C 43 | Q0-."E0AU0C'Q0"VQ0-32U0-DQ0I'Q1"T0A-(1A)"EO$$'|0A-27"EO$$''.USQ1"T 44 | 0A1D':QW"N:S^EQ1"UOSTRINGFAIL'.,4:WQSJMW':QK"E:QW"E0T10T'7ETUQ 45 | ET#8#4-4ETU0QQET|G1R::S^EGK"S-DNU0|DYU0'':QW"N0,4:W32768W'Q0-Y"E 46 | [EE-1UE 0A-^^0Q1:E:E"E0UE'QE[SMZ]S]C]E"NOPRIORFAIL'CO$$$$' 47 | O$$$!T!0U1!$!271.UC!$$!.USQ1"T0A1D'!$$$!:S^EQ1"UOSTRINGFAIL' 48 | !$$$$!-D.UT27U0!AA!Q00QT-QS"GQSJQT-QS,:S^EQ0"SG8:X1K0U0<Q0Q10 49 | QSJQT-QS,S^EQ0;%0-:Q8"EONOQUOTE'>Q0Q1U0QSJQ0IQC-1JI@2%T''QTJQ0I 50 | 0U1O..!1!0A-."EC'0A"V0A-32U0DQ0IO.'!V!CO.!@!-1U1!D!-DO.!F!271 51 | .UC0AU0CQ0"VQ0-32U0-DQ0I'Q0-B"EO$$'Q0-C"EOF$$'Q0-R"EO$$'Q0-S"E 52 | OF$$'Q0-N"EOF$$'Q0-_"EOF$$'O.!F$$!.US271Q1"T0A1D':S^EQ1"U 53 | OSTRINGFAIL'-D.UT:S^EQ1"UOSTRINGFAIL'-D.UUQH"T27U0Q00QU-QS"GQSJ 54 | QU-QS,:S^EQ0"UOF0'|OF0'|QU-QT"G27U0Q00QSJQU-QS,:S^EQ0"UOF0'''G8 55 | :X1K0U0<Q0Q10QSJQU-QS,S^EQ0;%0-:Q8"EONOQUOTE'>Q0Q1U0QSJQ0IQC-1J 56 | I@2%T2%U!F0!QTJQ0IQU-QTCQ0I0U1O..!A!Q01.UC.USQ1"T0A1D' 57 | :S^EQ1"UOSTRINGFAIL'-D.UTOAA!C!::S^EGC"UOA'R.UCQ01Q1"T0A1D' 58 | :S^EQ1"UOSTRINGFAIL'QC-1,.K0U1O..!E!271.UC0AU0CQ0"VQ0-32U0-DQ0I' 59 | Q0-B"EO$$'Q0-G"EO$$'Q0-I"EO$$'Q0-N"EO$$'Q0-R"EO$$'Q0-W"E 60 | O$$'Q0-_"EO$$'O.!Z!-DI^ZO..>Q1"T1Trailing, pending @OERROR' 61 | 0U10"N!OFFEND!1End of buffer while sub-squishingOERROR!NOQUOTE! 62 | 1Can't find a quote characterOSETPOS!PRIORFAIL! 63 | 1Prior recursion level failedOSETPOS!STRINGFAIL! 64 | 1Unterminated string!SETPOS!:1 from squished .=QC\:X1K13:1 65 | 10:1QCJ0+.,.:X1|:110:1|:1.,+.:X1!ERROR!ZJMW0,0XW7?:G17 66 | 1310-1U1'Q1]1*@A*-1E.-ZQO"NZJI 'JMZ"EQO"N:QW"N-1,3:W0,4:W 67 | 0,5:W'J<MW<0A&128"N0;'C>0A&127-13"ED'D.-Z;.U0<0A&128"N0;'C><.U10L 68 | .-Q0-1"L0;'R>Q1J-(0)-QO"GQ0J-1A-27"EI 'I 69 | '><ZJ-Z;-1A-10"N-1A-13"N-1A-32"N0;'''-D>MW'QH"FZJ."E10I'-1A-10"N10I 70 | 'R."E13I'-1A-13"N13I''ZJ:QW"N0:W-4"E2,0:W'-1,3:W0,4:WMW'| 71 | ?Squish run failed; aborting any output 72 | 0,0XF'0*Z"EIFile <.TES or .TEC>? QMRGQ'0,0XR0,0XQEIMF0,0XFZ"E 73 | Enter your macro then type MA$$ 74 | |J:@FS%=%%"SFEW0,.:XF.UF-:S."U:F.TEC'QFJ27:FQB"TET&64"E:F 75 | Creating ":G*" 76 | ''0,.K'J:S."UZJI.TESHXQ:ER^EQQ"U-FS.TES.TEC''HXQHKER^EQQQB"T 77 | ET&64"ESquishing ":G*" 78 | '':QF"EY128,0ET<"TZJ12I':A;>MAMP|YQB"F128,0ET'"T"TZJ12I'MAMFHPW 79 | HK|MF<"TZJ12I'MAHPWHK:Y;>'EFEX'' 80 | -------------------------------------------------------------------------------- /symbol_vector.txt: -------------------------------------------------------------------------------- 1 | sqlite3_set_authorizer,0,P 2 | sqlite3_backup_finish,0,P 3 | sqlite3_backup_init,0,P 4 | sqlite3_backup_pagecount,0,P 5 | sqlite3_backup_remaining,0,P 6 | sqlite3_backup_step,0,P 7 | sqlite3_enable_shared_cache,0,P 8 | sqlite3_complete,0,P 9 | sqlite3_compileoption_get,0,P 10 | sqlite3_compileoption_used,0,P 11 | sqlite3_exec,0,P 12 | sqlite3_auto_extension,0,P 13 | sqlite3_enable_load_extension,0,P 14 | sqlite3_load_extension,0,P 15 | sqlite3_reset_auto_extension,0,P 16 | sqlite3_busy_handler,0,P 17 | sqlite3_busy_timeout,0,P 18 | sqlite3_changes,0,P 19 | sqlite3_close,0,P 20 | sqlite3_close_v2,0,P 21 | sqlite3_collation_needed,0,P 22 | sqlite3_commit_hook,0,P 23 | sqlite3_config,0,P 24 | sqlite3_create_collation,0,P 25 | sqlite3_create_collation_v2,0,P 26 | sqlite3_create_function,0,P 27 | sqlite3_create_function_v2,0,P 28 | sqlite3_data_directory,0,D 29 | sqlite3_db_config,0,P 30 | sqlite3_db_filename,0,P 31 | sqlite3_db_mutex,0,P 32 | sqlite3_db_readonly,0,P 33 | sqlite3_db_release_memory,0,P 34 | sqlite3_errcode,0,P 35 | sqlite3_errmsg,0,P 36 | sqlite3_errstr,0,P 37 | sqlite3_extended_errcode,0,P 38 | sqlite3_extended_result_codes,0,P 39 | sqlite3_file_control,0,P 40 | sqlite3_get_autocommit,0,P 41 | sqlite3_global_recover,0,P 42 | sqlite3_initialize,0,P 43 | sqlite3_interrupt,0,P 44 | sqlite3_last_insert_rowid,0,P 45 | sqlite3_libversion,0,P 46 | sqlite3_libversion_number,0,P 47 | sqlite3_limit,0,P 48 | sqlite3_open,0,P 49 | sqlite3_open_v2,0,P 50 | sqlite3_overload_function,0,P 51 | sqlite3_profile,0,P 52 | sqlite3_progress_handler,0,P 53 | sqlite3_rollback_hook,0,P 54 | sqlite3_shutdown,0,P 55 | sqlite3_sleep,0,P 56 | sqlite3_sourceid,0,P 57 | sqlite3_table_column_metadata,0,P 58 | sqlite3_temp_directory,0,D 59 | sqlite3_test_control,0,P 60 | sqlite3_thread_cleanup,0,P 61 | sqlite3_threadsafe,0,P 62 | sqlite3_total_changes,0,P 63 | sqlite3_trace,0,P 64 | sqlite3_update_hook,0,P 65 | sqlite3_uri_boolean,0,P 66 | sqlite3_uri_int64,0,P 67 | sqlite3_uri_parameter,0,P 68 | sqlite3_version,0,D 69 | sqlite3_wal_autocheckpoint,0,P 70 | sqlite3_wal_checkpoint,0,P 71 | sqlite3_wal_checkpoint_v2,0,P 72 | sqlite3_wal_hook,0,P 73 | sqlite3_free,0,P 74 | sqlite3_malloc,0,P 75 | sqlite3_memory_alarm,0,P 76 | sqlite3_memory_highwater,0,P 77 | sqlite3_memory_used,0,P 78 | sqlite3_realloc,0,P 79 | sqlite3_release_memory,0,P 80 | sqlite3_soft_heap_limit,0,P 81 | sqlite3_soft_heap_limit64,0,P 82 | sqlite3_mutex_alloc,0,P 83 | sqlite3_mutex_enter,0,P 84 | sqlite3_mutex_free,0,P 85 | sqlite3_mutex_leave,0,P 86 | sqlite3_mutex_try,0,P 87 | sqlite3_vfs_find,0,P 88 | sqlite3_vfs_register,0,P 89 | sqlite3_vfs_unregister,0,P 90 | sqlite3_os_end,0,P 91 | sqlite3_os_init,0,P 92 | sqlite3_prepare,0,P 93 | sqlite3_prepare_v2,0,P 94 | sqlite3_log,0,P 95 | sqlite3_mprintf,0,P 96 | sqlite3_snprintf,0,P 97 | sqlite3_vmprintf,0,P 98 | sqlite3_vsnprintf,0,P 99 | sqlite3_randomness,0,P 100 | sqlite3_db_status,0,P 101 | sqlite3_status,0,P 102 | sqlite3_free_table,0,P 103 | sqlite3_get_table,0,P 104 | sqlite3_stricmp,0,P 105 | sqlite3_strnicmp,0,P 106 | sqlite3_value_numeric_type,0,P 107 | sqlite3_aggregate_context,0,P 108 | sqlite3_aggregate_count,0,P 109 | sqlite3_bind_blob,0,P 110 | sqlite3_bind_double,0,P 111 | sqlite3_bind_int,0,P 112 | sqlite3_bind_int64,0,P 113 | sqlite3_bind_null,0,P 114 | sqlite3_bind_parameter_count,0,P 115 | sqlite3_bind_parameter_index,0,P 116 | sqlite3_bind_parameter_name,0,P 117 | sqlite3_bind_text,0,P 118 | sqlite3_bind_value,0,P 119 | sqlite3_bind_zeroblob,0,P 120 | sqlite3_clear_bindings,0,P 121 | sqlite3_column_blob,0,P 122 | sqlite3_column_bytes,0,P 123 | sqlite3_column_bytes16,0,P 124 | sqlite3_column_count,0,P 125 | sqlite3_column_database_name,0,P 126 | sqlite3_column_decltype,0,P 127 | sqlite3_column_double,0,P 128 | sqlite3_column_int,0,P 129 | sqlite3_column_int64,0,P 130 | sqlite3_column_name,0,P 131 | sqlite3_column_origin_name,0,P 132 | sqlite3_column_table_name,0,P 133 | sqlite3_column_text,0,P 134 | sqlite3_column_type,0,P 135 | sqlite3_column_value,0,P 136 | sqlite3_context_db_handle,0,P 137 | sqlite3_data_count,0,P 138 | sqlite3_db_handle,0,P 139 | sqlite3_expired,0,P 140 | sqlite3_finalize,0,P 141 | sqlite3_get_auxdata,0,P 142 | sqlite3_next_stmt,0,P 143 | sqlite3_reset,0,P 144 | sqlite3_result_blob,0,P 145 | sqlite3_result_double,0,P 146 | sqlite3_result_error,0,P 147 | sqlite3_result_error_code,0,P 148 | sqlite3_result_error_nomem,0,P 149 | sqlite3_result_error_toobig,0,P 150 | sqlite3_result_int,0,P 151 | sqlite3_result_int64,0,P 152 | sqlite3_result_null,0,P 153 | sqlite3_result_text,0,P 154 | sqlite3_result_value,0,P 155 | sqlite3_result_zeroblob,0,P 156 | sqlite3_set_auxdata,0,P 157 | sqlite3_step,0,P 158 | sqlite3_stmt_busy,0,P 159 | sqlite3_stmt_readonly,0,P 160 | sqlite3_stmt_status,0,P 161 | sqlite3_transfer_bindings,0,P 162 | sqlite3_user_data,0,P 163 | sqlite3_value_blob,0,P 164 | sqlite3_value_bytes,0,P 165 | sqlite3_value_bytes16,0,P 166 | sqlite3_value_double,0,P 167 | sqlite3_value_int,0,P 168 | sqlite3_value_int64,0,P 169 | sqlite3_value_text,0,P 170 | sqlite3_value_type,0,P 171 | sqlite3_sql,0,P 172 | sqlite3_blob_bytes,0,P 173 | sqlite3_blob_close,0,P 174 | sqlite3_blob_open,0,P 175 | sqlite3_blob_read,0,P 176 | sqlite3_blob_reopen,0,P 177 | sqlite3_blob_write,0,P 178 | sqlite3_create_module,0,P 179 | sqlite3_create_module_v2,0,P 180 | sqlite3_declare_vtab,0,P 181 | sqlite3_vtab_config,0,P 182 | sqlite3_vtab_on_conflict,0,P 183 | -------------------------------------------------------------------------------- /table.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2001 September 15 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ************************************************************************* 12 | ** This file contains the sqlite3_get_table() and sqlite3_free_table() 13 | ** interface routines. These are just wrappers around the main 14 | ** interface routine of sqlite3_exec(). 15 | ** 16 | ** These routines are in a separate files so that they will not be linked 17 | ** if they are not used. 18 | */ 19 | #include "sqliteInt.h" 20 | #include <stdlib.h> 21 | #include <string.h> 22 | 23 | #ifndef SQLITE_OMIT_GET_TABLE 24 | 25 | /* 26 | ** This structure is used to pass data from sqlite3_get_table() through 27 | ** to the callback function is uses to build the result. 28 | */ 29 | typedef struct TabResult { 30 | char **azResult; /* Accumulated output */ 31 | char *zErrMsg; /* Error message text, if an error occurs */ 32 | int nAlloc; /* Slots allocated for azResult[] */ 33 | int nRow; /* Number of rows in the result */ 34 | int nColumn; /* Number of columns in the result */ 35 | int nData; /* Slots used in azResult[]. (nRow+1)*nColumn */ 36 | int rc; /* Return code from sqlite3_exec() */ 37 | } TabResult; 38 | 39 | /* 40 | ** This routine is called once for each row in the result table. Its job 41 | ** is to fill in the TabResult structure appropriately, allocating new 42 | ** memory as necessary. 43 | */ 44 | static int sqlite3_get_table_cb(void *pArg, int nCol, char **argv, char **colv){ 45 | TabResult *p = (TabResult*)pArg; /* Result accumulator */ 46 | int need; /* Slots needed in p->azResult[] */ 47 | int i; /* Loop counter */ 48 | char *z; /* A single column of result */ 49 | 50 | /* Make sure there is enough space in p->azResult to hold everything 51 | ** we need to remember from this invocation of the callback. 52 | */ 53 | if( p->nRow==0 && argv!=0 ){ 54 | need = nCol*2; 55 | }else{ 56 | need = nCol; 57 | } 58 | if( p->nData + need > p->nAlloc ){ 59 | char **azNew; 60 | p->nAlloc = p->nAlloc*2 + need; 61 | azNew = sqlite3_realloc( p->azResult, sizeof(char*)*p->nAlloc ); 62 | if( azNew==0 ) goto malloc_failed; 63 | p->azResult = azNew; 64 | } 65 | 66 | /* If this is the first row, then generate an extra row containing 67 | ** the names of all columns. 68 | */ 69 | if( p->nRow==0 ){ 70 | p->nColumn = nCol; 71 | for(i=0; i<nCol; i++){ 72 | z = sqlite3_mprintf("%s", colv[i]); 73 | if( z==0 ) goto malloc_failed; 74 | p->azResult[p->nData++] = z; 75 | } 76 | }else if( p->nColumn!=nCol ){ 77 | sqlite3_free(p->zErrMsg); 78 | p->zErrMsg = sqlite3_mprintf( 79 | "sqlite3_get_table() called with two or more incompatible queries" 80 | ); 81 | p->rc = SQLITE_ERROR; 82 | return 1; 83 | } 84 | 85 | /* Copy over the row data 86 | */ 87 | if( argv!=0 ){ 88 | for(i=0; i<nCol; i++){ 89 | if( argv[i]==0 ){ 90 | z = 0; 91 | }else{ 92 | int n = sqlite3Strlen30(argv[i])+1; 93 | z = sqlite3_malloc( n ); 94 | if( z==0 ) goto malloc_failed; 95 | memcpy(z, argv[i], n); 96 | } 97 | p->azResult[p->nData++] = z; 98 | } 99 | p->nRow++; 100 | } 101 | return 0; 102 | 103 | malloc_failed: 104 | p->rc = SQLITE_NOMEM; 105 | return 1; 106 | } 107 | 108 | /* 109 | ** Query the database. But instead of invoking a callback for each row, 110 | ** malloc() for space to hold the result and return the entire results 111 | ** at the conclusion of the call. 112 | ** 113 | ** The result that is written to ***pazResult is held in memory obtained 114 | ** from malloc(). But the caller cannot free this memory directly. 115 | ** Instead, the entire table should be passed to sqlite3_free_table() when 116 | ** the calling procedure is finished using it. 117 | */ 118 | int sqlite3_get_table( 119 | sqlite3 *db, /* The database on which the SQL executes */ 120 | const char *zSql, /* The SQL to be executed */ 121 | char ***pazResult, /* Write the result table here */ 122 | int *pnRow, /* Write the number of rows in the result here */ 123 | int *pnColumn, /* Write the number of columns of result here */ 124 | char **pzErrMsg /* Write error messages here */ 125 | ){ 126 | int rc; 127 | TabResult res; 128 | 129 | *pazResult = 0; 130 | if( pnColumn ) *pnColumn = 0; 131 | if( pnRow ) *pnRow = 0; 132 | if( pzErrMsg ) *pzErrMsg = 0; 133 | res.zErrMsg = 0; 134 | res.nRow = 0; 135 | res.nColumn = 0; 136 | res.nData = 1; 137 | res.nAlloc = 20; 138 | res.rc = SQLITE_OK; 139 | res.azResult = sqlite3_malloc(sizeof(char*)*res.nAlloc ); 140 | if( res.azResult==0 ){ 141 | db->errCode = SQLITE_NOMEM; 142 | return SQLITE_NOMEM; 143 | } 144 | res.azResult[0] = 0; 145 | rc = sqlite3_exec(db, zSql, sqlite3_get_table_cb, &res, pzErrMsg); 146 | assert( sizeof(res.azResult[0])>= sizeof(res.nData) ); 147 | res.azResult[0] = SQLITE_INT_TO_PTR(res.nData); 148 | if( (rc&0xff)==SQLITE_ABORT ){ 149 | sqlite3_free_table(&res.azResult[1]); 150 | if( res.zErrMsg ){ 151 | if( pzErrMsg ){ 152 | sqlite3_free(*pzErrMsg); 153 | *pzErrMsg = sqlite3_mprintf("%s",res.zErrMsg); 154 | } 155 | sqlite3_free(res.zErrMsg); 156 | } 157 | db->errCode = res.rc; /* Assume 32-bit assignment is atomic */ 158 | return res.rc; 159 | } 160 | sqlite3_free(res.zErrMsg); 161 | if( rc!=SQLITE_OK ){ 162 | sqlite3_free_table(&res.azResult[1]); 163 | return rc; 164 | } 165 | if( res.nAlloc>res.nData ){ 166 | char **azNew; 167 | azNew = sqlite3_realloc( res.azResult, sizeof(char*)*res.nData ); 168 | if( azNew==0 ){ 169 | sqlite3_free_table(&res.azResult[1]); 170 | db->errCode = SQLITE_NOMEM; 171 | return SQLITE_NOMEM; 172 | } 173 | res.azResult = azNew; 174 | } 175 | *pazResult = &res.azResult[1]; 176 | if( pnColumn ) *pnColumn = res.nColumn; 177 | if( pnRow ) *pnRow = res.nRow; 178 | return rc; 179 | } 180 | 181 | /* 182 | ** This routine frees the space the sqlite3_get_table() malloced. 183 | */ 184 | void sqlite3_free_table( 185 | char **azResult /* Result returned from from sqlite3_get_table() */ 186 | ){ 187 | if( azResult ){ 188 | int i, n; 189 | azResult--; 190 | assert( azResult!=0 ); 191 | n = SQLITE_PTR_TO_INT(azResult[0]); 192 | for(i=1; i<n; i++){ if( azResult[i] ) sqlite3_free(azResult[i]); } 193 | sqlite3_free(azResult); 194 | } 195 | } 196 | 197 | #endif /* SQLITE_OMIT_GET_TABLE */ 198 | -------------------------------------------------------------------------------- /vmsshell.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2013 April 4 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ************************************************************************* 12 | ** This file contains OpenVMS-specific routines for implementing the 13 | ** readline and history functions. These are NOT threadsafe and 14 | ** definitely expect to be called from within the shell module only! 15 | */ 16 | #include "sqliteInt.h" 17 | #if SQLITE_OS_VMS /* This file is used for OpenVMS only */ 18 | #include <descrip.h> 19 | #include <rms.h> 20 | #include <smgdef.h> 21 | #include <smg$routines.h> 22 | #include <ssdef.h> 23 | #include <starlet.h> 24 | #include <stdio.h> 25 | #include <stdlib.h> 26 | #include <str$routines.h> 27 | #include <stsdef.h> 28 | #include <unistd.h> 29 | #if defined(VAX) 30 | # include <sys$routines.h> 31 | #endif 32 | extern char *local_getline(char *, FILE *, int); 33 | 34 | /* Private common SMG$ storage */ 35 | static int kb = 0; 36 | static const int recall_size = 100; 37 | 38 | int vms_getname(char **zBuf, struct FAB *fab, struct RAB *rab){ 39 | *zBuf = calloc(1, NAM$C_MAXRSS+1); 40 | if( *zBuf!=0 ){ 41 | fab->fab$l_nam->nam$l_rsa = *zBuf; 42 | fab->fab$l_nam->nam$b_rss = NAM$C_MAXRSS; 43 | fab->fab$l_nam->nam$l_esa = *zBuf; 44 | fab->fab$l_nam->nam$b_ess = NAM$C_MAXRSS; 45 | } 46 | 47 | return 0; 48 | } 49 | void vms_read_history(char *zHistory){ 50 | const int flags = SMG$M_KEEP_CONTENTS; 51 | struct dsc$descriptor sLine = { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0}; 52 | int i, status; 53 | FILE *in; 54 | 55 | status = smg$create_virtual_keyboard(&kb,0,0,0,&recall_size); 56 | if( !$VMS_STATUS_SUCCESS(status) ){ 57 | sys$exit(status); 58 | } 59 | 60 | in = fopen(zHistory,"r","dna=SYS$LOGIN:.DAT"); 61 | if( in==0 ){ 62 | return; 63 | } 64 | 65 | for(i=1; i<=recall_size; i++){ 66 | if( (sLine.dsc$a_pointer = local_getline(0,in,0))==0 ){ 67 | break; 68 | } 69 | sLine.dsc$w_length = strlen(sLine.dsc$a_pointer); 70 | 71 | status = smg$replace_input_line(&kb,&sLine,&i,&flags); 72 | free(sLine.dsc$a_pointer); 73 | if( !$VMS_STATUS_SUCCESS(status) ){ 74 | break; 75 | } 76 | } 77 | 78 | fclose(in); 79 | } 80 | 81 | void vms_write_history(char *zHistory){ 82 | struct dsc$descriptor dLine = { 0, DSC$K_DTYPE_T, DSC$K_CLASS_D, 0}; 83 | int i, status = SS$_NORMAL; 84 | char *zResultant = 0; 85 | FILE *out; 86 | 87 | out = fopen(zHistory,"a+","dna=SYS$LOGIN:.DAT","acc",vms_getname,&zResultant); 88 | if( out==0 ){ 89 | fprintf(stderr, "-- Writing history file %s failed\n", zResultant); 90 | } else { 91 | ftruncate(fileno(out), 0); 92 | 93 | for(i=1; i<=recall_size; i++){ 94 | status = smg$return_input_line(&kb, &dLine, 0, &i); 95 | if( !$VMS_STATUS_SUCCESS(status) || dLine.dsc$w_length==0 ){ 96 | break; 97 | } 98 | fprintf(out, "%.*s\n", dLine.dsc$w_length, dLine.dsc$a_pointer); 99 | } 100 | 101 | str$free1_dx(&dLine); 102 | fclose(out); 103 | } 104 | if( zResultant!=0 ) free(zResultant); 105 | } 106 | 107 | /* 108 | ** This routine reads a line of text from SYS$INPUT, stores 109 | ** the text in memory obtained from malloc() and returns a pointer 110 | ** to the text. NULL is returned at end of file, or if malloc() 111 | ** fails. 112 | ** 113 | ** This interface uses SMG to handle command line recall and command 114 | ** line editing. 115 | */ 116 | char *vms_readline(char *zPrompt){ 117 | static struct dsc$descriptor dLine = { 0, DSC$K_DTYPE_T, DSC$K_CLASS_D, 0}; 118 | struct dsc$descriptor sPrompt; 119 | int status; 120 | char *zLine = 0; 121 | 122 | sPrompt.dsc$b_dtype = DSC$K_DTYPE_T; 123 | sPrompt.dsc$b_class = DSC$K_CLASS_S; 124 | if( zPrompt && *zPrompt ){ 125 | sPrompt.dsc$w_length = strlen(zPrompt); 126 | sPrompt.dsc$a_pointer = zPrompt; 127 | }else{ 128 | sPrompt.dsc$w_length = 0; 129 | sPrompt.dsc$a_pointer = 0; 130 | } 131 | 132 | status = smg$read_composed_line(&kb,0,&dLine,&sPrompt); 133 | if( $VMS_STATUS_SUCCESS(status) ){ 134 | zLine = malloc(dLine.dsc$w_length+1); 135 | if( zLine ){ 136 | memcpy(zLine,dLine.dsc$a_pointer,dLine.dsc$w_length); 137 | zLine[dLine.dsc$w_length] = '\0'; 138 | } 139 | } 140 | 141 | return zLine; 142 | } 143 | 144 | #endif /* SQLITE_OS_VMS */ 145 | -------------------------------------------------------------------------------- /wal.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2010 February 1 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ************************************************************************* 12 | ** This header file defines the interface to the write-ahead logging 13 | ** system. Refer to the comments below and the header comment attached to 14 | ** the implementation of each function in log.c for further details. 15 | */ 16 | 17 | #ifndef _WAL_H_ 18 | #define _WAL_H_ 19 | 20 | #include "sqliteInt.h" 21 | 22 | /* Additional values that can be added to the sync_flags argument of 23 | ** sqlite3WalFrames(): 24 | */ 25 | #define WAL_SYNC_TRANSACTIONS 0x20 /* Sync at the end of each transaction */ 26 | #define SQLITE_SYNC_MASK 0x13 /* Mask off the SQLITE_SYNC_* values */ 27 | 28 | #ifdef SQLITE_OMIT_WAL 29 | # define sqlite3WalOpen(x,y,z) 0 30 | # define sqlite3WalLimit(x,y) 31 | # define sqlite3WalClose(w,x,y,z) 0 32 | # define sqlite3WalBeginReadTransaction(y,z) 0 33 | # define sqlite3WalEndReadTransaction(z) 34 | # define sqlite3WalDbsize(y) 0 35 | # define sqlite3WalBeginWriteTransaction(y) 0 36 | # define sqlite3WalEndWriteTransaction(x) 0 37 | # define sqlite3WalUndo(x,y,z) 0 38 | # define sqlite3WalSavepoint(y,z) 39 | # define sqlite3WalSavepointUndo(y,z) 0 40 | # define sqlite3WalFrames(u,v,w,x,y,z) 0 41 | # define sqlite3WalCheckpoint(r,s,t,u,v,w,x,y,z) 0 42 | # define sqlite3WalCallback(z) 0 43 | # define sqlite3WalExclusiveMode(y,z) 0 44 | # define sqlite3WalHeapMemory(z) 0 45 | # define sqlite3WalFramesize(z) 0 46 | # define sqlite3WalFindFrame(x,y,z) 0 47 | #else 48 | 49 | #define WAL_SAVEPOINT_NDATA 4 50 | 51 | /* Connection to a write-ahead log (WAL) file. 52 | ** There is one object of this type for each pager. 53 | */ 54 | typedef struct Wal Wal; 55 | 56 | /* Open and close a connection to a write-ahead log. */ 57 | int sqlite3WalOpen(sqlite3_vfs*, sqlite3_file*, const char *, int, i64, Wal**); 58 | int sqlite3WalClose(Wal *pWal, int sync_flags, int, u8 *); 59 | 60 | /* Set the limiting size of a WAL file. */ 61 | void sqlite3WalLimit(Wal*, i64); 62 | 63 | /* Used by readers to open (lock) and close (unlock) a snapshot. A 64 | ** snapshot is like a read-transaction. It is the state of the database 65 | ** at an instant in time. sqlite3WalOpenSnapshot gets a read lock and 66 | ** preserves the current state even if the other threads or processes 67 | ** write to or checkpoint the WAL. sqlite3WalCloseSnapshot() closes the 68 | ** transaction and releases the lock. 69 | */ 70 | int sqlite3WalBeginReadTransaction(Wal *pWal, int *); 71 | void sqlite3WalEndReadTransaction(Wal *pWal); 72 | 73 | /* Read a page from the write-ahead log, if it is present. */ 74 | int sqlite3WalFindFrame(Wal *, Pgno, u32 *); 75 | int sqlite3WalReadFrame(Wal *, u32, int, u8 *); 76 | 77 | /* If the WAL is not empty, return the size of the database. */ 78 | Pgno sqlite3WalDbsize(Wal *pWal); 79 | 80 | /* Obtain or release the WRITER lock. */ 81 | int sqlite3WalBeginWriteTransaction(Wal *pWal); 82 | int sqlite3WalEndWriteTransaction(Wal *pWal); 83 | 84 | /* Undo any frames written (but not committed) to the log */ 85 | int sqlite3WalUndo(Wal *pWal, int (*xUndo)(void *, Pgno), void *pUndoCtx); 86 | 87 | /* Return an integer that records the current (uncommitted) write 88 | ** position in the WAL */ 89 | void sqlite3WalSavepoint(Wal *pWal, u32 *aWalData); 90 | 91 | /* Move the write position of the WAL back to iFrame. Called in 92 | ** response to a ROLLBACK TO command. */ 93 | int sqlite3WalSavepointUndo(Wal *pWal, u32 *aWalData); 94 | 95 | /* Write a frame or frames to the log. */ 96 | int sqlite3WalFrames(Wal *pWal, int, PgHdr *, Pgno, int, int); 97 | 98 | /* Copy pages from the log to the database file */ 99 | int sqlite3WalCheckpoint( 100 | Wal *pWal, /* Write-ahead log connection */ 101 | int eMode, /* One of PASSIVE, FULL and RESTART */ 102 | int (*xBusy)(void*), /* Function to call when busy */ 103 | void *pBusyArg, /* Context argument for xBusyHandler */ 104 | int sync_flags, /* Flags to sync db file with (or 0) */ 105 | int nBuf, /* Size of buffer nBuf */ 106 | u8 *zBuf, /* Temporary buffer to use */ 107 | int *pnLog, /* OUT: Number of frames in WAL */ 108 | int *pnCkpt /* OUT: Number of backfilled frames in WAL */ 109 | ); 110 | 111 | /* Return the value to pass to a sqlite3_wal_hook callback, the 112 | ** number of frames in the WAL at the point of the last commit since 113 | ** sqlite3WalCallback() was called. If no commits have occurred since 114 | ** the last call, then return 0. 115 | */ 116 | int sqlite3WalCallback(Wal *pWal); 117 | 118 | /* Tell the wal layer that an EXCLUSIVE lock has been obtained (or released) 119 | ** by the pager layer on the database file. 120 | */ 121 | int sqlite3WalExclusiveMode(Wal *pWal, int op); 122 | 123 | /* Return true if the argument is non-NULL and the WAL module is using 124 | ** heap-memory for the wal-index. Otherwise, if the argument is NULL or the 125 | ** WAL module is using shared-memory, return false. 126 | */ 127 | int sqlite3WalHeapMemory(Wal *pWal); 128 | 129 | #ifdef SQLITE_ENABLE_ZIPVFS 130 | /* If the WAL file is not empty, return the number of bytes of content 131 | ** stored in each frame (i.e. the db page-size when the WAL was created). 132 | */ 133 | int sqlite3WalFramesize(Wal *pWal); 134 | #endif 135 | 136 | #endif /* ifndef SQLITE_OMIT_WAL */ 137 | #endif /* _WAL_H_ */ 138 | -------------------------------------------------------------------------------- /walker.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2008 August 16 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ************************************************************************* 12 | ** This file contains routines used for walking the parser tree for 13 | ** an SQL statement. 14 | */ 15 | #include "sqliteInt.h" 16 | #include <stdlib.h> 17 | #include <string.h> 18 | 19 | 20 | /* 21 | ** Walk an expression tree. Invoke the callback once for each node 22 | ** of the expression, while decending. (In other words, the callback 23 | ** is invoked before visiting children.) 24 | ** 25 | ** The return value from the callback should be one of the WRC_* 26 | ** constants to specify how to proceed with the walk. 27 | ** 28 | ** WRC_Continue Continue descending down the tree. 29 | ** 30 | ** WRC_Prune Do not descend into child nodes. But allow 31 | ** the walk to continue with sibling nodes. 32 | ** 33 | ** WRC_Abort Do no more callbacks. Unwind the stack and 34 | ** return the top-level walk call. 35 | ** 36 | ** The return value from this routine is WRC_Abort to abandon the tree walk 37 | ** and WRC_Continue to continue. 38 | */ 39 | int sqlite3WalkExpr(Walker *pWalker, Expr *pExpr){ 40 | int rc; 41 | if( pExpr==0 ) return WRC_Continue; 42 | testcase( ExprHasProperty(pExpr, EP_TokenOnly) ); 43 | testcase( ExprHasProperty(pExpr, EP_Reduced) ); 44 | rc = pWalker->xExprCallback(pWalker, pExpr); 45 | if( rc==WRC_Continue 46 | && !ExprHasAnyProperty(pExpr,EP_TokenOnly) ){ 47 | if( sqlite3WalkExpr(pWalker, pExpr->pLeft) ) return WRC_Abort; 48 | if( sqlite3WalkExpr(pWalker, pExpr->pRight) ) return WRC_Abort; 49 | if( ExprHasProperty(pExpr, EP_xIsSelect) ){ 50 | if( sqlite3WalkSelect(pWalker, pExpr->x.pSelect) ) return WRC_Abort; 51 | }else{ 52 | if( sqlite3WalkExprList(pWalker, pExpr->x.pList) ) return WRC_Abort; 53 | } 54 | } 55 | return rc & WRC_Abort; 56 | } 57 | 58 | /* 59 | ** Call sqlite3WalkExpr() for every expression in list p or until 60 | ** an abort request is seen. 61 | */ 62 | int sqlite3WalkExprList(Walker *pWalker, ExprList *p){ 63 | int i; 64 | struct ExprList_item *pItem; 65 | if( p ){ 66 | for(i=p->nExpr, pItem=p->a; i>0; i--, pItem++){ 67 | if( sqlite3WalkExpr(pWalker, pItem->pExpr) ) return WRC_Abort; 68 | } 69 | } 70 | return WRC_Continue; 71 | } 72 | 73 | /* 74 | ** Walk all expressions associated with SELECT statement p. Do 75 | ** not invoke the SELECT callback on p, but do (of course) invoke 76 | ** any expr callbacks and SELECT callbacks that come from subqueries. 77 | ** Return WRC_Abort or WRC_Continue. 78 | */ 79 | int sqlite3WalkSelectExpr(Walker *pWalker, Select *p){ 80 | if( sqlite3WalkExprList(pWalker, p->pEList) ) return WRC_Abort; 81 | if( sqlite3WalkExpr(pWalker, p->pWhere) ) return WRC_Abort; 82 | if( sqlite3WalkExprList(pWalker, p->pGroupBy) ) return WRC_Abort; 83 | if( sqlite3WalkExpr(pWalker, p->pHaving) ) return WRC_Abort; 84 | if( sqlite3WalkExprList(pWalker, p->pOrderBy) ) return WRC_Abort; 85 | if( sqlite3WalkExpr(pWalker, p->pLimit) ) return WRC_Abort; 86 | if( sqlite3WalkExpr(pWalker, p->pOffset) ) return WRC_Abort; 87 | return WRC_Continue; 88 | } 89 | 90 | /* 91 | ** Walk the parse trees associated with all subqueries in the 92 | ** FROM clause of SELECT statement p. Do not invoke the select 93 | ** callback on p, but do invoke it on each FROM clause subquery 94 | ** and on any subqueries further down in the tree. Return 95 | ** WRC_Abort or WRC_Continue; 96 | */ 97 | int sqlite3WalkSelectFrom(Walker *pWalker, Select *p){ 98 | SrcList *pSrc; 99 | int i; 100 | struct SrcList_item *pItem; 101 | 102 | pSrc = p->pSrc; 103 | if( ALWAYS(pSrc) ){ 104 | for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){ 105 | if( sqlite3WalkSelect(pWalker, pItem->pSelect) ){ 106 | return WRC_Abort; 107 | } 108 | } 109 | } 110 | return WRC_Continue; 111 | } 112 | 113 | /* 114 | ** Call sqlite3WalkExpr() for every expression in Select statement p. 115 | ** Invoke sqlite3WalkSelect() for subqueries in the FROM clause and 116 | ** on the compound select chain, p->pPrior. Invoke the xSelectCallback() 117 | ** either before or after the walk of expressions and FROM clause, depending 118 | ** on whether pWalker->bSelectDepthFirst is false or true, respectively. 119 | ** 120 | ** Return WRC_Continue under normal conditions. Return WRC_Abort if 121 | ** there is an abort request. 122 | ** 123 | ** If the Walker does not have an xSelectCallback() then this routine 124 | ** is a no-op returning WRC_Continue. 125 | */ 126 | int sqlite3WalkSelect(Walker *pWalker, Select *p){ 127 | int rc; 128 | if( p==0 || pWalker->xSelectCallback==0 ) return WRC_Continue; 129 | rc = WRC_Continue; 130 | pWalker->walkerDepth++; 131 | while( p ){ 132 | if( !pWalker->bSelectDepthFirst ){ 133 | rc = pWalker->xSelectCallback(pWalker, p); 134 | if( rc ) break; 135 | } 136 | if( sqlite3WalkSelectExpr(pWalker, p) 137 | || sqlite3WalkSelectFrom(pWalker, p) 138 | ){ 139 | pWalker->walkerDepth--; 140 | return WRC_Abort; 141 | } 142 | if( pWalker->bSelectDepthFirst ){ 143 | rc = pWalker->xSelectCallback(pWalker, p); 144 | /* Depth-first search is currently only used for 145 | ** selectAddSubqueryTypeInfo() and that routine always returns 146 | ** WRC_Continue (0). So the following branch is never taken. */ 147 | if( NEVER(rc) ) break; 148 | } 149 | p = p->pPrior; 150 | } 151 | pWalker->walkerDepth--; 152 | return rc & WRC_Abort; 153 | } 154 | --------------------------------------------------------------------------------