forgotten commit. disabled until egl is adapted.
[AROS-Contrib.git] / sqlite3 / sqliteInt.h
blob586db1532c4cd3f14efc0782e2425673426de57b
1 /* vi:set ts=4 sts=4 sw=4: */
2 /*
3 * 2005 July 5, Markku Sukanen
4 * - modifying the code for AROS
6 ** 2001 September 15
7 **
8 ** The author disclaims copyright to this source code. In place of
9 ** a legal notice, here is a blessing:
11 ** May you do good and not evil.
12 ** May you find forgiveness for yourself and forgive others.
13 ** May you share freely, never taking more than you give.
15 ************************************************************************/
16 /**
17 * @file sqliteInt.h
18 * @brief Internal interface definitions for SQLite.
20 * */
21 /* $Id$ */
22 #ifndef _SQLITEINT_H_
23 #define _SQLITEINT_H_
26 * These #defines should enable >2GB file support on Posix if the underlying
27 * operating system supports it. If the OS lacks large file support, or if the
28 * OS is windows, these should be no-ops.
30 * Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch on
31 * the compiler command line. This is necessary if you are compiling on
32 * a recent machine (ex: RedHat 7.2) but you want your code to work on an older
33 * machine (ex: RedHat 6.0). If you compile on RedHat 7.2 without this option,
34 * LFS is enable. But LFS does not exist in the kernel in RedHat 6.0, so the
35 * code won't work. Hence, for maximum binary portability you should omit LFS.
37 * Similar is true for MacOS. LFS is only supported on MacOS 9 and later.
38 * */
39 #ifndef SQLITE_DISABLE_LFS
40 # define _LARGE_FILE 1
41 # ifndef _FILE_OFFSET_BITS
42 # define _FILE_OFFSET_BITS 64
43 # endif
44 # define _LARGEFILE_SOURCE 1
45 #endif
47 #if OS_AROS
48 # include <exec/types.h>
49 # include <exec/exec.h>
50 # include <proto/exec.h>
51 #endif
52 #include "sqlite3.h"
53 #include "hash.h"
54 #include "parse.h"
55 #include <stdio.h>
56 #include <stdlib.h>
57 #include <string.h>
58 #include <assert.h>
59 #include <stddef.h>
62 * The maximum number of in-memory pages to use for the main database table and
63 * for temporary tables. Internally, the MAX_PAGES and TEMP_PAGES macros are
64 * used. To override the default values at compilation time, the
65 * SQLITE_DEFAULT_CACHE_SIZE and SQLITE_DEFAULT_TEMP_CACHE_SIZE macros should
66 * be set.
67 * */
68 #ifdef SQLITE_DEFAULT_CACHE_SIZE
69 # define MAX_PAGES SQLITE_DEFAULT_CACHE_SIZE
70 #else
71 # define MAX_PAGES 2000
72 #endif
73 #ifdef SQLITE_DEFAULT_TEMP_CACHE_SIZE
74 # define TEMP_PAGES SQLITE_DEFAULT_TEMP_CACHE_SIZE
75 #else
76 # define TEMP_PAGES 500
77 #endif
80 * OMIT_TEMPDB is set to 1 if SQLITE_OMIT_TEMPDB is defined, or 0 afterward.
81 * Having this macro allows us to cause the C compiler to omit code used by
82 * TEMP tables without messy #ifndef statements.
83 * */
84 #ifdef SQLITE_OMIT_TEMPDB
85 # define OMIT_TEMPDB 1
86 #else
87 # define OMIT_TEMPDB 0
88 #endif
91 * If the following macro is set to 1, then NULL values are considered distinct
92 * for the SELECT DISTINCT statement and for UNION or EXCEPT compound queries.
93 * No other SQL database engine (among those tested) works this way except for
94 * OCELOT. But the SQL92 spec implies that this is how things should work.
96 * If the following macro is set to 0, then NULLs are indistinct for SELECT
97 * DISTINCT and for UNION.
98 * */
99 #define NULL_ALWAYS_DISTINCT 0
102 * If the following macro is set to 1, then NULL values are considered distinct
103 * when determining whether or not two entries are the same in a UNIQUE index.
104 * This is the way PostgreSQL, Oracle, DB2, MySQL, OCELOT, and Firebird all
105 * work. The SQL92 spec explicitly says this is the way things are suppose to
106 * work.
108 * If the following macro is set to 0, the NULLs are indistinct for a UNIQUE
109 * index. In this mode, you can only have a single NULL entry for a column
110 * declared UNIQUE. This is the way Informix and SQL Server work.
111 * */
112 #define NULL_DISTINCT_FOR_UNIQUE 1
115 * The maximum number of attached databases. This must be at least 2 in order
116 * to support the main database file (0) and the file used to hold temporary
117 * tables (1). And it must be less than 32 because we use a bitmask of
118 * databases with a u32 in places (for example the Parse.cookieMask field).
119 * */
120 #define MAX_ATTACHED 10
123 * The maximum value of a ?nnn wildcard that the parser will accept.
124 * */
125 #define SQLITE_MAX_VARIABLE_NUMBER 999
128 * When building SQLite for embedded systems where memory is scarce, you can
129 * define one or more of the following macros to omit extra features of the
130 * library and thus keep the size of the library to a minimum.
131 * */
132 /* #define SQLITE_OMIT_AUTHORIZATION 1 */
133 /* #define SQLITE_OMIT_MEMORYDB 1 */
134 /* #define SQLITE_OMIT_VACUUM 1 */
135 /* #define SQLITE_OMIT_DATETIME_FUNCS 1 */
136 /* #define SQLITE_OMIT_PROGRESS_CALLBACK 1 */
137 /* #define SQLITE_OMIT_AUTOVACUUM */
138 /* #define SQLITE_OMIT_ALTERTABLE */
141 * Provide a default value for TEMP_STORE in case it is not specified on the
142 * command-line.
143 * */
144 #ifndef TEMP_STORE
145 # define TEMP_STORE 1
146 #endif
149 * GCC does not define the offsetof() macro so we'll have to do it ourselves.
150 * */
151 #ifndef offsetof
152 # define offsetof(STRUCTURE,FIELD) ((int)((char*)&((STRUCTURE*)0)->FIELD))
153 #endif
156 * Integers of known sizes. These typedefs might change for architectures where
157 * the sizes very. Preprocessor macros are available so that the types can be
158 * conveniently redefined at compile-type. Like this:
160 * cc '-DUINTPTR_TYPE=long long int' ...
161 * */
162 #ifndef UINT64_TYPE
163 # if defined(_MSC_VER) || defined(__BORLANDC__)
164 # define UINT64_TYPE unsigned __int64
165 # else
166 # define UINT64_TYPE unsigned long long int
167 # endif
168 #endif
169 #ifndef UINT32_TYPE
170 # define UINT32_TYPE unsigned int
171 #endif
172 #ifndef UINT16_TYPE
173 # define UINT16_TYPE unsigned short int
174 #endif
175 #ifndef INT16_TYPE
176 # define INT16_TYPE short int
177 #endif
178 #ifndef UINT8_TYPE
179 # define UINT8_TYPE unsigned char
180 #endif
181 #ifndef INT8_TYPE
182 # define INT8_TYPE signed char
183 #endif
184 #ifndef LONGDOUBLE_TYPE
185 # define LONGDOUBLE_TYPE long double
186 #endif
187 typedef sqlite_int64 i64; /* 8-byte signed integer */
188 typedef UINT64_TYPE u64; /* 8-byte unsigned integer */
189 typedef UINT32_TYPE u32; /* 4-byte unsigned integer */
190 typedef UINT16_TYPE u16; /* 2-byte unsigned integer */
191 typedef INT16_TYPE i16; /* 2-byte signed integer */
192 typedef UINT8_TYPE u8; /* 1-byte unsigned integer */
193 typedef UINT8_TYPE i8; /* 1-byte signed integer */
196 * Macros to determine whether the machine is big or little endian, evaluated
197 * at runtime.
198 * */
199 extern const int sqlite3one;
200 #define SQLITE_BIGENDIAN (*(char *)(&sqlite3one)==0)
201 #define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1)
203 #if OS_AROS
204 # ifdef SQLITE_DEBUG
205 extern const char *arosErrLoc;
206 extern const char const *__arossql__NULL;
207 # define ERRLOC(X) arosErrLoc = __arossql__ ## X
208 # define SETFNC(X) CONST_STRPTR __arossql__ ## funcn = X
209 # else
210 # define ERRLOC(X)
211 # define SETFNC(X)
212 # endif
213 #else
214 typedef u8 BOOL;
215 typedef char* STRPTR;
216 typedef const char* CONST_STRPTR;
217 # ifndef TRUE
218 # define TRUE 1
219 # endif
220 # ifndef FALSE
221 # define FALSE 0
222 # endif
223 #endif
224 typedef int err_t;
228 * An instance of the following structure is used to store the busy-handler
229 * callback for a given sqlite handle.
231 ** The sqlite.busyHandler member of the sqlite struct contains the busy
232 ** callback for the database handle. Each pager opened via the sqlite
233 ** handle is passed a pointer to sqlite.busyHandler. The busy-handler
234 ** callback is currently invoked only from within pager.c.
236 typedef struct BusyHandler BusyHandler;
237 struct BusyHandler {
238 int (*xFunc)(void *,int); /* The busy callback */
239 void *pArg; /* First arg to busy callback */
243 ** Defer sourcing vdbe.h and btree.h until after the "u8" and
244 ** "BusyHandler typedefs.
246 #include "vdbe.h"
247 #include "btree.h"
250 ** This macro casts a pointer to an integer. Useful for doing
251 ** pointer arithmetic.
253 #define Addr(X) ((uptr)X)
256 ** If memory allocation problems are found, recompile with
258 ** -DSQLITE_DEBUG=1
260 ** to enable some sanity checking on malloc() and free(). To
261 ** check for memory leaks, recompile with
263 ** -DSQLITE_DEBUG=2
265 ** and a line of text will be written to standard error for
266 ** each malloc() and free(). This output can be analyzed
267 ** by an AWK script to determine if there are any leaks.
269 #ifdef SQLITE_MEMDEBUG
270 # define sqliteMalloc(X) sqlite3Malloc_(X,1,__FILE__,__LINE__)
271 # define sqliteMallocRaw(X) sqlite3Malloc_(X,0,__FILE__,__LINE__)
272 # define sqliteFree(X) sqlite3Free_(X,__FILE__,__LINE__)
273 # define sqliteRealloc(X,Y) sqlite3Realloc_(X,Y,__FILE__,__LINE__)
274 # define sqliteStrDup(X) sqlite3StrDup_(X,__FILE__,__LINE__)
275 # define sqliteStrNDup(X,Y) sqlite3StrNDup_(X,Y,__FILE__,__LINE__)
276 #else
277 # define sqliteFree sqlite3FreeX
278 # define sqliteMalloc sqlite3Malloc
279 # define sqliteMallocRaw sqlite3MallocRaw
280 # define sqliteRealloc sqlite3Realloc
281 # define sqliteStrDup sqlite3StrDup
282 # define sqliteStrNDup sqlite3StrNDup
283 #endif
286 ** This variable gets set if malloc() ever fails. After it gets set,
287 ** the SQLite library shuts down permanently.
289 extern int sqlite3_malloc_failed;
292 ** The following global variables are used for testing and debugging
293 ** only. They only work if SQLITE_DEBUG is defined.
295 #ifdef SQLITE_MEMDEBUG
296 extern int sqlite3_nMalloc; /* Number of sqliteMalloc() calls */
297 extern int sqlite3_nFree; /* Number of sqliteFree() calls */
298 extern int sqlite3_iMallocFail; /* Fail sqliteMalloc() after this many calls */
299 extern int sqlite3_iMallocReset; /* Set iMallocFail to this when it reaches 0 */
300 #endif
303 ** Name of the master database table. The master database table
304 ** is a special table that holds the names and attributes of all
305 ** user tables and indices.
307 #define MASTER_NAME "sqlite_master"
308 #define TEMP_MASTER_NAME "sqlite_temp_master"
311 ** The root-page of the master database table.
313 #define MASTER_ROOT 1
316 ** The name of the schema table.
318 #define SCHEMA_TABLE(x) ((!OMIT_TEMPDB)&&(x==1)?TEMP_MASTER_NAME:MASTER_NAME)
321 ** A convenience macro that returns the number of elements in
322 ** an array.
324 #define ArraySize(X) (sizeof(X)/sizeof(X[0]))
327 ** Forward references to structures
329 typedef struct Column Column;
330 typedef struct Table Table;
331 typedef struct Index Index;
332 typedef struct Expr Expr;
333 typedef struct ExprList ExprList;
334 typedef struct Parse Parse;
335 typedef struct Token Token;
336 typedef struct IdList IdList;
337 typedef struct SrcList SrcList;
338 typedef struct WhereInfo WhereInfo;
339 typedef struct WhereLevel WhereLevel;
340 typedef struct Select Select;
341 typedef struct AggExpr AggExpr;
342 typedef struct FuncDef FuncDef;
343 typedef struct Trigger Trigger;
344 typedef struct TriggerStep TriggerStep;
345 typedef struct TriggerStack TriggerStack;
346 typedef struct FKey FKey;
347 typedef struct Db Db;
348 typedef struct AuthContext AuthContext;
349 typedef struct KeyClass KeyClass;
350 typedef struct CollSeq CollSeq;
351 typedef struct KeyInfo KeyInfo;
352 typedef struct NameContext NameContext;
355 ** Each database file to be accessed by the system is an instance
356 ** of the following structure. There are normally two of these structures
357 ** in the sqlite.aDb[] array. aDb[0] is the main database file and
358 ** aDb[1] is the database file used to hold temporary tables. Additional
359 ** databases may be attached.
361 struct Db {
362 char *zName; /* Name of this database */
363 Btree *pBt; /* The B*Tree structure for this database file */
364 int schema_cookie; /* Database schema version number for this file */
365 Hash tblHash; /* All tables indexed by name */
366 Hash idxHash; /* All (named) indices indexed by name */
367 Hash trigHash; /* All triggers indexed by name */
368 Hash aFKey; /* Foreign keys indexed by to-table */
369 u16 flags; /* Flags associated with this database */
370 u8 inTrans; /* 0: not writable. 1: Transaction. 2: Checkpoint */
371 u8 safety_level; /* How aggressive at synching data to disk */
372 int cache_size; /* Number of pages to use in the cache */
373 Table *pSeqTab; /* The sqlite_sequence table used by AUTOINCREMENT */
374 void *pAux; /* Auxiliary data. Usually NULL */
375 void (*xFreeAux)(void*); /* Routine to free pAux */
379 ** These macros can be used to test, set, or clear bits in the
380 ** Db.flags field.
382 #define DbHasProperty(D,I,P) (((D)->aDb[I].flags&(P))==(P))
383 #define DbHasAnyProperty(D,I,P) (((D)->aDb[I].flags&(P))!=0)
384 #define DbSetProperty(D,I,P) (D)->aDb[I].flags|=(P)
385 #define DbClearProperty(D,I,P) (D)->aDb[I].flags&=~(P)
388 ** Allowed values for the DB.flags field.
390 ** The DB_SchemaLoaded flag is set after the database schema has been
391 ** read into internal hash tables.
393 ** DB_UnresetViews means that one or more views have column names that
394 ** have been filled out. If the schema changes, these column names might
395 ** changes and so the view will need to be reset.
397 #define DB_SchemaLoaded 0x0001 /* The schema has been loaded */
398 #define DB_UnresetViews 0x0002 /* Some views have defined column names */
400 #define SQLITE_UTF16NATIVE (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE)
403 ** Each database is an instance of the following structure.
405 ** The sqlite.lastRowid records the last insert rowid generated by an
406 ** insert statement. Inserts on views do not affect its value. Each
407 ** trigger has its own context, so that lastRowid can be updated inside
408 ** triggers as usual. The previous value will be restored once the trigger
409 ** exits. Upon entering a before or instead of trigger, lastRowid is no
410 ** longer (since after version 2.8.12) reset to -1.
412 ** The sqlite.nChange does not count changes within triggers and keeps no
413 ** context. It is reset at start of sqlite3_exec.
414 ** The sqlite.lsChange represents the number of changes made by the last
415 ** insert, update, or delete statement. It remains constant throughout the
416 ** length of a statement and is then updated by OP_SetCounts. It keeps a
417 ** context stack just like lastRowid so that the count of changes
418 ** within a trigger is not seen outside the trigger. Changes to views do not
419 ** affect the value of lsChange.
420 ** The sqlite.csChange keeps track of the number of current changes (since
421 ** the last statement) and is used to update sqlite_lsChange.
423 ** The member variables sqlite.errCode, sqlite.zErrMsg and sqlite.zErrMsg16
424 ** store the most recent error code and, if applicable, string. The
425 ** internal function sqlite3Error() is used to set these variables
426 ** consistently.
428 struct sqlite3 {
429 int nDb; /* Number of backends currently in use */
430 Db *aDb; /* All backends */
431 int flags; /* Miscellanous flags. See below */
432 int errCode; /* Most recent error code (SQLITE_*) */
433 u8 enc; /* Text encoding for this database. */
434 u8 autoCommit; /* The auto-commit flag. */
435 u8 file_format; /* What file format version is this database? */
436 u8 temp_store; /* 1: file 2: memory 0: default */
437 int nTable; /* Number of tables in the database */
438 CollSeq *pDfltColl; /* The default collating sequence (BINARY) */
439 i64 lastRowid; /* ROWID of most recent insert (see above) */
440 i64 priorNewRowid; /* Last randomly generated ROWID */
441 int magic; /* Magic number for detect library misuse */
442 int nChange; /* Value returned by sqlite3_changes() */
443 int nTotalChange; /* Value returned by sqlite3_total_changes() */
444 struct sqlite3InitInfo { /* Information used during initialization */
445 int iDb; /* When back is being initialized */
446 int newTnum; /* Rootpage of table being initialized */
447 u8 busy; /* TRUE if currently initializing */
448 } init;
449 struct Vdbe *pVdbe; /* List of active virtual machines */
450 int activeVdbeCnt; /* Number of vdbes currently executing */
451 void (*xTrace)(void*,const char*); /* Trace function */
452 void *pTraceArg; /* Argument to the trace function */
453 void *pCommitArg; /* Argument to xCommitCallback() */
454 int (*xCommitCallback)(void*);/* Invoked at every commit. */
455 void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*);
456 void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*);
457 void *pCollNeededArg;
458 sqlite3_value *pValue; /* Value used for transient conversions */
459 sqlite3_value *pErr; /* Most recent error message */
460 char *zErrMsg; /* Most recent error message (UTF-8 encoded) */
461 char *zErrMsg16; /* Most recent error message (UTF-16 encoded) */
462 #ifndef SQLITE_OMIT_AUTHORIZATION
463 int (*xAuth)(void*,int,const char*,const char*,const char*,const char*);
464 /* Access authorization function */
465 void *pAuthArg; /* 1st argument to the access auth function */
466 #endif
467 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
468 int (*xProgress)(void *); /* The progress callback */
469 void *pProgressArg; /* Argument to the progress callback */
470 int nProgressOps; /* Number of opcodes for progress callback */
471 #endif
472 #ifndef SQLITE_OMIT_GLOBALRECOVER
473 sqlite3 *pNext; /* Linked list of open db handles. */
474 #endif
475 Hash aFunc; /* All functions that can be in SQL exprs */
476 Hash aCollSeq; /* All collating sequences */
477 BusyHandler busyHandler; /* Busy callback */
478 int busyTimeout; /* Busy handler timeout, in msec */
479 Db aDbStatic[2]; /* Static space for the 2 default backends */
480 #ifdef SQLITE_SSE
481 sqlite3_stmt *pFetch; /* Used by SSE to fetch stored statements */
482 #endif
486 ** Possible values for the sqlite.flags and or Db.flags fields.
488 ** On sqlite.flags, the SQLITE_InTrans value means that we have
489 ** executed a BEGIN. On Db.flags, SQLITE_InTrans means a statement
490 ** transaction is active on that particular database file.
492 #define SQLITE_VdbeTrace 0x00000001 /* True to trace VDBE execution */
493 #define SQLITE_Initialized 0x00000002 /* True after initialization */
494 #define SQLITE_Interrupt 0x00000004 /* Cancel current operation */
495 #define SQLITE_InTrans 0x00000008 /* True if in a transaction */
496 #define SQLITE_InternChanges 0x00000010 /* Uncommitted Hash table changes */
497 #define SQLITE_FullColNames 0x00000020 /* Show full column names on SELECT */
498 #define SQLITE_ShortColNames 0x00000040 /* Show short columns names */
499 #define SQLITE_CountRows 0x00000080 /* Count rows changed by INSERT, */
500 /* DELETE, or UPDATE and return */
501 /* the count using a callback. */
502 #define SQLITE_NullCallback 0x00000100 /* Invoke the callback once if the */
503 /* result set is empty */
504 #define SQLITE_SqlTrace 0x00000200 /* Debug print SQL as it executes */
505 #define SQLITE_VdbeListing 0x00000400 /* Debug listings of VDBE programs */
506 #define SQLITE_WriteSchema 0x00000800 /* OK to update SQLITE_MASTER */
507 #define SQLITE_NoReadlock 0x00001000 /* Readlocks are omitted when
508 ** accessing read-only databases */
511 ** Possible values for the sqlite.magic field.
512 ** The numbers are obtained at random and have no special meaning, other
513 ** than being distinct from one another.
515 #define SQLITE_MAGIC_OPEN 0xa029a697 /* Database is open */
516 #define SQLITE_MAGIC_CLOSED 0x9f3c2d33 /* Database is closed */
517 #define SQLITE_MAGIC_BUSY 0xf03b7906 /* Database currently in use */
518 #define SQLITE_MAGIC_ERROR 0xb5357930 /* An SQLITE_MISUSE error occurred */
521 ** Each SQL function is defined by an instance of the following
522 ** structure. A pointer to this structure is stored in the sqlite.aFunc
523 ** hash table. When multiple functions have the same name, the hash table
524 ** points to a linked list of these structures.
526 struct FuncDef {
527 char *zName; /* SQL name of the function */
528 int nArg; /* Number of arguments. -1 means unlimited */
529 u8 iPrefEnc; /* Preferred text encoding (SQLITE_UTF8, 16LE, 16BE) */
530 void *pUserData; /* User data parameter */
531 FuncDef *pNext; /* Next function with same name */
532 void (*xFunc)(sqlite3_context*,int,sqlite3_value**); /* Regular function */
533 void (*xStep)(sqlite3_context*,int,sqlite3_value**); /* Aggregate step */
534 void (*xFinalize)(sqlite3_context*); /* Aggregate finializer */
535 u8 needCollSeq; /* True if sqlite3GetFuncCollSeq() might be called */
539 ** information about each column of an SQL table is held in an instance
540 ** of this structure.
542 struct Column {
543 char *zName; /* Name of this column */
544 Expr *pDflt; /* Default value of this column */
545 char *zType; /* Data type for this column */
546 CollSeq *pColl; /* Collating sequence. If NULL, use the default */
547 u8 notNull; /* True if there is a NOT NULL constraint */
548 u8 isPrimKey; /* True if this column is part of the PRIMARY KEY */
549 char affinity; /* One of the SQLITE_AFF_... values */
553 ** A "Collating Sequence" is defined by an instance of the following
554 ** structure. Conceptually, a collating sequence consists of a name and
555 ** a comparison routine that defines the order of that sequence.
557 ** There may two seperate implementations of the collation function, one
558 ** that processes text in UTF-8 encoding (CollSeq.xCmp) and another that
559 ** processes text encoded in UTF-16 (CollSeq.xCmp16), using the machine
560 ** native byte order. When a collation sequence is invoked, SQLite selects
561 ** the version that will require the least expensive encoding
562 ** transalations, if any.
564 ** The CollSeq.pUser member variable is an extra parameter that passed in
565 ** as the first argument to the UTF-8 comparison function, xCmp.
566 ** CollSeq.pUser16 is the equivalent for the UTF-16 comparison function,
567 ** xCmp16.
569 ** If both CollSeq.xCmp and CollSeq.xCmp16 are NULL, it means that the
570 ** collating sequence is undefined. Indices built on an undefined
571 ** collating sequence may not be read or written.
573 struct CollSeq {
574 char *zName; /* Name of the collating sequence, UTF-8 encoded */
575 u8 enc; /* Text encoding handled by xCmp() */
576 void *pUser; /* First argument to xCmp() */
577 int (*xCmp)(void*,int, const void*, int, const void*);
581 ** A sort order can be either ASC or DESC.
583 #define SQLITE_SO_ASC 0 /* Sort in ascending order */
584 #define SQLITE_SO_DESC 1 /* Sort in ascending order */
587 ** Column affinity types.
589 #define SQLITE_AFF_INTEGER 'i'
590 #define SQLITE_AFF_NUMERIC 'n'
591 #define SQLITE_AFF_TEXT 't'
592 #define SQLITE_AFF_NONE 'o'
596 ** Each SQL table is represented in memory by an instance of the
597 ** following structure.
599 ** Table.zName is the name of the table. The case of the original
600 ** CREATE TABLE statement is stored, but case is not significant for
601 ** comparisons.
603 ** Table.nCol is the number of columns in this table. Table.aCol is a
604 ** pointer to an array of Column structures, one for each column.
606 ** If the table has an INTEGER PRIMARY KEY, then Table.iPKey is the index of
607 ** the column that is that key. Otherwise Table.iPKey is negative. Note
608 ** that the datatype of the PRIMARY KEY must be INTEGER for this field to
609 ** be set. An INTEGER PRIMARY KEY is used as the rowid for each row of
610 ** the table. If a table has no INTEGER PRIMARY KEY, then a random rowid
611 ** is generated for each row of the table. Table.hasPrimKey is true if
612 ** the table has any PRIMARY KEY, INTEGER or otherwise.
614 ** Table.tnum is the page number for the root BTree page of the table in the
615 ** database file. If Table.iDb is the index of the database table backend
616 ** in sqlite.aDb[]. 0 is for the main database and 1 is for the file that
617 ** holds temporary tables and indices. If Table.isTransient
618 ** is true, then the table is stored in a file that is automatically deleted
619 ** when the VDBE cursor to the table is closed. In this case Table.tnum
620 ** refers VDBE cursor number that holds the table open, not to the root
621 ** page number. Transient tables are used to hold the results of a
622 ** sub-query that appears instead of a real table name in the FROM clause
623 ** of a SELECT statement.
625 struct Table {
626 char *zName; /* Name of the table */
627 int nCol; /* Number of columns in this table */
628 Column *aCol; /* Information about each column */
629 int iPKey; /* If not less then 0, use aCol[iPKey] as the primary key */
630 Index *pIndex; /* List of SQL indexes on this table. */
631 int tnum; /* Root BTree node for this table (see note above) */
632 Select *pSelect; /* NULL for tables. Points to definition if a view. */
633 u8 readOnly; /* True if this table should not be written by the user */
634 u8 iDb; /* Index into sqlite.aDb[] of the backend for this table */
635 u8 isTransient; /* True if automatically deleted when VDBE finishes */
636 u8 hasPrimKey; /* True if there exists a primary key */
637 u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
638 u8 autoInc; /* True if the integer primary key is autoincrement */
639 int nRef; /* Number of pointers to this Table */
640 Trigger *pTrigger; /* List of SQL triggers on this table */
641 FKey *pFKey; /* Linked list of all foreign keys in this table */
642 char *zColAff; /* String defining the affinity of each column */
643 #ifndef SQLITE_OMIT_ALTERTABLE
644 int addColOffset; /* Offset in CREATE TABLE statement to add a new column */
645 #endif
649 ** Each foreign key constraint is an instance of the following structure.
651 ** A foreign key is associated with two tables. The "from" table is
652 ** the table that contains the REFERENCES clause that creates the foreign
653 ** key. The "to" table is the table that is named in the REFERENCES clause.
654 ** Consider this example:
656 ** CREATE TABLE ex1(
657 ** a INTEGER PRIMARY KEY,
658 ** b INTEGER CONSTRAINT fk1 REFERENCES ex2(x)
659 ** );
661 ** For foreign key "fk1", the from-table is "ex1" and the to-table is "ex2".
663 ** Each REFERENCES clause generates an instance of the following structure
664 ** which is attached to the from-table. The to-table need not exist when
665 ** the from-table is created. The existance of the to-table is not checked
666 ** until an attempt is made to insert data into the from-table.
668 ** The sqlite.aFKey hash table stores pointers to this structure
669 ** given the name of a to-table. For each to-table, all foreign keys
670 ** associated with that table are on a linked list using the FKey.pNextTo
671 ** field.
673 struct FKey {
674 Table *pFrom; /* The table that constains the REFERENCES clause */
675 FKey *pNextFrom; /* Next foreign key in pFrom */
676 char *zTo; /* Name of table that the key points to */
677 FKey *pNextTo; /* Next foreign key that points to zTo */
678 int nCol; /* Number of columns in this key */
679 struct sColMap { /* Mapping of columns in pFrom to columns in zTo */
680 int iFrom; /* Index of column in pFrom */
681 char *zCol; /* Name of column in zTo. If 0 use PRIMARY KEY */
682 } *aCol; /* One entry for each of nCol column s */
683 u8 isDeferred; /* True if constraint checking is deferred till COMMIT */
684 u8 updateConf; /* How to resolve conflicts that occur on UPDATE */
685 u8 deleteConf; /* How to resolve conflicts that occur on DELETE */
686 u8 insertConf; /* How to resolve conflicts that occur on INSERT */
690 ** SQLite supports many different ways to resolve a contraint
691 ** error. ROLLBACK processing means that a constraint violation
692 ** causes the operation in process to fail and for the current transaction
693 ** to be rolled back. ABORT processing means the operation in process
694 ** fails and any prior changes from that one operation are backed out,
695 ** but the transaction is not rolled back. FAIL processing means that
696 ** the operation in progress stops and returns an error code. But prior
697 ** changes due to the same operation are not backed out and no rollback
698 ** occurs. IGNORE means that the particular row that caused the constraint
699 ** error is not inserted or updated. Processing continues and no error
700 ** is returned. REPLACE means that preexisting database rows that caused
701 ** a UNIQUE constraint violation are removed so that the new insert or
702 ** update can proceed. Processing continues and no error is reported.
704 ** RESTRICT, SETNULL, and CASCADE actions apply only to foreign keys.
705 ** RESTRICT is the same as ABORT for IMMEDIATE foreign keys and the
706 ** same as ROLLBACK for DEFERRED keys. SETNULL means that the foreign
707 ** key is set to NULL. CASCADE means that a DELETE or UPDATE of the
708 ** referenced table row is propagated into the row that holds the
709 ** foreign key.
711 ** The following symbolic values are used to record which type
712 ** of action to take.
714 #define OE_None 0 /* There is no constraint to check */
715 #define OE_Rollback 1 /* Fail the operation and rollback the transaction */
716 #define OE_Abort 2 /* Back out changes but do no rollback transaction */
717 #define OE_Fail 3 /* Stop the operation but leave all prior changes */
718 #define OE_Ignore 4 /* Ignore the error. Do not do the INSERT or UPDATE */
719 #define OE_Replace 5 /* Delete existing record, then do INSERT or UPDATE */
721 #define OE_Restrict 6 /* OE_Abort for IMMEDIATE, OE_Rollback for DEFERRED */
722 #define OE_SetNull 7 /* Set the foreign key value to NULL */
723 #define OE_SetDflt 8 /* Set the foreign key value to its default */
724 #define OE_Cascade 9 /* Cascade the changes */
726 #define OE_Default 99 /* Do whatever the default action is */
730 ** An instance of the following structure is passed as the first
731 ** argument to sqlite3VdbeKeyCompare and is used to control the
732 ** comparison of the two index keys.
734 ** If the KeyInfo.incrKey value is true and the comparison would
735 ** otherwise be equal, then return a result as if the second key
736 ** were larger.
738 struct KeyInfo {
739 u8 enc; /* Text encoding - one of the TEXT_Utf* values */
740 u8 incrKey; /* Increase 2nd key by epsilon before comparison */
741 int nField; /* Number of entries in aColl[] */
742 u8 *aSortOrder; /* If defined an aSortOrder[i] is true, sort DESC */
743 CollSeq *aColl[1]; /* Collating sequence for each term of the key */
747 ** Each SQL index is represented in memory by an
748 ** instance of the following structure.
750 ** The columns of the table that are to be indexed are described
751 ** by the aiColumn[] field of this structure. For example, suppose
752 ** we have the following table and index:
754 ** CREATE TABLE Ex1(c1 int, c2 int, c3 text);
755 ** CREATE INDEX Ex2 ON Ex1(c3,c1);
757 ** In the Table structure describing Ex1, nCol==3 because there are
758 ** three columns in the table. In the Index structure describing
759 ** Ex2, nColumn==2 since 2 of the 3 columns of Ex1 are indexed.
760 ** The value of aiColumn is {2, 0}. aiColumn[0]==2 because the
761 ** first column to be indexed (c3) has an index of 2 in Ex1.aCol[].
762 ** The second column to be indexed (c1) has an index of 0 in
763 ** Ex1.aCol[], hence Ex2.aiColumn[1]==0.
765 ** The Index.onError field determines whether or not the indexed columns
766 ** must be unique and what to do if they are not. When Index.onError=OE_None,
767 ** it means this is not a unique index. Otherwise it is a unique index
768 ** and the value of Index.onError indicate the which conflict resolution
769 ** algorithm to employ whenever an attempt is made to insert a non-unique
770 ** element.
772 struct Index {
773 STRPTR zName; /* Name of this index */
774 int nColumn; /* Number of columns in the table used by this index */
775 int *aiColumn; /* Which columns are used by this index. 1st is 0 */
776 Table *pTable; /* The SQL table being indexed */
777 int tnum; /* Page containing root of this index in database file */
778 u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
779 u8 autoIndex; /* True if is automatically created (ex: by UNIQUE) */
780 u8 iDb; /* Index in sqlite.aDb[] of where this index is stored */
781 char *zColAff; /* String defining the affinity of each column */
782 Index *pNext; /* The next index associated with the same table */
783 KeyInfo keyInfo; /* Info on how to order keys. MUST BE LAST */
787 ** Each token coming out of the lexer is an instance of
788 ** this structure. Tokens are also used as part of an expression.
790 ** Note if Token.z==0 then Token.dyn and Token.n are undefined and
791 ** may contain random values. Do not make any assuptions about Token.dyn
792 ** and Token.n when Token.z==0.
794 struct Token {
795 const unsigned char *z; /* Text of the token. Not NULL-terminated! */
796 unsigned dyn : 1; /* True for malloced memory, false for static */
797 unsigned n : 31; /* Number of characters in this token */
801 ** Each node of an expression in the parse tree is an instance
802 ** of this structure.
804 ** Expr.op is the opcode. The integer parser token codes are reused
805 ** as opcodes here. For example, the parser defines TK_GE to be an integer
806 ** code representing the ">=" operator. This same integer code is reused
807 ** to represent the greater-than-or-equal-to operator in the expression
808 ** tree.
810 ** Expr.pRight and Expr.pLeft are subexpressions. Expr.pList is a list
811 ** of argument if the expression is a function.
813 ** Expr.token is the operator token for this node. For some expressions
814 ** that have subexpressions, Expr.token can be the complete text that gave
815 ** rise to the Expr. In the latter case, the token is marked as being
816 ** a compound token.
818 ** An expression of the form ID or ID.ID refers to a column in a table.
819 ** For such expressions, Expr.op is set to TK_COLUMN and Expr.iTable is
820 ** the integer cursor number of a VDBE cursor pointing to that table and
821 ** Expr.iColumn is the column number for the specific column. If the
822 ** expression is used as a result in an aggregate SELECT, then the
823 ** value is also stored in the Expr.iAgg column in the aggregate so that
824 ** it can be accessed after all aggregates are computed.
826 ** If the expression is a function, the Expr.iTable is an integer code
827 ** representing which function. If the expression is an unbound variable
828 ** marker (a question mark character '?' in the original SQL) then the
829 ** Expr.iTable holds the index number for that variable.
831 ** If the expression is a subquery then Expr.iColumn holds an integer
832 ** register number containing the result of the subquery. If the
833 ** subquery gives a constant result, then iTable is -1. If the subquery
834 ** gives a different answer at different times during statement processing
835 ** then iTable is the address of a subroutine that computes the subquery.
837 ** The Expr.pSelect field points to a SELECT statement. The SELECT might
838 ** be the right operand of an IN operator. Or, if a scalar SELECT appears
839 ** in an expression the opcode is TK_SELECT and Expr.pSelect is the only
840 ** operand.
842 ** If the Expr is of type OP_Column, and the table it is selecting from
843 ** is a disk table or the "old.*" pseudo-table, then pTab points to the
844 ** corresponding table definition.
846 struct Expr {
847 u8 op; /* Operation performed by this node */
848 char affinity; /* The affinity of the column or 0 if not a column */
849 u8 iDb; /* Database referenced by this expression */
850 u8 flags; /* Various flags. See below */
851 CollSeq *pColl; /* The collation type of the column or 0 */
852 Expr *pLeft, *pRight; /* Left and right subnodes */
853 ExprList *pList; /* A list of expressions used as function arguments
854 ** or in "<expr> IN (<expr-list)" */
855 Token token; /* An operand token */
856 Token span; /* Complete text of the expression */
857 int iTable, iColumn; /* When op==TK_COLUMN, then this expr node means the
858 ** iColumn-th field of the iTable-th table. */
859 int iAgg; /* When op==TK_COLUMN and pParse->fillAgg==FALSE, pull
860 ** result from the iAgg-th element of the aggregator */
861 int iAggCtx; /* The value to pass as P1 of OP_AggGet. */
862 Select *pSelect; /* When the expression is a sub-select. Also the
863 ** right side of "<expr> IN (<select>)" */
864 Table *pTab; /* Table for OP_Column expressions. */
868 ** The following are the meanings of bits in the Expr.flags field.
870 #define EP_FromJoin 0x0001 /* Originated in ON or USING clause of a join */
871 #define EP_Agg 0x0002 /* Contains one or more aggregate functions */
872 #define EP_Resolved 0x0004 /* IDs have been resolved to COLUMNs */
873 #define EP_Error 0x0008 /* Expression contains one or more errors */
874 #define EP_Not 0x0010 /* Operator preceeded by NOT */
875 #define EP_VarSelect 0x0020 /* pSelect is correlated, not constant */
878 ** These macros can be used to test, set, or clear bits in the
879 ** Expr.flags field.
881 #define ExprHasProperty(E,P) (((E)->flags&(P))==(P))
882 #define ExprHasAnyProperty(E,P) (((E)->flags&(P))!=0)
883 #define ExprSetProperty(E,P) (E)->flags|=(P)
884 #define ExprClearProperty(E,P) (E)->flags&=~(P)
887 ** A list of expressions. Each expression may optionally have a
888 ** name. An expr/name combination can be used in several ways, such
889 ** as the list of "expr AS ID" fields following a "SELECT" or in the
890 ** list of "ID = expr" items in an UPDATE. A list of expressions can
891 ** also be used as the argument to a function, in which case the a.zName
892 ** field is not used.
894 struct ExprList {
895 int nExpr; /* Number of expressions on the list */
896 int nAlloc; /* Number of entries allocated below */
897 struct ExprList_item {
898 Expr *pExpr; /* The list of expressions */
899 char *zName; /* Token associated with this expression */
900 u8 sortOrder; /* 1 for DESC or 0 for ASC */
901 u8 isAgg; /* True if this is an aggregate like count(*) */
902 u8 done; /* A flag to indicate when processing is finished */
903 } *a; /* One entry for each expression */
907 ** An instance of this structure can hold a simple list of identifiers,
908 ** such as the list "a,b,c" in the following statements:
910 ** INSERT INTO t(a,b,c) VALUES ...;
911 ** CREATE INDEX idx ON t(a,b,c);
912 ** CREATE TRIGGER trig BEFORE UPDATE ON t(a,b,c) ...;
914 ** The IdList.a.idx field is used when the IdList represents the list of
915 ** column names after a table name in an INSERT statement. In the statement
917 ** INSERT INTO t(a,b,c) ...
919 ** If "a" is the k-th column of table "t", then IdList.a[0].idx==k.
921 struct IdList {
922 int nId; /* Number of identifiers on the list */
923 int nAlloc; /* Number of entries allocated for a[] below */
924 struct IdList_item {
925 char *zName; /* Name of the identifier */
926 int idx; /* Index in some Table.aCol[] of a column named zName */
927 } *a;
931 ** The bitmask datatype defined below is used for various optimizations.
933 typedef unsigned int Bitmask;
936 ** The following structure describes the FROM clause of a SELECT statement.
937 ** Each table or subquery in the FROM clause is a separate element of
938 ** the SrcList.a[] array.
940 ** With the addition of multiple database support, the following structure
941 ** can also be used to describe a particular table such as the table that
942 ** is modified by an INSERT, DELETE, or UPDATE statement. In standard SQL,
943 ** such a table must be a simple name: ID. But in SQLite, the table can
944 ** now be identified by a database name, a dot, then the table name: ID.ID.
946 struct SrcList {
947 i16 nSrc; /* Number of tables or subqueries in the FROM clause */
948 i16 nAlloc; /* Number of entries allocated in a[] below */
949 struct SrcList_item {
950 char *zDatabase; /* Name of database holding this table */
951 char *zName; /* Name of the table */
952 char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */
953 Table *pTab; /* An SQL table corresponding to zName */
954 Select *pSelect; /* A SELECT statement used in place of a table name */
955 int jointype; /* Type of join between this table and the next */
956 int iCursor; /* The VDBE cursor number used to access this table */
957 Expr *pOn; /* The ON clause of a join */
958 IdList *pUsing; /* The USING clause of a join */
959 Bitmask colUsed; /* Bit N (1<<N) set if column N or pTab is used */
960 } a[1]; /* One entry for each identifier on the list */
964 ** Permitted values of the SrcList.a.jointype field
966 #define JT_INNER 0x0001 /* Any kind of inner or cross join */
967 #define JT_NATURAL 0x0002 /* True for a "natural" join */
968 #define JT_LEFT 0x0004 /* Left outer join */
969 #define JT_RIGHT 0x0008 /* Right outer join */
970 #define JT_OUTER 0x0010 /* The "OUTER" keyword is present */
971 #define JT_ERROR 0x0020 /* unknown or unsupported join type */
974 ** For each nested loop in a WHERE clause implementation, the WhereInfo
975 ** structure contains a single instance of this structure. This structure
976 ** is intended to be private the the where.c module and should not be
977 ** access or modified by other modules.
979 struct WhereLevel {
980 int iMem; /* Memory cell used by this level */
981 Index *pIdx; /* Index used. NULL if no index */
982 int iTabCur; /* The VDBE cursor used to access the table */
983 int iIdxCur; /* The VDBE cursor used to acesss pIdx */
984 int score; /* How well this index scored */
985 int brk; /* Jump here to break out of the loop */
986 int cont; /* Jump here to continue with the next loop cycle */
987 int op, p1, p2; /* Opcode used to terminate the loop */
988 int iLeftJoin; /* Memory cell used to implement LEFT OUTER JOIN */
989 int top; /* First instruction of interior of the loop */
990 int inOp, inP1, inP2;/* Opcode used to implement an IN operator */
991 int bRev; /* Do the scan in the reverse direction */
995 ** The WHERE clause processing routine has two halves. The
996 ** first part does the start of the WHERE loop and the second
997 ** half does the tail of the WHERE loop. An instance of
998 ** this structure is returned by the first half and passed
999 ** into the second half to give some continuity.
1001 struct WhereInfo {
1002 Parse *pParse;
1003 SrcList *pTabList; /* List of tables in the join */
1004 int iTop; /* The very beginning of the WHERE loop */
1005 int iContinue; /* Jump here to continue with next record */
1006 int iBreak; /* Jump here to break out of the loop */
1007 int nLevel; /* Number of nested loop */
1008 WhereLevel a[1]; /* Information about each nest loop in the WHERE */
1012 ** A NameContext defines a context in which to resolve table and column
1013 ** names. The context consists of a list of tables (the pSrcList) field and
1014 ** a list of named expression (pEList). The named expression list may
1015 ** be NULL. The pSrc corresponds to the FROM clause of a SELECT or
1016 ** to the table being operated on by INSERT, UPDATE, or DELETE. The
1017 ** pEList corresponds to the result set of a SELECT and is NULL for
1018 ** other statements.
1020 ** NameContexts can be nested. When resolving names, the inner-most
1021 ** context is searched first. If no match is found, the next outer
1022 ** context is checked. If there is still no match, the next context
1023 ** is checked. This process continues until either a match is found
1024 ** or all contexts are check. When a match is found, the nRef member of
1025 ** the context containing the match is incremented.
1027 ** Each subquery gets a new NameContext. The pNext field points to the
1028 ** NameContext in the parent query. Thus the process of scanning the
1029 ** NameContext list corresponds to searching through successively outer
1030 ** subqueries looking for a match.
1032 struct NameContext {
1033 Parse *pParse; /* The parser */
1034 SrcList *pSrcList; /* One or more tables used to resolve names */
1035 ExprList *pEList; /* Optional list of named expressions */
1036 int nRef; /* Number of names resolved by this context */
1037 int nErr; /* Number of errors encountered while resolving names */
1038 u8 allowAgg; /* Aggregate functions allowed here */
1039 u8 hasAgg;
1040 int nDepth; /* Depth of subquery recursion. 1 for no recursion */
1041 NameContext *pNext; /* Next outer name context. NULL for outermost */
1045 ** An instance of the following structure contains all information
1046 ** needed to generate code for a single SELECT statement.
1048 ** nLimit is set to -1 if there is no LIMIT clause. nOffset is set to 0.
1049 ** If there is a LIMIT clause, the parser sets nLimit to the value of the
1050 ** limit and nOffset to the value of the offset (or 0 if there is not
1051 ** offset). But later on, nLimit and nOffset become the memory locations
1052 ** in the VDBE that record the limit and offset counters.
1054 struct Select {
1055 ExprList *pEList; /* The fields of the result */
1056 u8 op; /* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */
1057 u8 isDistinct; /* True if the DISTINCT keyword is present */
1058 SrcList *pSrc; /* The FROM clause */
1059 Expr *pWhere; /* The WHERE clause */
1060 ExprList *pGroupBy; /* The GROUP BY clause */
1061 Expr *pHaving; /* The HAVING clause */
1062 ExprList *pOrderBy; /* The ORDER BY clause */
1063 Select *pPrior; /* Prior select in a compound select statement */
1064 Expr *pLimit; /* LIMIT expression. NULL means not used. */
1065 Expr *pOffset; /* OFFSET expression. NULL means not used. */
1066 int iLimit, iOffset; /* Memory registers holding LIMIT & OFFSET counters */
1067 IdList **ppOpenTemp; /* OP_OpenTemp addresses used by multi-selects */
1068 u8 isResolved; /* True once sqlite3SelectResolve() has run. */
1069 u8 isAgg; /* True if this is an aggregate query */
1073 ** The results of a select can be distributed in several ways.
1075 #define SRT_Callback 1 /* Invoke a callback with each row of result */
1076 #define SRT_Mem 2 /* Store result in a memory cell */
1077 #define SRT_Set 3 /* Store result as unique keys in a table */
1078 #define SRT_Union 5 /* Store result as keys in a table */
1079 #define SRT_Except 6 /* Remove result from a UNION table */
1080 #define SRT_Table 7 /* Store result as data with a unique key */
1081 #define SRT_TempTable 8 /* Store result in a trasient table */
1082 #define SRT_Discard 9 /* Do not save the results anywhere */
1083 #define SRT_Sorter 10 /* Store results in the sorter */
1084 #define SRT_Subroutine 11 /* Call a subroutine to handle results */
1085 #define SRT_Exists 12 /* Put 0 or 1 in a memory cell */
1088 ** When a SELECT uses aggregate functions (like "count(*)" or "avg(f1)")
1089 ** we have to do some additional analysis of expressions. An instance
1090 ** of the following structure holds information about a single subexpression
1091 ** somewhere in the SELECT statement. An array of these structures holds
1092 ** all the information we need to generate code for aggregate
1093 ** expressions.
1095 ** Note that when analyzing a SELECT containing aggregates, both
1096 ** non-aggregate field variables and aggregate functions are stored
1097 ** in the AggExpr array of the Parser structure.
1099 ** The pExpr field points to an expression that is part of either the
1100 ** field list, the GROUP BY clause, the HAVING clause or the ORDER BY
1101 ** clause. The expression will be freed when those clauses are cleaned
1102 ** up. Do not try to delete the expression attached to AggExpr.pExpr.
1104 ** If AggExpr.pExpr==0, that means the expression is "count(*)".
1106 struct AggExpr {
1107 int isAgg; /* if TRUE contains an aggregate function */
1108 Expr *pExpr; /* The expression */
1109 FuncDef *pFunc; /* Information about the aggregate function */
1113 ** An SQL parser context. A copy of this structure is passed through
1114 ** the parser and down into all the parser action routine in order to
1115 ** carry around information that is global to the entire parse.
1117 ** The structure is divided into two parts. When the parser and code
1118 ** generate call themselves recursively, the first part of the structure
1119 ** is constant but the second part is reset at the beginning and end of
1120 ** each recursion.
1122 struct Parse {
1123 sqlite3 *db; /* The main database structure */
1124 int rc; /* Return code from execution */
1125 STRPTR zErrMsg; /* An error message */
1126 Vdbe *pVdbe; /* An engine for executing database bytecode */
1127 u8 colNamesSet; /* TRUE after OP_ColumnName has been issued to pVdbe */
1128 u8 nameClash; /* A permanent table name clashes with temp table name */
1129 u8 checkSchema; /* Causes schema cookie check after an error */
1130 u8 nested; /* Number of nested calls to the parser/code generator */
1131 u8 fillAgg; /* If true, ignore the Expr.iAgg field. Normally false */
1132 int nErr; /* Number of errors seen */
1133 int nTab; /* Number of previously allocated VDBE cursors */
1134 int nMem; /* Number of memory cells used so far */
1135 int nSet; /* Number of sets used so far */
1136 u32 writeMask; /* Start a write transaction on these databases */
1137 u32 cookieMask; /* Bitmask of schema verified databases */
1138 int cookieGoto; /* Address of OP_Goto to cookie verifier subroutine */
1139 int cookieValue[MAX_ATTACHED+2]; /* Values of cookies to verify */
1141 /* Above is constant between recursions. Below is reset before and after
1142 ** each recursion */
1144 int nVar; /* Number of '?' variables seen in the SQL so far */
1145 int nVarExpr; /* Number of used slots in apVarExpr[] */
1146 int nVarExprAlloc; /* Number of allocated slots in apVarExpr[] */
1147 Expr **apVarExpr; /* Pointers to :aaa and $aaaa wildcard expressions */
1148 u8 explain; /* True if the EXPLAIN flag is found on the query */
1149 Token sErrToken; /* The token at which the error occurred */
1150 Token sNameToken; /* Token with unqualified schema object name */
1151 Token sLastToken; /* The last token parsed */
1152 const char *zSql; /* All SQL text */
1153 const char *zTail; /* All SQL text past the last semicolon parsed */
1154 Table *pNewTable; /* A table being constructed by CREATE TABLE */
1155 Trigger *pNewTrigger; /* Trigger under construct by a CREATE TRIGGER */
1156 TriggerStack *trigStack; /* Trigger actions being coded */
1157 const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */
1158 int nAgg; /* Number of aggregate expressions */
1159 AggExpr *aAgg; /* An array of aggregate expressions */
1160 int nMaxDepth; /* Maximum depth of subquery recursion */
1164 ** An instance of the following structure can be declared on a stack and used
1165 ** to save the Parse.zAuthContext value so that it can be restored later.
1167 struct AuthContext {
1168 const char *zAuthContext; /* Put saved Parse.zAuthContext here */
1169 Parse *pParse; /* The Parse structure */
1173 ** Bitfield flags for P2 value in OP_Insert and OP_Delete
1175 #define OPFLAG_NCHANGE 1 /* Set to update db->nChange */
1176 #define OPFLAG_LASTROWID 2 /* Set to update db->lastRowid */
1179 * Each trigger present in the database schema is stored as an instance of
1180 * struct Trigger.
1182 * Pointers to instances of struct Trigger are stored in two ways.
1183 * 1. In the "trigHash" hash table (part of the sqlite3* that represents the
1184 * database). This allows Trigger structures to be retrieved by name.
1185 * 2. All triggers associated with a single table form a linked list, using the
1186 * pNext member of struct Trigger. A pointer to the first element of the
1187 * linked list is stored as the "pTrigger" member of the associated
1188 * struct Table.
1190 * The "step_list" member points to the first element of a linked list
1191 * containing the SQL statements specified as the trigger program.
1193 struct Trigger {
1194 char *name; /* The name of the trigger */
1195 char *table; /* The table or view to which the trigger applies */
1196 u8 iDb; /* Database containing this trigger */
1197 u8 iTabDb; /* Database containing Trigger.table */
1198 u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT */
1199 u8 tr_tm; /* One of TRIGGER_BEFORE, TRIGGER_AFTER */
1200 Expr *pWhen; /* The WHEN clause of the expresion (may be NULL) */
1201 IdList *pColumns; /* If this is an UPDATE OF <column-list> trigger,
1202 the <column-list> is stored here */
1203 int foreach; /* One of TK_ROW or TK_STATEMENT */
1204 Token nameToken; /* Token containing zName. Use during parsing only */
1206 TriggerStep *step_list; /* Link list of trigger program steps */
1207 Trigger *pNext; /* Next trigger associated with the table */
1211 ** A trigger is either a BEFORE or an AFTER trigger. The following constants
1212 ** determine which.
1214 ** If there are multiple triggers, you might of some BEFORE and some AFTER.
1215 ** In that cases, the constants below can be ORed together.
1217 #define TRIGGER_BEFORE 1
1218 #define TRIGGER_AFTER 2
1221 * An instance of struct TriggerStep is used to store a single SQL statement
1222 * that is a part of a trigger-program.
1224 * Instances of struct TriggerStep are stored in a singly linked list (linked
1225 * using the "pNext" member) referenced by the "step_list" member of the
1226 * associated struct Trigger instance. The first element of the linked list is
1227 * the first step of the trigger-program.
1229 * The "op" member indicates whether this is a "DELETE", "INSERT", "UPDATE" or
1230 * "SELECT" statement. The meanings of the other members is determined by the
1231 * value of "op" as follows:
1233 * (op == TK_INSERT)
1234 * orconf -> stores the ON CONFLICT algorithm
1235 * pSelect -> If this is an INSERT INTO ... SELECT ... statement, then
1236 * this stores a pointer to the SELECT statement. Otherwise NULL.
1237 * target -> A token holding the name of the table to insert into.
1238 * pExprList -> If this is an INSERT INTO ... VALUES ... statement, then
1239 * this stores values to be inserted. Otherwise NULL.
1240 * pIdList -> If this is an INSERT INTO ... (<column-names>) VALUES ...
1241 * statement, then this stores the column-names to be
1242 * inserted into.
1244 * (op == TK_DELETE)
1245 * target -> A token holding the name of the table to delete from.
1246 * pWhere -> The WHERE clause of the DELETE statement if one is specified.
1247 * Otherwise NULL.
1249 * (op == TK_UPDATE)
1250 * target -> A token holding the name of the table to update rows of.
1251 * pWhere -> The WHERE clause of the UPDATE statement if one is specified.
1252 * Otherwise NULL.
1253 * pExprList -> A list of the columns to update and the expressions to update
1254 * them to. See sqlite3Update() documentation of "pChanges"
1255 * argument.
1258 struct TriggerStep {
1259 int op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */
1260 int orconf; /* OE_Rollback etc. */
1261 Trigger *pTrig; /* The trigger that this step is a part of */
1263 Select *pSelect; /* Valid for SELECT and sometimes
1264 INSERT steps (when pExprList == 0) */
1265 Token target; /* Valid for DELETE, UPDATE, INSERT steps */
1266 Expr *pWhere; /* Valid for DELETE, UPDATE steps */
1267 ExprList *pExprList; /* Valid for UPDATE statements and sometimes
1268 INSERT steps (when pSelect == 0) */
1269 IdList *pIdList; /* Valid for INSERT statements only */
1271 TriggerStep * pNext; /* Next in the link-list */
1275 * An instance of struct TriggerStack stores information required during code
1276 * generation of a single trigger program. While the trigger program is being
1277 * coded, its associated TriggerStack instance is pointed to by the
1278 * "pTriggerStack" member of the Parse structure.
1280 * The pTab member points to the table that triggers are being coded on. The
1281 * newIdx member contains the index of the vdbe cursor that points at the temp
1282 * table that stores the new.* references. If new.* references are not valid
1283 * for the trigger being coded (for example an ON DELETE trigger), then newIdx
1284 * is set to -1. The oldIdx member is analogous to newIdx, for old.* references.
1286 * The ON CONFLICT policy to be used for the trigger program steps is stored
1287 * as the orconf member. If this is OE_Default, then the ON CONFLICT clause
1288 * specified for individual triggers steps is used.
1290 * struct TriggerStack has a "pNext" member, to allow linked lists to be
1291 * constructed. When coding nested triggers (triggers fired by other triggers)
1292 * each nested trigger stores its parent trigger's TriggerStack as the "pNext"
1293 * pointer. Once the nested trigger has been coded, the pNext value is restored
1294 * to the pTriggerStack member of the Parse stucture and coding of the parent
1295 * trigger continues.
1297 * Before a nested trigger is coded, the linked list pointed to by the
1298 * pTriggerStack is scanned to ensure that the trigger is not about to be coded
1299 * recursively. If this condition is detected, the nested trigger is not coded.
1301 struct TriggerStack {
1302 Table *pTab; /* Table that triggers are currently being coded on */
1303 int newIdx; /* Index of vdbe cursor to "new" temp table */
1304 int oldIdx; /* Index of vdbe cursor to "old" temp table */
1305 int orconf; /* Current orconf policy */
1306 int ignoreJump; /* where to jump to for a RAISE(IGNORE) */
1307 Trigger *pTrigger; /* The trigger currently being coded */
1308 TriggerStack *pNext; /* Next trigger down on the trigger stack */
1312 ** The following structure contains information used by the sqliteFix...
1313 ** routines as they walk the parse tree to make database references
1314 ** explicit.
1316 typedef struct DbFixer DbFixer;
1317 struct DbFixer {
1318 Parse *pParse; /* The parsing context. Error messages written here */
1319 const char *zDb; /* Make sure all objects are contained in this database */
1320 const char *zType; /* Type of the container - used for error messages */
1321 const Token *pName; /* Name of the container - used for error messages */
1325 ** A pointer to this structure is used to communicate information
1326 ** from sqlite3Init and OP_ParseSchema into the sqlite3InitCallback.
1328 typedef struct {
1329 sqlite3 *db; /* The database being initialized */
1330 STRPTR *pzErrMsg; /* Error message stored here */
1331 } InitData;
1334 * This global flag is set for performance testing of triggers. When it is set
1335 * SQLite will perform the overhead of building new and old trigger references
1336 * even when no triggers exist
1338 extern int sqlite3_always_code_trigger_setup;
1341 ** Internal function prototypes
1343 int sqlite3StrICmp(const char *, const char *);
1344 int sqlite3StrNICmp(const char *, const char *, int);
1345 int sqlite3HashNoCase(const char *, int);
1346 int sqlite3IsNumber(const char*, int*, u8);
1347 int sqlite3Compare(const char *, const char *);
1348 int sqlite3SortCompare(const char *, const char *);
1349 void sqlite3RealToSortable(double r, char *);
1350 #ifdef SQLITE_MEMDEBUG
1351 void *sqlite3Malloc_(int,int,char*,int);
1352 void sqlite3Free_(void*,char*,int);
1353 void *sqlite3Realloc_(void*,int,char*,int);
1354 char *sqlite3StrDup_(const char*,char*,int);
1355 char *sqlite3StrNDup_(const char*, int,char*,int);
1356 void sqlite3CheckMemory(void*,int);
1357 #else
1358 void *sqlite3Malloc(int);
1359 void *sqlite3MallocRaw(int);
1360 void sqlite3Free(void*);
1361 void *sqlite3Realloc(void*,int);
1362 char *sqlite3StrDup(const char*);
1363 char *sqlite3StrNDup(const char*, int);
1364 # define sqlite3CheckMemory(a,b)
1365 # define sqlite3MallocX sqlite3Malloc
1366 #endif
1367 void sqlite3FreeX(void*);
1368 void *sqlite3MallocX(int);
1369 char *sqlite3MPrintf(const char*, ...);
1370 char *sqlite3VMPrintf(const char*, va_list);
1371 void sqlite3DebugPrintf(const char*, ...);
1372 void *sqlite3TextToPtr(const char*);
1373 void sqlite3SetString(STRPTR *, ...);
1374 void sqlite3ErrorMsg(Parse*, const char*, ...);
1375 void sqlite3Dequote(char*);
1376 int sqlite3KeywordCode(const char*, int);
1377 int sqlite3RunParser(Parse*, const char*, STRPTR *);
1378 void sqlite3FinishCoding(Parse*);
1379 Expr *sqlite3Expr(int, Expr*, Expr*, const Token*);
1380 Expr *sqlite3RegisterExpr(Parse*,Token*);
1381 Expr *sqlite3ExprAnd(Expr*, Expr*);
1382 void sqlite3ExprSpan(Expr*,Token*,Token*);
1383 Expr *sqlite3ExprFunction(ExprList*, Token*);
1384 void sqlite3ExprAssignVarNumber(Parse*, Expr*);
1385 void sqlite3ExprDelete(Expr*);
1386 ExprList *sqlite3ExprListAppend(ExprList*,Expr*,Token*);
1387 void sqlite3ExprListDelete(ExprList*);
1388 int sqlite3Init(sqlite3*, STRPTR*);
1389 int sqlite3InitCallback(void*, int, char**, char**);
1390 void sqlite3Pragma(Parse*,Token*,Token*,Token*,int);
1391 void sqlite3ResetInternalSchema(sqlite3*, int);
1392 void sqlite3BeginParse(Parse*,int);
1393 void sqlite3RollbackInternalChanges(sqlite3*);
1394 void sqlite3CommitInternalChanges(sqlite3*);
1395 Table *sqlite3ResultSetOfSelect(Parse*,char*,Select*);
1396 void sqlite3OpenMasterTable(Vdbe *v, int);
1397 void sqlite3StartTable(Parse*,Token*,Token*,Token*,int,int);
1398 void sqlite3AddColumn(Parse*,Token*);
1399 void sqlite3AddNotNull(Parse*, int);
1400 void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int);
1401 void sqlite3AddColumnType(Parse*,Token*,Token*);
1402 void sqlite3AddDefaultValue(Parse*,Expr*);
1403 void sqlite3AddCollateType(Parse*, const char*, int);
1404 void sqlite3EndTable(Parse*,Token*,Token*,Select*);
1406 #ifndef SQLITE_OMIT_VIEW
1407 void sqlite3CreateView(Parse*,Token*,Token*,Token*,Select*,int);
1408 int sqlite3ViewGetColumnNames(Parse*,Table*);
1409 #else
1410 # define sqlite3ViewGetColumnNames(A,B) 0
1411 #endif
1413 void sqlite3DropTable(Parse*, SrcList*, int);
1414 void sqlite3DeleteTable(sqlite3*, Table*);
1415 void sqlite3Insert(Parse*, SrcList*, ExprList*, Select*, IdList*, int);
1416 IdList *sqlite3IdListAppend(IdList*, Token*);
1417 int sqlite3IdListIndex(IdList*,const char*);
1418 SrcList *sqlite3SrcListAppend(SrcList*, Token*, Token*);
1419 void sqlite3SrcListAddAlias(SrcList*, Token*);
1420 void sqlite3SrcListAssignCursors(Parse*, SrcList*);
1421 void sqlite3IdListDelete(IdList*);
1422 void sqlite3SrcListDelete(SrcList*);
1423 void sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*,
1424 Token*);
1425 void sqlite3DropIndex(Parse*, SrcList*);
1426 void sqlite3AddKeyType(Vdbe*, ExprList*);
1427 void sqlite3AddIdxKeyType(Vdbe*, Index*);
1428 int sqlite3Select(Parse*, Select*, int, int, Select*, int, int*, char *aff);
1429 Select *sqlite3SelectNew(ExprList*,SrcList*,Expr*,ExprList*,Expr*,ExprList*,
1430 int,Expr*,Expr*);
1431 void sqlite3SelectDelete(Select*);
1432 void sqlite3SelectUnbind(Select*);
1433 Table *sqlite3SrcListLookup(Parse*, SrcList*);
1434 int sqlite3IsReadOnly(Parse*, Table*, int);
1435 void sqlite3OpenTableForReading(Vdbe*, int iCur, Table*);
1436 void sqlite3OpenTable(Vdbe*, int iCur, Table*, int);
1437 void sqlite3DeleteFrom(Parse*, SrcList*, Expr*);
1438 void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int);
1439 WhereInfo *sqlite3WhereBegin(Parse*, SrcList*, Expr*, ExprList**);
1440 void sqlite3WhereEnd(WhereInfo*);
1441 void sqlite3ExprCode(Parse*, Expr*);
1442 void sqlite3ExprCodeAndCache(Parse*, Expr*);
1443 int sqlite3ExprCodeExprList(Parse*, ExprList*);
1444 void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
1445 void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
1446 void sqlite3NextedParse(Parse*, const char*, ...);
1447 Table *sqlite3FindTable(sqlite3*,const char*, const char*);
1448 Table *sqlite3LocateTable(Parse*,const char*, const char*);
1449 Index *sqlite3FindIndex(sqlite3*,const char*, const char*);
1450 void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*);
1451 void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*);
1452 void sqlite3Vacuum(Parse*, Token*);
1453 int sqlite3RunVacuum(STRPTR*, sqlite3*);
1454 char *sqlite3NameFromToken(Token*);
1455 int sqlite3ExprCheck(Parse*, Expr*, int, int*);
1456 int sqlite3ExprCompare(Expr*, Expr*);
1457 int sqliteFuncId(Token*);
1458 int sqlite3ExprResolveNames(NameContext *, Expr *);
1459 int sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
1460 Vdbe *sqlite3GetVdbe(Parse*);
1461 void sqlite3Randomness(int, void*);
1462 void sqlite3RollbackAll(sqlite3*);
1463 void sqlite3CodeVerifySchema(Parse*, int);
1464 void sqlite3BeginTransaction(Parse*, int);
1465 void sqlite3CommitTransaction(Parse*);
1466 void sqlite3RollbackTransaction(Parse*);
1467 int sqlite3ExprIsConstant(Expr*);
1468 int sqlite3ExprIsInteger(Expr*, int*);
1469 int sqlite3IsRowid(const char*);
1470 void sqlite3GenerateRowDelete(sqlite3*, Vdbe*, Table*, int, int);
1471 void sqlite3GenerateRowIndexDelete(sqlite3*, Vdbe*, Table*, int, char*);
1472 void sqlite3GenerateIndexKey(Vdbe*, Index*, int);
1473 void sqlite3GenerateConstraintChecks(Parse*,Table*,int,char*,int,int,int,int);
1474 void sqlite3CompleteInsertion(Parse*, Table*, int, char*, int, int, int);
1475 void sqlite3OpenTableAndIndices(Parse*, Table*, int, int);
1476 void sqlite3BeginWriteOperation(Parse*, int, int);
1477 Expr *sqlite3ExprDup(Expr*);
1478 void sqlite3TokenCopy(Token*, Token*);
1479 ExprList *sqlite3ExprListDup(ExprList*);
1480 SrcList *sqlite3SrcListDup(SrcList*);
1481 IdList *sqlite3IdListDup(IdList*);
1482 Select *sqlite3SelectDup(Select*);
1483 FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,int,u8,int);
1484 void sqlite3RegisterBuiltinFunctions(sqlite3*);
1485 void sqlite3RegisterDateTimeFunctions(sqlite3*);
1486 BOOL sqlite3SafetyOn(sqlite3*);
1487 BOOL sqlite3SafetyOff(sqlite3*);
1488 BOOL sqlite3SafetyCheck(sqlite3*);
1489 void sqlite3ChangeCookie(sqlite3*, Vdbe*, int);
1491 #ifndef SQLITE_OMIT_TRIGGER
1492 void sqlite3BeginTrigger(Parse*, Token*,Token*,int,int,IdList*,SrcList*,
1493 int,Expr*,int);
1494 void sqlite3FinishTrigger(Parse*, TriggerStep*, Token*);
1495 void sqlite3DropTrigger(Parse*, SrcList*);
1496 void sqlite3DropTriggerPtr(Parse*, Trigger*, int);
1497 int sqlite3TriggersExist(Parse*, Table*, int, ExprList*);
1498 int sqlite3CodeRowTrigger(Parse*, int, ExprList*, int, Table *, int, int,
1499 int, int);
1500 void sqliteViewTriggers(Parse*, Table*, Expr*, int, ExprList*);
1501 void sqlite3DeleteTriggerStep(TriggerStep*);
1502 TriggerStep *sqlite3TriggerSelectStep(Select*);
1503 TriggerStep *sqlite3TriggerInsertStep(Token*, IdList*, ExprList*,
1504 Select*,int);
1505 TriggerStep *sqlite3TriggerUpdateStep(Token*, ExprList*, Expr*, int);
1506 TriggerStep *sqlite3TriggerDeleteStep(Token*, Expr*);
1507 void sqlite3DeleteTrigger(Trigger*);
1508 void sqlite3UnlinkAndDeleteTrigger(sqlite3*,int,const char*);
1509 #else
1510 # define sqlite3TriggersExist(A,B,C,D,E,F) 0
1511 # define sqlite3DeleteTrigger(A)
1512 # define sqlite3DropTriggerPtr(A,B,C)
1513 # define sqlite3UnlinkAndDeleteTrigger(A,B,C)
1514 # define sqlite3CodeRowTrigger(A,B,C,D,E,F,G,H,I) 0
1515 #endif
1517 int sqlite3JoinType(Parse*, Token*, Token*, Token*);
1518 void sqlite3CreateForeignKey(Parse*, ExprList*, Token*, ExprList*, int);
1519 void sqlite3DeferForeignKey(Parse*, int);
1520 #ifndef SQLITE_OMIT_AUTHORIZATION
1521 void sqlite3AuthRead(Parse*,Expr*,SrcList*);
1522 int sqlite3AuthCheck(Parse*,int, const char*, const char*, const char*);
1523 void sqlite3AuthContextPush(Parse*, AuthContext*, const char*);
1524 void sqlite3AuthContextPop(AuthContext*);
1525 #else
1526 # define sqlite3AuthRead(a,b,c)
1527 # define sqlite3AuthCheck(a,b,c,d,e) SQLITE_OK
1528 # define sqlite3AuthContextPush(a,b,c)
1529 # define sqlite3AuthContextPop(a) ((void)(a))
1530 #endif
1531 void sqlite3Attach(Parse*, Token*, Token*, int, Token*);
1532 void sqlite3Detach(Parse*, Token*);
1533 int sqlite3BtreeFactory(const sqlite3 *db, const char *zFilename,
1534 int omitJournal, int nCache, Btree **ppBtree);
1535 int sqlite3FixInit(DbFixer*, Parse*, int, const char*, const Token*);
1536 int sqlite3FixSrcList(DbFixer*, SrcList*);
1537 int sqlite3FixSelect(DbFixer*, Select*);
1538 int sqlite3FixExpr(DbFixer*, Expr*);
1539 int sqlite3FixExprList(DbFixer*, ExprList*);
1540 int sqlite3FixTriggerStep(DbFixer*, TriggerStep*);
1541 double sqlite3AtoF(const char *z, const char **);
1542 char *sqlite3_snprintf(int,char*,const char*,...);
1543 BOOL sqlite3GetInt32(const char *, int*);
1544 BOOL sqlite3FitsIn64Bits(const char *);
1545 int sqlite3utf16ByteLen(const void *pData, int nChar);
1546 int sqlite3utf8CharLen(const char *pData, int nByte);
1547 int sqlite3ReadUtf8(const unsigned char *);
1548 int sqlite3PutVarint(unsigned char *, u64);
1549 int sqlite3GetVarint(const unsigned char *, u64 *);
1550 int sqlite3GetVarint32(const unsigned char *, u32 *);
1551 int sqlite3VarintLen(u64 v);
1552 void sqlite3IndexAffinityStr(Vdbe *, Index *);
1553 void sqlite3TableAffinityStr(Vdbe *, Table *);
1554 char sqlite3CompareAffinity(Expr *pExpr, char aff2);
1555 int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
1556 char sqlite3ExprAffinity(Expr *pExpr);
1557 BOOL sqlite3atoi64(const char*, i64*);
1558 void sqlite3Error(sqlite3*, int, const char*,...);
1559 void *sqlite3HexToBlob(const char *z);
1560 int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
1561 CONST_STRPTR sqlite3ErrStr(int);
1562 int sqlite3ReadUniChar(const char *zStr, int *pOffset, u8 *pEnc, int fold);
1563 int sqlite3ReadSchema(Parse *pParse);
1564 CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char *,int,int);
1565 CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char *zName, int nName);
1566 CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr);
1567 int sqlite3CheckCollSeq(Parse *, CollSeq *);
1568 int sqlite3CheckIndexCollSeq(Parse *, Index *);
1569 int sqlite3CheckObjectName(Parse *, const char *);
1570 void sqlite3VdbeSetChanges(sqlite3 *, int);
1571 void sqlite3utf16Substr(sqlite3_context *,int,sqlite3_value **);
1573 const void *sqlite3ValueText(sqlite3_value*, u8);
1574 int sqlite3ValueBytes(sqlite3_value*, u8);
1575 void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, void(*)(void*));
1576 void sqlite3ValueFree(sqlite3_value*);
1577 sqlite3_value *sqlite3ValueNew();
1578 sqlite3_value *sqlite3GetTransientValue(sqlite3*db);
1579 int sqlite3ValueFromExpr(Expr *, u8, u8, sqlite3_value **);
1580 void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
1581 extern const unsigned char sqlite3UpperToLower[];
1582 void sqlite3RootPageMoved(Db*, int, int);
1583 void sqlite3Reindex(Parse*, Token*, Token*);
1584 void sqlite3AlterFunctions(sqlite3*);
1585 void sqlite3AlterRenameTable(Parse*, SrcList*, Token*);
1586 int sqlite3GetToken(const unsigned char *, int *);
1587 void sqlite3NestedParse(Parse*, const char*, ...);
1588 void sqlite3ExpirePreparedStatements(sqlite3*);
1589 void sqlite3CodeSubselect(Parse *, Expr *);
1590 int sqlite3SelectResolve(Parse *, Select *, NameContext *);
1591 void sqlite3ColumnDefault(Vdbe *, Table *, int);
1592 void sqlite3AlterFinishAddColumn(Parse *, Token *);
1593 void sqlite3AlterBeginAddColumn(Parse *, SrcList *);
1594 const char *sqlite3TestErrorName(int);
1595 CollSeq *sqlite3GetCollSeq(sqlite3*, CollSeq *, const char *, int);
1597 #ifdef SQLITE_SSE
1598 #include "sseInt.h"
1599 #endif
1601 #endif