Lines Matching defs:Table
520 #define SQLITE_LOCKED 6 /* A table in the database is locked */
1788 ** full table scans in the query optimizer. ^The default setting is determined
1791 ** The ability to disable the use of covering indices for full table scans
1946 ** the table has a column of type [INTEGER PRIMARY KEY] then that column
1950 ** most recent successful [INSERT] into a rowid table or [virtual table]
1957 ** ^(If an [INSERT] occurs within a trigger or within a [virtual table]
1959 ** row as long as the trigger or virtual table method is running.
1960 ** But once the trigger or virtual table method ends, the value returned
1962 ** table method began.)^
2002 ** are not counted. Only real table changes are counted.
2004 ** ^(A "row change" is a change to a single row of a single table
2007 ** rollback, ABORT processing, [DROP TABLE], or by any other
2052 ** do rollbacks or ABORT processing, or [DROP TABLE] processing. The
2149 ** an attempt is made to access a database table associated with
2151 ** or process has the table locked.
2207 ** for a specified amount of time when a table is locked. ^The handler
2231 ** Definition: A <b>result table</b> is memory data structure created by the
2232 ** [sqlite3_get_table()] interface. A result table records the
2235 ** The table conceptually has a number of rows and columns. But
2236 ** these numbers are not part of the result table itself. These
2240 ** A result table is an array of pointers to zero-terminated UTF-8 strings.
2247 ** A result table might consist of one or more memory allocations.
2248 ** It is not safe to pass a result table directly to [sqlite3_free()].
2249 ** A result table should be deallocated using [sqlite3_free_table()].
2251 ** ^(As an example of the result table format, suppose a query result
2263 ** result table has 8 entries. Suppose the result table is stored
2279 ** string of its 2nd parameter and returns a result table to the
2283 ** it must pass the result table pointer to sqlite3_free_table() in order to
2361 ** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES('%q')", zText);
2389 ** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES(%Q)", zText);
2510 ** select random [ROWID | ROWIDs] when inserting new records into a table that
2563 ** a NULL value in place of the table column that would have
2566 ** columns of a table.
2649 #define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */
2650 #define SQLITE_CREATE_TABLE 2 /* Table Name NULL */
2651 Table Name */
2652 #define SQLITE_CREATE_TEMP_TABLE 4 /* Table Name NULL */
2653 #define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */
2655 #define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */
2657 #define SQLITE_DELETE 9 /* Table Name NULL */
2658 #define SQLITE_DROP_INDEX 10 /* Index Name Table Name */
2659 #define SQLITE_DROP_TABLE 11 /* Table Name NULL */
2660 #define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */
2661 #define SQLITE_DROP_TEMP_TABLE 13 /* Table Name NULL */
2662 #define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */
2664 #define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */
2666 #define SQLITE_INSERT 18 /* Table Name NULL */
2668 #define SQLITE_READ 20 /* Table Name Column Name */
2671 #define SQLITE_UPDATE 23 /* Table Name Column Name */
2674 #define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */
2676 #define SQLITE_ANALYZE 28 /* Table Name NULL */
2677 #define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */
2678 #define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */
2928 ** <table border="1" align=center cellpadding=5>
2953 ** </table>
3157 ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
3163 ** <dd>The maximum number of columns in a table definition or in the
3384 ** that can be stored in a database table. SQLite uses dynamic typing
3652 ** ^These routines provide a means to determine the database, table, and
3653 ** table column that is the origin of a particular result column in
3655 ** ^The name of the database or table or column can be returned as
3657 ** the database name, the _table_ routines return the table name, and
3666 ** database, table, and column.
3676 ** occurs. ^Otherwise, they return the name of the attached database, table,
3706 ** returned result set of that [SELECT] is a table column (not an
3707 ** expression or subquery) then the declared type of the table
3714 ** CREATE TABLE t1(c1 VARIANT);
3940 ** conversion automatically. ^(The following table details the conversions
3944 ** <table border="1">
3963 ** </table>
3966 ** The table above makes reference to standard C library functions atoi()
3969 ** used in the table
5026 ** a rowid table.
5031 ** row is updated, inserted or deleted in a rowid table.
5038 ** database and table name containing the affected row.
5199 ** CAPI3REF: Extract Metadata About A Column Of A Table
5202 ** database table accessible using the [database connection] handle
5208 ** table or NULL. ^If it is NULL, then all attached databases are searched
5209 ** for the table using the same algorithm used by the database engine to
5210 ** resolve unqualified table references.
5212 ** ^The third and fourth parameters to this function are the table and column
5221 ** <table border="1">
5229 ** </table>
5236 ** ^If the specified table is actually a view, an [error code] is returned.
5253 ** error occurs during this process, or if the requested table or column
5263 const char *zTableName, /* Table name */
5387 ** The interface to the virtual-table mechanism is currently considered
5391 ** When the virtual-table mechanism stabilizes, we will declare the
5396 ** Structures used by the virtual table interface
5404 ** CAPI3REF: Virtual Table Object
5405 ** KEYWORDS: sqlite3_module {virtual table module}
5407 ** This structure, sometimes called a "virtual table module",
5411 ** ^A virtual table module is created by filling in a persistent
5455 ** CAPI3REF: Virtual Table Indexing Information
5459 ** of the [virtual table] interface to
5461 ** method of a [virtual table module]. The fields under **Inputs** are the
5481 ** relevant to the particular virtual table being queried.
5491 ** virtual table and is not checked again by SQLite.)^
5504 ** to a linear scan of an SQLite table with N rows. A cost of log(N)
5506 ** binary search on a unique indexed field of an SQLite table with N rows.
5512 ** structure for SQLite version 3.8.2. If a virtual table extension is
5527 } *aConstraint; /* Table of WHERE clause constraints */
5548 ** CAPI3REF: Virtual Table Constraint Operator Codes
5553 ** a query that uses a [virtual table].
5563 ** CAPI3REF: Register A Virtual Table Implementation
5565 ** ^These routines are used to register a new [virtual table module] name.
5567 ** creating a new [virtual table] using the module and before using a
5568 ** preexisting [virtual table] for the module.
5573 ** the implementation of the [virtual table module]. ^The fourth
5575 ** into the [xCreate] and [xConnect] methods of the virtual table module
5576 ** when a new virtual table is be being created or reinitialized.
5602 ** CAPI3REF: Virtual Table Instance Object
5605 ** Every [virtual table module] implementation uses a subclass
5607 ** of the [virtual table]. Each subclass will
5620 const sqlite3_module *pModule; /* The module for this virtual table */
5623 /* Virtual table implementations will typically add additional fields */
5627 ** CAPI3REF: Virtual Table Cursor Object
5628 ** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor}
5630 ** Every [virtual table module] implementation uses a subclass of the
5632 ** [virtual table] and are used
5633 ** to loop through the virtual table. Cursors are created using the
5644 sqlite3_vtab *pVtab; /* Virtual table of this cursor */
5645 /* Virtual table implementations will typically add additional fields */
5649 ** CAPI3REF: Declare The Schema Of A Virtual Table
5652 ** [virtual table module] call this interface
5659 ** CAPI3REF: Overload A Function For A Virtual Table
5662 ** using the [xFindFunction] method of the [virtual table module].
5672 ** by a [virtual table].
5677 ** The interface to the virtual-table mechanism defined above (back up
5682 ** When the virtual-table mechanism stabilizes, we will declare the
5704 ** in row iRow, column zColumn, table zTable in database zDb;
5749 ** table. Incremental BLOB I/O is not possible on [WITHOUT ROWID] tables.
5773 ** to a different row of the same database table. ^The new row is identified
5775 ** changed. ^The database, table and column on which the blob handle is open
5781 ** the nominated column.)^ ^If the new row is not present in the table, or if
6545 ** statements. For example, if the number of table steps greatly exceeds
6546 ** the number of table searches or result rows, that would tend to indicate
6547 ** that the prepared statement is using a full table scan rather than
6574 ** a table as part of a full table scan. Large numbers for this counter
6739 ** <table border=1 width=85% align=center>
6746 ** </table>
7072 ** shared-cache table, and more than one other connection currently holds
7073 ** a read-lock on the same table, then SQLite arbitrarily selects one of
7133 ** <b>The "DROP TABLE" Exception</b>
7137 ** one exception. When executing a "DROP TABLE" or "DROP INDEX" statement,
7142 ** invoked immediately. If the application then re-attempts the "DROP TABLE"
7148 ** the special "DROP TABLE/INDEX" case, the extended error code is just
7394 ** CAPI3REF: Virtual Table Interface Configuration
7397 ** of a [virtual table] implementation to configure
7398 ** various facets of the virtual table interface.
7401 ** xCreate virtual table method then the behavior is undefined.
7410 ** CAPI3REF: Virtual Table Configuration Options
7413 ** [sqlite3_vtab_config()] interface that [virtual table] implementations
7420 ** where X is an integer. If X is zero, then the [virtual table] whose
7428 ** If X is non-zero, then the virtual table implementation guarantees
7438 ** Virtual table implementations that are required to handle OR REPLACE
7441 ** CONFLICT policy is REPLACE, the virtual table implementation should
7451 ** CAPI3REF: Determine The Virtual Table Conflict Policy
7454 ** of a [virtual table] implementation for an INSERT or UPDATE operation. ^The
7458 ** [virtual table].
7467 ** inform a [virtual table] implementation what the [ON CONFLICT] mode
7641 ** limits the size of a row in a table or index.
7653 ** * Columns in a table
7663 ** not have more than a dozen or so columns in any table. And if
7725 ** table and for temporary tables. The SQLITE_DEFAULT_CACHE_SIZE
8109 ** This is the header file for the generic hash-table implementation
8119 /* A complete hash table is an instance of the following structure.
8127 ** All elements of the hash table are on a single doubly-linked list.
8136 ** Hash.ht table is never allocated because if there are few elements
8137 ** in the table, it is faster to do a linear search than to manage
8138 ** the hash table.
8141 unsigned int htsize; /* Number of buckets in the hash table */
8142 unsigned int count; /* Number of entries in this table */
8144 struct _ht { /* the hash table */
8150 /* Each element in the hash table is an instance of the following
8157 HashElem *next, *prev; /* Next and previous elements in the table */
8171 ** Macros for looping over all elements of a hash table. The idiom is
8189 ** Number of entries in a hash table
8513 ** table or index. This is an unsigned integer type. For 99.9% of
8694 ** Name of the master database table. The master database table
8695 ** is a special table that holds the names and attributes of all
8702 ** The root-page of the master database table.
8707 ** The name of the schema table.
8812 typedef struct Table Table;
8937 ** Every SQLite table must have either BTREE_INTKEY or BTREE_BLOBKEY set.
8938 ** With BTREE_INTKEY, the table key is a 64-bit integer and arbitrary data
8944 #define BTREE_INTKEY 1 /* Table has only 64-bit signed integer keys */
8945 #define BTREE_BLOBKEY 2 /* Table has keys only - no data */
8986 Btree*, /* BTree containing table to open */
10349 Hash fkeyHash; /* All foreign keys by referenced table name */
10350 Table *pSeqTab; /* The sqlite_sequence table used by AUTOINCREMENT */
10422 ** A hash table for function definitions.
10428 FuncDef *a[23]; /* Hash table for functions */
10462 int newTnum; /* Rootpage of table being initialized */
10513 FuncDefHash aFunc; /* Hash table of connection functions */
10553 #define SQLITE_InternChanges 0x00000002 /* Uncommitted Hash table changes */
10600 #define SQLITE_Stat3 0x0800 /* Use the SQLITE_STAT3 table */
10636 ** hash table. When multiple functions have the same name, the hash table
10759 ** Each SQLite module (virtual table definition) is defined by an
10761 ** hash table.
10771 ** information about each column of an SQL table is held in an instance
10789 #define COLFLAG_HIDDEN 0x0002 /* A hidden column in a virtual table */
10857 ** An object of this type is created for each virtual table present in
10863 ** instance of the sqlite3_vtab* handle used to access the virtual table
10869 ** then be used by the virtual table implementation to access real tables
10872 ** connection as that used to execute SQL operations on the virtual table.
10874 ** All VTable objects that correspond to a single table in a shared
10876 ** the Table.pVTable member variable of the corresponding Table object.
10878 ** table, it searches the list for the VTable that corresponds to the
10882 ** When an in-memory Table object is deleted (for example when the
10885 ** immediately. Instead, they are moved from the Table.pVTable list to
10899 sqlite3 *db; /* Database connection associated with this table */
10909 ** Each SQL table is represented in memory by an instance of the
10912 ** Table.zName is the name of the table. The case of the original
10913 ** CREATE TABLE statement is stored, but case is not significant for
10916 ** Table.nCol is the number of columns in this table. Table.aCol is a
10919 ** If the table has an INTEGER PRIMARY KEY, then Table.iPKey is the index of
10920 ** the column that is that key. Otherwise Table.iPKey is negative. Note
10923 ** the table. If a table has no INTEGER PRIMARY KEY, then a random rowid
10924 ** is generated for each row of the table. TF_HasPrimaryKey is set if
10925 ** the table has any PRIMARY KEY, INTEGER or otherwise.
10927 ** Table.tnum is the page number for the root BTree page of the table in the
10928 ** database file. If Table.iDb is the index of the database table backend
10931 ** then the table is stored in a file that is automatically deleted
10932 ** when the VDBE cursor to the table is closed. In this case Table.tnum
10933 ** refers VDBE cursor number that holds the table open, not to the root
10935 ** sub-query that appears instead of a real table name in the FROM clause
10938 struct Table {
10939 char *zName; /* Name of the table or view */
10941 Index *pIndex; /* List of SQL indexes on this table. */
10943 FKey *pFKey; /* Linked list of all foreign keys in this table */
10948 LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */
10949 int tnum; /* Root BTree node for this table (see note above) */
10951 i16 nCol; /* Number of columns in this table */
10952 u16 nRef; /* Number of pointers to this Table */
10953 LogEst szTabRow; /* Estimated size of each table row in bytes */
10955 LogEst costMult; /* Cost multiplier for using this table */
10960 int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */
10968 Schema *pSchema; /* Schema that contains this table */
10969 Table *pNextZombie; /* Next on the Parse.pZombieTab list */
10973 ** Allowed values for Table.tabFlags.
10975 #define TF_Readonly 0x01 /* Read-only system table */
10976 #define TF_Ephemeral 0x02 /* An ephemeral table */
10977 #define TF_HasPrimaryKey 0x04 /* Table has a primary key */
10979 #define TF_Virtual 0x10 /* Is a virtual table */
10984 ** Test to see whether or not a table is a virtual table. This is
10986 ** table support is omitted from the build.
10996 /* Does the table have a rowid */
11002 ** A foreign key is associated with two tables. The "from" table is
11003 ** the table that contains the REFERENCES clause that creates the foreign
11004 ** key. The "to" table is the table that is named in the REFERENCES clause.
11007 ** CREATE TABLE ex1(
11012 ** For foreign key "fk1", the from-table is "ex1" and the to-table is "ex2".
11015 ** from-table == child-table
11016 ** to-table == parent-table
11019 ** which is attached to the from-table. The to-table need not exist when
11020 ** the from-table is created. The existence of the to-table is not checked.
11022 ** The list of all parents for child Table X is held at X.pFKey.
11024 ** A list of all children for a table named Z (which might not even exist)
11028 Table *pFrom; /* Table containing the REFERENCES clause (aka: Child) */
11030 char *zTo; /* Name of table that the key points to (aka: Parent) */
11063 ** referenced table row is propagated into the row that holds the
11109 ** Records are used to store the content of a table row and to store
11135 ** The columns of the table that are to be indexed are described
11137 ** we have the following table and index:
11139 ** CREATE TABLE Ex1(c1 int, c2 int, c3 text);
11142 ** In the Table structure describing Ex1, nCol==3 because there are
11143 ** three columns in the table. In the Index structure describing
11161 Table *pTable; /* The SQL table being indexed */
11163 Index *pNext; /* The next index associated with the same table */
11192 #define SQLITE_IDXTYPE_PRIMARYKEY 2 /* Is the PRIMARY KEY for the table */
11201 ** Each sample stored in the sqlite_stat3 table is represented in memory
11243 ** than the source table */
11245 int sortingIdxPTab; /* Cursor number of pseudo-table */
11250 Table *pTab; /* Source table */
11251 int iTable; /* Cursor number of the source table */
11252 int iColumn; /* Column number within the source table */
11265 int iDistinct; /* Ephemeral table used to enforce DISTINCT */
11312 ** An expression of the form ID or ID.ID refers to a column in a table.
11314 ** the integer cursor number of a VDBE cursor pointing to that table and
11330 ** If the Expr is of type OP_Column, and the table it is selecting from
11331 ** is a disk table or the "old.*" pseudo-table, then pTab points to the
11332 ** corresponding table definition.
11378 int iTable; /* TK_COLUMN: cursor number of table holding column
11385 i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */
11390 Table *pTab; /* Table for TK_COLUMN expressions. */
11464 ** of the result column in the form: DATABASE.TABLE.COLUMN. This later
11475 unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */
11507 ** column names after a table name in an INSERT statement. In the statement
11511 ** If "a" is the k-th column of table "t", then IdList.a[0].idx==k.
11516 int idx; /* Index in some Table.aCol[] of a column named zName */
11543 ** Each table or subquery in the FROM clause is a separate element of
11547 ** can also be used to describe a particular table such as the table that
11549 ** such a table must be a simple name: ID. But in SQLite, the table can
11550 ** now be identified by a database name, a dot, then the table name: ID.ID.
11552 ** The jointype starts out showing the join type between the current table
11553 ** and the next table on the list. The parser builds the list this way.
11555 ** jointype expresses the join between the table and the previous table.
11557 ** In the colUsed field, the high-order bit (bit 63) is set if the table
11565 char *zDatabase; /* Name of database holding this table */
11566 char *zName; /* Name of the table */
11568 Table *pTab; /* An SQL table corresponding to zName */
11569 Select *pSelect; /* A SELECT statement used in place of a table name */
11581 int iCursor; /* The VDBE cursor number used to access this table */
11611 #define WHERE_OMIT_OPEN_CLOSE 0x0010 /* Table cursors are already open */
11613 #define WHERE_ONETABLE_ONLY 0x0040 /* Only code the 1st table in pTabList */
11629 ** A NameContext defines a context in which to resolve table and column
11633 ** to the table being operated on by INSERT, UPDATE, or DELETE. The
11717 #define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */
11756 ** row of result as the key in table pDest->iSDParm.
11760 ** SRT_EphemTab Create an temporary table pDest->iSDParm and store
11764 ** the table first.
11772 ** SRT_Table Store results in temporary table pDest->iSDParm.
11773 ** SRT_Fifo This is like SRT_EphemTab except that the table
11778 ** SRT_DistFifo Store results in a temporary table pDest->iSDParm.
11779 ** But also use temporary table pDest->iSDParm+1 as
11825 ** tables, the following information is attached to the Table.u.autoInc.p
11826 ** pointer of each autoincrement table to record some side information that
11827 ** the code generator needs. We have to keep per-table autoincrement
11834 Table *pTab; /* Table this info block refers to */
11903 ** used to store the set of table-locks required by the statement being
11931 int iPartIdxTab; /* Table corresponding to a partial index */
11937 int iTable; /* Table cursor number */
11938 i16 iColumn; /* Table column number */
11949 int regRowid; /* Register holding rowid of CREATE TABLE entry */
11954 TableLock *aTableLock; /* Required table locks for shared-cache mode */
11960 Table *pTriggerTab; /* Table triggers are being coded for */
11961 int addrCrTab; /* Address of OP_CreateTable opcode on CREATE TABLE */
11995 Table *pNewTable; /* A table being constructed by CREATE TABLE */
12002 Table **apVtabLock; /* Pointer to virtual tables needing locking */
12004 Table *pZombieTab; /* List of Table objects to delete after code gen */
12035 #define OPFLAG_CLEARCACHE 0x20 /* Clear pseudo-table cache in OP_Column */
12047 * 1. In the "trigHash" hash table (part of the sqlite3* that represents the
12049 * 2. All triggers associated with a single table form a linked list, using the
12052 * struct Table.
12059 char *table; /* The table or view to which the trigger applies */
12066 Schema *pTabSchema; /* Schema containing the table */
12068 Trigger *pNext; /* Next trigger associated with the table */
12098 * target -> A token holding the quoted name of the table to insert into.
12106 * target -> A token holding the quoted name of the table to delete from.
12111 * target -> A token holding the quoted name of the table to update rows of.
12124 Token target; /* Target table for DELETE, UPDATE, INSERT */
12286 ** (common table expressions) created by a single WITH clause.
12515 SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse*,Select*);
12517 SQLITE_PRIVATE Index *sqlite3PrimaryKeyIndex(Table*);
12556 SQLITE_PRIVATE int sqlite3ViewGetColumnNames(Parse*,Table*);
12565 SQLITE_PRIVATE void sqlite3CodeDropTable(Parse*, Table*, int, int);
12566 SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3*, Table*);
12596 SQLITE_PRIVATE Table *sqlite3SrcListLookup(Parse*, SrcList*);
12597 SQLITE_PRIVATE int sqlite3IsReadOnly(Parse*, Table*, int);
12598 SQLITE_PRIVATE void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int);
12613 SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8);
12614 SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int);
12633 SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3*,const char*, const char*);
12634 SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*);
12635 SQLITE_PRIVATE Table *sqlite3LocateTableItem(Parse*,int isView,struct SrcList_item *);
12667 SQLITE_PRIVATE void sqlite3GenerateRowDelete(Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8);
12668 SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*);
12671 SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(Parse*,Table*,int*,int,int,int,int,
12673 SQLITE_PRIVATE void sqlite3CompleteInsertion(Parse*,Table*,int,int,int,int*,int,int,int);
12674 SQLITE_PRIVATE int sqlite3OpenTableAndIndices(Parse*, Table*, int, int, u8*, int*, int*);
12680 SQLITE_PRIVATE void sqlite3RowidConstraint(Parse*, int, Table*);
12696 SQLITE_PRIVATE void sqlite3MaterializeView(Parse*, Table*, Expr*, int);
12705 SQLITE_PRIVATE Trigger *sqlite3TriggersExist(Parse *, Table*, int, ExprList*, int *pMask);
12706 SQLITE_PRIVATE Trigger *sqlite3TriggerList(Parse *, Table *);
12707 SQLITE_PRIVATE void sqlite3CodeRowTrigger(Parse*, Trigger *, int, ExprList*, int, Table *,
12709 SQLITE_PRIVATE void sqlite3CodeRowTriggerDirect(Parse *, Trigger *, Table *, int, int, int);
12710 void sqliteViewTriggers(Parse*, Table*, Expr*, int, ExprList*);
12719 SQLITE_PRIVATE u32 sqlite3TriggerColmask(Parse*,Trigger*,ExprList*,int,int,Table*,int);
12809 SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe*, Table*, int);
12879 SQLITE_PRIVATE void sqlite3ResolveSelfReference(Parse*,Table*,int,Expr*,ExprList*);
12881 SQLITE_PRIVATE void sqlite3ColumnDefault(Vdbe *, Table *, int, int);
12973 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table*);
12974 SQLITE_PRIVATE void sqlite3VtabDisconnect(sqlite3 *db, Table *p);
12983 SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3*, Table*);
12986 SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*);
12992 SQLITE_PRIVATE int sqlite3VtabCallConnect(Parse*, Table*);
13027 SQLITE_PRIVATE void sqlite3FkCheck(Parse*, Table*, int, int, int*, int);
13028 SQLITE_PRIVATE void sqlite3FkDropTable(Parse*, SrcList *, Table*);
13029 SQLITE_PRIVATE void sqlite3FkActions(Parse*, Table*, ExprList*, int, int*, int);
13030 SQLITE_PRIVATE int sqlite3FkRequired(Parse*, Table*, int*, int);
13031 SQLITE_PRIVATE u32 sqlite3FkOldmask(Parse*, Table*);
13032 SQLITE_PRIVATE FKey *sqlite3FkReferences(Table *);
13041 SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *, Table*);
13042 SQLITE_PRIVATE int sqlite3FkLocateIndex(Parse*,Table*,FKey*,Index**,int**);
13071 #define IN_INDEX_ROWID 1 /* Search the rowid of the table */
13075 #define IN_INDEX_NOOP 5 /* No table available. Use comparisons */
13247 ** The following 256 byte lookup table is used to support SQLites built-in
13379 ** Hash table for global functions - functions common to all
13380 ** database connections. After initialization, this table is
13916 ** A pseudo-table is a single-row table implemented by registers.
13923 Btree *pBt; /* Separate file holding temporary table */
13936 Bool isEphemeral:1; /* True for an ephemeral table */
13938 Bool isTable:1; /* True if a table requiring integer keys */
13939 Bool isOrdered:1; /* True if the underlying table is BTREE_UNORDERED */
13941 sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
14163 ** any virtual table method invocations made by the vdbe program. It is
14166 ** "DROP TABLE" statements and to prevent some nasty side effects of
14167 ** malloc failure when SQLite is invoked recursively by a virtual table
14518 sqlite3DeleteTable(db, (Table *)sqliteHashData(p));
16147 ** fatal. For example, if a malloc fails while resizing a hash table, this
16149 ** hash table will continue to function normally. So a malloc failure
16150 ** during a hash table resize is a benign fault.
17301 ** small chunk list, or into the large chunk hash table.
17472 ** chunk table or in the large chunk hash table. This is
20599 ** The following table is searched linearly, so it is good to put the
21755 ** This lookup table is used to help decode the first byte of
23623 /* Turn bulk memory into a hash table object by initializing the
23626 ** "pNew" is a pointer to the hash table that is to be initialized.
23636 /* Remove all entries from a hash table. Reclaim all memory.
23637 ** Call this routine to delete a hash table or to reset a hash table
23641 HashElem *elem; /* For looping over all elements of the table */
23671 /* Link pNew element into the hash table pH. If pEntry!=0 then also
23675 Hash *pH, /* The complete hash table */
23702 /* Resize the hash table so that it cantains "new_size" buckets.
23704 ** The hash table might fail to resize if sqlite3_malloc() fails or
23709 struct _ht *new_ht; /* The new hash table */
23719 /* The inability to allocates space for a larger hash table is
23724 ** use the actual amount of space allocated for the hash table (which
23745 ** hash table that matches the given key. The hash for this key has
23774 /* Remove a single entry from the hash table given a pointer to that
23808 /* Attempt to locate an element of the hash table pH with a key
23828 /* Insert an element into the hash table pH. The key is pKey,nKey
23837 ** the new data is returned and the hash table is unchanged.
23840 ** element corresponding to "key" is removed from the hash table.
23843 unsigned int h; /* the hash of the key modulo hash table size */
37535 ** But sometimes (for example when during a DROP of a large table) most
37573 /* Number of u32 values in hash table. */
37575 /* Maximum number of entries in hash table before
37598 ** a hash table that will hold up to BITVEC_MXHASH distinct values.
37619 u32 aHash[BITVEC_NINT]; /* Hash table representation */
37749 ** that BitvecClear can use to rebuilt its hash table.
38644 /* Hash table of all pages. The following variables may only be accessed
38650 PgHdr1 **apHash; /* Hash table for fast lookup by key */
38663 PgHdr1 *pNext; /* Next in hash table chain */
38944 ** This function is used to resize the hash table used by the cache passed
39021 ** Remove the page supplied as an argument from the hash table
39293 /* Step 1: Search the hash table for an existing entry. */
41927 ** Find a page in the hash table given its page number. Return
42894 ** in this case. But for things like temporary table (which will be
47644 ** database page number associated with each wal frame, and a hash-table
47659 ** Even without using the hash table, the last frame for page P
47666 ** The hash table consists of HASHTABLE_NSLOT 16-bit unsigned integers.
47668 ** hash table for each page number in the mapping section, so the hash
47669 ** table is never more than half full. The expected number of collisions
47670 ** prior to finding a match is 1. Each entry of the hash table is an
47675 ** K will be (mxFrame%HASHTABLE_NPAGE).) Unused slots of the hash table
47678 ** To look for page P in the hash table, first compute a hash iKey on
47683 ** Then start scanning entries of the hash table, starting with iKey
47684 ** (wrapping around to the beginning when the end of the hash table is
47687 ** wrap-around.) Because the hash table is never more than half full,
47711 ** Both readers can use the same hash table and mapping section to get
47712 ** the correct result. There may be entries in the hash table with
47714 ** slots in the hash table and so the first reader will get an answer as
47715 ** if no values greater than K0 had ever been inserted into the hash table
47720 ** When a rollback occurs, the value of K is decreased. Hash table entries
47722 ** from the hash table at this point.
47933 ** Each page of the wal-index mapping contains a hash-table made up of
47967 ** is a hash-table following every HASHTABLE_NPAGE page numbers in the
47978 ** The block of page numbers associated with the first hash-table in a
47980 ** hash-table on each aligned 32KB page of the wal-index.
48304 ** Return pointers to the hash table and page number array stored on
48308 ** Set output variable *paHash to point to the start of the hash table
48310 ** number of the first frame indexed by this hash table. If a
48311 ** slot in the hash table is set to N, it refers to frame number
48315 ** first frame indexed by the hash table, frame (*piZero+1).
48319 int iHash, /* Find the iHash'th table */
48350 ** Return the number of the wal-index page that contains the hash-table
48378 ** Remove entries from the hash table that point to WAL slots greater
48384 ** At most only the hash table containing pWal->hdr.mxFrame needs to be
48390 volatile ht_slot *aHash = 0; /* Pointer to hash table to clear */
48391 volatile u32 *aPgno = 0; /* Page number array for hash table */
48404 /* Obtain pointers to the hash-table and page-number array containing
48406 ** that the page said hash-table and array reside on is already mapped.
48412 /* Zero all hash-table entries that correspond to frame numbers greater
48431 ** via the hash table even after the cleanup.
48455 volatile ht_slot *aHash = 0; /* Hash table */
48460 ** page number array and hash table entry.
48463 int iKey; /* Hash table key */
48464 int idx; /* Value to write to hash-table slot */
48470 /* If this is the first entry to be added to this hash-table, zero the
48471 ** entire hash table and aPgno[] array before proceding.
48482 ** the hash-table before writing any new entries.
48489 /* Write the aPgno[] array entry and the hash-table slot. */
48498 /* Verify that the number of entries in the hash table exactly equals
48503 int nEntry = 0; /* Number of entries in the hash table */
48509 ** via the hash table. This turns out to be a really, really expensive
49802 /* Search the hash table or tables for an entry matching page number
49804 ** hash table (each hash table indexes up to HASHTABLE_NPAGE frames).
49808 ** table). This means the value just read from the hash
49818 ** if we had exclusive access to the hash-table:
49821 ** This condition filters out normal hash-table collisions.
49825 ** table after the current read-transaction had started.
49828 volatile ht_slot *aHash; /* Pointer to hash table */
50904 ** is opened on the table with root page BtShared.iTable. Locks are removed
50910 Pgno iTable; /* Root page of table */
50986 ** table (because there exists one or more read-locks on the table),
51017 u16 maxLeaf; /* Maximum local payload in a LEAFDATA table */
51018 u16 minLeaf; /* Minimum local payload in a LEAFDATA table */
51123 ** because the table is empty or because BtreeCursorFirst() has not been
51135 ** The table that this cursor was opened on still exists, but has been
51179 ** The pointer map is a lookup table that identifies the parent page for
51426 ** a statement since we will be comparing table and column names
51641 ** shared-cache table level locks. If the library is compiled with the
51661 ** table with root page iRoot. Return 1 if it does and 0 if not.
51663 ** For example, when writing to a table with root-page iRoot via
51670 ** the corresponding table. This makes things a bit more complicated,
51671 ** as this module treats each table as a separate structure. To determine
51672 ** the table corresponding to the index being written, this
51675 ** Instead of a lock on the table/index rooted at page iRoot, the caller may
51676 ** hold a write-lock on the schema table (root page 1). This is also
51708 /* Figure out the root-page that the lock should be held on. For table
51711 ** table. */
51725 ** write-lock on the schema table, or (if the client is reading) a
51746 ** table or index rooted at iRoot because other shared connections are
51747 ** simultaneously reading that same table or index.
51751 ** the iRoot table. Except, if the other Btree object has the
51755 ** For example, before writing to any part of the table or index
51776 ** (READ_LOCK or WRITE_LOCK) on the table with root-page iTab. Return
51816 ** may hold a WRITE_LOCK on any table in this file (since there can
51836 ** Add a lock on the table with root-page iTable to the shared-btree used
51864 ** table, and that lock is obtained in BtreeBeginTrans(). */
51872 /* First search the list for an existing lock on this table. */
51881 ** with table iTable, allocate one and link it into the list.
51909 ** Release all the table locks (locks obtained via calls to
52008 ** This function is called before modifying the contents of a table
52013 ** table is about to be deleted. In this case invalidate all incrblob
52014 ** cursors open on any row within the table with root-page pgnoRoot.
52141 /* If this is an intKey table, then the above call to BtreeKeySize()
52144 ** table, then malloc space for and store the pCur->nKey bytes of key
52173 ** the table with root-page iRoot. Usually, this is called just before cursor
52174 ** pExcept is used to modify the table (BtreeDelete() or BtreeInsert()).
53647 ** The call to sqlite3BtreeRollback() drops any table-locks held by
55121 ** cursors open with wrFlag==0 on the same table. Otherwise
55138 int iTable, /* Root page of table to open */
55149 ** b-tree database, the connection is holding the required table locks,
55187 int iTable, /* Root page of table to open */
55305 ** that is currently pointing to a row in a (non-empty) table.
55318 ** For a table with the INTKEY flag set, this routine returns the key
55487 ** invalidated if some other cursor writes to the same table, or if
55493 ** * Creating a table (may require moving an overflow page).
55688 ** in the table.
55735 ** table btrees (pPage->intKey==1). The number of bytes of available
55881 ** If the table has a virtual root page, then the cursor is moved to point
55882 ** to the virtual root page instead of the actual root page. A table has a
55884 ** single child page. This can only happen with the table rooted at page 1.
55895 ** indicating a table b-tree, or if the caller did specify a KeyInfo
55934 ** NULL, the caller expects a table b-tree. If this is not the case,
55940 ** in such a way that page pRoot is linked into a second b-tree table
56017 /* Move the cursor to the first entry in the table. Return SQLITE_OK
56019 ** or set *pRes to 1 if the table is empty.
56040 /* Move the cursor to the last entry in the table. Return SQLITE_OK
56042 ** or set *pRes to 1 if the table is empty.
56103 ** is smaller than intKey/pIdxKey or if the table is empty
56116 i64 intKey, /* The table key */
56177 ** be the right kind (index or table) of b-tree page. Otherwise
56314 ** Return TRUE if the cursor is not pointing at an entry of the table.
56317 ** past the last entry in the table or sqlite3BtreePrev() moves past
56318 ** the first entry. TRUE is also returned if the table is empty.
56321 /* TODO: What if the cursor is in CURSOR_REQUIRESEEK but all table entries
58016 ** of the table is a linear scan through the file. That
58476 ** define what table the record should be inserted into. The cursor
58479 ** For an INTKEY table, only the nKey value of the key is used. pKey is
58480 ** ignored. For a ZERODATA table, the pData and nData are both ignored.
58496 BtCursor *pCur, /* Insert data into the table of this cursor */
58526 ** intkey table, the caller should be inserting integer keys with a
58530 /* Save the positions of any other cursors open on this table.
58533 ** example, when inserting data into a table with auto-generated integer
58545 /* If this is an insert into a table b-tree, invalidate any incrblob
58567 TRACE(("INSERT: table=%d nkey=%lld ndata=%d page=%d %s\n",
58619 ** entry in the table, and the next row inserted has an integer key
58685 /* Save the positions of any other cursors open on this table before
58693 /* If this is a delete operation to remove a row from a table b-tree,
58759 ** Create a new BTree table. Write into *piTable the page
58760 ** number for the root page of the new table.
58774 int ptfFlags; /* Page-type flage for the root page of new table */
58790 /* Creating a new table may probably require moving an existing database
58798 ** root page of the new table should go. meta[3] is the largest root-page
58824 ** the new table (assuming an error did not occur). But we were
58924 BtShared *pBt, /* The BTree that contains the table */
58971 ** Delete all information from a single table in the database. iTable is
58972 ** the page number of the root of the table. After this routine returns,
58976 ** read cursors on the table. Open write cursors are moved to the
58977 ** root of the table.
58979 ** If pnChange is not NULL, then table iTable must be an intkey table. The
58981 ** entries in the table.
58992 /* Invalidate all incrblob cursors open on table iTable (assuming iTable
58993 ** is the root of a table b-tree - if it is not, the following call is
59003 ** Delete all information from the single table that pCur is open on.
59005 ** This routine only work for pCur on an ephemeral table.
59012 ** Erase all information in a table and add the root of the table to
59013 ** the freelist. Except, the root of the principle table (the one on
59017 ** cursors on the table.
59039 /* It is illegal to drop a table if any cursors are open on the
59072 /* If the table being dropped is the table with the largest root-page
59081 /* The table being dropped does not have the largest root-page
59696 ** a table. nRoot is the number of entries in aRoot.
59917 ** sqlite_master table. Otherwise SQLITE_OK.
59932 ** Obtain a lock on the table whose root page is iTab. The
59958 ** INTKEY table currently pointing at a valid table entry.
59981 /* Save the positions of all other cursors open on this table. This is
59985 ** Note that pCsr must be open on a BTREE_INTKEY table and saveCursorPosition()
59986 ** and hence saveAllCursors() cannot fail on a BTREE_INTKEY table, hence
59995 ** (c) the connection holds a write-lock on the table (if required),
59997 ** (e) the cursor points at a valid row of an intKey table.
61925 ** sqlite_stat3 table to the record format SQLite uses internally.
62039 ** in the sqlite_stat4 table.
63464 ** to 6.6 percent. The test case is inserting 1000 rows into a table
64987 ** the blob of data that it corresponds to. In a table record, all serial
64992 ** The following table describes the various storage classes for data:
65362 ** This function compares two index or table record keys in the same way
65622 ** This function compares the two table rows or index records
67131 ** 3 The name of the table that the column derives from
67132 ** 4 The name of the table column that the result column derives from
67226 ** Return the name of the table from which a result column derives.
67242 ** Return the name of the table column from which a result column derives.
68079 int nField, /* Number of fields in the table or index */
68081 int isBtreeCursor /* True for B-Tree. False for pseudo-table or vtab */
69586 ** with a CREATE TABLE statement.)
70301 ** If the OPFLAG_CLEARCACHE bit is set on P5 and P1 is a pseudo-table cursor,
70303 ** The first OP_Column against a pseudo-table after the value of the content
70342 assert( pC->pVtabCursor==0 ); /* OP_Column never called on virtual table */
70592 ** use as a data record in a database table or as a key
70743 ** Store the number of entries (an integer value) in the table or index
71103 ** are queried from within xNext() and other v-table methods using
71106 ** v-table would have to be ready for the sqlite3_vtab structure itself
71108 ** a v-table method.
71192 ** Open a read-only cursor for the database table whose root page is
71216 ** value, it is set to the number of columns in the table.
71237 ** Open a read/write cursor named P1 on the table or index whose root
71245 ** value, it is set to the number of columns in the table, or to the
71246 ** largest index of any column of the table that is actually used.
71249 ** in read/write mode. For a given table, there can be one or more read-only
71334 testcase( nField==0 ); /* Table with INTEGER PRIMARY KEY and nothing else */
71360 ** Open a new cursor P1 to a transient table.
71363 ** table is deleted automatically when the cursor is closed.
71365 ** P2 is the number of columns in the ephemeral table.
71366 ** The cursor points to a BTree table if P4==0 and to a BTree index
71408 ** opening it. If a transient table is required, just use the
71409 ** automatically created table with root-page 1 (an BLOB_INTKEY table).
71455 ** Open a new cursor that points to a fake table that contains a single
71460 ** A pseudo-table created by this opcode is used to hold a single
71463 ** is the only cursor opcode that works with a pseudo-table.
71466 ** the pseudo-table.
71497 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
71515 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
71533 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
71551 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
71695 /* res might be negative because the table is empty. Check to
71712 ** P1 is an open table cursor and P2 is a rowid integer. Arrange
71880 ** P1 is the index of a cursor open on an SQL table btree (with integer
71949 ** Get a new integer record number (a.k.a "rowid") used as the key to a table.
71951 ** table that cursor P1 points to. The new record number is written
71963 VdbeCursor *pC; /* Cursor of table to get the new rowid */
71986 ** it already exists in the table. If it does not exist, we have
72057 ** an AUTOINCREMENT table. */
72094 ** Write an entry into the table of cursor P1. A new entry is
72118 ** Parameter P4 may point to a string containing the table-name, or
72142 VdbeCursor *pC; /* Cursor to table into which insert is written */
72146 const char *zTbl; /* Table name - used by the opdate hook */
72209 ** record in the table. If it is left pointing at the next record, then
72216 ** P1 must not be pseudo-table. It has to be a real table with
72219 ** If P4 is not NULL, then it is the name of the table that P1 is
72235 ** OP_Column on the same table without any intervening operations that
72328 ** of a real table, not a pseudo-table.
72339 ** of a real table, not a pseudo-table.
72407 ** Store in register P2 an integer which is the key of the table entry that
72410 ** P1 can be either an ordinary table or a virtual table. There used to
72412 ** one opcode now works for both table types.
72476 ** will refer to the last entry in the database table or index.
72477 ** If the table or index is empty and P2>0, then jump immediately to P2.
72478 ** If P2 is 0 or if the table or index is not empty, fall through
72536 ** will refer to the first entry in the database table or index.
72537 ** If the table or index is empty and P2>0, then jump immediately to P2.
72538 ** If P2 is 0 or if the table or index is not empty, fall through
72580 ** table or index. If there are no more key/value pairs then fall through
72588 ** The P1 cursor must be for a real table, not a pseudo-table. P1 must have
72612 ** table or index. If there is no previous key/value pairs then fall through
72621 ** The P1 cursor must be for a real table, not a pseudo-table. If P1 is
72793 ** the rowid of the table entry to which this index entry points.
72916 ** Delete an entire database table or index whose root page in the database
72919 ** The table being destroyed is in the main database file if P3==0. If
72920 ** P3==1 then the table to be clear is in the auxiliary database file
72921 ** that is used to store tables create using CREATE TEMPORARY TABLE.
72928 ** movement was required (because the table being dropped was already
72979 ** Delete all contents of the database table or index whose root page
72981 ** remove the table or index from the database file.
72983 ** The table being clear is in the main database file if P2==0. If
72984 ** P2==1 then the table to be clear is in the auxiliary database file
72985 ** that is used to store tables create using CREATE TEMPORARY TABLE.
72987 ** If the P3 value is non-zero, then the table referred to must be an
72988 ** intkey table (an SQL table, not an index). In this case the row change
72989 ** count is incremented by the number of rows in the table being cleared.
72991 ** also incremented by the number of rows in the table being cleared.
73017 ** Delete all contents from the ephemeral table or sorter
73041 ** Allocate a new table in the main database file if P1==0 or in the
73043 ** P1>1. Write the root page number of the new table into
73046 ** The difference between a table and an index is this: A table must
73057 ** P1>1. Write the root page number of the new table into
73087 ** Read and parse all entries from the SQLITE_MASTER table of database P1
73143 ** Read the sqlite_stat1 table for database P1 and load the content
73144 ** of that table into the internal index hash table. This will cause
73157 ** the table named P4 in database P1. This is called after a table
73930 ** Obtain a lock on a particular table. This instruction is only used when
73937 ** P2 contains the root-page of the table to lock.
73939 ** P4 contains a pointer to the name of the table being locked. This is only
73952 sqlite3SetString(&p->zErrMsg, db, "database table is locked: %s", z);
73963 ** xBegin method for that table.
73966 ** within a callback to a virtual table xSync() method. If it is, the error
73981 ** P4 is the name of a virtual table in database P1. Call the xCreate method
73982 ** for that table.
73993 ** P4 is the name of a virtual table in database P1. Call the xDestroy method
73994 ** of that table.
74007 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
74009 ** table and stores that cursor in P1.
74053 ** This opcode invokes the xFilter method on the virtual table specified
74121 ** the row of the virtual-table that the
74177 ** Advance virtual table P1 to the next row in its result set and
74178 ** jump to instruction P2. Or, if the virtual table has reached
74201 ** some other method is next invoked on the save virtual table cursor.
74222 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
74254 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
74264 ** row. This can be NULL to have the virtual table select the new
74561 int iCol; /* Table column this handle is open on */
74642 const char *zTable, /* The table containing the blob */
74652 ** db/table/row entry. The reason for using a vdbe program instead
74684 Table *pTab;
74708 sqlite3ErrorMsg(pParse, "cannot open virtual table: %s", zTable);
74712 sqlite3ErrorMsg(pParse, "cannot open table without rowid: %s", zTable);
74799 /* Make sure a mutex is held on the table to be accessed */
74819 ** think that the table has one more column than it really
74960 ** database table.
76274 ** Table of methods for JournalFile sqlite3_file object.
76562 ** Table of methods for MemJournal sqlite3_file object.
76783 ** table and column.
76923 ** Subqueries stores the original database, table and column names for their
76924 ** result sets in ExprList.a[].zSpan, in the form "DATABASE.TABLE.COLUMN".
76960 ** pExpr->iTable Set to the cursor number for the table obtained
76962 ** pExpr->pTab Points to the Table structure of X.Y (even if
76964 ** pExpr->iColumn Set to the column number within the table.
76971 ** can be used. The zTable variable is the name of the table (the "Y"). This
76973 ** means that the form of the name is Z and that columns from any table
76981 const char *zDb, /* Name of the database containing table, or NULL */
76982 const char *zTab, /* Name of table containing column, or NULL */
76989 int cntTab = 0; /* Number of matching table names */
76997 Table *pTab = 0; /* Table hold the row */
77072 ** is for the right-hand table of a NATURAL JOIN or is in a
77164 ** SELECT a+b AS x FROM table WHERE x<10;
77245 /* If a column from a table in pSrcList is referenced, then record
77415 /* A table name and column name: ID.ID
77416 ** Or a database, table and column: ID.ID.ID
78070 ** table columns and result-set columns. At the same time, do error
78074 ** To resolve table columns references we look for nodes (or subtrees) of the
78080 ** Y: The name of a table in a FROM clause. Or in a trigger
78083 ** Z: The name of a column in table Y.
78088 ** Expr.pTab Points to the Table object for X.Y
78097 ** Table-name and function resolution occurs on the substituted expression
78185 ** Resolve names in expressions that can only reference a single table:
78197 Table *pTab, /* The table being referenced */
78254 ** CREATE TABLE t1(a);
79225 Table *pTab;
79671 Table *pTab;
79690 if( IsVirtual(pTab) ) return 0; /* FROM clause not a virtual table */
79708 ** Generate code that checks the left-most column of index table iCur to see if
79755 ** IN_INDEX_ROWID - The cursor was opened on a database table.
79759 ** populated epheremal table.
79766 ** SELECT <column> FROM <table>
79769 ** an ephemeral table might need to be generated from the RHS and then
79770 ** pX->iTable made to point to the ephermeral table instead of an
79771 ** existing table.
79775 ** IN_INDEX_MEMBERSHIP, then the generated table will be used for a
79782 ** An epheremal table must be used unless the selected <column> is guaranteed
79787 ** for fast set membership tests) then an epheremal table must
79814 int eType = 0; /* Type of RHS table. IN_INDEX_* */
79815 int iTab = pParse->nTab++; /* Cursor of the RHS table */
79822 /* Check to see if an existing table or index can be used to
79824 ** ephemeral table.
79829 Table *pTab; /* Table <table>. */
79842 /* Code an OP_Transaction and OP_TableLock for <table>. */
79864 ** be used in place of a temp-table, it must be ordered according
79900 ** then it is not worth creating an ephermeral table to evaluate
79913 /* Could not find an existing table or index to use as the RHS b-tree.
79914 ** We will have to generate an ephemeral table to do the job.
79950 ** to some integer key column of a table B-Tree. In this case, use an
80010 ** expression it is handled the same way. An ephemeral table is
80030 ** table allocated and opened above.
80059 ** store it in the temporary table. If <expr> is a column, then use
80094 /* Evaluate the expression and insert it into the temp table */
80204 /* Compute the RHS. After this step, the table with cursor
80287 /* In this case, the RHS is the ROWID of table b-tree
80432 ** particular table is stored in a particular register.
80565 ** Generate code to extract the value of the iCol-th column of a table.
80569 Table *pTab, /* The table containing the value */
80570 int iTabCur, /* The table cursor. Or the PK cursor for WITHOUT ROWID */
80591 ** table pTab and store the column value in a register. An effort
80600 Table *pTab, /* Description of the table we are reading from */
80601 int iColumn, /* Index of the table column */
80602 int iTable, /* The cursor pointing to the table */
81072 ** a virtual table column.
81076 ** see if it is a column in a virtual table. This is done because
81169 ** new.* pseudo-table, or 0 for the old.* pseudo-table. Expr.iColumn
81170 ** is set to the column of the pseudo-table to read, or to -1 to
81175 ** to reference another column of the old.* pseudo-table, where
81177 ** set to (n+1), where n is the number of columns in each pseudo-table.
81178 ** For a reference to any other column in the new.* pseudo-table, p1
81180 ** example, if the table on which triggers are being fired is
81183 ** CREATE TABLE t1(a, b);
81191 Table *pTab = pExpr->pTab;
81657 ** new.* pseudo-table, or 0 for the old.* pseudo-table. Expr.iColumn
81658 ** is set to the column of the pseudo-table to read, or to -1 to
82230 ** Expr.iTable<0 then assume a table number given by iTab.
82257 ** to count references to table columns in the arguments of an
82369 /* If we reach this point, it means that pExpr refers to a table
82594 ** that implements the ALTER TABLE command.
82599 ** ALTER TABLE logic from the build.
82606 ** ALTER TABLE command. The first argument is the text of a CREATE TABLE or
82607 ** CREATE INDEX command. The second is a table name. The table name in
82608 ** the CREATE TABLE or CREATE INDEX statement is replaced with the third
82611 ** sqlite_rename_table('CREATE TABLE abc(a, b, c)', 'def')
82612 ** -> 'CREATE TABLE def(a, b, c)'
82635 /* The principle used to locate the table name in the CREATE TABLE
82636 ** statement is that the table name is the first non-space token that
82668 ** generated by the ALTER TABLE ... RENAME command to modify the definition
82669 ** of any foreign key constraints that use the table being renamed as the
82670 ** parent table. It is passed three arguments:
82672 ** 1) The complete text of the CREATE TABLE statement being modified,
82673 ** 2) The old name of the table being renamed, and
82674 ** 3) The new name of the table being renamed.
82676 ** It returns the new CREATE TABLE statement. For example:
82678 ** sqlite_rename_parent('CREATE TABLE t1(a REFERENCES t2)', 't2', 't3')
82679 ** -> 'CREATE TABLE t1(a REFERENCES t3)'
82732 ** ALTER TABLE command. The first argument is the text of a CREATE TRIGGER
82733 ** statement. The second is a table name. The table name in the CREATE
82736 ** TRIGGER, not CREATE INDEX and CREATE TABLE.
82756 /* The principle used to locate the table name in the CREATE TRIGGER
82757 ** statement is that the table name is the first token that is immediatedly
82765 /* Ran out of input before finding the table name. Return NULL. */
82787 ** Note that ON cannot be a database, table or column name, so
82797 /* Variable tname now contains the token that is the old table-name
82808 ** Register built-in functions used to help implement ALTER TABLE
82859 ** tables that have foreign key constraints that refer to table pTab (i.e.
82860 ** constraints for which pTab is the parent table) from the sqlite_master
82861 ** table.
82863 static char *whereForeignKeys(Parse *pParse, Table *pTab){
82875 ** temporary triggers on table pTab from the sqlite_temp_master table. If
82876 ** table pTab has no temporary triggers, or is itself stored in the
82879 static char *whereTempTriggers(Parse *pParse, Table *pTab){
82884 /* If the table is not located in the temp-db (in which case NULL is
82906 ** Generate code to drop and reload the internal representation of table
82908 ** Argument zName is the name of the table in the database schema at
82911 ** "ALTER TABLE RENAME TO" statement.
82913 static void reloadTableSchema(Parse *pParse, Table *pTab, const char *zName){
82928 /* Drop any table triggers from the internal schema. */
82936 /* Drop the table and index from the internal schema. */
82939 /* Reload the table, index and permanent trigger schemas. */
82945 /* Now, if the table is not stored in the temp database, reload any temp
82955 ** Parameter zName is the name of a table that is about to be altered
82956 ** (either with ALTER TABLE ... RENAME TO or ALTER TABLE ... ADD COLUMN).
82957 ** If the table is a system table, this function leaves an error message
82960 ** Or, if zName is not a system table, zero is returned.
82964 sqlite3ErrorMsg(pParse, "table %s may not be altered", zName);
82971 ** Generate code to implement the "ALTER TABLE xxx RENAME TO yyy"
82976 SrcList *pSrc, /* The table to rename. */
82977 Token *pName /* The new table name. */
82979 int iDb; /* Database that contains the table */
82981 Table *pTab; /* Table being renamed */
82985 const char *zTabName; /* Original name of the table */
83004 /* Get a NULL terminated version of the new table name. */
83008 /* Check that a table or index named 'zName' does not already exist
83013 "there is already another table or index with this name: %s", zName);
83017 /* Make sure it is not a system table being altered, or a reserved name
83018 ** that the table is being renamed to.
83054 ** Then modify the schema cookie (since the ALTER TABLE modifies the
83055 ** schema). Open a statement transaction if the table is a virtual
83056 ** table.
83065 /* If this is a virtual table, invoke the xRename() function if
83067 ** of any resources used by the v-table implementation (including other
83068 ** SQLite tables) that are identified by the name of the virtual table.
83085 /* If foreign-key support is enabled, rewrite the CREATE TABLE
83087 ** for which the renamed table is the parent table. */
83098 /* Modify the sqlite_master table to use the new table name. */
83110 "WHEN type='table' THEN %Q "
83115 "(type='table' OR type='index' OR type='trigger');",
83124 /* If the sqlite_sequence table exists in this database, then update
83125 ** it with the new table name.
83135 /* If there are TEMP triggers on this table, modify the sqlite_temp_master
83136 ** table. Don't do this if the table being ALTERed is itself located in
83153 Table *pFrom = p->pFrom;
83161 /* Drop and reload the internal table schema. */
83198 ** This function is called after an "ALTER TABLE ... ADD" statement
83202 ** The Table structure pParse->pNewTable was extended to include
83206 Table *pNew; /* Copy of pParse->pNewTable */
83207 Table *pTab; /* Table being altered */
83210 const char *zTab; /* Table name */
83284 /* Modify the CREATE TABLE statement. */
83296 "WHERE type = 'table' AND name = %Q",
83310 /* Reload the schema of the modified table. */
83315 ** This function is called by the parser after the table-name in
83316 ** an "ALTER TABLE <table-name> ADD" statement is parsed. Argument
83317 ** pSrc is the full-name of the table being altered.
83319 ** This routine makes a (partial) copy of the Table structure
83320 ** for the table being altered and sets Parse.pNewTable to point
83323 ** the copy. The copy of the Table structure is deleted by tokenize.c
83327 ** coding the "ALTER TABLE ... ADD" statement.
83330 Table *pNew;
83331 Table *pTab;
83338 /* Look up the table being altered. */
83364 /* Put a copy of the Table struct in Parse.pNewTable for the
83368 ** table because user table are not allowed to have the "sqlite_"
83371 pNew = (Table*)sqlite3DbMallocZero(db, sizeof(Table));
83431 ** CREATE TABLE sqlite_stat1(tbl, idx, stat);
83432 ** CREATE TABLE sqlite_stat2(tbl, idx, sampleno, sample);
83433 ** CREATE TABLE sqlite_stat3(tbl, idx, nEq, nLt, nDLt, sample);
83434 ** CREATE TABLE sqlite_stat4(tbl, idx, nEq, nLt, nDLt, sample);
83437 ** The sqlite_stat2 table is not created or used unless the SQLite version
83439 ** with SQLITE_ENABLE_STAT2. The sqlite_stat2 table is deprecated.
83440 ** The sqlite_stat2 table is superseded by sqlite_stat3, which is only
83455 ** name in the idx column. The tbl column is the name of the table to
83459 ** number of rows in the table, except for partial indices.) The second
83476 ** rows in the table identified by sqlite_stat1.tbl.
83482 ** 3.6.18 and 3.7.8. The "stat2" table contains additional information
83484 ** the "idx" column and the "tbl" column is the name of the table to which
83486 ** table for each index.
83501 ** writes the sqlite_stat2 table. This version of SQLite only supports
83512 ** As with sqlite_stat2, the sqlite_stat4 table contains histogram data
83517 ** The sqlite_stat4 table contains multiple entries for each index.
83518 ** The idx column names the index and the tbl column is the table of the
83545 ** The sqlite_stat3 table is like sqlite_stat4 except that it only
83571 ** The sqlite_stat1 table is always relevant. sqlite_stat2 is now
83577 ** Argument zWhere may be a pointer to a buffer containing a table name,
83579 ** the sqlite_statN tables associated with the named table are deleted.
83580 ** If zWhere==0, then code is generated to delete all stat table entries.
83585 int iStatCur, /* Open the sqlite_stat1 table on this cursor */
83586 const char *zWhere, /* Delete entries for this table or index */
83622 Table *pStat;
83625 /* The sqlite_statN table does not exist. Create it. Note that a
83626 ** side-effect of the CREATE TABLE statement is to leave the rootpage
83627 ** of the new table in register pParse->regRoot. This is important
83630 "CREATE TABLE %Q.%s(%s)", pDb->zName, zTab, aTable[i].zCols
83636 /* The table already exists. If zWhere is not NULL, delete all entries
83637 ** associated with the table zWhere. If zWhere is NULL, delete the
83638 ** entire contents of the table. */
83648 /* The sqlite_stat[134] table already exists. Delete all rows. */
83683 i64 iRowid; /* Rowid in main table of the key */
83693 tRowcnt nRow; /* Number of rows in the entire table */
83789 ** WITHOUT ROWID table, N is the number of PRIMARY KEY columns, not the
83790 ** total number of columns in the table.
83796 ** PRIMARY KEY of the table. The covering index that implements the
83797 ** original WITHOUT ROWID table as N==K as a special case.
83970 ** iCol occurs many times in the table. However, if we have already
84196 #define STAT_GET_STAT1 0 /* "stat" column of stat1 table */
84213 ** stat1 table entry information.
84235 ** table for this index.
84359 ** a single table.
84363 Table *pTab, /* Table whose indices are to be analyzed */
84365 int iStatCur, /* Index of VdbeCursor that writes the sqlite_stat1 table */
84372 int iTabCur; /* Table cursor */
84377 u8 needTableCnt = 1; /* True to count the table */
84385 int regTabname = iMem++; /* Register containing table name */
84414 /* Establish a read-lock on the table at the shared-cache level.
84415 ** Open a read-only cursor on the table. Also allocate a cursor number
84483 ** the sqlite_stat4 table. */
84495 ** (or for a WITHOUT ROWID table, the number of PK columns),
84608 /* Add the entry to the stat1 table. */
84615 /* Add the entries to the stat3 or stat4 table. */
84712 Table *pTab = (Table*)sqliteHashData(k);
84719 ** Generate code that will do an analysis of a single table in
84723 static void analyzeTable(Parse *pParse, Table *pTab, Index *pOnlyIdx){
84752 ** Form 3 analyzes all indices associated with the named table.
84759 Table *pTab;
84779 /* Form 2: Analyze the database or table named */
84795 /* Form 3: Analyze the fully qualified table name */
84888 ** sqlite_stat1 table.
84890 ** argv[0] = name of the table
84895 ** the table.
84900 Table *pTable;
84990 ** occur in the stat4 table for this index before pFinal. Set
85010 ** Look up an index by name. Or, if the name of a WITHOUT ROWID table
85011 ** is supplied instead, find the PRIMARY KEY index for that table.
85020 Table *pTab = sqlite3FindTable(db, zName, zDb);
85027 ** Load the content from either the sqlite_stat4 or sqlite_stat3 table
85077 ** loaded from the stat4 table. In this case ignore stat3 data. */
85127 ** the sqlite_stat4 table. In this case ignore stat3 data. */
85193 ** If the sqlite_stat1 table is not present in the database, SQLITE_ERROR
85195 ** during compilation and the sqlite_stat3/4 table is present, no data is
85199 ** sqlite_stat4 table is not present in the database, SQLITE_ERROR is
85201 ** table (if it is present) before returning.
85227 /* Check to make sure the sqlite_stat1 table exists */
85234 /* Load new statistics out of the sqlite_stat1 table */
85245 /* Load the statistics from the sqlite_stat4 table. */
85702 ** a specific database to all table references where the database name
85899 ** the table and the column that are being accessed. The auth function
85934 ** table zTab in database zDb. This function assumes that an authorization
85943 const char *zTab, /* Table name */
85966 ** The pExpr should be a TK_COLUMN expression. The table referred to
85967 ** is in pTabList or else it is the NEW or OLD table of a trigger.
85978 SrcList *pTabList /* All table that pExpr might refer to */
85981 Table *pTab = 0; /* The table being read */
85982 const char *zCol; /* Name of the column of the table */
85983 int iSrc; /* Index in pTabList->a[] of table being read */
85985 int iCol; /* Index of column in table */
85991 ** temporary table. */
86108 ** CREATE TABLE
86109 ** DROP TABLE
86133 int iDb; /* The database containing the table to be locked */
86134 int iTab; /* The root page of the table to be locked */
86136 const char *zName; /* Name of the table */
86140 ** Record the fact that we want to lock a table at run-time.
86142 ** The table to be locked has root page iTab and is found in database iDb.
86151 int iDb, /* Index of the database containing the table to lock */
86152 int iTab, /* Root page number of the table to be locked */
86154 const char *zName /* Name of the table to be locked */
86186 ** Code an OP_TableLock instruction for each table locked by the
86283 ** obtain the required table-locks. This is a no-op unless the
86367 ** table given the name of that table and (optionally) the name of the
86368 ** database containing the table. Return NULL if not found.
86370 ** If zDatabase is 0, all databases are searched for the table and the
86371 ** first matching table is returned. (No checking for duplicate table
86377 SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){
86378 Table *p = 0;
86397 ** table given the name of that table and (optionally) the name of the
86398 ** database containing the table. Return NULL if not found. Also leave an
86405 SQLITE_PRIVATE Table *sqlite3LocateTable(
86407 int isView, /* True if looking for a VIEW rather than a TABLE */
86408 const char *zName, /* Name of the table we are looking for */
86411 Table *p;
86421 const char *zMsg = isView ? "no such view" : "no such table";
86433 ** Locate the table identified by *p.
86441 SQLITE_PRIVATE Table *sqlite3LocateTableItem(
86464 ** table and the first matching index is returned. (No checking
86503 ** unlike that index from its Table then remove the index from
86504 ** the index hash table and free all memory structures associated
86618 ** Delete memory allocated for the column names of a table or view (the
86619 ** Table.aCol[] array).
86621 static void sqliteDeleteColumnNames(sqlite3 *db, Table *pTable){
86639 ** Table. No changes are made to disk by this routine.
86642 ** the table data structure from the hash table. But it does destroy
86644 ** the table.
86646 Table object
86647 ** contains lookaside memory. (Table objects in the schema do not use
86648 ** lookaside memory, but some ephemeral Table objects do.) Or the
86650 ** used by the Table object.
86652 SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
86658 /* Do not delete the table until the reference count reaches zero. */
86668 /* Delete all indices associated with this table. */
86683 /* Delete any foreign keys attached to this table. */
86686 /* Delete the Table structure itself.
86705 ** Unlink the given table from the hash tables and the delete the
86706 ** table structure with all its indices and foreign keys.
86709 Table *p;
86716 testcase( zTabName[0]==0 ); /* Zero-length table names are allowed */
86749 ** Open the sqlite_master table stored in database number iDb for
86750 ** writing. The table is opened using cursor 0.
86797 /* The table or view or trigger name is passed to this routine via tokens
86798 ** pName1 and pName2. If the table name was fully qualified, for example:
86800 ** CREATE TABLE xxx.yyy (...);
86803 ** the table name is not fully qualified, i.e.:
86805 ** CREATE TABLE yyy(...);
86810 ** pName2) that stores the unqualified table name. The index of the
86845 ** unqualified name for a new schema object (table, index, view or
86861 ** Return the PRIMARY KEY index of a table
86863 SQLITE_PRIVATE Index *sqlite3PrimaryKeyIndex(Table *pTab){
86870 ** Return the column of index pIdx that corresponds to table
86882 ** Begin constructing a new table representation in memory. This is
86884 ** to a CREATE TABLE statement. In particular, this routine is called
86885 ** after seeing tokens "CREATE" and "TABLE" and the table name. The isTemp
86886 ** flag is true if the table should be stored in the auxiliary database
86889 ** CREATE and TABLE.
86891 ** The new table record is initialized and put in pParse->pNewTable.
86892 ** As more of the CREATE TABLE statement is parsed, additional action
86894 ** At the end of the CREATE TABLE statement, the sqlite3EndTable() routine
86895 ** is called to complete the construction of the new table record.
86899 Token *pName1, /* First part of the name of the table or view */
86900 Token *pName2, /* Second part of the name of the table or view */
86901 int isTemp, /* True if this is a TEMP table */
86903 int isVirtual, /* True if this is a VIRTUAL table */
86904 int noErr /* Do nothing if table already exists */
86906 Table *pTable;
86907 char *zName = 0; /* The name of the new table */
86910 int iDb; /* Database number to create the table in */
86911 Token *pName; /* Unqualified name of the table to create */
86913 /* The table or view name to create is passed to this routine via tokens
86914 ** pName1 and pName2. If the table name was fully qualified, for example:
86916 ** CREATE TABLE xxx.yyy (...);
86919 ** the table name is not fully qualified, i.e.:
86921 ** CREATE TABLE yyy(...);
86926 ** pName2) that stores the unqualified table name. The variable iDb is
86927 ** set to the index of the database that the table or view is to be
86933 /* If creating a temp table, the name may not be qualified. Unless
86935 sqlite3ErrorMsg(pParse, "temporary table name must be unqualified");
86974 /* Make sure the new table name does not collide with an existing
86975 ** index or table name in the same database. Issue an error message if
86989 sqlite3ErrorMsg(pParse, "table %T already exists", pName);
87002 pTable = sqlite3DbMallocZero(db, sizeof(Table));
87017 /* If this is the magic sqlite_sequence table used by autoincrement,
87018 ** then record a pointer to this table in the main database structure
87019 ** so that INSERT can find the table easily.
87028 /* Begin generating the code that will insert the table record into
87029 ** the SQLITE_MASTER table. Note in particular that we must go ahead
87030 ** and allocate the record number for the table entry now. Before any
87032 ** indices to be created and the table record must come before the
87033 ** indices. Hence, the record number for the table must be allocated
87065 /* This just creates a place-holder record in the sqlite_master table.
87070 ** The root page number of the new table is left in reg pParse->regRoot.
87113 ** Add a new column to the table currently being constructed.
87116 ** in a CREATE TABLE statement. sqlite3StartTable() gets called
87121 Table *p;
87166 ** parsing a CREATE TABLE statement. A "NOT NULL" constraint has
87171 Table *p;
87182 ** substrings in the following table. If one of the substrings is
87185 ** the table take priority. For example, if zType is 'BLOBINT',
87199 ** If none of the substrings in the above table are found,
87266 ** parsing a CREATE TABLE statement. The pFirst token is the first
87274 Table *p;
87287 ** of the table currently under construction.
87293 ** parsing a CREATE TABLE statement.
87296 Table *p;
87321 ** Designate the PRIMARY KEY for the table. pList is a list of names
87323 ** most recently added column of the table is the primary key.
87325 ** A table can have at most one primary key. If the table already has
87330 ** then we will try to use that column as the rowid. Set the Table.iPKey
87331 ** field of the table under construction to be the index of the
87332 ** INTEGER PRIMARY KEY column. Table.iPKey is set to -1 if there is
87345 Table *pTab = pParse->pNewTable;
87352 "table \"%s\" has more than one primary key", pTab->zName);
87406 ** Add a new CHECK constraint to the table currently under construction.
87413 Table *pTab = pParse->pNewTable;
87430 ** Set the collation function of the most recently parsed table column
87434 Table *p;
87579 ** Generate a CREATE TABLE statement appropriate for the given
87580 ** table. Memory to hold the text of the statement is obtained
87583 static char *createTableStmt(sqlite3 *db, Table *p){
87608 sqlite3_snprintf(n, zStmt, "CREATE TABLE ");
87673 ** Estimate the total row width for a table.
87675 static void estimateTableWidth(Table *pTab){
87709 ** This routine runs at the end of parsing a CREATE TABLE statement that
87712 ** are appropriate for a WITHOUT ROWID table instead of a rowid table.
87718 ** (2) Bypass the creation of the sqlite_master table entry
87720 ** identified by the sqlite_master table entry of the table itself.
87722 ** schema to the rootpage from the main table.
87724 ** (5) Add all table columns to the PRIMARY KEY Index object
87731 static void convertToWithoutRowidTable(Parse *pParse, Table *pTab){
87740 ** root-page for the table into a OP_CreateIndex opcode. The index
87749 ** table entry.
87756 /* Locate the PRIMARY KEY index. Or, if this table was originally
87757 ** an INTEGER PRIMARY KEY table, create a new PRIMARY KEY index.
87784 /* The root page of the PRIMARY KEY is the table root page */
87813 /* Add all table columns to the PRIMARY KEY index
87834 ** a CREATE TABLE statement.
87836 ** The table structure that other action routines have been building
87840 ** An entry for the table is made in the master table on disk, unless
87841 ** this is a temporary table or db->init.busy==1. When db->init.busy==1
87842 ** it means we are reading the sqlite_master table because we just
87843 ** connected to the database or because the sqlite_master table has
87844 ** recently changed, so the entry for this table already exists in
87845 ** the sqlite_master table. We do not want to create it again.
87848 ** was called to create a table generated from a
87849 ** "CREATE TABLE ... AS SELECT ..." statement. The column names of
87850 ** the new table will match the result set of the SELECT.
87855 Token *pEnd, /* The ')' before options in the CREATE TABLE */
87856 u8 tabOpts, /* Extra table options. Usually 0. */
87859 Table *p; /* The new table */
87861 int iDb; /* Database in which the table lives */
87862 Index *pIdx; /* An implied index of the table */
87873 ** "sqlite_master" or "sqlite_temp_master" table on the disk.
87875 ** for the table from the db->init.newTnum field. (The page number
87890 sqlite3ErrorMsg(pParse, "PRIMARY KEY missing on table %s", p->zName);
87907 /* Estimate the average row size for the table and for all implied indices */
87913 /* If not initializing, then create a record for the new table
87914 ** in the SQLITE_MASTER table of the database.
87916 ** If this is a TEMPORARY table, write the entry into the auxiliary
87922 char *zType; /* "view" or "table" */
87923 char *zType2; /* "VIEW" or "TABLE" */
87924 char *zStmt; /* Text of the CREATE TABLE or CREATE VIEW statement */
87932 ** Initialize zType for the new view or table.
87935 /* A regular table */
87936 zType = "table";
87937 zType2 = "TABLE";
87946 /* If this is a CREATE TABLE xx AS SELECT ..., execute the SELECT
87947 ** statement to populate the new table. The root-page number for the
87948 ** new table is in register pParse->regRoot.
87952 ** by the new table.
87954 ** A shared-cache write-lock is not required to write to the new table,
87961 Table *pSelTab;
87995 ** SQLITE_MASTER table. We just need to update that slot with all
88014 /* Check to see if we need to create an sqlite_sequence table for
88022 "CREATE TABLE %Q.sqlite_sequence(name,seq)",
88035 /* Add the table to the in-memory representation of the database.
88038 Table *pOld;
88079 Table *p;
88135 /* Use sqlite3EndTable() to add the view to the SQLITE_MASTER table */
88143 ** The Table structure pTable is really a VIEW. Fill in the names of
88147 SQLITE_PRIVATE int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){
88148 Table *pSelTab; /* A fake table from which we get the result set */
88181 ** CREATE TABLE main.ex1(a);
88191 /* If we get this far, it means we need to compute the table names.
88247 Table *pTab = sqliteHashData(i);
88262 ** used by SQLite when the btree layer moves a table root page. The
88263 ** root-page of a table or index in database iDb has changed from iFrom
88266 ** Ticket #1728: The symbol table might still contain information
88269 ** have the same rootpage number as the real table or index that is
88272 ** or tables and not the table/index that is actually being moved.
88287 Table *pTab = sqliteHashData(pElem);
88303 ** Write code to erase the table with root-page iTable from database iDb.
88304 ** Also write code to modify the sqlite_master table and internal schema
88305 ** if a root-page of another table is moved by the btree-layer whilst
88315 ** is non-zero, then it is the root page number of a table moved to
88316 ** location iTable. The following code modifies the sqlite_master table to
88331 ** Write VDBE code to erase table pTab and all associated indices on disk.
88333 ** in case a root-page belonging to another table is moved by the btree layer
88336 static void destroyTable(Parse *pParse, Table *pTab){
88347 ** table and index root-pages in order, starting with the numerically
88392 ** after a DROP INDEX or DROP TABLE command.
88398 const char *zName /* Name of index or table */
88415 ** Generate code to drop a table.
88417 SQLITE_PRIVATE void sqlite3CodeDropTable(Parse *pParse, Table *pTab, int iDb, int isView){
88433 /* Drop all triggers associated with the table being dropped. Code
88446 /* Remove any entries of the sqlite_sequence table associated with
88447 ** the table being dropped. This is done before the table is dropped
88448 ** at the btree level, in case the sqlite_sequence table needs to
88459 /* Drop all SQLITE_MASTER table and index entries that refer to the
88460 ** table. The program name loops through the master table and deletes
88461 ** every row that refers to a table of the same name as the one being
88463 ** created in the temp database that refers to a table in another
88473 /* Remove the table entry from SQLite's internal schema and modify
88485 ** This routine is called to do the work of a DROP TABLE statement.
88486 ** pName is the name of the table to be dropped.
88489 Table *pTab;
88510 /* If pTab is a virtual table, call ViewGetColumnNames() to ensure
88553 sqlite3ErrorMsg(pParse, "table %s may not be dropped", pTab->zName);
88558 /* Ensure DROP TABLE is not used on a view, and DROP VIEW is not used
88559 ** on a table.
88562 sqlite3ErrorMsg(pParse, "use DROP TABLE to delete table %s", pTab->zName);
88571 /* Generate code to remove the table from the master table
88587 ** This routine is called to create a new foreign key on the table
88589 ** in the current table point to the foreign key. If pFromCol==0 then
88591 ** the table referred to (a.k.a the "parent" table). pToCol is a list
88592 ** of tables in the parent pTo table. flags contains all
88596 ** An FKey structure is created and added to the table currently
88604 ExprList *pFromCol, /* Columns in this table that point to other table */
88605 Token *pTo, /* Name of the other table */
88606 ExprList *pToCol, /* Columns in the other table */
88613 Table *p = pParse->pNewTable;
88626 " should reference only one column of table %T",
88634 "columns in the referenced table");
88704 /* Link the foreign key to the table as the last step.
88725 Table *pTab;
88745 Table *pTab = pIndex->pTable; /* The table that is indexed */
88766 /* Require a write-lock on the table to perform this operation */
88783 /* Open the table. Loop through all rows of the table, inserting index
88859 ** Create a new index for an SQL table. pName1.pName2 is the name of the index
88860 ** and pTblList is the name of the table that is to be indexed. Both will
88863 ** as the table to be indexed. pParse->pNewTable is a table that is
88864 ** currently being constructed by a CREATE TABLE statement.
88868 ** to the table currently under construction.
88878 SrcList *pTblName, /* Table to index. Use pParse->pNewTable if 0 */
88887 Table *pTab = 0; /* Table to be indexed */
88895 Db *pDb; /* The specific table containing the indexed database */
88899 const Column *pTabCol; /* A column in the table */
88914 ** Find the table that is to be indexed. Return early if not found.
88919 ** to search for the table. 'Fix' the table name to this db
88920 ** before looking up the table.
88928 /* If the index name was unqualified, check if the table
88929 ** is a temp table. If so, set the database to 1. Do not do this
88951 "cannot create a TEMP index on non-TEMP table \"%s\"",
88969 sqlite3ErrorMsg(pParse, "table %s may not be indexed", pTab->zName);
88987 ** index or table with the same name.
88990 ** sqlite_master table (because some other process changed the schema) and
88991 ** one of the index names collides with the name of a temporary table or
89007 sqlite3ErrorMsg(pParse, "there is already a table named %s", zName);
89047 ** key out of the last column added to the table under construction.
89105 /* Scan the names of the columns of the table to be indexed and
89124 sqlite3ErrorMsg(pParse, "table %s has no column named %s",
89179 ** CREATE TABLE t(x PRIMARY KEY, y);
89180 ** CREATE TABLE t(x, y, UNIQUE(x, y));
89182 ** Either way, check to see if the table already has such an index. If
89214 ** constraint specified somewhere in the CREATE TABLE statement.
89233 /* Link the new Index structure to its table and to the other
89253 /* If this is the initial CREATE INDEX statement (or CREATE TABLE if the
89256 ** the index in the sqlite_master table and populate the index with
89258 ** table to parse the schema, or if this index is the PRIMARY KEY index
89259 ** of a WITHOUT ROWID table.
89262 ** or UNIQUE index in a CREATE TABLE statement. Since the table
89319 /* When adding an index to the list of indices for a table, make
89358 ** number of rows in the table that match any particular value of the
89378 ** number of rows in the table. Or 10, if the estimated number of rows
89379 ** in the table is less than that. */
89431 Table *pTab = pIndex->pTable;
89444 /* Generate code to remove the index and from the master table */
89625 ** Append a new table name to the given SrcList. Create a new SrcList if
89633 ** If pDatabase is not null, it means that the table has an optional
89634 ** database name prefix. Like this: "database.table". The pDatabase
89635 ** points to the table name and the pTable points to the database name.
89636 ** The SrcList.a[].zName field is filled with the table name which might
89645 ** Then B is a table name and the database name is unspecified. If called
89650 ** Then C is the table name and B is the database name. If C is defined
89661 Token *pTable, /* Table to append */
89662 Token *pDatabase /* Database of the table */
89733 ** are the name of the table and database named in the FROM clause term.
89747 Token *pTable, /* Name of the table to add to the FROM clause */
89750 Select *pSubquery, /* A subquery used in place of a table name */
90003 ** inserting multiple rows in a table, or inserting a row and index entries.)
90066 Table *pTab = pIdx->pTable;
90091 Table *pTab /* The table with the non-unique rowid */
90131 static void reindexTable(Parse *pParse, Table *pTab, char const *zColl){
90155 Table *pTab; /* A table in the database */
90161 pTab = (Table*)sqliteHashData(k);
90179 ** indices associated with the named table.
90184 char *z; /* Name of a table or index */
90186 Table *pTab; /* A table in the database */
90190 Token *pObjName; /* Name of the table or index to be reindexed */
90291 Token *pName, /* Name of the common-table */
90292 ExprList *pArglist, /* Optional column name list for the table */
90293 Select *pQuery /* Query used to initialize the table */
90306 sqlite3ErrorMsg(pParse, "duplicate WITH table name: %s", zName);
90492 ** Locate and return an entry from the db.aCollSeq hash table. If the entry
90496 ** Each pointer stored in the sqlite3.aCollSeq hash table contains an
90529 ** to the hash table).
90640 FuncDefHash *pHash, /* Hash table to search */
90655 ** Insert a new FuncDef into a FuncDefHash hash table.
90658 FuncDefHash *pHash, /* The hash table into which to insert */
90755 ** new entry to the hash table and return it.
90797 Table *pTab = sqliteHashData(pElem);
90852 ** the name of a single table, as one might find in an INSERT, DELETE,
90853 ** or UPDATE statement. Look up that table in the symbol table and
90854 ** return a pointer. Set an error message and return NULL if the table
90859 ** pSrc->a[0].pTab Pointer to the Table object
90863 SQLITE_PRIVATE Table *sqlite3SrcListLookup(Parse *pParse, SrcList *pSrc){
90865 Table *pTab;
90880 ** Check to make sure the given table is writable. If it is not
90884 SQLITE_PRIVATE int sqlite3IsReadOnly(Parse *pParse, Table *pTab, int viewOk){
90885 /* A table is not writable under the following circumstances:
90887 ** 1) It is a virtual table and no implementation of the xUpdate method
90889 ** 2) It is a system table (i.e. sqlite_master), this call is not
90901 sqlite3ErrorMsg(pParse, "table %s may not be modified", pTab->zName);
90917 ** Evaluate a view and store its result in an ephemeral table. The
90919 ** set of rows in the view that are to be added to the ephemeral table.
90923 Table *pView, /* View definition */
90925 int iCur /* Cursor number for ephemerial table */
91051 SrcList *pTabList, /* The table from which we should delete things */
91055 Table *pTab; /* The table from which records will be deleted */
91059 Index *pIdx; /* For looping over indices of the table */
91060 int iTabCur; /* Cursor number for the table */
91073 Index *pPk; /* The PRIMARY KEY index on the table */
91078 int iEphCur = 0; /* Ephemeral table holding all primary key values */
91083 int addrEphOpen = 0; /* Instruction to open the Ephermeral table */
91087 Trigger *pTrigger; /* List of table triggers, if required */
91097 /* Locate the table which we want to delete. This table has to be
91100 ** an SrcList* parameter instead of just a Table* parameter.
91105 /* Figure out if we have any triggers and if the table being
91139 /* Assign cursor numbers to the table and all its indices.
91163 ** a ephemeral table.
91191 ** It is easier just to erase the whole table. Prior to version 3.6.5,
91211 /* For a rowid table, initialize the RowSet to an empty set */
91217 /* For a WITHOUT ROWID table, create an ephermeral table used to
91295 /* Unless this is a view, open cursors for the table we are
91355 /* Close the cursors open on the table and its indexes. */
91364 /* Update the sqlite_sequence table by storing the content of the
91401 ** single table to be deleted. Both the original table entry and
91407 ** store for the table. (This will be either the table itself,
91408 ** in the case of a rowid table, or the PRIMARY KEY index in the case
91409 ** of a WITHOUT ROWID table.)
91421 Table *pTab, /* Table containing the row to be deleted */
91468 /* Populate the OLD.* pseudo-table register array. These values will be
91497 ** refer to this table (i.e. constraints attached to other tables)
91502 /* Delete the index and table entries. Skip this step if pTab is really
91532 ** index entries associated with a single row of a single table, pTab
91537 ** btree for the table pTab. (This will be either the table itself
91550 Table *pTab, /* Table containing the row to be deleted */
91551 int iDataCur, /* Cursor of table holding data. */
91582 ** iCur is the index of a cursor open on the pTab table and pointing to
91583 ** the entry that needs indexing. If pTab is a WITHOUT ROWID table, then
91607 ** on a table with multiple indices, and especially with the ROWID or
91622 Table *pTab = pIdx->pTable;
91645 ** might be stored in the table as an integer (using a compact
92117 ** routines in the function table. The noopFunc macro provides this.
93312 ** to the global function hash table. This occurs at start-time (as
93472 ** I.1) For each FK for which the table is the child table, search
93473 ** the parent table for a match. If none is found increment the
93476 ** I.2) For each FK for which the table is the parent table,
93477 ** search the child table for rows that correspond to the new
93478 ** row in the parent table. Decrement the counter for each row
93483 ** D.1) For each FK for which the table is the child table,
93484 ** search the parent table for a row that corresponds to the
93485 ** deleted row in the child table. If such a row is not found,
93488 ** D.2) For each FK for which the table is the parent table, search
93489 ** the child table for rows that correspond to the deleted row
93490 ** in the parent table. For each found increment the counter.
93518 ** TODO: How should dropping a table be handled? How should renaming a
93519 ** table be handled?
93554 ** CREATE TABLE t1(a, b INTEGER PRIMARY KEY, c);
93565 ** table are collectively subject to a UNIQUE or PRIMARY KEY constraint.
93566 ** Given that pParent is the parent table for foreign key constraint pFKey,
93577 ** array is the index of the child table column that is mapped by the FK
93578 ** constraint to the parent table column stored in the left-most column
93580 ** child table column that corresponds to the second left-most column of
93591 ** foreign key definition, and the parent table does not have a
93595 ** foreign key definition, and the PRIMARY KEY of the parent table
93597 ** the child table.
93605 Table *pParent, /* Parent table of FK constraint pFKey */
93607 Index **ppIdx, /* OUT: Unique index on parent table */
93621 ** maps to the INTEGER PRIMARY KEY of table pParent. If so, leave *ppIdx
93632 ** mapped to the primary key of table pParent, or
93655 ** the PRIMARY KEY of table pParent. The PRIMARY KEY index may be
93666 ** map to an explicit list of columns in table pParent. Check if this
93714 ** child table of foreign key constraint pFKey. If an SQL UPDATE is executed
93715 ** on the child table of pFKey, this function is invoked twice for each row
93720 ** row in the parent table that corresponds to the row being inserted into
93721 ** or deleted from the child table. If the parent row can be found, no
93723 ** found in the parent table:
93741 Table *pTab, /* Parent table of FK pFKey */
93744 int *aiCol, /* Map from parent key columns to child table columns */
93745 int regData, /* Address of array containing child table row */
93758 ** Check if any of the key columns in the child table row are NULL. If
93760 ** search for a matching row in the parent table. */
93773 ** column of the parent table (table pTab). */
93786 /* If the parent table is the same as the child table, and we are about
93812 /* If the parent table is the same as the child table, and we are about
93852 ** one row into the table, raise a constraint immediately instead of
93872 ** to column iCol of table pTab.
93880 Table *pTab, /* The table whose content is at r[regBase]... */
93881 int regBase, /* Contents of table pTab */
93907 ** Return an Expr object that refers to column iCol of table pTab which
93912 Table *pTab, /* The table whose column is desired */
93913 int iCursor, /* The open cursor on the table */
93927 ** from the parent table of foreign key constraint pFKey and, if pFKey is
93928 ** deferred, when a row is inserted into the same table. When generating
93933 ** table that correspond to the parent table row being deleted or inserted.
93955 SrcList *pSrc, /* The child table to be scanned */
93956 Table *pTab, /* The parent table */
93959 int *aiCol, /* Map from pIdx cols to child table cols */
93990 Expr *pLeft; /* Value from parent table row */
93991 Expr *pRight; /* Column ref to child table */
93993 i16 iCol; /* Index of column in child table */
93994 const char *zCol; /* Name of column in child table */
94006 /* If the child table is the same as the parent table, then add terms
94019 Expr *pLeft; /* Value from parent table row */
94020 Expr *pRight; /* Column ref to child table */
94069 ** FKey.pNextTo) holding all children of table pTab. For example,
94072 ** CREATE TABLE t1(a PRIMARY KEY);
94073 ** CREATE TABLE t2(b REFERENCES t1(a);
94075 ** Calling this function with table "t1" as an argument returns a pointer
94076 ** to the FKey structure representing the foreign key constraint on table
94079 ** table).
94081 SQLITE_PRIVATE FKey *sqlite3FkReferences(Table *pTab){
94106 ** This function is called to generate code that runs when table pTab is
94109 ** table pTab.
94113 ** (a) The table is the parent table of a FK constraint, or
94114 ** (b) The table is the child table of a deferred FK constraint and it is
94119 ** the table from the database. Triggers are disabled while running this
94122 SQLITE_PRIVATE void sqlite3FkDropTable(Parse *pParse, SrcList *pName, Table *pTab){
94130 /* Search for a deferred foreign key constraint for which this table
94131 ** is the child table. If one cannot be found, return without
94173 ** for which pTab is the child table. An UPDATE statement against pTab
94174 ** is currently being processed. For each column of the table that is
94184 Table *pTab, /* Table being updated */
94200 ** for which pTab is the parent table. An UPDATE statement against pTab
94201 ** is currently being processed. For each column of the table that is
94211 Table *pTab,
94236 ** table pTab to generate VDBE code to perform foreign key constraint
94250 ** the original record is deleted from the table using the calling convention
94256 Table *pTab, /* Row is being deleted from this table */
94278 ** child table (the table that the foreign key definition is part of). */
94280 Table *pTo; /* Parent table of foreign key pFKey */
94295 /* Find the parent table of this foreign key. Also find a unique index
94296 ** on the parent key columns in the parent table. If either of these
94308 /* If isIgnoreErrors is true, then a table is being dropped. In this
94309 ** case SQLite runs a "DELETE FROM xxx" on the table being dropped
94311 ** If the parent table of an FK constraint on the current table is
94313 ** FK counter for each row of the current table with non-NULL keys.
94340 ** values read from the parent table are NULL. */
94350 /* Take a shared-cache advisory read-lock on the parent table. Allocate
94352 ** in the parent table. */
94357 /* A row is being removed from the child table. Search for the parent.
94363 /* A row is being added to the child table. If a parent row cannot
94371 /* Loop through all the foreign key constraints that refer to this table.
94386 /* Inserting a single row into a parent table cannot cause an immediate
94397 /* Create a SrcList structure containing the child table. We need the
94398 ** child table as a SrcList for sqlite3WhereBegin() */
94412 ** on the parent table of this FK, then throw an exception
94430 ** row contained in table pTab.
94434 Table *pTab /* Table being modified */
94457 ** row contained in table pTab. If the operation is a DELETE, then
94459 ** to an array of size N, where N is the number of columns in table pTab.
94463 ** UPDATE statement modifies the rowid fields of the table.
94471 Table *pTab, /* Table being modified */
94478 ** table in question is either the child or parent table for any
94502 ** compiled on table pTab, which is the parent table of foreign-key pFKey.
94513 ** For example, if pFKey is the foreign key and pTab is table "p" in
94516 ** CREATE TABLE p(pk PRIMARY KEY);
94517 ** CREATE TABLE c(ck REFERENCES p ON DELETE CASCADE);
94531 Table *pTab, /* Table being updated or deleted from */
94545 char const *zFrom; /* Name of child table */
94548 int *aiCol = 0; /* child table cols -> parent key cols */
94562 Token tFromCol; /* Name of column in child table */
94563 Token tToCol; /* Name of column in parent table */
94564 int iFromCol; /* Idx of column in child table */
94578 ** parent table are used for the comparison. */
94717 Table *pTab, /* Table being updated or deleted from */
94724 ** refer to table pTab. If there is an action associated with the FK
94744 ** table pTab. Remove the deleted foreign keys from the Schema.fkeyHash
94745 ** hash table.
94747 SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){
94754 /* Remove the FK from the fkeyHash hash table. */
94805 ** (1) acquire a lock for table pTab then
94808 ** If pTab is a WITHOUT ROWID table, then it is the PRIMARY KEY index
94809 ** for that table that is actually opened.
94813 int iCur, /* The cursor number of the table */
94815 Table *pTab, /* The table to be opened */
94840 ** the table, according to the affinity of the column:
94868 Table *pTab = pIdx->pTable;
94886 ** Compute the affinity string for table pTab, if it has not already been
94905 SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe *v, Table *pTab, int iReg){
94935 ** Return non-zero if the table pTab in database iDb or any of its indices
94938 ** run without using a temporary table for the results of the SELECT.
94940 static int readsTable(Parse *p, int iDb, Table *pTab){
94976 ** Locate or create an AutoincInfo structure associated with table pTab
94980 ** There is at most one AutoincInfo structure per table even if the
94981 ** same table is autoincremented multiple times due to inserts within
94983 ** first use of table pTab. On 2nd and subsequent uses, the original
94988 ** (1) Register to hold the name of the pTab table.
94998 Table *pTab /* The table we are writing to */
95014 pToplevel->nMem++; /* Register to hold name of table */
95030 Db *pDb; /* Database only autoinc table */
95080 ** table (either directly or through triggers) needs to call this
95121 Table *pDest, /* The table we are inserting into */
95130 ** insert into TABLE (IDLIST) values(EXPRLIST)
95131 ** insert into TABLE (IDLIST) select
95133 ** The IDLIST following the table name is always optional. If omitted,
95134 table is substituted. The IDLIST
95147 ** open write cursor to <table> and its indices
95149 ** write the resulting record into <table>
95154 ** INSERT INTO <table> SELECT ...
95157 ** in other words if the SELECT pulls all columns from a single table
95165 ** open a write cursor to <table>
95167 ** transfer all records in <table2> over to <table>
95169 ** foreach index on <table>
95170 ** open a write cursor on the <table> index
95177 ** and the SELECT clause does not read from <table> at any time.
95189 ** B: open write cursor to <table> and its indices
95191 ** insert the select result into <table> from R..R+n
95196 ** values from a SELECT but the data is being inserted into a table
95198 ** we have to use a intermediate table to store the results of
95210 ** B: open temp table
95212 ** insert row from R..R+n into temp table
95214 ** M: open write cursor to <table> and its indices
95215 ** rewind temp table
95216 ** C: loop over rows of intermediate table
95217 ** transfer values form intermediate table into <table>
95223 SrcList *pTabList, /* Name of table into which we are inserting */
95229 Table *pTab; /* The table to insert into. aka TABLE */
95230 char *zTab; /* Name of the table into which we are inserting */
95231 const char *zDb; /* Name of the database holding this table */
95234 Index *pIdx; /* For looping over indices of the table */
95236 int nHidden = 0; /* Number of hidden columns if TABLE is virtual */
95245 int iDb; /* Index of database holding TABLE */
95246 Db *pDb; /* The database containing table being inserted into */
95247 u8 useTempTable = 0; /* Store SELECT results in intermediate table */
95249 u8 withoutRowid; /* 0 for normal table. 1 for WITHOUT ROWID table */
95250 u8 bIdListInOrder = 1; /* True if IDLIST is in table order */
95285 /* Locate the table into which we will be inserting new information.
95303 /* Figure out if we have any triggers and if the table being
95327 /* Cannot insert into a read-only table.
95357 /* If this is an AUTOINCREMENT table, look up the sequence number in the
95358 ** sqlite_sequence table and store it in memory cell regAutoinc.
95374 ** all elements of the IDLIST really are columns of the table and
95377 ** If the table has an INTEGER PRIMARY KEY column and that column
95381 ** is appears in the original table. (The index of the INTEGER
95382 ** PRIMARY KEY in the original table is pTab->iPKey.)
95404 sqlite3ErrorMsg(pParse, "table %S has no column named %s",
95440 ** should be written into a temporary table (template 4). Set to
95442 ** the destination table (template 3).
95444 ** A temp table must be used if the table being updated is also one
95446 ** temp table in the case of row triggers.
95454 ** and add it to a transient table srcTab. The code generated
95457 ** B: open temp table
95459 ** insert row from R..R+n into temp table
95464 int regTempRowid; /* Register to hold temp table ROWID */
95497 /* If there is no IDLIST term but the table has an integer primary
95499 ** column index in the original table definition.
95506 ** of columns to be inserted into the table.
95515 "table %S has %d columns but %d values were supplied",
95531 /* If this is not a view, open the table and and all indices */
95550 ** rewind temp table, if empty goto D
95551 ** C: loop over rows of intermediate table
95552 ** transfer values form intermediate table into <table>
95563 ** insert the select result into <table> from R..R+n
95600 /* Cannot have triggers on a virtual table. If it were possible,
95627 ** If this is a real table, attempt conversions as required by the
95628 ** table column affinities.
95787 /* Update the sqlite_sequence table by storing the content of the
95829 ** on table pTab.
95835 ** case of a WITHOUT ROWID table. The second register in the range will
95836 ** contain the content of the first table column. The third register will
95837 ** contain the content of the second table column. And so forth.
95845 ** rowid for a normal table or the PRIMARY KEY for a WITHOUT ROWID table)
95847 ** the iDataCur content table is guaranteed to be unchanged by the UPDATE.
95852 ** that the table is a WITHOUT ROWID table and has no rowid. On an INSERT,
95863 ** table and all applicable indices (that is to say, all indices for which
95864 ** aRegIdx[] is not zero). iDataCur is the cursor for the main table when
95865 ** inserting or updating a rowid table, or the cursor for the PRIMARY KEY
95866 ** index when operating on a WITHOUT ROWID table. iIdxCur is the cursor
95912 Table *pTab, /* The table being inserted or updated */
95914 int iDataCur, /* Canonical data cursor (main table or PK index) */
95944 assert( pTab->pSelect==0 ); /* This table is not a VIEW */
95949 ** pPk index or 1 for a rowid table. In other words, nPkField is the
95950 ** number of fields in the true primary key of the table. */
96036 ** exist in the table.
96072 /* Check to see if the new rowid already exists in the table. Skip
96090 /* If there are DELETE triggers on this table and the
96092 ** remove the conflicting row from the table. This will fire
96093 ** the triggers and remove both the table and index b-tree entries.
96096 ** flag is not set, but the table has one or more indexes, call
96098 ** only. The table b-tree entry will be replaced by the new entry
96110 ** table.
96145 ** WITHOUT ROWID table.
96192 ** of a WITHOUT ROWID table and there has been no change the
96243 ** table, only conflict if the new PRIMARY KEY values are actually
96322 Table *pTab, /* the table into which we are inserting */
96335 int regRec; /* Register holding assemblied record for the table */
96341 assert( pTab->pSelect==0 ); /* This table is not a VIEW */
96384 ** Allocate cursors for the pTab table and all its indices and generate
96388 ** the table itself, but the PRIMARY KEY index in the case of a WITHOUT
96389 ** ROWID table) is returned in *piDataCur. The first index cursor is
96396 ** For a rowid table, *piDataCur will be exactly one less than *piIdxCur.
96397 table, *piDataCur will be somewhere in the range
96403 Table *pTab, /* Table to be opened */
96405 int iBase, /* Use this for the table cursor, if there is one */
96406 u8 *aToOpen, /* If not NULL: boolean for each table and index */
96532 ** Sometimes the xfer optimization will only work if the destination table
96535 ** does a test to see if the destination table is empty and jumps over the
96545 Table *pDest, /* The table we are inserting into */
96551 Table *pSrc; /* The table in the FROM clause of SELECT */
96570 ** attached to it. Proceeding may generate a false "no such table: xxx"
96579 return 0; /* tab1 must not be a virtual table */
96631 return 0; /* FROM clause does not contain a real table */
96634 return 0; /* tab1 and tab2 may not be the same table */
96641 return 0; /* tab2 must not be a virtual table */
96690 /* Disallow the transfer optimization if the destination table constains
96707 ** table (tab1) is initially empty.
96727 ** only if the destination table is initially empty. This code makes
98670 /* End of the automatically generated pragma table.
98987 /* Locate the pragma in the lookup table */
99617 ** PRAGMA table_info(<table>)
99619 ** Return a single row for each column of the named table. The columns of
99629 Table *pTab;
99682 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "table", SQLITE_STATIC);
99687 Table *pTab = sqliteHashData(i);
99709 Table *pTab;
99734 Table *pTab;
99794 Table *pTab;
99806 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "table", SQLITE_STATIC);
99842 Table *pTab; /* Child table contain "REFERENCES" keyword */
99843 Table *pParent; /* Parent table that child points to */
99844 Index *pIdx; /* Index in the parent table */
99847 HashElem *k; /* Loop counter: Next table in schema */
99862 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "table", SQLITE_STATIC);
99873 pTab = (Table*)sqliteHashData(k);
100056 Table *pTab = sqliteHashData(x);
100088 Table *pTab = sqliteHashData(x);
100139 /* Verify that an index entry exists for the current table row */
100306 ** creating or dropping a table or index). The schema version is used by
100610 ** argv[1] = root page number for table or index. 0 for trigger or view.
100633 /* Call the parser to process a CREATE TABLE, INDEX or VIEW.
100636 ** structures that describe the table, index, or view.
100668 ** constraint for a CREATE TABLE. The index should have already
100669 ** been created when we processed the CREATE TABLE. All we have
100675 /* This can occur if there exists an index on a TEMP table which
100677 ** the permanent table is hidden by the TEMP table, we can also
100678 ** safely ignore the index on the permanent table.
100702 Table *pTab;
100712 ** The master database table has a structure like this
100715 "CREATE TABLE sqlite_master(\n"
100725 "CREATE TEMP TABLE sqlite_temp_master(\n"
100744 ** initialized. zMasterName is the name of the master table.
100860 ** file_format==2 Version 3.1.3. // ALTER TABLE ADD COLUMN
100920 ** purpose of this is to allow access to the sqlite_master table
101068 ** expr.c is trying to resolve a reference to a transient table (i.e. one
101296 ** locked the sqlite3_master table, return SQLITE_LOCKED. If any other error
101475 int tabTnct; /* Ephemeral table used for DISTINCT processing */
101671 ** Return the index of a column in a table. Return -1 if the column
101672 ** is not contained in the table.
101674 static int columnIndex(Table *pTab, const char *zCol){
101684 ** table that has a column named zCol.
101686 ** When found, set *piTab and *piCol to the table index and column index
101722 ** where tab1 is the iSrc'th table in SrcList pSrc and tab2 is the
101729 int iLeft, /* Index of first table to join in pSrc */
101730 int iColLeft, /* Index of column in first table */
101731 int iRight, /* Index of second table in pSrc */
101732 int iColRight, /* Index of column in second table */
101772 ** expression depends on table iRightJoinTable even if that table is not
101802 ** The left most table is the first entry in Select.pSrc. The right-most
101803 ** table is the last entry. The join operator is held in the entry to
101813 struct SrcList_item *pLeft; /* Left table being joined */
101814 struct SrcList_item *pRight; /* Right table being joined */
101820 Table *pLeftTab = pLeft->pTab;
101821 Table *pRightTab = pRight->pTab;
101837 char *zName; /* Name of column in the right table */
101838 int iLeft; /* Matching left table */
101839 int iLeftCol; /* Matching column in the left table */
101877 int iLeft; /* Table on the left with matching column name */
101935 KeyInfo *pKI; /* Original KeyInfo on the sorter table */
102030 ** (example: "a IN (SELECT * FROM table)") but it has more than 1 result
102064 int srcTab, /* Pull data from this table */
102098 ** there are columns in the table on the left. The error will be caught
102181 ** table iParm.
102195 ** the temporary table iParm.
102219 ** output table as well. */
102242 ** item into the set table with bogus data.
102540 int bUseTmp /* True if a temp table was used */
102687 ** original CREATE TABLE statement if the expression is a column. The
102732 /* The expression is a column. Locate the table the column is being
102733 ** extracted from in NameContext.pSrcList. This table may be real
102734 ** database table or a subquery.
102736 Table *pTab = 0; /* Table structure column is extracted from */
102759 ** CREATE TABLE t1(col INTEGER);
102775 /* The "table" is actually a sub-select or a view in the FROM clause
102792 /* A real table */
102926 Table *pTab;
102963 ** column names for a table that would hold the expression list.
103008 Table *pTab; /* Table associated with this expression */
103078 Table *pTab, /* Add column type information to this table */
103112 ** Given a SELECT statement, generate a Table structure that describes
103115 SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse *pParse, Select *pSelect){
103116 Table *pTab;
103127 pTab = sqlite3DbMallocZero(db, sizeof(Table) );
103307 ** <recursive-table> AS (<setup-query> UNION [ALL] <recursive-query>)
103312 ** There is exactly one reference to the recursive-table in the FROM clause
103316 ** into a Queue table. Rows are extracted from the Queue table one by
103318 ** extracted row (now in the iCurrent table) becomes the content of the
103319 ** recursive-table for a recursive-query run. The output of the recursive-query
103320 ** is added back into the Queue table. Then another row is extracted from Queue
103321 ** and the iteration continues until the Queue table is empty.
103324 ** inserted into the Queue table. The iDistinct table keeps a copy of all rows
103328 ** If the query has an ORDER BY, then entries in the Queue table are kept in
103330 ** an ORDER BY, the Queue table is just a FIFO.
103345 int nCol = p->pEList->nExpr; /* Number of columns in the recursive table */
103350 int iCurrent = 0; /* The Current table */
103351 int regCurrent; /* Register holding Current table */
103352 int iQueue; /* The Queue table */
103355 SelectDest destQueue; /* SelectDest targetting the Queue table */
103376 /* Locate the cursor number of the Current table */
103385 ** the Distinct table must be exactly one greater than Queue in order
103407 VdbeComment((v, "Queue table"));
103446 ** the value for the recursive-table. Store the results in the Queue.
103545 /* Create the destination temporary table if necessary
103625 int unionTab; /* Cursor number of the temporary table holding result */
103636 /* We can reuse a temporary table generated by a SELECT to our
103643 /* We will need to create our own temporary table to hold the
103695 /* Convert the data in the temporary table into whatever form
103743 /* Code the SELECTs to our left into temporary table "tab1".
103752 /* Code the current SELECT into temporary table "tab2"
103935 ** item into the set table with bogus data.
104418 ** a column in table number iTable with a copy of the iColumn-th
104426 ** changes to pExpr so that it refers directly to the source table
104432 int iTable, /* Table to be substituted */
104461 int iTable, /* Table to be substituted */
104473 int iTable, /* Table to be replaced */
104507 ** subquery first and store the results in a temporary table, then
104508 ** run the outer query on that temporary table. This requires two
104509 ** passes over the data. Furthermore, because the temporary table
104520 ** exist on the table t1, a complete scan of the data might be
104543 ** table sqlite_once that consists of a single row containing a
104640 int iParent; /* VDBE cursor number of the pSub result set temp table */
104835 /* Delete the transient table structure associated with the
104846 /* Defer deleting the Table object associated with the
104854 Table *pTabToDel = pSubitem->pTab;
105053 ** where table is a database table, not a sub-select or view. If the query
105054 Table object representing
105057 static Table *isSimpleCount(Select *p, AggInfo *pAggInfo){
105058 Table *pTab;
105090 Table *pTab = pFrom->pTab;
105177 ** WITH contexts, from inner to outermost. If the table identified by
105178 ** FROM clause element pItem is really a common-table-expression (CTE)
105179 ** then return a pointer to the CTE definition for that table. Otherwise
105253 Table *pTab;
105270 pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
105304 pParse, "multiple references to recursive table: %s", pCte->zName
105319 sqlite3ErrorMsg(pParse, "table %s has %d values for %d columns",
105351 ** sqlite3SelectExpand() when walking a SELECT tree to resolve table
105385 ** for instances of the "*" operator or the TABLE.* operator.
105386 ** If found, expand each "*" to be every column in every table
105387 ** and TABLE.* to be every column in TABLE.
105416 /* Look up every table named in the FROM clause of the select. If
105417 ** an entry of the FROM clause is a subquery instead of a table or view,
105418 ** then create a transient table structure to describe the subquery.
105421 Table *pTab;
105444 pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
105455 /* An ordinary table or view name in the FROM clause */
105468 /* We reach here if the named table is a really a view */
105490 ** all columns in all tables. And for every TABLE.* insert the names
105491 ** of all columns in TABLE. The parser inserted a special expression
105541 /* This expression is a "*" or a "TABLE.*" and needs to be
105543 int tableSeen = 0; /* Set to 1 when TABLE matches */
105544 char *zTName = 0; /* text of name of TABLE */
105551 Table *pTab = pFrom->pTab;
105596 ** table to the right of the join */
105601 ** using clause from the table on the right. */
105644 sqlite3ErrorMsg(pParse, "no such table: %s", zTName);
105710 ** information to the Table structure that represents the result set
105713 ** The Table structure that represents the result set was constructed
105730 Table *pTab = pFrom->pTab;
105747 ** the Table structures of all FROM-clause subqueries in a
105769 ** * Ephemeral Table objects are created for all FROM-clause subqueries.
105771 ** * Wildcards "*" and "TABLE.*" in result sets are expanded.
105942 Table *pTab, /* Table being queried */
105947 char *zEqp = sqlite3MPrintf(pParse->db, "SCAN TABLE %s%s%s",
106109 /* Generate a subroutine that will fill an ephemeral table with
106176 ** The second form is preferred as a single index (or temp-table) may be
106178 ** written the query must use a temp-table for at least one of the ORDER
106179 ** BY and DISTINCT, and an index or separate temp-table for the other.
106213 /* If the output is destined for a temporary table, open that table.
106411 ** we do not have to sort. The OP_OpenEphemeral table will be
106475 /* If the index or temporary table used by the GROUP BY sort
106477 ** clause, cancel the ephemeral table open coded earlier.
106591 Table *pTab;
106593 /* If isSimpleCount() returns a pointer to a Table structure, then
106598 ** where the Table structure returned represents table <tbl>.
106601 ** OP_Count instruction is executed either on the intkey table that
106602 ** contains the data for table <tbl> or on one of its indexes. It
106860 /************** Begin file table.c *******************************************/
106899 ** This routine is called once for each row in the result table. Its job
106974 ** Instead, the entire table should be passed to sqlite3_free_table() when
106980 char ***pazResult, /* Write the result table here */
107058 /************** End of table.c ***********************************************/
107092 ** Given table pTab, return a list of all the triggers attached to
107093 ** the table. The list is connected by Trigger.pNext pointers.
107105 SQLITE_PRIVATE Trigger *sqlite3TriggerList(Parse *pParse, Table *pTab){
107119 && 0==sqlite3StrICmp(pTrig->table, pTab->zName)
107145 SrcList *pTableName,/* The name of the table/view the trigger applies to */
107151 Table *pTab; /* Table that the trigger fires off of */
107195 /* If the trigger name was unqualified, and the table is a temp table,
107197 ** If sqlite3SrcListLookup() returns 0, indicating the table does not
107206 /* Ensure the table name matches database name and that the table exists */
107215 /* The table does not exist. */
107218 ** Normally, whenever a table is dropped, all associated triggers are
107219 ** dropped too. But if a TEMP trigger is created on a non-TEMP table
107220 ** and the table is dropped by a different database connection, the
107223 ** "orphaned trigger" - a trigger whose associated table is missing.
107252 /* Do not create a trigger on a system table */
107254 sqlite3ErrorMsg(pParse, "cannot create trigger on system table");
107269 " trigger on table: %S", pTableName, 0);
107303 pTrigger->table = sqlite3DbStrDup(db, pTableName->a[0].zName);
107366 /* Make an entry in the sqlite_master table */
107374 pTrig->table, z);
107389 Table *pTab;
107390 int n = sqlite3Strlen30(pLink->table);
107391 pTab = sqlite3HashFind(&pLink->pTabSchema->tblHash, pLink->table, n);
107456 Token *pTableName, /* Name of the table into which we insert */
107485 Token *pTableName, /* Name of the table to be updated */
107510 Token *pTableName, /* The table from which rows are deleted */
107531 sqlite3DbFree(db, pTrigger->table);
107586 ** Return a pointer to the Table structure for the table that a trigger
107589 static Table *tableOfTrigger(Trigger *pTrigger){
107590 int n = sqlite3Strlen30(pTrigger->table);
107591 return sqlite3HashFind(&pTrigger->pTabSchema->tblHash, pTrigger->table, n);
107599 Table *pTable;
107666 Table *pTab = tableOfTrigger(pTrigger);
107695 ** Return a list of all triggers on table pTab if there exists at least
107697 ** performed on the table, and, if that operation is an UPDATE, if at
107702 Table *pTab, /* The table the contains the triggers */
107874 Table *pTab, /* The table pTrigger is attached to */
107988 Table *pTab, /* The table trigger pTrigger is attached to */
108015 ** table pTab. The reg, orconf and ignoreJump parameters passed to this
108022 Table *pTab, /* The table to code triggers from */
108053 ** on table pTab. The operation to code triggers for (INSERT, UPDATE or DELETE)
108063 ** in the trigger program. If N is the number of columns in table pTab
108093 Trigger *pTrigger, /* List of triggers on table pTab */
108097 Table *pTab, /* The table to code triggers from */
108110 /* Sanity checking: The schema for the trigger and for the table are
108111 ** always defined. The trigger must be in the same schema as the table
108129 ** Triggers may access values stored in the old.* or new.* pseudo-table.
108136 ** table may be accessed using an [old|new].<col> reference. Bit 1 is set if
108138 ** are more than 32 columns in the table, and at least one of the columns
108145 ** applies to the old.* table. If 1, the new.* table.
108155 Trigger *pTrigger, /* List of triggers on table pTab */
108159 Table *pTab, /* The table to code triggers from */
108205 SrcList *pSrc, /* The virtual table to be modified */
108206 Table *pTab, /* The virtual table */
108217 table pTab. This routine sets the P4 parameter of the
108221 ** column definition. This was either supplied by the user when the table
108222 ** was created, or added later to the table definition by an ALTER TABLE
108223 ** command. If the latter, then the row-records in the table btree on disk
108229 ** Column definitions created by an ALTER TABLE command may only have
108232 ** when the ALTER TABLE is executed and one of the literal values written
108233 ** into the sqlite_master table.)
108245 SQLITE_PRIVATE void sqlite3ColumnDefault(Vdbe *v, Table *pTab, int i, int iReg){
108275 SrcList *pTabList, /* The table in which we should change things */
108281 Table *pTab; /* The table to be updated */
108294 ** an expression for the i-th column of the table.
108297 u8 chngPk; /* PRIMARY KEY changed in a WITHOUT ROWID table */
108298 u8 chngRowid; /* Rowid changed in a normal table */
108303 int iDb; /* Database containing the table being updated */
108315 int iEph = 0; /* Ephemeral table holding all primary key values */
108323 int regNew; /* Content of the NEW.* table in triggers */
108324 int regOld = 0; /* Content of OLD.* table in triggers */
108335 /* Locate the table which we want to update.
108341 /* Figure out if we have any triggers and if the table being
108365 /* Allocate a cursors for the main database table and for all indices.
108457 /* There is one entry in the aRegIdx[] array for each index on the table
108514 ** a ephemeral table.
108676 ** table and index records, and as the values for any new.* references
108827 /* Update the sqlite_sequence table by storing the content of the
108866 ** Generate code for an UPDATE of a virtual table.
108868 ** The strategy is that we create an ephemerial table that contains
108875 ** Then we loop over this ephemeral table and for each row in
108876 ** the ephermeral table call VUpdate.
108878 ** When finished, drop the ephemeral table.
108882 ** it out of the ephemeral table before calling VUpdate.
108886 SrcList *pSrc, /* The virtual table to be modified */
108887 Table *pTab, /* The virtual table */
108898 int ephemTab; /* Table holding the result of the SELECT */
108925 /* Create the ephemeral table into which the update results will
108933 /* fill the ephemeral table
108938 /* Generate code to scan the ephemeral table and call VUpdate. */
109194 "SELECT 'CREATE TABLE vacuum_db.' || substr(sql,14) "
109195 " FROM sqlite_master WHERE type='table' AND name!='sqlite_sequence'"
109216 "WHERE type = 'table' AND name!='sqlite_sequence' "
109221 /* Copy over the sequence table
109239 ** from the SQLITE_MASTER table.
109246 " OR (type='table' AND rootpage=0)"
109348 ** Before a virtual table xCreate() or xConnect() method is invoked, the
109355 VTable *pVTable; /* The virtual table being constructed */
109356 Table *pTab; /* The Table object to which the virtual table belongs */
109406 ** External API function used to create a new virtual-table module.
109418 ** External API function used to create a new virtual-table module.
109431 ** Lock the virtual table so that it cannot be disconnected.
109435 ** If a disconnect is attempted while a virtual table is locked,
109444 ** pTab is a pointer to a Table structure representing a virtual-table.
109446 ** this virtual-table, if one has been created, or NULL otherwise.
109448 SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3 *db, Table *pTab){
109456 ** Decrement the ref-count on a virtual table object. When the ref-count
109477 ** Table p is a virtual table. This function moves all elements in the
109483 static VTable *vtabDisconnectAll(sqlite3 *db, Table *p){
109489 ** that contains table p is held by the caller. See header comments
109516 ** Table *p is a virtual table. This function removes the VTable object
109517 ** for table *p associated with database connection db from the linked
109523 SQLITE_PRIVATE void sqlite3VtabDisconnect(sqlite3 *db, Table *p){
109542 ** Disconnect all the virtual table objects in the sqlite3.pDisconnect list.
109554 ** associated with the database the virtual table is stored in is held
109555 ** or, if the virtual table is stored in a non-sharable database, then
109579 ** Clear any and all virtual-table information from the Table record.
109580 ** This routine is called, for example, just before deleting the Table
109583 ** Since it is a virtual-table, the Table structure contains a pointer
109592 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table *p){
109606 ** string will be freed automatically when the table is
109609 static void addModuleArgument(sqlite3 *db, Table *pTable, char *zArg){
109630 ** The parser calls this routine when it first sees a CREATE VIRTUAL TABLE
109636 Token *pName1, /* Name of new table, or database name */
109637 Token *pName2, /* Name of new table or NULL */
109638 Token *pModuleName, /* Name of the module for the virtual table */
109639 int ifNotExists /* No error if the table already exists */
109641 int iDb; /* The database the table is being created in */
109642 Table *pTable; /* The new virtual table */
109662 /* Creating a virtual table invokes the authorization callback twice.
109664 ** sqlite_master table, has already been made by sqlite3StartTable().
109665 ** The second call, to obtain permission to create the table, is made now.
109677 ** virtual table currently under construction in pParse->pTable.
109689 ** The parser calls this routine after the CREATE VIRTUAL TABLE statement
109693 Table *pTab = pParse->pNewTable; /* The table being constructed */
109701 /* If the CREATE VIRTUAL TABLE statement is being entered for the
109702 ** first time (in other words if the virtual table is actually being
109705 ** in the sqlite_master table.
109713 /* Compute the complete text of the CREATE VIRTUAL TABLE statement */
109717 zStmt = sqlite3MPrintf(db, "CREATE VIRTUAL TABLE %T", &pParse->sNameToken);
109720 ** SQLITE_MASTER table. We just need to update that slot with all
109724 ** entry in the sqlite_master table tht was created for this vtab
109730 "SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q "
109743 zWhere = sqlite3MPrintf(db, "name='%q' AND type='table'", pTab->zName);
109749 /* If we are rereading the sqlite_master table create the in-memory
109750 ** record of the table. The xConnect() method is not called until
109751 ** the first time the virtual table is used in an SQL statement. This
109753 ** the required virtual table implementations are registered. */
109755 Table *pOld;
109772 ** of an argument to the module name in a CREATE VIRTUAL TABLE statement.
109782 ** in an argument to the module name in a CREATE VIRTUAL TABLE statement.
109796 ** Invoke a virtual table constructor (either xCreate or xConnect). The
109802 Table *pTab,
109831 /* Invoke the virtual table constructor */
109864 ** columns of the table to see if any of them contain the token "hidden".
109908 ** of the virtual table pTab. If an error occurs, an error code is returned
109911 ** This call is a no-op if table pTab is not a virtual table.
109913 SQLITE_PRIVATE int sqlite3VtabCallConnect(Parse *pParse, Table *pTab){
109924 /* Locate the required virtual table module */
109945 ** more v-table. Return SQLITE_NOMEM if a malloc fails, or SQLITE_OK otherwise.
109966 ** Add the virtual table pVTab to the array sqlite3.aVTrans[]. Space should
109977 ** of the virtual table named zTab in database iDb.
109985 Table *pTab;
109992 /* Locate the required virtual table module */
110020 ** This function is used to set the schema of a virtual table. It is only
110022 ** virtual table module.
110028 Table *pTab;
110083 ** of the virtual table named zTab in database iDb. This occurs
110084 ** when a DROP TABLE is mentioned.
110086 ** This call is a no-op if zTab is not a virtual table.
110090 Table *pTab;
110183 ** If the virtual table pVtab supports the transaction interface
110233 ** as the second argument to the virtual table method invoked.
110237 ** SAVEPOINT_RELEASE, then the xRelease method of each virtual table with
110240 ** If any virtual table method returns an error code other than SQLITE_OK,
110242 ** function immediately. If all calls to virtual table methods are successful,
110281 ** If pExpr is a column in a virtual table, then let the virtual
110282 ** table implementation have an opportunity to overload the function.
110284 ** This routine is used to allow virtual table implementations to
110297 Table *pTab;
110308 /* Check to see the left operand is a column in a virtual table */
110320 /* Call the xFindFunction method on the virtual table implementation
110352 ** Make sure virtual table pTab is contained in the pParse->apVirtualLock[]
110357 SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse *pParse, Table *pTab){
110360 Table **apVtabLock;
110378 ** table update operation currently in progress.
110396 ** of the virtual table being implemented.
110444 ** generating the code that loops through a table looking for applicable
110514 int iTabCur; /* The VDBE cursor used to access the table */
110556 Bitmask maskSelf; /* Bitmask identifying table iTab */
110560 u8 iTab; /* Position in FROM clause of table for this loop */
110902 #define WHERE_IDX_ONLY 0x00000040 /* Use index only - omit table */
110964 ** table and iaCur[1] gets the cursor used by an auxiliary index.
111184 ** There is one cursor per table in the FROM clause. The number of
111414 ** for terms of the form "X <op> <expr>" where X is column iColumn of table
111459 ** where X is a reference to the iColumn of table iCur and <op> is one of
111476 ** the form "X <op> Y" where Y is a column in another table if no terms of
111686 ** a single table T (as shown in example B above) then create a new virtual
111698 ** If all subterms are indexable by a single table T, then set
111701 ** WhereTerm.u.pOrInfo->indexable |= the cursor number for table T
111704 ** "T.C <op> <expr>" where C is any column of table T and
111838 ** something other than == on a column in the single table. The 1-bit
111840 ** "table.column=expr" for some single table. The one bit that is set
111841 ** will correspond to the common table. We still need to check to make
111848 ** Note that terms of the form "table.column1=table.column2" (the
111849 ** same table on both sizes of the ==) cannot be optimized.
111854 int iCursor = -1; /* Table cursor common to all terms */
111857 /* Search for a table and column that appears on one side or the
111858 ** other of the == operator in every subterm. That table and column
111860 ** such table and column. Set okToChngToIN if an appropriate table
111889 /* No candidate table+column was found. This can only occur
111898 /* We have found a candidate table and column. Check to see if that
111899 ** table and column is common to every term in the OR clause */
111991 WhereMaskSet *pMaskSet; /* Set of table index masks */
112029 ** on left table of a LEFT JOIN. Ticket #3015 */
112296 int iBase, /* Cursor for table associated with pIdx */
112332 Table *pTab;
112337 /* If there is more than one table or sub-select in the FROM clause of
112344 /* If any of the expressions is an IPK column on table iBase, then return
112353 /* Loop through all indices on the table, checking each to see if it makes
112447 struct SrcList_item *pSrc, /* Table we are trying to access */
112481 Table *pTable; /* The table being indexed */
112534 ** original table never needs to be accessed. Automatic indices must
112536 ** original table changes and the index and table cannot both be used
112642 ** to this virtual table */
112655 ** virtual table then allocate space for the aOrderBy part of
112731 ** The table object reference passed as the second argument to this function
112732 ** must represent a virtual table. This function invokes the xBestIndex()
112733 ** method of the virtual table with the sqlite3_index_info object that
112744 static int vtabBestIndex(Parse *pParse, Table *pTab, sqlite3_index_info *p){
112768 "table %s: xBestIndex returned an invalid plan", pTab->zName);
113461 ** For example, consider table t1(a,b,c,d,e,f) with index i1(a,b,c).
113493 ** CREATE TABLE t1(a TEXT PRIMARY KEY, b);
113622 ** Argument pLevel describes a strategy for scanning table pTab. This
113624 ** of the subset of table rows scanned by the strategy in the form of an
113640 static char *explainIndexRange(sqlite3 *db, WhereLoop *pLoop, Table *pTab){
113683 ** record is added to the output to describe the table scan strategy in
113688 SrcList *pTabList, /* Table list this loop refers to */
113719 zMsg = sqlite3MAppendf(db, zMsg, "%s TABLE %s", zMsg, pItem->zName);
113758 zMsg = sqlite3MAppendf(db, zMsg, "%s VIRTUAL TABLE INDEX %d:%s", zMsg,
113781 int iCur; /* The VDBE cursor for the table */
113825 /* If this is the right table of a LEFT OUTER JOIN, allocate and
113826 ** initialize a memory cell that records if this table matches any
113827 ** row of the left table of the join.
113847 /* Case 1: The table is a virtual-table. Use the VFilter and VNext
114223 /* Seek the table cursor, if required */
114227 /* pIdx is a covering index. No need to access the main table. */
114269 ** CREATE TABLE t1(a,b,c,d);
114303 ** Added 2014-05-26: If the table is a WITHOUT ROWID table, then
114309 SrcList *pOrTab; /* Shortened table list or OR-clause generation */
114322 Table *pTab = pTabItem->pTab;
114332 /* Set up a new SrcList in pOrTab containing the table being scanned
114428 /* Loop through table entries that match term pOrTerm. */
114461 /* Check if the temp table already contains this key. If so,
114464 ** insert the key into the temp table and proceed with processing
114469 ** the temp table. And if iSet is -1, assume that there is no
114470 ** need to insert the key into the temp table, as it will never
114495 ** contained one or more AND term from a notReady table. The
114496 ** terms from the notReady table could not be tested and will
114526 /* Finish the loop through table entries that match term pOrTerm. */
114548 ** scan of the entire table.
114624 ** at least one row of the right table has matched the left table.
114672 Table *pTab = pItem->pTab;
115169 int iCol; /* Index of the column in the table */
115171 LogEst rLogSize; /* Logarithm of table size */
115359 ** visiting the rows in the main table. */
115430 ** the table is used by an index. Only the first 63 columns are considered.
115459 ** Add all WhereLoop objects for a single table of the join where the table
115460 ** is idenfied by pBuilder->pNew->iTab. That table is guaranteed to be
115461 ** a b-tree table, not a virtual table.
115466 ** For a full scan, assuming the table (or index) contains nRow rows:
115468 ** cost = nRow * 3.0 // full-table scan
115473 ** estimated average size of the index and table records.
115492 ** of a full table scan.
115496 Bitmask mExtra /* Extra prerequesites for using this table */
115509 LogEst rSize; /* number of rows in the table */
115510 LogEst rLogSize; /* Logarithm of the number of rows in the table */
115512 Table *pTab; /* Table being queried */
115532 Index *pFirst; /* First of real indices on the table */
115545 /* The real indices of the table are only considered if the
115578 ** the table being indexed. */
115581 /* TUNING: Each index lookup yields 20 rows in the table. This
115618 /* Full table scan */
115620 /* TUNING: Cost of full table scan is (N*3.0). */
115652 ** index and table rows. If this is a non-covering index scan,
115653 ** also add the cost of visiting table rows (N*3.0). */
115682 ** Add all WhereLoop objects for a table of the join identified by
115683 ** pBuilder->pNew->iTab. That table is guaranteed to be a virtual table.
115693 Table *pTab;
115807 /* Do not attempt to use an IN constraint if the virtual table
115813 /* A virtual table that is constrained by an IN clause may not
115946 ** the planner may elect to "OR" together a full-table scan and an
116037 int iColumn; /* A column number within table iCur */
116066 ** The rowid for a table is always UNIQUE and NOT NULL so whenever the
116090 /* Mark off any ORDER BY term X that is a column in the table of
116151 /* Get the column number in the table (iColumn) and sort order
116679 ** Most queries use only a single table (they are not joins) and have
116697 Table *pTab;
116773 ** The basic idea is to do a nested loop, one loop for each table in
116775 ** same as a SELECT with only a single table in the FROM clause.) For
116796 ** There are Btree cursors associated with each table. t1 uses cursor
116809 ** refer to those indices, a complete table scan can be avoided and the
116901 ** only generate code for the first table in pTabList and assume that
116972 ** its Expr.iRightJoinTable value to find the bitmask of the right table
116973 ** of the join. Subtracting one from the right table bitmask gives a
117147 Table *pTab; /* Table to open */
117148 int iDb; /* Index of database containing table/index */
117199 ** WITHOUT ROWID table. No need for a separate index */
117349 Table *pTab = pTabItem->pTab;
117353 /* For a co-routine, change all OP_Column references to the table of
117399 ** from the index instead of from the table where possible. In some cases
117400 ** this optimization prevents the table from ever being read, which can
117404 ** sqlite3WhereEnd will have created code that references the table
117406 ** that reference the table and converts them into opcodes that
117606 ** table.
117704 ** slots in the yy_action[] table.
117706 ** The action table is constructed as a single large table named yy_action[].
117713 ** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table
117724 ** yy_action[] A single table containing all actions.
117725 ** yy_lookahead[] A table containing the lookahead for each entry in
118192 /* The next table maps tokens into fallback tokens. If a construct
118220 0, /* TABLE => nothing */
118350 ** are required. The following table supplies these names */
118356 "TABLE", "CREATE", "IF", "NOT",
118449 /* 26 */ "create_table ::= createkw temp TABLE ifnotexists nm dbnm",
118529 /* 106 */ "cmd ::= DROP TABLE ifexists fullname",
118727 /* 304 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
118728 /* 305 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column",
118734 /* 311 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm",
119135 /* The following table contains information about every rule that
119570 case 26: /* create_table ::= createkw temp TABLE ifnotexists nm dbnm */
119622 sqlite3ErrorMsg(pParse, "unknown table option: %.*s", yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.z);
119802 case 106: /* cmd ::= DROP TABLE ifexists fullname */
120559 "qualified table names are not allowed on INSERT, UPDATE, and DELETE "
120642 case 304: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
120647 case 305: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column */
120664 case 311: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
121063 ** might be implemented more directly using a hand-written hash table.
121215 testcase( i==19 ); /* TABLE */
121762 /* If the pParse->declareVtab flag is set, do not delete any table
121764 ** will take responsibility for freeing the Table structure.
121779 Table *p = pParse->pZombieTab;
122960 Table *pTab = (Table *)sqliteHashData(p);
123008 ** SQL statements below, as the v-table implementation may be storing
123059 HashElem *i; /* Hash table iterator */
123340 /* SQLITE_LOCKED */ "database table is locked",
123350 /* SQLITE_EMPTY */ "table contains no data",
123387 int count /* Number of times table has been busy */
123551 ** to the hash table.
123692 ** Declare that a function has been overloaded by a virtual table.
123989 ** following table describes the relationship between these two values
124130 Table *pTab; /* A table in the database */
124137 pTab = (Table*)sqliteHashData(k);
125058 ** Return meta information about a specific column of a database table.
125065 const char *zTableName, /* Table name */
125075 Table *pTab = 0;
125093 /* Locate the table in question */
125126 ** 2. The table is not a view and the column name identified an
125158 zErrMsg = sqlite3MPrintf(db, "no such table column: %s.%s", zTableName,
126099 ** the %_segments table in sorted order. This means that when the end
126163 ** The segment directory in table %_segdir stores meta-information for
126203 ** leaf nodes are written in to the %_segments table in order, this
126322 ** When an fts3 table is created, it passes any arguments passed to
126323 ** the tokenizer clause of the CREATE VIRTUAL TABLE statement to the
126327 ** be used for the fts3 table (customized by the tokenizer clause arguments).
126349 ** TABLE statement that created the fts3 table. For example, if
126465 ** This is the header file for the generic hash-table implementation
126467 ** hash table implementation for the full-text indexing module.
126477 /* A complete hash table is an instance of the following structure.
126488 int count; /* Number of entries in this table */
126490 int htsize; /* Number of buckets in the hash table */
126491 struct _fts3ht { /* the hash table */
126497 /* Each element in the hash table is an instance of the following
126504 Fts3HashElem *next, *prev; /* Next and previous elements in the table */
126510 ** There are 2 different modes of operation for a hash table:
126543 ** Macros for looping over all elements of a hash table. The idiom is
126561 ** Number of entries in a hash table
126591 ** Fts3Table.pendingTerms hash table. Normally, the hash table is
126595 ** segment is created and the hash table cleared immediately.
126734 const char *zName; /* virtual table name */
126735 int nColumn; /* number of named columns in virtual table */
126745 ** statements is run and reset within a single virtual table API call.
126754 u8 bHasStat; /* True if %_stat table exists (2==unknown) */
126755 u8 bHasDocsize; /* True if %_docsize table exists */
126759 char *zSegmentsTbl; /* Name of %_segments table */
126760 sqlite3_blob *pSegments; /* Blob handle open on %_segments table */
126768 ** A single FTS4 table may have multiple full-text indexes. For each index
126774 ** pending data structures, including hash table overhead, but not including
126782 Fts3Hash hPending; /* Pending terms table for this index */
126791 ** methods of the virtual table are called at appropriate times. These
126807 ** When the core wants to read from the virtual table, it creates a
126808 ** virtual table cursor (an instance of the following structure) using
126828 sqlite3_int64 nDoc; /* Documents in table */
126847 ** CREATE VIRTUAL TABLE ex1 USING fts3(a,b,c,d);
126856 #define FTS3_FULLSCAN_SEARCH 0 /* Linear scan of %_content table */
126857 #define FTS3_DOCID_SEARCH 1 /* Lookup by rowid on %_content table */
126925 ** where nCol is the number of columns in the queried FTS table. The array
127311 ** The xDisconnect() virtual table method.
127365 ** The xDestroy() virtual table method.
127375 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_content'", zDb, p->zName);
127377 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_segments'", zDb,p->zName);
127378 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_segdir'", zDb, p->zName);
127379 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_docsize'", zDb, p->zName);
127380 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_stat'", zDb, p->zName);
127391 ** Invoke sqlite3_declare_vtab() to declare the schema for the FTS3 table
127410 /* Create a list of user columns for the virtual table */
127416 /* Create the whole "CREATE TABLE" statement to pass to SQLite */
127418 "CREATE TABLE x(%s %Q HIDDEN, docid HIDDEN, %Q HIDDEN)",
127434 ** Create the %_stat table if it does not already exist.
127438 "CREATE TABLE IF NOT EXISTS %Q.'%q_stat'"
127447 ** required by the FTS3 table passed as the only argument. This is done
127451 ** FTS4 table, not an FTS3 table) then also create the %_docsize and
127461 char *zContentCols; /* Columns of %_content table */
127463 /* Create a list of user columns for the content table */
127474 /* Create the content table */
127476 "CREATE TABLE %Q.'%q_content'(%s)",
127484 "CREATE TABLE %Q.'%q_segments'(blockid INTEGER PRIMARY KEY, block BLOB);",
127488 "CREATE TABLE %Q.'%q_segdir'("
127501 "CREATE TABLE %Q.'%q_docsize'(docid INTEGER PRIMARY KEY, size BLOB);",
127640 ** table has the three user-defined columns "a", "b", and "c", the following
127692 ** of columns in the %_content table (one for the docid plus one for each
127697 ** bracket. For example, if zFunc is "zip" and the FTS3 table has three
127760 ** representing the indexes maintained by the current FTS table. FTS tables
127763 ** (if any) specified as part of the CREATE VIRTUAL TABLE statement.
127778 struct Fts3Index **apIndex /* OUT: Array of indexes for this table */
127814 ** This function is called when initializing an FTS4 table that uses the
127816 ** of the new FTS4 table.
127820 ** a table of that name. If found, the output variables are populated
127823 ** *pnCol: Set to the number of columns table xxx has,
127829 ** the name of the corresponding column in table xxx. The array
127834 ** If the table cannot be found, an error code is returned and the output
127841 const char *zTbl, /* Name of content table */
127861 int nCol; /* Number of table columns */
127900 ** methods of the FTS3 virtual table.
127906 ** argv[2] -> table name
127912 void *pAux, /* Hash table containing tokenizers */
127925 int nCol = 0; /* Number of columns in the FTS table */
127928 int nName; /* Bytes required to hold table name */
127931 sqlite3_tokenizer *pTokenizer = 0; /* Tokenizer for this table */
127934 struct Fts3Index *aIndex = 0; /* Array of indexes for this table */
127937 int bNoDocsize = 0; /* True to omit %_docsize table */
127973 ** + Figures out the number of columns the FTSX table will have, and
128096 ** TABLE statement, use all columns from the content table.
128244 /* Check to see if a legacy fts3 table has been "upgraded" by the
128245 ** addition of a %_stat table so that it can use incremental merge.
128256 /* Declare the table schema to SQLite. */
128283 ** The xConnect() and xCreate() methods for the virtual table. All the
128288 void *pAux, /* Pointer to tokenizer hash table */
128298 void *pAux, /* Pointer to tokenizer hash table */
128326 ** 3. Linear scan of %_content table.
128338 /* By default use a full table scan. This is an expensive option,
128469 ** on the xClose method of the virtual table interface.
128490 ** (or the equivalent for a content=xxx table) and set pCsr->pStmt to
128511 ** of the %_content table that contains the last match. Return
128529 ** table is missing a row that is present in the full-text index.
128585 ** table, then there are always 20 bytes of zeroed padding following the
128681 Fts3Table *p, /* Virtual table handle */
128699 char *zBlob = 0; /* Blob read from %_segments table */
129492 Fts3Table *p, /* FTS table handle */
129575 Fts3Table *p, /* FTS3 table handle */
129591 ** made by an fts4aux module, not an FTS table. In this case calling
129649 Fts3Table *p, /* FTS3 table handle */
129681 Fts3Table *p, /* FTS virtual table handle */
129706 Fts3Cursor *pCsr, /* Virtual table cursor handle */
129772 Fts3Table *p, /* Virtual table handle */
129844 ** Advance the cursor to the next row in the %_content table that
129846 ** the next row that matches. For a full-table scan, this will be
129847 ** simply the next row in the %_content table. For a docid lookup,
129900 ** This is the xFilter interface for the virtual table. See
129901 ** the virtual table xFilter method documentation for additional
129904 ** If idxNum==FTS3_FULLSCAN_SEARCH then do a full table scan against
129905 ** the %_content table.
129908 ** in the %_content table.
129993 /* Compile a SELECT statement for this cursor. For a full-table-scan, the
129994 ** statement loops through all rows of the %_content table. For a
130021 ** This is the xEof method of the virtual table. SQLite calls this
130031 table. The
130047 ** (iCol == p->nColumn) -> Magic column with the same name as the table.
130069 /* The extra column whose name is the same as the table.
130102 sqlite3_vtab *pVtab, /* Virtual table handle */
130112 ** hash-table to the database.
130131 ** of blocks from the segments table. But this is not considered overhead
130158 ** If it is currently unknown whether or not the FTS table has an %_stat
130159 ** table (if p->bHasStat==2), attempt to determine this (set p->bHasStat
130201 ** the pending-terms hash-table have already been flushed into the database
130217 ** hash-table. Any changes made to the database are reverted by SQLite.
130345 ** where 't' is the name of an FTS3 table.
130353 Fts3Table *p; /* Virtual table handle */
130399 ** virtual table.
130402 sqlite3_vtab *pVtab, /* Virtual table handle */
130435 ** Implementation of FTS3 xRename method. Rename an fts3 table.
130438 sqlite3_vtab *pVtab, /* Virtual table handle */
130439 const char *zName /* New name of table */
130445 /* At this point it must be known if the %_stat table exists or not.
130449 /* As it happens, the pending terms table is always empty here. This is
130450 ** because an "ALTER TABLE RENAME TABLE" statement inside a transaction
130452 ** flushes the pending terms table. But leave the (no-op) call to
130462 "ALTER TABLE %Q.'%q_content' RENAME TO '%q_content';",
130469 "ALTER TABLE %Q.'%q_docsize' RENAME TO '%q_docsize';",
130475 "ALTER TABLE %Q.'%q_stat' RENAME TO '%q_stat';",
130480 "ALTER TABLE %Q.'%q_segments' RENAME TO '%q_segments';",
130484 "ALTER TABLE %Q.'%q_segdir' RENAME TO '%q_segdir';",
130493 ** Flush the contents of the pending-terms table to disk.
130525 ** Discard the contents of the pending terms table.
130566 ** allocated for the tokenizer hash table.
130628 /* Allocate and initialize the hash-table used to store tokenizers. */
130636 /* Load the built-in tokenizers into the hash table */
130658 /* Create the virtual table wrapper around the hash-table and overload
130685 /* An error has occurred. Delete the hash table and return the error code. */
130750 Fts3Table *pTab, /* FTS Table pointer */
131171 Fts3Table *pTab, /* Virtual table handle */
131462 ** of data that will fit on a single leaf page of an intkey table in
131470 ** data from the %_stat table to calculate it.
131472 ** Entry 0 of the %_stat table is a blob containing (nCol+1) FTS3
131473 ** varints, where nCol is the number of columns in the FTS3 table.
131475 ** the table. The following nCol varints contain the total amount of
131476 ** data stored in all rows of each column of the table, from left
131545 ** table actually contains the same data as the index. To prevent this from
132127 ** 2. After scanning the current FTS table row for the deferred tokens,
132376 ** the FTS table (considering all rows), and
132378 ** 2. For each column, the number of rows in the table for which the
132390 ** values are set to the number of documents in the table. In other
132392 ** column of each row of the table.
132617 ** Initialize API pointer table, if required.
132681 ** Schema of the terms table.
132684 "CREATE TABLE x(term, col, documents, occurrences, languageid HIDDEN)"
132700 char const *zFts3; /* Name of fts3 table */
132705 Fts3auxTable *p; /* Virtual table object to return */
132711 ** CREATE VIRTUAL TABLE xxx USING fts4aux(fts4-table);
132712 ** CREATE VIRTUAL TABLE xxx USING fts4aux(fts4-table-db, fts4-table);
133282 const char **azCol; /* Array of column names for fts3 table */
134123 char **azCol, /* Array of column names for fts3 table */
134174 ** of each column in the target fts3 table, in order from left to right.
134177 ** The iDefaultCol parameter should be passed the index of the table column
134181 ** match any table column.
134186 char **azCol, /* Array of column names for fts3 table */
134272 ** Function to query the hash-table of tokenizers (see README.tokenizers).
134361 ** of a column of the fts3 table that the query expression may refer to.
134485 ** We've modified it slightly to serve as a standalone hash table
134519 /* Turn bulk memory into a hash table object by initializing the
134522 ** "pNew" is a pointer to the hash table that is to be initialized.
134525 ** determines what kind of key the hash table will use. "copyKey" is
134526 ** true if the hash table should make its own private copy of keys and
134540 /* Remove all entries from a hash table. Reclaim all memory.
134541 ** Call this routine to delete a hash table or to reset a hash table
134545 Fts3HashElem *elem; /* For looping over all elements of the table */
134634 /* Link an element into the hash table
134637 Fts3Hash *pH, /* The complete hash table */
134660 /* Resize the hash table so that it cantains "new_size" buckets.
134661 ** "new_size" must be a power of 2. The hash table might fail
134667 struct _fts3ht *new_ht; /* The new hash table */
134687 ** hash table that matches the given key. The hash for this key has
134715 /* Remove a single entry from the hash table given a pointer to that
134769 ** Attempt to locate an element of the hash table pH with a key
134780 /* Insert an element into the hash table pH. The key is pKey,nKey
134790 ** the new data is returned and the hash table is unchanged.
134793 ** element corresponding to "key" is removed from the hash table.
134796 Fts3Hash *pH, /* The hash table to insert into */
134802 int h; /* the hash of the key modulo hash table size */
135552 ** hash table. This function may be called as follows:
135563 ** the string <key-name> must already exist in the has table. Otherwise,
135568 ** to string <key-name> (after the hash-table is updated, if applicable).
135665 Fts3Hash *pHash, /* Tokenizer hash table */
135948 ** the hash table pointed to by argument pHash. The hash table must
135956 ** defined at compilation time, a temporary virtual table (see header
135961 ** of both the scalar and, if created, the virtual table.
136079 ** else we need to reindex. One solution would be a meta-table to
136257 ** This file contains code for the "fts3tokenize" virtual table module.
136258 ** An fts3tokenize virtual table is created as follows:
136260 ** CREATE VIRTUAL TABLE <tbl> USING fts3tokenize(
136264 ** The table created has the following schema:
136266 ** CREATE TABLE <tbl>(input, token, start, end, position)
136272 ** The virtual table module tokenizes this <string>, using the FTS3
136273 ** tokenizer specified by the arguments to the CREATE VIRTUAL TABLE
136294 ** Virtual table structure.
136303 ** Virtual table cursor structure.
136387 ** Schema of the tokenizer table.
136389 #define FTS3_TOK_SCHEMA "CREATE TABLE x(input, token, start, end, position)"
136398 ** argv[2]: table name
136403 void *pHash, /* Hash table of tokenizers */
136627 /* CREATE TABLE x(input, token, start, end, position) */
136744 ** win (reduced IO and CPU) if SQLite stops calling the virtual table xNext()
136909 ** or the pending-terms table being flushed), leaves are written into the
136987 Fts3Table *p, /* Virtual table handle */
137054 ** Read a single entry from the %_segdir table. The entry from absolute
137127 Fts3Table *pTab, /* FTS3 table handle */
137152 Fts3Table *pTab, /* Fts3 table handle */
137173 Fts3Table *pTab, /* Fts3 table handle */
137190 Fts3Table *p, /* The FTS3 table */
137208 ** shared-cache table-lock on the %_segdir table. This is required before
137209 ** writing data to the fts3 table. If this lock is not acquired first, then
137245 ** in the %_segdir table on disk. This function is used to convert three
137247 ** can be used to query the %_segdir table.
137260 Fts3Table *p, /* FTS3 table handle */
137276 ** all rows in the %_segdir table, from oldest to newest. If successful,
137281 ** each FTS3 table.
137283 ** The statement returns the following columns from the %_segdir table:
137292 Fts3Table *p, /* FTS3 table */
137448 Fts3Hash *pHash, /* Pending terms hash table to add entry to */
137477 ** pending-terms hash-table. The docid used is that currently stored in
137483 Fts3Table *p, /* Table into which text will be inserted */
137507 ** zText==0. In this case, add zero token entries to the hash table and
137561 Fts3Table *p, /* Full-text table handle */
137605 ** pendingTerms hash table.
137641 ** apVal[p->nColumn+2] Hidden column with same name as table
137646 Fts3Table *p, /* Full-text table */
137666 ** table. The SQL for this statement is:
137671 ** defined columns in the FTS3 table, plus one for the docid field.
137716 ** Remove all data from the FTS3 table. Clear the hash table containing
137722 /* Discard the contents of the pending-terms hash table. */
137756 Fts3Table *p, /* The FTS table to delete from */
137801 ** This function allocates a new level iLevel index in the segdir table.
137860 ** The %_segments table is declared as follows:
137862 ** CREATE TABLE %_segments(blockid INTEGER PRIMARY KEY, block BLOB)
137864 ** This function reads data from a single row of the %_segments table. The
137868 ** identified table row is. Whether or not paBlob is NULL, *pnBlob is set
137871 ** If an error occurs, or the table does not contain the specified row,
137882 ** on the database file for longer than necessary). Thus, any virtual table
137887 Fts3Table *p, /* FTS3 table handle */
138151 /* A pending-terms seg-reader for an FTS4 table that uses order=desc.
138325 ** the contents of the pending-terms hash table to the database.
138346 ** through each term in the pending-terms table. Or, if isPrefixIter is
138348 ** the pending terms hash table contains the terms "sqlite", "mysql" and
138361 Fts3Table *p, /* Virtual table handle */
138578 ** Insert a record into the %_segments table.
138581 Fts3Table *p, /* Virtual table handle */
138598 ** Find the largest relative level number in the table. If successful, set
138619 ** Insert a record into the %_segdir table.
138622 Fts3Table *p, /* Virtual table handle */
138678 Fts3Table *p, /* Virtual table handle */
138815 Fts3Table *p, /* Virtual table handle */
138884 Fts3Table *p, /* Virtual table handle */
138913 /* Find the next free blockid in the %_segments table */
139026 Fts3Table *p, /* Virtual table handle */
139049 /* The entire tree fits on the root node. Write it to the segdir table. */
139074 ** pRowid would mean the FTS3 table were empty.
139076 ** If successful, *pisEmpty is set to true if the table is empty except for
139084 /* If using the content=xxx option, assume the table is never empty */
139103 ** Segment levels are stored in the 'level' column of the %_segdir table.
139167 ** Delete all entries in the %_segments table associated with the segment
139169 ** of the %_segdir table.
139172 Fts3Table *p, /* FTS table handle */
139204 Fts3Table *p, /* Virtual table handle */
139323 Fts3Table *p, /* Virtual table handle */
139391 Fts3Table *p, /* Virtual table handle */
139423 Fts3Table *p, /* Virtual table handle */
139432 Fts3Table *p, /* Virtual table handle */
139507 Fts3Table *p, /* Virtual table handle */
139745 Fts3Table *p, /* FTS table handle */
139759 /* Loop through all entries in the %_segdir table corresponding to
140018 Fts3Table *p, /* Table into which to insert */
140046 ** Record 0 of the %_stat table contains a blob consisting of N varints,
140047 ** where N is the number of user defined columns in the fts3 table plus
140051 ** Varint 0: Total number of rows in the table.
140054 ** the column for all rows of the table.
140057 ** columns of all rows of the table.
140062 Fts3Table *p, /* Table being updated */
140170 ** The entire FTS index is discarded and rebuilt. If the table is one
140172 ** the current contents of the xxx table. Otherwise, it is rebuilt based
140173 ** on the contents of the %_content table.
140186 /* Compose and prepare an SQL statement to loop through the content table */
140256 Fts3Table *p, /* FTS3 table handle */
140470 Fts3Table *p, /* Fts3 table handle */
140621 Fts3Table *p, /* Fts3 table handle */
140706 Fts3Table *p, /* FTS3 table handle */
140733 ** table. However, this is not permitted in this case. The problem is that
140734 ** space has already been reserved in the %_segments table, and so the
140735 ** start_block and end_block fields of the %_segdir table must be populated.
140744 ** table until we are sure it is needed.
140810 ** Query to see if the entry in the %_segments table with blockid iEnd is
140818 ** is, then a NULL entry has been inserted into the %_segments table
140853 Fts3Table *p, /* Fts3 table handle */
140890 /* Check for the zero-length marker in the %_segments table */
140985 Fts3Table *p, /* FTS Table handle */
141007 ** In the %_segdir table, a segment is defined by the values in three
141030 Fts3Table *p, /* Fts3 table handle */
141066 /* Insert the marker in the %_segments table to make sure nobody tries
141084 ** Remove an entry from the %_segdir table. This involves running the
141095 Fts3Table *p, /* FTS3 table handle */
141119 Fts3Table *p, /* FTS3 table handle */
141242 ** table, and modifying existing entries in both the %_segments and %_segdir
141249 Fts3Table *p, /* FTS3 table handle */
141334 Fts3Table *p, /* FTS table handle */
141401 ** exists, is stored in the rowid==1 row of the %_stat table.
141404 ** table and return SQLITE_OK. Otherwise, if an error occurs, return an
141498 Blob hint = {0, 0, 0}; /* Hint read from %_stat table */
141515 /* Search the %_segdir table for the absolute level with the smallest
141531 /* If the hint read from the %_stat table is not empty, check if the
141555 ** nMin segments and no hint in the %_stat table. No work to do.
141626 /* Write the hint values into the %_stat table for the next incr-merger */
141652 ** INSERT INTO table(table) VALUES('merge=A,B');
141659 Fts3Table *p, /* FTS3 table handle */
141696 ** INSERT INTO table(table) VALUES('automerge=X');
141702 Fts3Table *p, /* FTS3 table handle */
141760 Fts3Table *p, /* FTS3 table handle */
141826 ** content table. If no error occurs and the contents do match, set *pbOk
141855 /* This block calculates the checksum according to the %_content table */
141942 ** 2. By scanning and tokenizing the content table.
141948 Fts3Table *p /* FTS3 table handle */
142034 ** table, not for all rows.
142039 int i; /* Used to iterate through table columns */
142120 Fts3Cursor *pCsr, /* Fts3 table cursor */
142144 ** present in the FTS3 table. If it is, delete it and adjust the contents
142154 int bFound = 0; /* True if *pRowid really is in the table */
142158 int isEmpty = 0; /* Deleting *pRowid leaves the table empty */
142162 /* Deleting this row means the whole table is empty. In this case
142164 ** data in the pendingTerms hash table. */
142185 ** tables. The schema of the virtual table being:
142187 ** CREATE TABLE <table name>(
142189 ** <table name> HIDDEN,
142210 /* At this point it must be known if the %_stat table exists or not.
142276 ** the %_content table. If we hit the duplicate rowid constraint (or any
142338 ** Flush any data in the pending-terms hash table to disk. If successful,
142449 int nCol; /* Number of columns in table */
142899 Fts3Table *pTab, /* FTS3 table snippet comes from */
143119 ** rows of the table. Y is the number of rows for which column iCol contains
143416 sqlite3_int64 nDoc; /* Number of rows in table */
143605 /* Loop through all columns of the table being considered for snippets.
143607 ** columns of the FTS3 table. Otherwise, only column iCol is considered.
143665 int iCol; /* Column of table to populate aTerm for */
143736 /* Loop through the table columns, appending offset information to
143843 Fts3Cursor *pCsr, /* FTS3 table cursor */
143997 ** As part of a tokenchars= or separators= option, the CREATE VIRTUAL TABLE
143998 ** statement has specified that the tokenizer for this table shall consider
144660 ** algorithms packaged as an SQLite virtual table module.
144667 ** The data structure for a single virtual r-tree table is stored in three
144669 ** in the table name is replaced with the user-supplied name of the r-tree
144670 ** table.
144672 ** CREATE TABLE %_node(nodeno INTEGER PRIMARY KEY, data BLOB)
144673 ** CREATE TABLE %_parent(nodeno INTEGER PRIMARY KEY, parentnode INTEGER)
144674 ** CREATE TABLE %_rowid(rowid INTEGER PRIMARY KEY, nodeno INTEGER)
144677 ** table. For each node that is not the root node of the r-tree, there is
144678 ** an entry in the %_parent table associating the node with its parent.
144679 ** And for each row of data in the table, there is an entry in the %_rowid
144680 ** table that maps from the entries rowid to the id of the node that it
144683 ** The root node of an r-tree always exists, even if the r-tree table is
144685 ** table must be the same size as the root node. The content of each node
144740 /* Size of hash table Rtree.aHash. This hash table is not expected to
144746 /* The xBestIndex method of this virtual table requires an estimate of
144747 ** the number of rows in the virtual table to calculate the costs of
144749 ** sqlite_stat1 table (with RTREE_MIN_ROWEST as a hard-coded minimum).
144757 ** An rtree virtual-table object.
144762 int iNodeSize; /* Size in bytes of each node in the node table */
144767 char *zDb; /* Name of database containing r-tree table */
144768 char *zName; /* Name of r-tree table */
144770 i64 nRowEst; /* Estimated number of rows in this table */
144795 RtreeNode *aHash[HASHSIZE]; /* Hash table of in-memory nodes. */
144803 ** If SQLITE_RTREE_INT_ONLY is defined, then this virtual table will
145090 ** in the Rtree.aHash table.
145097 ** Search the node hash table for node iNode. If found, return a pointer
145107 ** Add node pNode to the node hash table.
145118 ** Remove node pNode from the node hash table.
145163 /* Check if the requested node is already in the hash table. If so,
145396 ** the virtual table module xCreate() and xConnect() methods.
145403 ** Rtree virtual table module xCreate method.
145416 ** Rtree virtual table module xConnect method.
145456 ** Rtree virtual table module xDisconnect method.
145464 ** Rtree virtual table module xDestroy method.
145470 "DROP TABLE '%q'.'%q_node';"
145471 "DROP TABLE '%q'.'%q_rowid';"
145472 "DROP TABLE '%q'.'%q_parent';",
145491 ** Rtree virtual table module xOpen method.
145528 ** Rtree virtual table module xClose method.
145542 ** Rtree virtual table module xEof method.
146030 ** Rtree virtual table module xNext method.
146044 ** Rtree virtual table module xRowid method.
146058 ** Rtree virtual table module xColumn method.
146091 ** return SQLITE_OK. If there is no such record in the table, set
146165 ** Rtree virtual table module xFilter method.
146282 ** Rtree virtual table module xBestIndex method. There are three
146283 ** table scan strategies to choose from (in order from most to
146289 ** 2 See below R-tree query or full-table scan.
146491 Rtree *pRtree, /* Rtree table */
146551 Rtree *pRtree, /* Rtree table */
146577 ** Write mapping (iRowid->iNode) to the <rtree>_rowid table.
146587 ** Write mapping (iNode->iPar) to the <rtree>_parent table.
147074 /* Remove the node from the in-memory hash table and link it into
147356 /* Delete the corresponding entry in the <rtree>_rowid table. */
147454 /* Constraint handling. A write operation on an r-tree table may return
147494 ** the table. If so, the constraint has failed. */
147518 ** record to delete from the r-tree table. The following block does
147565 "ALTER TABLE %Q.'%q_node' RENAME TO \"%w_node\";"
147566 "ALTER TABLE %Q.'%q_parent' RENAME TO \"%w_parent\";"
147567 "ALTER TABLE %Q.'%q_rowid' RENAME TO \"%w_rowid\";"
147581 ** of the number of rows in the virtual table. If possible, this is based
147618 rtreeCreate, /* xCreate - create a table */
147619 rtreeConnect, /* xConnect - connect to an existing table */
147621 rtreeDisconnect, /* xDisconnect - Disconnect from a table */
147622 rtreeDestroy, /* xDestroy - Drop a table */
147636 rtreeRename, /* xRename - rename the table */
147653 /* Read and write the xxx_node table */
147658 /* Read and write the xxx_rowid table */
147663 /* Read and write the xxx_parent table */
147675 "CREATE TABLE \"%w\".\"%w_node\"(nodeno INTEGER PRIMARY KEY, data BLOB);"
147676 "CREATE TABLE \"%w\".\"%w_rowid\"(rowid INTEGER PRIMARY KEY, nodeno INTEGER);"
147677 "CREATE TABLE \"%w\".\"%w_parent\"(nodeno INTEGER PRIMARY KEY,"
147740 ** determine the node-size used by the rtree table being created or connected
147745 ** table already exists. In this case the node-size is determined by inspecting
147790 ** methods of the r-tree virtual table.
147794 ** argv[2] -> table name
147800 int argc, const char *const*argv, /* Parameters to CREATE TABLE statement */
147801 sqlite3_vtab **ppVtab, /* OUT: New virtual table */
147813 "Wrong number of columns for an rtree table", /* 1 */
147814 "Too few columns for an rtree table", /* 2 */
147815 "Too many columns for an rtree table" /* 3 */
147849 ** the r-tree table schema.
147855 char *zSql = sqlite3_mprintf("CREATE TABLE x(%s", argv[3]);
147972 ** virtual table module "rtree" and the debugging/analysis scalar