Home | History | Annotate | Download | only in dist

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 */
37555 ** But sometimes (for example when during a DROP of a large table) most
37593 /* Number of u32 values in hash table. */
37595 /* Maximum number of entries in hash table before
37618 ** a hash table that will hold up to BITVEC_MXHASH distinct values.
37639 u32 aHash[BITVEC_NINT]; /* Hash table representation */
37769 ** that BitvecClear can use to rebuilt its hash table.
38664 /* Hash table of all pages. The following variables may only be accessed
38670 PgHdr1 **apHash; /* Hash table for fast lookup by key */
38683 PgHdr1 *pNext; /* Next in hash table chain */
38964 ** This function is used to resize the hash table used by the cache passed
39041 ** Remove the page supplied as an argument from the hash table
39313 /* Step 1: Search the hash table for an existing entry. */
41947 ** Find a page in the hash table given its page number. Return
42914 ** in this case. But for things like temporary table (which will be
47664 ** database page number associated with each wal frame, and a hash-table
47679 ** Even without using the hash table, the last frame for page P
47686 ** The hash table consists of HASHTABLE_NSLOT 16-bit unsigned integers.
47688 ** hash table for each page number in the mapping section, so the hash
47689 ** table is never more than half full. The expected number of collisions
47690 ** prior to finding a match is 1. Each entry of the hash table is an
47695 ** K will be (mxFrame%HASHTABLE_NPAGE).) Unused slots of the hash table
47698 ** To look for page P in the hash table, first compute a hash iKey on
47703 ** Then start scanning entries of the hash table, starting with iKey
47704 ** (wrapping around to the beginning when the end of the hash table is
47707 ** wrap-around.) Because the hash table is never more than half full,
47731 ** Both readers can use the same hash table and mapping section to get
47732 ** the correct result. There may be entries in the hash table with
47734 ** slots in the hash table and so the first reader will get an answer as
47735 ** if no values greater than K0 had ever been inserted into the hash table
47740 ** When a rollback occurs, the value of K is decreased. Hash table entries
47742 ** from the hash table at this point.
47953 ** Each page of the wal-index mapping contains a hash-table made up of
47987 ** is a hash-table following every HASHTABLE_NPAGE page numbers in the
47998 ** The block of page numbers associated with the first hash-table in a
48000 ** hash-table on each aligned 32KB page of the wal-index.
48324 ** Return pointers to the hash table and page number array stored on
48328 ** Set output variable *paHash to point to the start of the hash table
48330 ** number of the first frame indexed by this hash table. If a
48331 ** slot in the hash table is set to N, it refers to frame number
48335 ** first frame indexed by the hash table, frame (*piZero+1).
48339 int iHash, /* Find the iHash'th table */
48370 ** Return the number of the wal-index page that contains the hash-table
48398 ** Remove entries from the hash table that point to WAL slots greater
48404 ** At most only the hash table containing pWal->hdr.mxFrame needs to be
48410 volatile ht_slot *aHash = 0; /* Pointer to hash table to clear */
48411 volatile u32 *aPgno = 0; /* Page number array for hash table */
48424 /* Obtain pointers to the hash-table and page-number array containing
48426 ** that the page said hash-table and array reside on is already mapped.
48432 /* Zero all hash-table entries that correspond to frame numbers greater
48451 ** via the hash table even after the cleanup.
48475 volatile ht_slot *aHash = 0; /* Hash table */
48480 ** page number array and hash table entry.
48483 int iKey; /* Hash table key */
48484 int idx; /* Value to write to hash-table slot */
48490 /* If this is the first entry to be added to this hash-table, zero the
48491 ** entire hash table and aPgno[] array before proceding.
48502 ** the hash-table before writing any new entries.
48509 /* Write the aPgno[] array entry and the hash-table slot. */
48518 /* Verify that the number of entries in the hash table exactly equals
48523 int nEntry = 0; /* Number of entries in the hash table */
48529 ** via the hash table. This turns out to be a really, really expensive
49822 /* Search the hash table or tables for an entry matching page number
49824 ** hash table (each hash table indexes up to HASHTABLE_NPAGE frames).
49828 ** table). This means the value just read from the hash
49838 ** if we had exclusive access to the hash-table:
49841 ** This condition filters out normal hash-table collisions.
49845 ** table after the current read-transaction had started.
49848 volatile ht_slot *aHash; /* Pointer to hash table */
50924 ** is opened on the table with root page BtShared.iTable. Locks are removed
50930 Pgno iTable; /* Root page of table */
51006 ** table (because there exists one or more read-locks on the table),
51037 u16 maxLeaf; /* Maximum local payload in a LEAFDATA table */
51038 u16 minLeaf; /* Minimum local payload in a LEAFDATA table */
51143 ** because the table is empty or because BtreeCursorFirst() has not been
51155 ** The table that this cursor was opened on still exists, but has been
51199 ** The pointer map is a lookup table that identifies the parent page for
51446 ** a statement since we will be comparing table and column names
51661 ** shared-cache table level locks. If the library is compiled with the
51681 ** table with root page iRoot. Return 1 if it does and 0 if not.
51683 ** For example, when writing to a table with root-page iRoot via
51690 ** the corresponding table. This makes things a bit more complicated,
51691 ** as this module treats each table as a separate structure. To determine
51692 ** the table corresponding to the index being written, this
51695 ** Instead of a lock on the table/index rooted at page iRoot, the caller may
51696 ** hold a write-lock on the schema table (root page 1). This is also
51728 /* Figure out the root-page that the lock should be held on. For table
51731 ** table. */
51745 ** write-lock on the schema table, or (if the client is reading) a
51766 ** table or index rooted at iRoot because other shared connections are
51767 ** simultaneously reading that same table or index.
51771 ** the iRoot table. Except, if the other Btree object has the
51775 ** For example, before writing to any part of the table or index
51796 ** (READ_LOCK or WRITE_LOCK) on the table with root-page iTab. Return
51836 ** may hold a WRITE_LOCK on any table in this file (since there can
51856 ** Add a lock on the table with root-page iTable to the shared-btree used
51884 ** table, and that lock is obtained in BtreeBeginTrans(). */
51892 /* First search the list for an existing lock on this table. */
51901 ** with table iTable, allocate one and link it into the list.
51929 ** Release all the table locks (locks obtained via calls to
52028 ** This function is called before modifying the contents of a table
52033 ** table is about to be deleted. In this case invalidate all incrblob
52034 ** cursors open on any row within the table with root-page pgnoRoot.
52161 /* If this is an intKey table, then the above call to BtreeKeySize()
52164 ** table, then malloc space for and store the pCur->nKey bytes of key
52193 ** the table with root-page iRoot. Usually, this is called just before cursor
52194 ** pExcept is used to modify the table (BtreeDelete() or BtreeInsert()).
53667 ** The call to sqlite3BtreeRollback() drops any table-locks held by
55141 ** cursors open with wrFlag==0 on the same table. Otherwise
55158 int iTable, /* Root page of table to open */
55169 ** b-tree database, the connection is holding the required table locks,
55207 int iTable, /* Root page of table to open */
55325 ** that is currently pointing to a row in a (non-empty) table.
55338 ** For a table with the INTKEY flag set, this routine returns the key
55507 ** invalidated if some other cursor writes to the same table, or if
55513 ** * Creating a table (may require moving an overflow page).
55708 ** in the table.
55755 ** table btrees (pPage->intKey==1). The number of bytes of available
55901 ** If the table has a virtual root page, then the cursor is moved to point
55902 ** to the virtual root page instead of the actual root page. A table has a
55904 ** single child page. This can only happen with the table rooted at page 1.
55915 ** indicating a table b-tree, or if the caller did specify a KeyInfo
55954 ** NULL, the caller expects a table b-tree. If this is not the case,
55960 ** in such a way that page pRoot is linked into a second b-tree table
56037 /* Move the cursor to the first entry in the table. Return SQLITE_OK
56039 ** or set *pRes to 1 if the table is empty.
56060 /* Move the cursor to the last entry in the table. Return SQLITE_OK
56062 ** or set *pRes to 1 if the table is empty.
56123 ** is smaller than intKey/pIdxKey or if the table is empty
56136 i64 intKey, /* The table key */
56197 ** be the right kind (index or table) of b-tree page. Otherwise
56334 ** Return TRUE if the cursor is not pointing at an entry of the table.
56337 ** past the last entry in the table or sqlite3BtreePrev() moves past
56338 ** the first entry. TRUE is also returned if the table is empty.
56341 /* TODO: What if the cursor is in CURSOR_REQUIRESEEK but all table entries
58036 ** of the table is a linear scan through the file. That
58496 ** define what table the record should be inserted into. The cursor
58499 ** For an INTKEY table, only the nKey value of the key is used. pKey is
58500 ** ignored. For a ZERODATA table, the pData and nData are both ignored.
58516 BtCursor *pCur, /* Insert data into the table of this cursor */
58546 ** intkey table, the caller should be inserting integer keys with a
58550 /* Save the positions of any other cursors open on this table.
58553 ** example, when inserting data into a table with auto-generated integer
58565 /* If this is an insert into a table b-tree, invalidate any incrblob
58587 TRACE(("INSERT: table=%d nkey=%lld ndata=%d page=%d %s\n",
58639 ** entry in the table, and the next row inserted has an integer key
58705 /* Save the positions of any other cursors open on this table before
58713 /* If this is a delete operation to remove a row from a table b-tree,
58779 ** Create a new BTree table. Write into *piTable the page
58780 ** number for the root page of the new table.
58794 int ptfFlags; /* Page-type flage for the root page of new table */
58810 /* Creating a new table
58818 ** root page of the new table should go. meta[3] is the largest root-page
58844 ** the new table (assuming an error did not occur). But we were
58944 BtShared *pBt, /* The BTree that contains the table */
58991 ** Delete all information from a single table in the database. iTable is
58992 ** the page number of the root of the table. After this routine returns,
58996 ** read cursors on the table. Open write cursors are moved to the
58997 ** root of the table.
58999 ** If pnChange is not NULL, then table iTable must be an intkey table. The
59001 ** entries in the table.
59012 /* Invalidate all incrblob cursors open on table iTable (assuming iTable
59013 ** is the root of a table b-tree - if it is not, the following call is
59023 ** Delete all information from the single table that pCur is open on.
59025 ** This routine only work for pCur on an ephemeral table.
59032 ** Erase all information in a table and add the root of the table to
59033 ** the freelist. Except, the root of the principle table (the one on
59037 ** cursors on the table.
59059 /* It is illegal to drop a table if any cursors are open on the
59092 /* If the table being dropped is the table with the largest root-page
59101 /* The table being dropped does not have the largest root-page
59716 ** a table. nRoot is the number of entries in aRoot.
59937 ** sqlite_master table. Otherwise SQLITE_OK.
59952 ** Obtain a lock on the table whose root page is iTab. The
59978 ** INTKEY table currently pointing at a valid table entry.
60001 /* Save the positions of all other cursors open on this table. This is
60005 ** Note that pCsr must be open on a BTREE_INTKEY table and saveCursorPosition()
60006 ** and hence saveAllCursors() cannot fail on a BTREE_INTKEY table, hence
60015 ** (c) the connection holds a write-lock on the table (if required),
60017 ** (e) the cursor points at a valid row of an intKey table.
61945 ** sqlite_stat3 table to the record format SQLite uses internally.
62059 ** in the sqlite_stat4 table.
63484 ** to 6.6 percent. The test case is inserting 1000 rows into a table
65007 ** the blob of data that it corresponds to. In a table record, all serial
65012 ** The following table describes the various storage classes for data:
65382 ** This function compares two index or table record keys in the same way
65642 ** This function compares the two table rows or index records
67151 ** 3 The name of the table that the column derives from
67152 ** 4 The name of the table column that the result column derives from
67246 ** Return the name of the table from which a result column derives.
67262 ** Return the name of the table column from which a result column derives.
68099 int nField, /* Number of fields in the table or index */
68101 int isBtreeCursor /* True for B-Tree. False for pseudo-table or vtab */
69606 ** with a CREATE TABLE statement.)
70321 ** If the OPFLAG_CLEARCACHE bit is set on P5 and P1 is a pseudo-table cursor,
70323 ** The first OP_Column against a pseudo-table after the value of the content
70362 assert( pC->pVtabCursor==0 ); /* OP_Column never called on virtual table */
70612 ** use as a data record in a database table or as a key
70763 ** Store the number of entries (an integer value) in the table or index
71123 ** are queried from within xNext() and other v-table methods using
71126 ** v-table would have to be ready for the sqlite3_vtab structure itself
71128 ** a v-table method.
71212 ** Open a read-only cursor for the database table whose root page is
71236 ** value, it is set to the number of columns in the table.
71257 ** Open a read/write cursor named P1 on the table or index whose root
71265 ** value, it is set to the number of columns in the table, or to the
71266 ** largest index of any column of the table that is actually used.
71269 ** in read/write mode. For a given table, there can be one or more read-only
71354 testcase( nField==0 ); /* Table with INTEGER PRIMARY KEY and nothing else */
71380 ** Open a new cursor P1 to a transient table.
71383 ** table is deleted automatically when the cursor is closed.
71385 ** P2 is the number of columns in the ephemeral table.
71386 ** The cursor points to a BTree table if P4==0 and to a BTree index
71428 ** opening it. If a transient table is required, just use the
71429 ** automatically created table with root-page 1 (an BLOB_INTKEY table).
71475 ** Open a new cursor that points to a fake table that contains a single
71480 ** A pseudo-table created by this opcode is used to hold a single
71483 ** is the only cursor opcode that works with a pseudo-table.
71486 ** the pseudo-table.
71517 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
71535 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
71553 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
71571 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
71715 /* res might be negative because the table is empty. Check to
71732 ** P1 is an open table cursor and P2 is a rowid integer. Arrange
71900 ** P1 is the index of a cursor open on an SQL table btree (with integer
71969 ** Get a new integer record number (a.k.a "rowid") used as the key to a table.
71971 ** table that cursor P1 points to. The new record number is written
71983 VdbeCursor *pC; /* Cursor of table to get the new rowid */
72006 ** it already exists in the table. If it does not exist, we have
72077 ** an AUTOINCREMENT table. */
72114 ** Write an entry into the table of cursor P1. A new entry is
72138 ** Parameter P4 may point to a string containing the table-name, or
72162 VdbeCursor *pC; /* Cursor to table into which insert is written */
72166 const char *zTbl; /* Table name - used by the opdate hook */
72229 ** record in the table. If it is left pointing at the next record, then
72236 ** P1 must not be pseudo-table. It has to be a real table with
72239 ** If P4 is not NULL, then it is the name of the table that P1 is
72255 ** OP_Column on the same table without any intervening operations that
72348 ** of a real table, not a pseudo-table.
72359 ** of a real table, not a pseudo-table.
72427 ** Store in register P2 an integer which is the key of the table entry that
72430 ** P1 can be either an ordinary table or a virtual table. There used to
72432 ** one opcode now works for both table types.
72496 ** will refer to the last entry in the database table or index.
72497 ** If the table or index is empty and P2>0, then jump immediately to P2.
72498 ** If P2 is 0 or if the table or index is not empty, fall through
72556 ** will refer to the first entry in the database table or index.
72557 ** If the table or index is empty and P2>0, then jump immediately to P2.
72558 ** If P2 is 0 or if the table or index is not empty, fall through
72600 ** table or index. If there are no more key/value pairs then fall through
72608 ** The P1 cursor must be for a real table, not a pseudo-table. P1 must have
72632 ** table or index. If there is no previous key/value pairs then fall through
72641 ** The P1 cursor must be for a real table, not a pseudo-table. If P1 is
72813 ** the rowid of the table entry to which this index entry points.
72936 ** Delete an entire database table or index whose root page in the database
72939 ** The table being destroyed is in the main database file if P3==0. If
72940 ** P3==1 then the table to be clear is in the auxiliary database file
72941 ** that is used to store tables create using CREATE TEMPORARY TABLE.
72948 ** movement was required (because the table being dropped was already
72999 ** Delete all contents of the database table or index whose root page
73001 ** remove the table or index from the database file.
73003 ** The table being clear is in the main database file if P2==0. If
73004 ** P2==1 then the table to be clear is in the auxiliary database file
73005 ** that is used to store tables create using CREATE TEMPORARY TABLE.
73007 ** If the P3 value is non-zero, then the table referred to must be an
73008 ** intkey table (an SQL table, not an index). In this case the row change
73009 ** count is incremented by the number of rows in the table being cleared.
73011 ** also incremented by the number of rows in the table being cleared.
73037 ** Delete all contents from the ephemeral table or sorter
73061 ** Allocate a new table in the main database file if P1==0 or in the
73063 ** P1>1. Write the root page number of the new table into
73066 ** The difference between a table and an index is this: A table must
73077 ** P1>1. Write the root page number of the new table into
73107 ** Read and parse all entries from the SQLITE_MASTER table of database P1
73163 ** Read the sqlite_stat1 table for database P1 and load the content
73164 ** of that table into the internal index hash table. This will cause
73177 ** the table named P4 in database P1. This is called after a table
73950 ** Obtain a lock on a particular table. This instruction is only used when
73957 ** P2 contains the root-page of the table to lock.
73959 ** P4 contains a pointer to the name of the table being locked. This is only
73972 sqlite3SetString(&p->zErrMsg, db, "database table is locked: %s", z);
73983 ** xBegin method for that table.
73986 ** within a callback to a virtual table xSync() method. If it is, the error
74001 ** P4 is the name of a virtual table in database P1. Call the xCreate method
74002 ** for that table.
74013 ** P4 is the name of a virtual table in database P1. Call the xDestroy method
74014 ** of that table.
74027 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
74029 ** table and stores that cursor in P1.
74073 ** This opcode invokes the xFilter method on the virtual table specified
74141 ** the row of the virtual-table that the
74197 ** Advance virtual table P1 to the next row in its result set and
74198 ** jump to instruction P2. Or, if the virtual table has reached
74221 ** some other method is next invoked on the save virtual table cursor.
74242 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
74274 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
74284 ** row. This can be NULL to have the virtual table select the new
74581 int iCol; /* Table column this handle is open on */
74662 const char *zTable, /* The table containing the blob */
74672 ** db/table/row entry. The reason for using a vdbe program instead
74704 Table *pTab;
74728 sqlite3ErrorMsg(pParse, "cannot open virtual table: %s", zTable);
74732 sqlite3ErrorMsg(pParse, "cannot open table without rowid: %s", zTable);
74819 /* Make sure a mutex is held on the table to be accessed */
74839 ** think that the table has one more column than it really
74980 ** database table.
76294 ** Table of methods for JournalFile sqlite3_file object.
76582 ** Table of methods for MemJournal sqlite3_file object.
76803 ** table and column.
76943 ** Subqueries stores the original database, table and column names for their
76944 ** result sets in ExprList.a[].zSpan, in the form "DATABASE.TABLE.COLUMN".
76980 ** pExpr->iTable Set to the cursor number for the table obtained
76982 ** pExpr->pTab Points to the Table structure of X.Y (even if
76984 ** pExpr->iColumn Set to the column number within the table.
76991 ** can be used. The zTable variable is the name of the table (the "Y"). This
76993 ** means that the form of the name is Z and that columns from any table
77001 const char *zDb, /* Name of the database containing table, or NULL */
77002 const char *zTab, /* Name of table containing column, or NULL */
77009 int cntTab = 0; /* Number of matching table names */
77017 Table *pTab = 0; /* Table hold the row */
77092 ** is for the right-hand table of a NATURAL JOIN or is in a
77184 ** SELECT a+b AS x FROM table WHERE x<10;
77265 /* If a column from a table in pSrcList is referenced, then record
77435 /* A table name and column name: ID.ID
77436 ** Or a database, table and column: ID.ID.ID
78090 ** table columns and result-set columns. At the same time, do error
78094 ** To resolve table columns references we look for nodes (or subtrees) of the
78100 ** Y: The name of a table in a FROM clause. Or in a trigger
78103 ** Z: The name of a column in table Y.
78108 ** Expr.pTab Points to the Table object for X.Y
78117 ** Table-name and function resolution occurs on the substituted expression
78205 ** Resolve names in expressions that can only reference a single table:
78217 Table *pTab, /* The table being referenced */
78274 ** CREATE TABLE t1(a);
79245 Table *pTab;
79691 Table *pTab;
79710 if( IsVirtual(pTab) ) return 0; /* FROM clause not a virtual table */
79728 ** Generate code that checks the left-most column of index table iCur to see if
79775 ** IN_INDEX_ROWID - The cursor was opened on a database table.
79779 ** populated epheremal table.
79786 ** SELECT <column> FROM <table>
79789 ** an ephemeral table might need to be generated from the RHS and then
79790 ** pX->iTable made to point to the ephermeral table instead of an
79791 ** existing table.
79795 ** IN_INDEX_MEMBERSHIP, then the generated table will be used for a
79802 ** An epheremal table must be used unless the selected <column> is guaranteed
79807 ** for fast set membership tests) then an epheremal table must
79834 int eType = 0; /* Type of RHS table. IN_INDEX_* */
79835 int iTab = pParse->nTab++; /* Cursor of the RHS table */
79842 /* Check to see if an existing table or index can be used to
79844 ** ephemeral table.
79849 Table *pTab; /* Table <table>. */
79862 /* Code an OP_Transaction and OP_TableLock for <table>. */
79884 ** be used in place of a temp-table, it must be ordered according
79920 ** then it is not worth creating an ephermeral table to evaluate
79933 /* Could not find an existing table or index to use as the RHS b-tree.
79934 ** We will have to generate an ephemeral table to do the job.
79970 ** to some integer key column of a table B-Tree. In this case, use an
80030 ** expression it is handled the same way. An ephemeral table is
80050 ** table allocated and opened above.
80079 ** store it in the temporary table. If <expr> is a column, then use
80114 /* Evaluate the expression and insert it into the temp table */
80224 /* Compute the RHS. After this step, the table with cursor
80307 /* In this case, the RHS is the ROWID of table b-tree
80452 ** particular table is stored in a particular register.
80585 ** Generate code to extract the value of the iCol-th column of a table.
80589 Table *pTab, /* The table containing the value */
80590 int iTabCur, /* The table cursor. Or the PK cursor for WITHOUT ROWID */
80611 ** table pTab and store the column value in a register. An effort
80620 Table *pTab, /* Description of the table we are reading from */
80621 int iColumn, /* Index of the table column */
80622 int iTable, /* The cursor pointing to the table */
81092 ** a virtual table column.
81096 ** see if it is a column in a virtual table. This is done because
81189 ** new.* pseudo-table, or 0 for the old.* pseudo-table. Expr.iColumn
81190 ** is set to the column of the pseudo-table to read, or to -1 to
81195 ** to reference another column of the old.* pseudo-table, where
81197 ** set to (n+1), where n is the number of columns in each pseudo-table.
81198 ** For a reference to any other column in the new.* pseudo-table, p1
81200 ** example, if the table on which triggers are being fired is
81203 ** CREATE TABLE t1(a, b);
81211 Table *pTab = pExpr->pTab;
81677 ** new.* pseudo-table, or 0 for the old.* pseudo-table. Expr.iColumn
81678 ** is set to the column of the pseudo-table to read, or to -1 to
82250 ** Expr.iTable<0 then assume a table number given by iTab.
82277 ** to count references to table columns in the arguments of an
82389 /* If we reach this point, it means that pExpr refers to a table
82614 ** that implements the ALTER TABLE command.
82619 ** ALTER TABLE logic from the build.
82626 ** ALTER TABLE command. The first argument is the text of a CREATE TABLE or
82627 ** CREATE INDEX command. The second is a table name. The table name in
82628 ** the CREATE TABLE or CREATE INDEX statement is replaced with the third
82631 ** sqlite_rename_table('CREATE TABLE abc(a, b, c)', 'def')
82632 ** -> 'CREATE TABLE def(a, b, c)'
82655 /* The principle used to locate the table name in the CREATE TABLE
82656 ** statement is that the table name is the first non-space token that
82688 ** generated by the ALTER TABLE ... RENAME command to modify the definition
82689 ** of any foreign key constraints that use the table being renamed as the
82690 ** parent table. It is passed three arguments:
82692 ** 1) The complete text of the CREATE TABLE statement being modified,
82693 ** 2) The old name of the table being renamed, and
82694 ** 3) The new name of the table being renamed.
82696 ** It returns the new CREATE TABLE statement. For example:
82698 ** sqlite_rename_parent('CREATE TABLE t1(a REFERENCES t2)', 't2', 't3')
82699 ** -> 'CREATE TABLE t1(a REFERENCES t3)'
82752 ** ALTER TABLE command. The first argument is the text of a CREATE TRIGGER
82753 ** statement. The second is a table name. The table name in the CREATE
82756 ** TRIGGER, not CREATE INDEX and CREATE TABLE.
82776 /* The principle used to locate the table name in the CREATE TRIGGER
82777 ** statement is that the table name is the first token that is immediatedly
82785 /* Ran out of input before finding the table name. Return NULL. */
82807 ** Note that ON cannot be a database, table or column name, so
82817 /* Variable tname now contains the token that is the old table-name
82828 ** Register built-in functions used to help implement ALTER TABLE
82879 ** tables that have foreign key constraints that refer to table pTab (i.e.
82880 ** constraints for which pTab is the parent table) from the sqlite_master
82881 ** table.
82883 static char *whereForeignKeys(Parse *pParse, Table *pTab){
82895 ** temporary triggers on table pTab from the sqlite_temp_master table. If
82896 ** table pTab has no temporary triggers, or is itself stored in the
82899 static char *whereTempTriggers(Parse *pParse, Table *pTab){
82904 /* If the table is not located in the temp-db (in which case NULL is
82926 ** Generate code to drop and reload the internal representation of table
82928 ** Argument zName is the name of the table in the database schema at
82931 ** "ALTER TABLE RENAME TO" statement.
82933 static void reloadTableSchema(Parse *pParse, Table *pTab, const char *zName){
82948 /* Drop any table triggers from the internal schema. */
82956 /* Drop the table and index from the internal schema. */
82959 /* Reload the table, index and permanent trigger schemas. */
82965 /* Now, if the table is not stored in the temp database, reload any temp
82975 ** Parameter zName is the name of a table that is about to be altered
82976 ** (either with ALTER TABLE ... RENAME TO or ALTER TABLE ... ADD COLUMN).
82977 ** If the table is a system table, this function leaves an error message
82980 ** Or, if zName is not a system table, zero is returned.
82984 sqlite3ErrorMsg(pParse, "table %s may not be altered", zName);
82991 ** Generate code to implement the "ALTER TABLE xxx RENAME TO yyy"
82996 SrcList *pSrc, /* The table to rename. */
82997 Token *pName /* The new table name. */
82999 int iDb; /* Database that contains the table */
83001 Table *pTab; /* Table being renamed */
83005 const char *zTabName; /* Original name of the table */
83024 /* Get a NULL terminated version of the new table name. */
83028 /* Check that a table or index named 'zName' does not already exist
83033 "there is already another table or index with this name: %s", zName);
83037 /* Make sure it is not a system table being altered, or a reserved name
83038 ** that the table is being renamed to.
83074 ** Then modify the schema cookie (since the ALTER TABLE modifies the
83075 ** schema). Open a statement transaction if the table is a virtual
83076 ** table.
83085 /* If this is a virtual table, invoke the xRename() function if
83087 ** of any resources used by the v-table implementation (including other
83088 ** SQLite tables) that are identified by the name of the virtual table.
83105 /* If foreign-key support is enabled, rewrite the CREATE TABLE
83107 ** for which the renamed table is the parent table. */
83118 /* Modify the sqlite_master table to use the new table name. */
83130 "WHEN type='table' THEN %Q "
83135 "(type='table' OR type='index' OR type='trigger');",
83144 /* If the sqlite_sequence table exists in this database, then update
83145 ** it with the new table name.
83155 /* If there are TEMP triggers on this table, modify the sqlite_temp_master
83156 ** table. Don't do this if the table being ALTERed is itself located in
83173 Table *pFrom = p->pFrom;
83181 /* Drop and reload the internal table schema. */
83218 ** This function is called after an "ALTER TABLE ... ADD" statement
83222 ** The Table structure pParse->pNewTable was extended to include
83226 Table *pNew; /* Copy of pParse->pNewTable */
83227 Table *pTab; /* Table being altered */
83230 const char *zTab; /* Table name */
83304 /* Modify the CREATE TABLE statement. */
83316 "WHERE type = 'table' AND name = %Q",
83330 /* Reload the schema of the modified table. */
83335 ** This function is called by the parser after the table-name in
83336 ** an "ALTER TABLE <table-name> ADD" statement is parsed. Argument
83337 ** pSrc is the full-name of the table being altered.
83339 ** This routine makes a (partial) copy of the Table structure
83340 ** for the table being altered and sets Parse.pNewTable to point
83343 ** the copy. The copy of the Table structure is deleted by tokenize.c
83347 ** coding the "ALTER TABLE ... ADD" statement.
83350 Table *pNew;
83351 Table *pTab;
83358 /* Look up the table being altered. */
83384 /* Put a copy of the Table struct in Parse.pNewTable for the
83388 ** table because user table are not allowed to have the "sqlite_"
83391 pNew = (Table*)sqlite3DbMallocZero(db, sizeof(Table));
83451 ** CREATE TABLE sqlite_stat1(tbl, idx, stat);
83452 ** CREATE TABLE sqlite_stat2(tbl, idx, sampleno, sample);
83453 ** CREATE TABLE sqlite_stat3(tbl, idx, nEq, nLt, nDLt, sample);
83454 ** CREATE TABLE sqlite_stat4(tbl, idx, nEq, nLt, nDLt, sample);
83457 ** The sqlite_stat2 table is not created or used unless the SQLite version
83459 ** with SQLITE_ENABLE_STAT2. The sqlite_stat2 table is deprecated.
83460 ** The sqlite_stat2 table is superseded by sqlite_stat3, which is only
83475 ** name in the idx column. The tbl column is the name of the table to
83479 ** number of rows in the table, except for partial indices.) The second
83496 ** rows in the table identified by sqlite_stat1.tbl.
83502 ** 3.6.18 and 3.7.8. The "stat2" table contains additional information
83504 ** the "idx" column and the "tbl" column is the name of the table to which
83506 ** table for each index.
83521 ** writes the sqlite_stat2 table. This version of SQLite only supports
83532 ** As with sqlite_stat2, the sqlite_stat4 table contains histogram data
83537 ** The sqlite_stat4 table contains multiple entries for each index.
83538 ** The idx column names the index and the tbl column is the table of the
83565 ** The sqlite_stat3 table is like sqlite_stat4 except that it only
83591 ** The sqlite_stat1 table is always relevant. sqlite_stat2 is now
83597 ** Argument zWhere may be a pointer to a buffer containing a table name,
83599 ** the sqlite_statN tables associated with the named table are deleted.
83600 ** If zWhere==0, then code is generated to delete all stat table entries.
83605 table on this cursor */
83606 const char *zWhere, /* Delete entries for this table or index */
83642 Table *pStat;
83645 /* The sqlite_statN table does not exist. Create it. Note that a
83646 ** side-effect of the CREATE TABLE statement is to leave the rootpage
83647 ** of the new table in register pParse->regRoot. This is important
83650 "CREATE TABLE %Q.%s(%s)", pDb->zName, zTab, aTable[i].zCols
83656 /* The table already exists. If zWhere is not NULL, delete all entries
83657 ** associated with the table zWhere. If zWhere is NULL, delete the
83658 ** entire contents of the table. */
83668 /* The sqlite_stat[134] table already exists. Delete all rows. */
83703 i64 iRowid; /* Rowid in main table of the key */
83713 tRowcnt nRow; /* Number of rows in the entire table */
83809 ** WITHOUT ROWID table, N is the number of PRIMARY KEY columns, not the
83810 ** total number of columns in the table.
83816 ** PRIMARY KEY of the table. The covering index that implements the
83817 ** original WITHOUT ROWID table as N==K as a special case.
83990 ** iCol occurs many times in the table. However, if we have already
84216 #define STAT_GET_STAT1 0 /* "stat" column of stat1 table */
84233 ** stat1 table entry information.
84255 ** table for this index.
84379 ** a single table.
84383 Table *pTab, /* Table whose indices are to be analyzed */
84385 int iStatCur, /* Index of VdbeCursor that writes the sqlite_stat1 table */
84392 int iTabCur; /* Table cursor */
84397 u8 needTableCnt = 1; /* True to count the table */
84405 int regTabname = iMem++; /* Register containing table name */
84434 /* Establish a read-lock on the table at the shared-cache level.
84435 ** Open a read-only cursor on the table. Also allocate a cursor number
84503 ** the sqlite_stat4 table. */
84515 ** (or for a WITHOUT ROWID table, the number of PK columns),
84628 /* Add the entry to the stat1 table. */
84635 /* Add the entries to the stat3 or stat4 table. */
84732 Table *pTab = (Table*)sqliteHashData(k);
84739 ** Generate code that will do an analysis of a single table in
84743 static void analyzeTable(Parse *pParse, Table *pTab, Index *pOnlyIdx){
84772 ** Form 3 analyzes all indices associated with the named table.
84779 Table *pTab;
84799 /* Form 2: Analyze the database or table named */
84815 /* Form 3: Analyze the fully qualified table name */
84908 ** sqlite_stat1 table.
84910 ** argv[0] = name of the table
84915 ** the table.
84920 Table *pTable;
85010 ** occur in the stat4 table for this index before pFinal. Set
85030 ** Look up an index by name. Or, if the name of a WITHOUT ROWID table
85031 ** is supplied instead, find the PRIMARY KEY index for that table.
85040 Table *pTab = sqlite3FindTable(db, zName, zDb);
85047 ** Load the content from either the sqlite_stat4 or sqlite_stat3 table
85097 ** loaded from the stat4 table. In this case ignore stat3 data. */
85147 ** the sqlite_stat4 table. In this case ignore stat3 data. */
85213 ** If the sqlite_stat1 table is not present in the database, SQLITE_ERROR
85215 ** during compilation and the sqlite_stat3/4 table is present, no data is
85219 ** sqlite_stat4 table is not present in the database, SQLITE_ERROR is
85221 ** table (if it is present) before returning.
85247 /* Check to make sure the sqlite_stat1 table exists */
85254 /* Load new statistics out of the sqlite_stat1 table */
85265 /* Load the statistics from the sqlite_stat4 table. */
85722 ** a specific database to all table references where the database name
85919 ** the table and the column that are being accessed. The auth function
85954 ** table zTab in database zDb. This function assumes that an authorization
85963 const char *zTab, /* Table name */
85986 ** The pExpr should be a TK_COLUMN expression. The table referred to
85987 ** is in pTabList or else it is the NEW or OLD table of a trigger.
85998 SrcList *pTabList /* All table that pExpr might refer to */
86001 Table *pTab = 0; /* The table being read */
86002 const char *zCol; /* Name of the column of the table */
86003 int iSrc; /* Index in pTabList->a[] of table being read */
86005 int iCol; /* Index of column in table */
86011 ** temporary table. */
86128 ** CREATE TABLE
86129 TABLE
86153 int iDb; /* The database containing the table to be locked */
86154 int iTab; /* The root page of the table to be locked */
86156 const char *zName; /* Name of the table */
86160 ** Record the fact that we want to lock a table at run-time.
86162 ** The table to be locked has root page iTab and is found in database iDb.
86171 int iDb, /* Index of the database containing the table to lock */
86172 int iTab, /* Root page number of the table to be locked */
86174 const char *zName /* Name of the table to be locked */
86206 ** Code an OP_TableLock instruction for each table locked by the
86303 ** obtain the required table-locks. This is a no-op unless the
86387 ** table given the name of that table and (optionally) the name of the
86388 ** database containing the table. Return NULL if not found.
86390 ** If zDatabase is 0, all databases are searched for the table and the
86391 ** first matching table is returned. (No checking for duplicate table
86397 SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){
86398 Table *p = 0;
86417 ** table given the name of that table and (optionally) the name of the
86418 ** database containing the table. Return NULL if not found. Also leave an
86425 SQLITE_PRIVATE Table *sqlite3LocateTable(
86427 int isView, /* True if looking for a VIEW rather than a TABLE */
86428 const char *zName, /* Name of the table we are looking for */
86431 Table *p;
86441 const char *zMsg = isView ? "no such view" : "no such table";
86453 ** Locate the table identified by *p.
86461 SQLITE_PRIVATE Table *sqlite3LocateTableItem(
86484 ** table and the first matching index is returned. (No checking
86523 ** unlike that index from its Table then remove the index from
86524 ** the index hash table and free all memory structures associated
86638 ** Delete memory allocated for the column names of a table or view (the
86639 ** Table.aCol[] array).
86641 static void sqliteDeleteColumnNames(sqlite3 *db, Table *pTable){
86659 ** Table. No changes are made to disk by this routine.
86662 ** the table data structure from the hash table. But it does destroy
86664 ** the table.
86666 ** The db parameter is optional. It is needed if the Table object
86667 ** contains lookaside memory. (Table objects in the schema do not use
86668 ** lookaside memory, but some ephemeral Table objects do.) Or the
86670 ** used by the Table object.
86672 SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
86678 /* Do not delete the table until the reference count reaches zero. */
86688 /* Delete all indices associated with this table. */
86703 /* Delete any foreign keys attached to this table. */
86706 /* Delete the Table structure itself.
86725 ** Unlink the given table from the hash tables and the delete the
86726 ** table structure with all its indices and foreign keys.
86729 Table *p;
86736 testcase( zTabName[0]==0 ); /* Zero-length table names are allowed */
86769 ** Open the sqlite_master table stored in database number iDb for
86770 ** writing. The table is opened using cursor 0.
86817 /* The table or view or trigger name is passed to this routine via tokens
86818 ** pName1 and pName2. If the table name was fully qualified, for example:
86820 ** CREATE TABLE xxx.yyy (...);
86823 ** the table name is not fully qualified, i.e.:
86825 ** CREATE TABLE yyy(...);
86830 ** pName2) that stores the unqualified table name. The index of the
86865 ** unqualified name for a new schema object (table, index, view or
86881 ** Return the PRIMARY KEY index of a table
86883 SQLITE_PRIVATE Index *sqlite3PrimaryKeyIndex(Table *pTab){
86890 ** Return the column of index pIdx that corresponds to table
86902 ** Begin constructing a new table representation in memory. This is
86904 ** to a CREATE TABLE statement. In particular, this routine is called
86905 ** after seeing tokens "CREATE" and "TABLE" and the table name. The isTemp
86906 ** flag is true if the table should be stored in the auxiliary database
86909 ** CREATE and TABLE.
86911 ** The new table record is initialized and put in pParse->pNewTable.
86912 ** As more of the CREATE TABLE statement is parsed, additional action
86914 ** At the end of the CREATE TABLE statement, the sqlite3EndTable() routine
86915 ** is called to complete the construction of the new table record.
86919 Token *pName1, /* First part of the name of the table or view */
86920 Token *pName2, /* Second part of the name of the table or view */
86921 int isTemp, /* True if this is a TEMP table */
86923 int isVirtual, /* True if this is a VIRTUAL table */
86924 int noErr /* Do nothing if table already exists */
86926 Table *pTable;
86927 char *zName = 0; /* The name of the new table */
86930 int iDb; /* Database number to create the table in */
86931 Token *pName; /* Unqualified name of the table to create */
86933 /* The table or view name to create is passed to this routine via tokens
86934 ** pName1 and pName2. If the table name was fully qualified, for example:
86936 ** CREATE TABLE xxx.yyy (...);
86939 ** the table name is not fully qualified, i.e.:
86941 ** CREATE TABLE yyy(...);
86946 ** pName2) that stores the unqualified table name. The variable iDb is
86947 ** set to the index of the database that the table or view is to be
86953 /* If creating a temp table, the name may not be qualified. Unless
86955 sqlite3ErrorMsg(pParse, "temporary table name must be unqualified");
86994 /* Make sure the new table name does not collide with an existing
86995 ** index or table name in the same database. Issue an error message if
87009 sqlite3ErrorMsg(pParse, "table %T already exists", pName);
87022 pTable = sqlite3DbMallocZero(db, sizeof(Table));
87037 /* If this is the magic sqlite_sequence table used by autoincrement,
87038 ** then record a pointer to this table in the main database structure
87039 ** so that INSERT can find the table easily.
87048 /* Begin generating the code that will insert the table record into
87049 ** the SQLITE_MASTER table. Note in particular that we must go ahead
87050 ** and allocate the record number for the table entry now. Before any
87052 ** indices to be created and the table record must come before the
87053 ** indices. Hence, the record number for the table must be allocated
87085 /* This just creates a place-holder record in the sqlite_master table.
87090 ** The root page number of the new table is left in reg pParse->regRoot.
87133 ** Add a new column to the table currently being constructed.
87136 ** in a CREATE TABLE statement. sqlite3StartTable() gets called
87141 Table *p;
87186 ** parsing a CREATE TABLE statement. A "NOT NULL" constraint has
87191 Table *p;
87202 ** substrings in the following table. If one of the substrings is
87205 ** the table take priority. For example, if zType is 'BLOBINT',
87219 ** If none of the substrings in the above table are found,
87286 ** parsing a CREATE TABLE statement. The pFirst token is the first
87294 Table *p;
87307 ** of the table currently under construction.
87313 ** parsing a CREATE TABLE statement.
87316 Table *p;
87341 ** Designate the PRIMARY KEY for the table. pList is a list of names
87343 ** most recently added column of the table is the primary key.
87345 ** A table can have at most one primary key. If the table already has
87350 ** then we will try to use that column as the rowid. Set the Table.iPKey
87351 ** field of the table under construction to be the index of the
87352 ** INTEGER PRIMARY KEY column. Table.iPKey is set to -1 if there is
87365 Table *pTab = pParse->pNewTable;
87372 "table \"%s\" has more than one primary key", pTab->zName);
87426 ** Add a new CHECK constraint to the table currently under construction.
87433 Table *pTab = pParse->pNewTable;
87450 ** Set the collation function of the most recently parsed table column
87454 Table *p;
87599 ** Generate a CREATE TABLE statement appropriate for the given
87600 ** table. Memory to hold the text of the statement is obtained
87603 static char *createTableStmt(sqlite3 *db, Table *p){
87628 sqlite3_snprintf(n, zStmt, "CREATE TABLE ");
87693 ** Estimate the total row width for a table.
87695 static void estimateTableWidth(Table *pTab){
87729 ** This routine runs at the end of parsing a CREATE TABLE statement that
87732 ** are appropriate for a WITHOUT ROWID table instead of a rowid table.
87738 ** (2) Bypass the creation of the sqlite_master table entry
87740 ** identified by the sqlite_master table entry of the table itself.
87742 ** schema to the rootpage from the main table.
87744 ** (5) Add all table columns to the PRIMARY KEY Index object
87751 static void convertToWithoutRowidTable(Parse *pParse, Table *pTab){
87760 ** root-page for the table into a OP_CreateIndex opcode. The index
87769 ** table entry.
87776 /* Locate the PRIMARY KEY index. Or, if this table was originally
87777 ** an INTEGER PRIMARY KEY table, create a new PRIMARY KEY index.
87804 /* The root page of the PRIMARY KEY is the table root page */
87833 /* Add all table columns to the PRIMARY KEY index
87854 ** a CREATE TABLE statement.
87856 ** The table structure that other action routines have been building
87860 ** An entry for the table is made in the master table on disk, unless
87861 ** this is a temporary table or db->init.busy==1. When db->init.busy==1
87862 ** it means we are reading the sqlite_master table because we just
87863 ** connected to the database or because the sqlite_master table has
87864 ** recently changed, so the entry for this table already exists in
87865 ** the sqlite_master table. We do not want to create it again.
87868 ** was called to create a table generated from a
87869 ** "CREATE TABLE ... AS SELECT ..." statement. The column names of
87870 ** the new table will match the result set of the SELECT.
87875 Token *pEnd, /* The ')' before options in the CREATE TABLE */
87876 u8 tabOpts, /* Extra table options. Usually 0. */
87879 Table *p; /* The new table */
87881 int iDb; /* Database in which the table lives */
87882 Index *pIdx; /* An implied index of the table */
87893 ** "sqlite_master" or "sqlite_temp_master" table on the disk.
87895 ** for the table from the db->init.newTnum field. (The page number
87910 sqlite3ErrorMsg(pParse, "PRIMARY KEY missing on table %s", p->zName);
87927 /* Estimate the average row size for the table and for all implied indices */
87933 /* If not initializing, then create a record for the new table
87934 ** in the SQLITE_MASTER table of the database.
87936 ** If this is a TEMPORARY table, write the entry into the auxiliary
87942 char *zType; /* "view" or "table" */
87943 char *zType2; /* "VIEW" or "TABLE" */
87944 char *zStmt; /* Text of the CREATE TABLE or CREATE VIEW statement */
87952 ** Initialize zType for the new view or table.
87955 /* A regular table */
87956 zType = "table";
87957 zType2 = "TABLE";
87966 /* If this is a CREATE TABLE xx AS SELECT ..., execute the SELECT
87967 ** statement to populate the new table. The root-page number for the
87968 ** new table is in register pParse->regRoot.
87972 ** by the new table.
87974 ** A shared-cache write-lock is not required to write to the new table,
87981 Table *pSelTab;
88015 ** SQLITE_MASTER table. We just need to update that slot with all
88034 /* Check to see if we need to create an sqlite_sequence table for
88042 "CREATE TABLE %Q.sqlite_sequence(name,seq)",
88055 /* Add the table to the in-memory representation of the database.
88058 Table *pOld;
88099 Table *p;
88155 /* Use sqlite3EndTable() to add the view to the SQLITE_MASTER table */
88163 ** The Table structure pTable is really a VIEW. Fill in the names of
88167 SQLITE_PRIVATE int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){
88168 Table *pSelTab; /* A fake table from which we get the result set */
88201 ** CREATE TABLE main.ex1(a);
88211 /* If we get this far, it means we need to compute the table names.
88267 Table *pTab = sqliteHashData(i);
88282 ** used by SQLite when the btree layer moves a table root page. The
88283 ** root-page of a table or index in database iDb has changed from iFrom
88286 ** Ticket #1728: The symbol table might still contain information
88289 ** have the same rootpage number as the real table or index that is
88292 ** or tables and not the table/index that is actually being moved.
88307 Table *pTab = sqliteHashData(pElem);
88323 ** Write code to erase the table with root-page iTable from database iDb.
88324 ** Also write code to modify the sqlite_master table and internal schema
88325 ** if a root-page of another table is moved by the btree-layer whilst
88335 ** is non-zero, then it is the root page number of a table moved to
88336 ** location iTable. The following code modifies the sqlite_master table to
88351 ** Write VDBE code to erase table pTab and all associated indices on disk.
88353 ** in case a root-page belonging to another table is moved by the btree layer
88356 static void destroyTable(Parse *pParse, Table *pTab){
88367 ** table and index root-pages in order, starting with the numerically
88412 ** after a DROP INDEX or DROP TABLE command.
88418 const char *zName /* Name of index or table */
88435 ** Generate code to drop a table.
88437 SQLITE_PRIVATE void sqlite3CodeDropTable(Parse *pParse, Table *pTab, int iDb, int isView){
88453 /* Drop all triggers associated with the table being dropped. Code
88466 /* Remove any entries of the sqlite_sequence table associated with
88467 ** the table being dropped. This is done before the table is dropped
88468 ** at the btree level, in case the sqlite_sequence table needs to
88479 /* Drop all SQLITE_MASTER table and index entries that refer to the
88480 ** table. The program name loops through the master table and deletes
88481 ** every row that refers to a table of the same name as the one being
88483 ** created in the temp database that refers to a table in another
88493 /* Remove the table entry from SQLite's internal schema and modify
88505 ** This routine is called to do the work of a DROP TABLE statement.
88506 ** pName is the name of the table to be dropped.
88509 Table *pTab;
88530 /* If pTab is a virtual table, call ViewGetColumnNames() to ensure
88573 sqlite3ErrorMsg(pParse, "table %s may not be dropped", pTab->zName);
88578 /* Ensure DROP TABLE is not used on a view, and DROP VIEW is not used
88579 ** on a table.
88582 sqlite3ErrorMsg(pParse, "use DROP TABLE to delete table %s", pTab->zName);
88591 /* Generate code to remove the table from the master table
88607 ** This routine is called to create a new foreign key on the table
88609 ** in the current table point to the foreign key. If pFromCol==0 then
88611 ** the table referred to (a.k.a the "parent" table). pToCol is a list
88612 ** of tables in the parent pTo table. flags contains all
88616 ** An FKey structure is created and added to the table currently
88624 ExprList *pFromCol, /* Columns in this table that point to other table */
88625 Token *pTo, /* Name of the other table */
88626 ExprList *pToCol, /* Columns in the other table */
88633 Table *p = pParse->pNewTable;
88646 " should reference only one column of table %T",
88654 "columns in the referenced table");
88724 /* Link the foreign key to the table as the last step.
88745 Table *pTab;
88765 Table *pTab = pIndex->pTable; /* The table that is indexed */
88786 /* Require a write-lock on the table to perform this operation */
88803 /* Open the table. Loop through all rows of the table, inserting index
88879 ** Create a new index for an SQL table. pName1.pName2 is the name of the index
88880 ** and pTblList is the name of the table that is to be indexed. Both will
88883 ** as the table to be indexed. pParse->pNewTable is a table that is
88884 ** currently being constructed by a CREATE TABLE statement.
88888 ** to the table currently under construction.
88898 SrcList *pTblName, /* Table to index. Use pParse->pNewTable if 0 */
88907 Table *pTab = 0; /* Table to be indexed */
88915 Db *pDb; /* The specific table containing the indexed database */
88919 const Column *pTabCol; /* A column in the table */
88934 ** Find the table that is to be indexed. Return early if not found.
88939 ** to search for the table. 'Fix' the table name to this db
88940 ** before looking up the table.
88948 /* If the index name was unqualified, check if the table
88949 ** is a temp table. If so, set the database to 1. Do not do this
88971 "cannot create a TEMP index on non-TEMP table \"%s\"",
88989 sqlite3ErrorMsg(pParse, "table %s may not be indexed", pTab->zName);
89007 ** index or table with the same name.
89010 ** sqlite_master table (because some other process changed the schema) and
89011 ** one of the index names collides with the name of a temporary table or
89027 sqlite3ErrorMsg(pParse, "there is already a table named %s", zName);
89067 ** key out of the last column added to the table under construction.
89125 /* Scan the names of the columns of the table to be indexed and
89144 sqlite3ErrorMsg(pParse, "table %s has no column named %s",
89199 ** CREATE TABLE t(x PRIMARY KEY, y);
89200 ** CREATE TABLE t(x, y, UNIQUE(x, y));
89202 ** Either way, check to see if the table already has such an index. If
89234 ** constraint specified somewhere in the CREATE TABLE statement.
89253 /* Link the new Index structure to its table and to the other
89273 /* If this is the initial CREATE INDEX statement (or CREATE TABLE if the
89276 ** the index in the sqlite_master table and populate the index with
89278 ** table to parse the schema, or if this index is the PRIMARY KEY index
89279 ** of a WITHOUT ROWID table.
89282 ** or UNIQUE index in a CREATE TABLE statement. Since the table
89339 /* When adding an index to the list of indices for a table, make
89378 ** number of rows in the table that match any particular value of the
89398 ** number of rows in the table. Or 10, if the estimated number of rows
89399 ** in the table is less than that. */
89451 Table *pTab = pIndex->pTable;
89464 /* Generate code to remove the index and from the master table */
89645 ** Append a new table name to the given SrcList. Create a new SrcList if
89653 ** If pDatabase is not null, it means that the table has an optional
89654 ** database name prefix. Like this: "database.table". The pDatabase
89655 ** points to the table name and the pTable points to the database name.
89656 ** The SrcList.a[].zName field is filled with the table name which might
89665 ** Then B is a table name and the database name is unspecified. If called
89670 ** Then C is the table name and B is the database name. If C is defined
89681 Token *pTable, /* Table to append */
89682 Token *pDatabase /* Database of the table */
89753 ** are the name of the table and database named in the FROM clause term.
89767 Token *pTable, /* Name of the table to add to the FROM clause */
89770 Select *pSubquery, /* A subquery used in place of a table name */
90023 ** inserting multiple rows in a table, or inserting a row and index entries.)
90086 Table *pTab = pIdx->pTable;
90111 Table *pTab /* The table with the non-unique rowid */
90151 static void reindexTable(Parse *pParse, Table *pTab, char const *zColl){
90175 Table *pTab; /* A table in the database */
90181 pTab = (Table*)sqliteHashData(k);
90199 ** indices associated with the named table.
90204 char *z; /* Name of a table or index */
90206 Table *pTab; /* A table in the database */
90210 Token *pObjName; /* Name of the table or index to be reindexed */
90311 Token *pName, /* Name of the common-table */
90312 ExprList *pArglist, /* Optional column name list for the table */
90313 Select *pQuery /* Query used to initialize the table */
90326 sqlite3ErrorMsg(pParse, "duplicate WITH table name: %s", zName);
90512 ** Locate and return an entry from the db.aCollSeq hash table. If the entry
90516 ** Each pointer stored in the sqlite3.aCollSeq hash table contains an
90549 ** to the hash table).
90660 FuncDefHash *pHash, /* Hash table to search */
90675 ** Insert a new FuncDef into a FuncDefHash hash table.
90678 FuncDefHash *pHash, /* The hash table into which to insert */
90775 ** new entry to the hash table and return it.
90817 Table *pTab = sqliteHashData(pElem);
90872 ** the name of a single table, as one might find in an INSERT, DELETE,
90873 ** or UPDATE statement. Look up that table in the symbol table and
90874 ** return a pointer. Set an error message and return NULL if the table
90879 ** pSrc->a[0].pTab Pointer to the Table object
90883 SQLITE_PRIVATE Table *sqlite3SrcListLookup(Parse *pParse, SrcList *pSrc){
90885 Table *pTab;
90900 ** Check to make sure the given table is writable. If it is not
90904 SQLITE_PRIVATE int sqlite3IsReadOnly(Parse *pParse, Table *pTab, int viewOk){
90905 /* A table is not writable under the following circumstances:
90907 ** 1) It is a virtual table and no implementation of the xUpdate method
90909 ** 2) It is a system table (i.e. sqlite_master), this call is not
90921 sqlite3ErrorMsg(pParse, "table %s may not be modified", pTab->zName);
90937 ** Evaluate a view and store its result in an ephemeral table. The
90939 ** set of rows in the view that are to be added to the ephemeral table.
90943 Table *pView, /* View definition */
90945 int iCur /* Cursor number for ephemerial table */
91071 SrcList *pTabList, /* The table from which we should delete things */
91075 Table *pTab; /* The table from which records will be deleted */
91079 Index *pIdx; /* For looping over indices of the table */
91080 int iTabCur; /* Cursor number for the table */
91093 Index *pPk; /* The PRIMARY KEY index on the table */
91098 int iEphCur = 0; /* Ephemeral table holding all primary key values */
91103 int addrEphOpen = 0; /* Instruction to open the Ephermeral table */
91107 Trigger *pTrigger; /* List of table triggers, if required */
91117 /* Locate the table which we want to delete. This table has to be
91120 ** an SrcList* parameter instead of just a Table* parameter.
91125 /* Figure out if we have any triggers and if the table being
91159 /* Assign cursor numbers to the table and all its indices.
91183 ** a ephemeral table.
91211 ** It is easier just to erase the whole table. Prior to version 3.6.5,
91231 /* For a rowid table, initialize the RowSet to an empty set */
91237 /* For a WITHOUT ROWID table, create an ephermeral table used to
91315 /* Unless this is a view, open cursors for the table we are
91375 /* Close the cursors open on the table and its indexes. */
91384 /* Update the sqlite_sequence table by storing the content of the
91421 ** single table to be deleted. Both the original table entry and
91427 ** store for the table. (This will be either the table itself,
91428 ** in the case of a rowid table, or the PRIMARY KEY index in the case
91429 ** of a WITHOUT ROWID table.)
91441 Table *pTab, /* Table containing the row to be deleted */
91488 /* Populate the OLD.* pseudo-table register array. These values will be
91517 ** refer to this table (i.e. constraints attached to other tables)
91522 /* Delete the index and table entries. Skip this step if pTab is really
91552 ** index entries associated with a single row of a single table, pTab
91557 ** btree for the table pTab. (This will be either the table itself
91570 Table *pTab, /* Table containing the row to be deleted */
91571 int iDataCur, /* Cursor of table holding data. */
91602 ** iCur is the index of a cursor open on the pTab table and pointing to
91603 ** the entry that needs indexing. If pTab is a WITHOUT ROWID table, then
91627 ** on a table with multiple indices, and especially with the ROWID or
91642 Table *pTab = pIdx->pTable;
91665 ** might be stored in the table as an integer (using a compact
92137 ** routines in the function table. The noopFunc macro provides this.
93332 ** to the global function hash table. This occurs at start-time (as
93492 ** I.1) For each FK for which the table is the child table, search
93493 ** the parent table for a match. If none is found increment the
93496 ** I.2) For each FK for which the table is the parent table,
93497 ** search the child table for rows that correspond to the new
93498 ** row in the parent table. Decrement the counter for each row
93503 ** D.1) For each FK for which the table is the child table,
93504 ** search the parent table for a row that corresponds to the
93505 ** deleted row in the child table. If such a row is not found,
93508 ** D.2) For each FK for which the table is the parent table, search
93509 ** the child table for rows that correspond to the deleted row
93510 ** in the parent table. For each found increment the counter.
93538 ** TODO: How should dropping a table be handled? How should renaming a
93539 ** table be handled?
93574 ** CREATE TABLE t1(a, b INTEGER PRIMARY KEY, c);
93585 ** table are collectively subject to a UNIQUE or PRIMARY KEY constraint.
93586 ** Given that pParent is the parent table for foreign key constraint pFKey,
93597 ** array is the index of the child table column that is mapped by the FK
93598 ** constraint to the parent table column stored in the left-most column
93600 ** child table column that corresponds to the second left-most column of
93611 ** foreign key definition, and the parent table does not have a
93615 ** foreign key definition, and the PRIMARY KEY of the parent table
93617 ** the child table.
93625 Table *pParent, /* Parent table of FK constraint pFKey */
93627 Index **ppIdx, /* OUT: Unique index on parent table */
93641 ** maps to the INTEGER PRIMARY KEY of table pParent. If so, leave *ppIdx
93652 ** mapped to the primary key of table pParent, or
93675 ** the PRIMARY KEY of table pParent. The PRIMARY KEY index may be
93686 ** map to an explicit list of columns in table pParent. Check if this
93734 ** child table of foreign key constraint pFKey. If an SQL UPDATE is executed
93735 ** on the child table of pFKey, this function is invoked twice for each row
93740 ** row in the parent table that corresponds to the row being inserted into
93741 ** or deleted from the child table. If the parent row can be found, no
93743 ** found in the parent table:
93761 Table *pTab, /* Parent table of FK pFKey */
93764 int *aiCol, /* Map from parent key columns to child table columns */
93765 int regData, /* Address of array containing child table row */
93778 ** Check if any of the key columns in the child table row are NULL. If
93780 ** search for a matching row in the parent table. */
93793 ** column of the parent table (table pTab). */
93806 /* If the parent table is the same as the child table, and we are about
93832 /* If the parent table is the same as the child table, and we are about
93872 ** one row into the table, raise a constraint immediately instead of
93892 ** to column iCol of table pTab.
93900 Table *pTab, /* The table whose content is at r[regBase]... */
93901 int regBase, /* Contents of table pTab */
93927 ** Return an Expr object that refers to column iCol of table pTab which
93932 Table *pTab, /* The table whose column is desired */
93933 int iCursor, /* The open cursor on the table */
93947 ** from the parent table of foreign key constraint pFKey and, if pFKey is
93948 ** deferred, when a row is inserted into the same table. When generating
93953 ** table that correspond to the parent table row being deleted or inserted.
93975 SrcList *pSrc, /* The child table to be scanned */
93976 Table *pTab, /* The parent table */
93979 int *aiCol, /* Map from pIdx cols to child table cols */
94010 Expr *pLeft; /* Value from parent table row */
94011 Expr *pRight; /* Column ref to child table */
94013 i16 iCol; /* Index of column in child table */
94014 const char *zCol; /* Name of column in child table */
94026 /* If the child table is the same as the parent table, then add terms
94039 Expr *pLeft; /* Value from parent table row */
94040 Expr *pRight; /* Column ref to child table */
94089 ** FKey.pNextTo) holding all children of table pTab. For example,
94092 ** CREATE TABLE t1(a PRIMARY KEY);
94093 ** CREATE TABLE t2(b REFERENCES t1(a);
94095 ** Calling this function with table "t1" as an argument returns a pointer
94096 ** to the FKey structure representing the foreign key constraint on table
94099 ** table).
94101 SQLITE_PRIVATE FKey *sqlite3FkReferences(Table *pTab){
94126 ** This function is called to generate code that runs when table pTab is
94129 ** table pTab.
94133 ** (a) The table is the parent table of a FK constraint, or
94134 ** (b) The table is the child table of a deferred FK constraint and it is
94139 ** the table from the database. Triggers are disabled while running this
94142 SQLITE_PRIVATE void sqlite3FkDropTable(Parse *pParse, SrcList *pName, Table *pTab){
94150 /* Search for a deferred foreign key constraint for which this table
94151 ** is the child table. If one cannot be found, return without
94193 ** for which pTab is the child table. An UPDATE statement against pTab
94194 ** is currently being processed. For each column of the table that is
94204 Table *pTab, /* Table being updated */
94220 ** for which pTab is the parent table. An UPDATE statement against pTab
94221 ** is currently being processed. For each column of the table that is
94231 Table *pTab,
94256 ** table pTab to generate VDBE code to perform foreign key constraint
94270 ** the original record is deleted from the table using the calling convention
94276 Table *pTab, /* Row is being deleted from this table */
94298 ** child table (the table that the foreign key definition is part of). */
94300 Table *pTo; /* Parent table of foreign key pFKey */
94315 /* Find the parent table of this foreign key. Also find a unique index
94316 ** on the parent key columns in the parent table. If either of these
94328 /* If isIgnoreErrors is true, then a table is being dropped. In this
94329 ** case SQLite runs a "DELETE FROM xxx" on the table being dropped
94331 ** If the parent table of an FK constraint on the current table is
94333 ** FK counter for each row of the current table with non-NULL keys.
94360 ** values read from the parent table are NULL. */
94370 /* Take a shared-cache advisory read-lock on the parent table. Allocate
94372 ** in the parent table. */
94377 /* A row is being removed from the child table. Search for the parent.
94383 /* A row is being added to the child table. If a parent row cannot
94391 /* Loop through all the foreign key constraints that refer to this table.
94406 /* Inserting a single row into a parent table cannot cause an immediate
94417 /* Create a SrcList structure containing the child table. We need the
94418 ** child table as a SrcList for sqlite3WhereBegin() */
94432 ** on the parent table of this FK, then throw an exception
94450 ** row contained in table pTab.
94454 Table *pTab /* Table being modified */
94477 ** row contained in table pTab. If the operation is a DELETE, then
94479 ** to an array of size N, where N is the number of columns in table pTab.
94483 ** UPDATE statement modifies the rowid fields of the table.
94491 Table *pTab, /* Table being modified */
94498 ** table in question is either the child or parent table for any
94522 ** compiled on table pTab, which is the parent table of foreign-key pFKey.
94533 ** For example, if pFKey is the foreign key and pTab is table "p" in
94536 ** CREATE TABLE p(pk PRIMARY KEY);
94537 ** CREATE TABLE c(ck REFERENCES p ON DELETE CASCADE);
94551 Table *pTab, /* Table being updated or deleted from */
94565 char const *zFrom; /* Name of child table */
94568 int *aiCol = 0; /* child table cols -> parent key cols */
94582 Token tFromCol; /* Name of column in child table */
94583 Token tToCol; /* Name of column in parent table */
94584 int iFromCol; /* Idx of column in child table */
94598 ** parent table are used for the comparison. */
94737 Table *pTab, /* Table being updated or deleted from */
94744 ** refer to table pTab. If there is an action associated with the FK
94764 ** table pTab. Remove the deleted foreign keys from the Schema.fkeyHash
94765 ** hash table.
94767 SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){
94774 /* Remove the FK from the fkeyHash hash table. */
94825 ** (1) acquire a lock for table pTab then
94828 ** If pTab is a WITHOUT ROWID table, then it is the PRIMARY KEY index
94829 ** for that table that is actually opened.
94833 int iCur, /* The cursor number of the table */
94835 Table *pTab, /* The table to be opened */
94860 ** the table, according to the affinity of the column:
94888 Table *pTab = pIdx->pTable;
94906 ** Compute the affinity string for table pTab, if it has not already been
94925 SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe *v, Table *pTab, int iReg){
94955 ** Return non-zero if the table pTab in database iDb or any of its indices
94958 ** run without using a temporary table for the results of the SELECT.
94960 static int readsTable(Parse *p, int iDb, Table *pTab){
94996 ** Locate or create an AutoincInfo structure associated with table pTab
95000 ** There is at most one AutoincInfo structure per table even if the
95001 ** same table is autoincremented multiple times due to inserts within
95003 ** first use of table pTab. On 2nd and subsequent uses, the original
95008 ** (1) Register to hold the name of the pTab table.
95018 Table *pTab /* The table we are writing to */
95034 pToplevel->nMem++; /* Register to hold name of table */
95050 Db *pDb; /* Database only autoinc table */
95100 ** table (either directly or through triggers) needs to call this
95141 Table *pDest, /* The table we are inserting into */
95150 ** insert into TABLE (IDLIST) values(EXPRLIST)
95151 ** insert into TABLE (IDLIST) select
95153 ** The IDLIST following the table name is always optional. If omitted,
95154 ** then a list of all columns for the table is substituted. The IDLIST
95167 ** open write cursor to <table> and its indices
95169 ** write the resulting record into <table>
95174 ** INSERT INTO <table> SELECT ...
95177 ** in other words if the SELECT pulls all columns from a single table
95185 ** open a write cursor to <table>
95187 ** transfer all records in <table2> over to <table>
95189 ** foreach index on <table>
95190 ** open a write cursor on the <table> index
95197 ** and the SELECT clause does not read from <table> at any time.
95209 ** B: open write cursor to <table> and its indices
95211 ** insert the select result into <table> from R..R+n
95216 ** values from a SELECT but the data is being inserted into a table
95218 ** we have to use a intermediate table to store the results of
95230 ** B: open temp table
95232 ** insert row from R..R+n into temp table
95234 ** M: open write cursor to <table> and its indices
95235 ** rewind temp table
95236 ** C: loop over rows of intermediate table
95237 ** transfer values form intermediate table into <table>
95243 SrcList *pTabList, /* Name of table into which we are inserting */
95249 Table *pTab; /* The table to insert into. aka TABLE */
95250 char *zTab; /* Name of the table into which we are inserting */
95251 const char *zDb; /* Name of the database holding this table */
95254 Index *pIdx; /* For looping over indices of the table */
95256 int nHidden = 0; /* Number of hidden columns if TABLE is virtual */
95265 int iDb; /* Index of database holding TABLE */
95266 Db *pDb; /* The database containing table being inserted into */
95267 u8 useTempTable = 0; /* Store SELECT results in intermediate table */
95269 u8 withoutRowid; /* 0 for normal table. 1 for WITHOUT ROWID table */
95270 u8 bIdListInOrder = 1; /* True if IDLIST is in table order */
95305 /* Locate the table into which we will be inserting new information.
95323 /* Figure out if we have any triggers and if the table being
95347 /* Cannot insert into a read-only table.
95377 /* If this is an AUTOINCREMENT table, look up the sequence number in the
95378 ** sqlite_sequence table and store it in memory cell regAutoinc.
95394 ** all elements of the IDLIST really are columns of the table and
95397 ** If the table has an INTEGER PRIMARY KEY column and that column
95401 ** is appears in the original table. (The index of the INTEGER
95402 ** PRIMARY KEY in the original table is pTab->iPKey.)
95424 sqlite3ErrorMsg(pParse, "table %S has no column named %s",
95460 ** should be written into a temporary table (template 4). Set to
95462 ** the destination table (template 3).
95464 ** A temp table must be used if the table being updated is also one
95466 ** temp table in the case of row triggers.
95474 ** and add it to a transient table srcTab. The code generated
95477 ** B: open temp table
95479 ** insert row from R..R+n into temp table
95484 int regTempRowid; /* Register to hold temp table ROWID */
95517 /* If there is no IDLIST term but the table has an integer primary
95519 ** column index in the original table definition.
95526 ** of columns to be inserted into the table.
95535 "table %S has %d columns but %d values were supplied",
95551 /* If this is not a view, open the table and and all indices */
95570 ** rewind temp table, if empty goto D
95571 ** C: loop over rows of intermediate table
95572 ** transfer values form intermediate table into <table>
95583 ** insert the select result into <table> from R..R+n
95620 /* Cannot have triggers on a virtual table. If it were possible,
95647 ** If this is a real table, attempt conversions as required by the
95648 ** table column affinities.
95807 /* Update the sqlite_sequence table by storing the content of the
95849 ** on table pTab.
95855 ** case of a WITHOUT ROWID table. The second register in the range will
95856 ** contain the content of the first table column. The third register will
95857 ** contain the content of the second table column. And so forth.
95865 ** rowid for a normal table or the PRIMARY KEY for a WITHOUT ROWID table)
95867 ** the iDataCur content table is guaranteed to be unchanged by the UPDATE.
95872 ** that the table is a WITHOUT ROWID table and has no rowid. On an INSERT,
95883 ** table and all applicable indices (that is to say, all indices for which
95884 ** aRegIdx[] is not zero). iDataCur is the cursor for the main table when
95885 ** inserting or updating a rowid table, or the cursor for the PRIMARY KEY
95886 ** index when operating on a WITHOUT ROWID table. iIdxCur is the cursor
95932 Table *pTab, /* The table being inserted or updated */
95934 int iDataCur, /* Canonical data cursor (main table or PK index) */
95964 assert( pTab->pSelect==0 ); /* This table is not a VIEW */
95969 ** pPk index or 1 for a rowid table. In other words, nPkField is the
95970 ** number of fields in the true primary key of the table. */
96056 ** exist in the table.
96092 /* Check to see if the new rowid already exists in the table. Skip
96110 /* If there are DELETE triggers on this table and the
96112 ** remove the conflicting row from the table. This will fire
96113 ** the triggers and remove both the table and index b-tree entries.
96116 ** flag is not set, but the table has one or more indexes, call
96118 ** only. The table b-tree entry will be replaced by the new entry
96130 ** table.
96165 ** WITHOUT ROWID table.
96212 ** of a WITHOUT ROWID table and there has been no change the
96263 ** table, only conflict if the new PRIMARY KEY values are actually
96342 Table *pTab, /* the table into which we are inserting */
96355 int regRec; /* Register holding assemblied record for the table */
96361 assert( pTab->pSelect==0 ); /* This table is not a VIEW */
96404 ** Allocate cursors for the pTab table and all its indices and generate
96408 ** the table itself, but the PRIMARY KEY index in the case of a WITHOUT
96409 ** ROWID table) is returned in *piDataCur. The first index cursor is
96416 ** For a rowid table, *piDataCur will be exactly one less than *piIdxCur.
96417 ** For a WITHOUT ROWID table, *piDataCur will be somewhere in the range
96423 Table *pTab, /* Table to be opened */
96425 int iBase, /* Use this for the table cursor, if there is one */
96426 u8 *aToOpen, /* If not NULL: boolean for each table and index */
96552 ** Sometimes the xfer optimization will only work if the destination table
96555 ** does a test to see if the destination table is empty and jumps over the
96565 Table *pDest, /* The table we are inserting into */
96571 Table *pSrc; /* The table in the FROM clause of SELECT */
96590 ** attached to it. Proceeding may generate a false "no such table: xxx"
96599 return 0; /* tab1 must not be a virtual table */
96651 return 0; /* FROM clause does not contain a real table */
96654 return 0; /* tab1 and tab2 may not be the same table */
96661 return 0; /* tab2 must not be a virtual table */
96710 /* Disallow the transfer optimization if the destination table constains
96727 ** table (tab1) is initially empty.
96747 ** only if the destination table is initially empty. This code makes
98690 /* End of the automatically generated pragma table.
99007 /* Locate the pragma in the lookup table */
99637 ** PRAGMA table_info(<table>)
99639 ** Return a single row for each column of the named table. The columns of
99649 Table *pTab;
99702 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "table", SQLITE_STATIC);
99707 Table *pTab = sqliteHashData(i);
99729 Table *pTab;
99754 Table *pTab;
99814 Table *pTab;
99826 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "table", SQLITE_STATIC);
99862 Table *pTab; /* Child table contain "REFERENCES" keyword */
99863 Table *pParent; /* Parent table that child points to */
99864 Index *pIdx; /* Index in the parent table */
99867 HashElem *k; /* Loop counter: Next table in schema */
99882 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "table", SQLITE_STATIC);
99893 pTab = (Table*)sqliteHashData(k);
100076 Table *pTab = sqliteHashData(x);
100108 Table *pTab = sqliteHashData(x);
100159 /* Verify that an index entry exists for the current table row */
100326 ** creating or dropping a table or index). The schema version is used by
100630 ** argv[1] = root page number for table or index. 0 for trigger or view.
100653 /* Call the parser to process a CREATE TABLE, INDEX or VIEW.
100656 ** structures that describe the table, index, or view.
100688 ** constraint for a CREATE TABLE. The index should have already
100689 ** been created when we processed the CREATE TABLE. All we have
100695 /* This can occur if there exists an index on a TEMP table which
100697 ** the permanent table is hidden by the TEMP table, we can also
100698 ** safely ignore the index on the permanent table.
100722 Table *pTab;
100732 ** The master database table has a structure like this
100735 "CREATE TABLE sqlite_master(\n"
100745 "CREATE TEMP TABLE sqlite_temp_master(\n"
100764 ** initialized. zMasterName is the name of the master table.
100880 ** file_format==2 Version 3.1.3. // ALTER TABLE ADD COLUMN
100940 ** purpose of this is to allow access to the sqlite_master table
101088 ** expr.c is trying to resolve a reference to a transient table (i.e. one
101316 ** locked the sqlite3_master table, return SQLITE_LOCKED. If any other error
101495 int tabTnct; /* Ephemeral table used for DISTINCT processing */
101691 ** Return the index of a column in a table. Return -1 if the column
101692 ** is not contained in the table.
101694 static int columnIndex(Table *pTab, const char *zCol){
101704 ** table that has a column named zCol.
101706 ** When found, set *piTab and *piCol to the table index and column index
101742 ** where tab1 is the iSrc'th table in SrcList pSrc and tab2 is the
101749 int iLeft, /* Index of first table to join in pSrc */
101750 int iColLeft, /* Index of column in first table */
101751 int iRight, /* Index of second table in pSrc */
101752 int iColRight, /* Index of column in second table */
101792 ** expression depends on table iRightJoinTable even if that table is not
101822 ** The left most table is the first entry in Select.pSrc. The right-most
101823 ** table is the last entry. The join operator is held in the entry to
101833 struct SrcList_item *pLeft; /* Left table being joined */
101834 struct SrcList_item *pRight; /* Right table being joined */
101840 Table *pLeftTab = pLeft->pTab;
101841 Table *pRightTab = pRight->pTab;
101857 char *zName; /* Name of column in the right table */
101858 int iLeft; /* Matching left table */
101859 int iLeftCol; /* Matching column in the left table */
101897 int iLeft; /* Table on the left with matching column name */
101955 KeyInfo *pKI; /* Original KeyInfo on the sorter table */
102050 ** (example: "a IN (SELECT * FROM table)") but it has more than 1 result
102084 int srcTab, /* Pull data from this table */
102118 ** there are columns in the table on the left. The error will be caught
102201 ** table iParm.
102215 ** the temporary table iParm.
102239 ** output table as well. */
102262 ** item into the set table with bogus data.
102560 int bUseTmp /* True if a temp table was used */
102707 ** original CREATE TABLE statement if the expression is a column. The
102752 /* The expression is a column. Locate the table the column is being
102753 ** extracted from in NameContext.pSrcList. This table may be real
102754 ** database table or a subquery.
102756 Table *pTab = 0; /* Table structure column is extracted from */
102779 ** CREATE TABLE t1(col INTEGER);
102795 /* The "table" is actually a sub-select or a view in the FROM clause
102812 /* A real table */
102946 Table *pTab;
102983 ** column names for a table that would hold the expression list.
103028 Table *pTab; /* Table associated with this expression */
103098 Table *pTab, /* Add column type information to this table */
103132 ** Given a SELECT statement, generate a Table structure that describes
103135 SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse *pParse, Select *pSelect){
103136 Table *pTab;
103147 pTab = sqlite3DbMallocZero(db, sizeof(Table) );
103327 ** <recursive-table> AS (<setup-query> UNION [ALL] <recursive-query>)
103332 ** There is exactly one reference to the recursive-table in the FROM clause
103336 ** into a Queue table. Rows are extracted from the Queue table one by
103338 ** extracted row (now in the iCurrent table) becomes the content of the
103339 ** recursive-table for a recursive-query run. The output of the recursive-query
103340 ** is added back into the Queue table. Then another row is extracted from Queue
103341 ** and the iteration continues until the Queue table is empty.
103344 ** inserted into the Queue table. The iDistinct table keeps a copy of all rows
103348 ** If the query has an ORDER BY, then entries in the Queue table are kept in
103350 ** an ORDER BY, the Queue table is just a FIFO.
103365 int nCol = p->pEList->nExpr; /* Number of columns in the recursive table */
103370 int iCurrent = 0; /* The Current table */
103371 int regCurrent; /* Register holding Current table */
103372 int iQueue; /* The Queue table */
103375 SelectDest destQueue; /* SelectDest targetting the Queue table */
103396 /* Locate the cursor number of the Current table */
103405 ** the Distinct table must be exactly one greater than Queue in order
103427 VdbeComment((v, "Queue table"));
103466 ** the value for the recursive-table. Store the results in the Queue.
103565 /* Create the destination temporary table if necessary
103645 int unionTab; /* Cursor number of the temporary table holding result */
103656 /* We can reuse a temporary table generated by a SELECT to our
103663 /* We will need to create our own temporary table to hold the
103715 /* Convert the data in the temporary table into whatever form
103763 /* Code the SELECTs to our left into temporary table "tab1".
103772 /* Code the current SELECT into temporary table "tab2"
103955 ** item into the set table with bogus data.
104438 ** a column in table number iTable with a copy of the iColumn-th
104446 ** changes to pExpr so that it refers directly to the source table
104452 int iTable, /* Table to be substituted */
104481 int iTable, /* Table to be substituted */
104493 int iTable, /* Table to be replaced */
104527 ** subquery first and store the results in a temporary table, then
104528 ** run the outer query on that temporary table. This requires two
104529 ** passes over the data. Furthermore, because the temporary table
104540 ** exist on the table t1, a complete scan of the data might be
104563 ** table sqlite_once that consists of a single row containing a
104660 int iParent; /* VDBE cursor number of the pSub result set temp table */
104855 /* Delete the transient table structure associated with the
104866 /* Defer deleting the Table object associated with the
104874 Table *pTabToDel = pSubitem->pTab;
105073 ** where table is a database table, not a sub-select or view. If the query
105074 ** does match this pattern, then a pointer to the Table object representing
105077 static Table *isSimpleCount(Select *p, AggInfo *pAggInfo){
105078 Table *pTab;
105110 Table *pTab = pFrom->pTab;
105197 ** WITH contexts, from inner to outermost. If the table identified by
105198 ** FROM clause element pItem is really a common-table-expression (CTE)
105199 ** then return a pointer to the CTE definition for that table. Otherwise
105273 Table *pTab;
105290 pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
105324 pParse, "multiple references to recursive table: %s", pCte->zName
105339 sqlite3ErrorMsg(pParse, "table %s has %d values for %d columns",
105371 ** sqlite3SelectExpand() when walking a SELECT tree to resolve table
105405 ** for instances of the "*" operator or the TABLE.* operator.
105406 ** If found, expand each "*" to be every column in every table
105407 ** and TABLE.* to be every column in TABLE.
105436 /* Look up every table named in the FROM clause of the select. If
105437 ** an entry of the FROM clause is a subquery instead of a table or view,
105438 ** then create a transient table structure to describe the subquery.
105441 Table *pTab;
105464 pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
105475 /* An ordinary table or view name in the FROM clause */
105488 /* We reach here if the named table is a really a view */
105510 ** all columns in all tables. And for every TABLE.* insert the names
105511 ** of all columns in TABLE. The parser inserted a special expression
105561 /* This expression is a "*" or a "TABLE.*" and needs to be
105563 int tableSeen = 0; /* Set to 1 when TABLE matches */
105564 char *zTName = 0; /* text of name of TABLE */
105571 Table *pTab = pFrom->pTab;
105616 ** table to the right of the join */
105621 ** using clause from the table on the right. */
105664 sqlite3ErrorMsg(pParse, "no such table: %s", zTName);
105730 ** information to the Table structure that represents the result set
105733 ** The Table structure that represents the result set was constructed
105750 Table *pTab = pFrom->pTab;
105767 ** the Table structures of all FROM-clause subqueries in a
105789 ** * Ephemeral Table objects are created for all FROM-clause subqueries.
105791 ** * Wildcards "*" and "TABLE.*" in result sets are expanded.
105962 Table *pTab, /* Table being queried */
105967 char *zEqp = sqlite3MPrintf(pParse->db, "SCAN TABLE %s%s%s",
106129 /* Generate a subroutine that will fill an ephemeral table with
106196 ** The second form is preferred as a single index (or temp-table) may be
106198 ** written the query must use a temp-table for at least one of the ORDER
106199 ** BY and DISTINCT, and an index or separate temp-table for the other.
106233 /* If the output is destined for a temporary table, open that table.
106431 ** we do not have to sort. The OP_OpenEphemeral table will be
106495 /* If the index or temporary table used by the GROUP BY sort
106497 ** clause, cancel the ephemeral table open coded earlier.
106611 Table *pTab;
106613 /* If isSimpleCount() returns a pointer to a Table structure, then
106618 ** where the Table structure returned represents table <tbl>.
106621 ** OP_Count instruction is executed either on the intkey table that
106622 ** contains the data for table <tbl> or on one of its indexes. It
106880 /************** Begin file table.c *******************************************/
106919 ** This routine is called once for each row in the result table. Its job
106994 ** Instead, the entire table should be passed to sqlite3_free_table() when
107000 char ***pazResult, /* Write the result table here */
107078 /************** End of table.c ***********************************************/
107112 ** Given table pTab, return a list of all the triggers attached to
107113 ** the table. The list is connected by Trigger.pNext pointers.
107125 SQLITE_PRIVATE Trigger *sqlite3TriggerList(Parse *pParse, Table *pTab){
107139 && 0==sqlite3StrICmp(pTrig->table, pTab->zName)
107165 SrcList *pTableName,/* The name of the table/view the trigger applies to */
107171 Table *pTab; /* Table that the trigger fires off of */
107215 /* If the trigger name was unqualified, and the table is a temp table,
107217 ** If sqlite3SrcListLookup() returns 0, indicating the table does not
107226 /* Ensure the table name matches database name and that the table exists */
107235 /* The table does not exist. */
107238 ** Normally, whenever a table is dropped, all associated triggers are
107239 ** dropped too. But if a TEMP trigger is created on a non-TEMP table
107240 ** and the table is dropped by a different database connection, the
107243 ** "orphaned trigger" - a trigger whose associated table is missing.
107272 /* Do not create a trigger on a system table */
107274 sqlite3ErrorMsg(pParse, "cannot create trigger on system table");
107289 " trigger on table: %S", pTableName, 0);
107323 pTrigger->table = sqlite3DbStrDup(db, pTableName->a[0].zName);
107386 /* Make an entry in the sqlite_master table */
107394 pTrig->table, z);
107409 Table *pTab;
107410 int n = sqlite3Strlen30(pLink->table);
107411 pTab = sqlite3HashFind(&pLink->pTabSchema->tblHash, pLink->table, n);
107476 Token *pTableName, /* Name of the table into which we insert */
107505 Token *pTableName, /* Name of the table to be updated */
107530 Token *pTableName, /* The table from which rows are deleted */
107551 sqlite3DbFree(db, pTrigger->table);
107606 ** Return a pointer to the Table structure for the table that a trigger
107609 static Table *tableOfTrigger(Trigger *pTrigger){
107610 int n = sqlite3Strlen30(pTrigger->table);
107611 return sqlite3HashFind(&pTrigger->pTabSchema->tblHash, pTrigger->table, n);
107619 Table *pTable;
107686 Table *pTab = tableOfTrigger(pTrigger);
107715 ** Return a list of all triggers on table pTab if there exists at least
107717 ** performed on the table, and, if that operation is an UPDATE, if at
107722 Table *pTab, /* The table the contains the triggers */
107894 Table *pTab, /* The table pTrigger is attached to */
108008 Table *pTab, /* The table trigger pTrigger is attached to */
108035 ** table pTab. The reg, orconf and ignoreJump parameters passed to this
108042 Table *pTab, /* The table to code triggers from */
108073 ** on table pTab. The operation to code triggers for (INSERT, UPDATE or DELETE)
108083 ** in the trigger program. If N is the number of columns in table pTab
108113 Trigger *pTrigger, /* List of triggers on table pTab */
108117 Table *pTab, /* The table to code triggers from */
108130 /* Sanity checking: The schema for the trigger and for the table are
108131 ** always defined. The trigger must be in the same schema as the table
108149 ** Triggers may access values stored in the old.* or new.* pseudo-table.
108156 ** table may be accessed using an [old|new].<col> reference. Bit 1 is set if
108158 ** are more than 32 columns in the table, and at least one of the columns
108165 ** applies to the old.* table. If 1, the new.* table.
108175 Trigger *pTrigger, /* List of triggers on table pTab */
108179 Table *pTab, /* The table to code triggers from */
108225 SrcList *pSrc, /* The virtual table to be modified */
108226 Table *pTab, /* The virtual table */
108237 ** i-th column of table pTab. This routine sets the P4 parameter of the
108241 ** column definition. This was either supplied by the user when the table
108242 ** was created, or added later to the table definition by an ALTER TABLE
108243 ** command. If the latter, then the row-records in the table btree on disk
108249 ** Column definitions created by an ALTER TABLE command may only have
108252 ** when the ALTER TABLE is executed and one of the literal values written
108253 ** into the sqlite_master table.)
108265 SQLITE_PRIVATE void sqlite3ColumnDefault(Vdbe *v, Table *pTab, int i, int iReg){
108295 SrcList *pTabList, /* The table in which we should change things */
108301 Table *pTab; /* The table to be updated */
108314 ** an expression for the i-th column of the table.
108317 u8 chngPk; /* PRIMARY KEY changed in a WITHOUT ROWID table */
108318 u8 chngRowid; /* Rowid changed in a normal table */
108323 int iDb; /* Database containing the table being updated */
108335 int iEph = 0; /* Ephemeral table holding all primary key values */
108343 int regNew; /* Content of the NEW.* table in triggers */
108344 int regOld = 0; /* Content of OLD.* table in triggers */
108355 /* Locate the table which we want to update.
108361 /* Figure out if we have any triggers and if the table being
108385 /* Allocate a cursors for the main database table and for all indices.
108477 /* There is one entry in the aRegIdx[] array for each index on the table
108534 ** a ephemeral table.
108696 ** table and index records, and as the values for any new.* references
108847 /* Update the sqlite_sequence table by storing the content of the
108886 ** Generate code for an UPDATE of a virtual table.
108888 ** The strategy is that we create an ephemerial table that contains
108895 ** Then we loop over this ephemeral table and for each row in
108896 ** the ephermeral table call VUpdate.
108898 ** When finished, drop the ephemeral table.
108902 ** it out of the ephemeral table before calling VUpdate.
108906 SrcList *pSrc, /* The virtual table to be modified */
108907 Table *pTab, /* The virtual table */
108918 int ephemTab; /* Table holding the result of the SELECT */
108945 /* Create the ephemeral table into which the update results will
108953 /* fill the ephemeral table
108958 /* Generate code to scan the ephemeral table and call VUpdate. */
109214 "SELECT 'CREATE TABLE vacuum_db.' || substr(sql,14) "
109215 " FROM sqlite_master WHERE type='table' AND name!='sqlite_sequence'"
109236 "WHERE type = 'table' AND name!='sqlite_sequence' "
109241 /* Copy over the sequence table
109259 ** from the SQLITE_MASTER table.
109266 " OR (type='table' AND rootpage=0)"
109368 ** Before a virtual table xCreate() or xConnect() method is invoked, the
109375 VTable *pVTable; /* The virtual table being constructed */
109376 Table *pTab; /* The Table object to which the virtual table belongs */
109426 ** External API function used to create a new virtual-table module.
109438 ** External API function used to create a new virtual-table module.
109451 ** Lock the virtual table so that it cannot be disconnected.
109455 ** If a disconnect is attempted while a virtual table is locked,
109464 ** pTab is a pointer to a Table structure representing a virtual-table.
109466 ** this virtual-table, if one has been created, or NULL otherwise.
109468 SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3 *db, Table *pTab){
109476 ** Decrement the ref-count on a virtual table object. When the ref-count
109497 ** Table p is a virtual table. This function moves all elements in the
109503 static VTable *vtabDisconnectAll(sqlite3 *db, Table *p){
109509 ** that contains table p is held by the caller. See header comments
109536 ** Table *p is a virtual table. This function removes the VTable object
109537 ** for table *p associated with database connection db from the linked
109543 SQLITE_PRIVATE void sqlite3VtabDisconnect(sqlite3 *db, Table *p){
109562 ** Disconnect all the virtual table objects in the sqlite3.pDisconnect list.
109574 ** associated with the database the virtual table is stored in is held
109575 ** or, if the virtual table is stored in a non-sharable database, then
109599 ** Clear any and all virtual-table information from the Table record.
109600 ** This routine is called, for example, just before deleting the Table
109603 ** Since it is a virtual-table, the Table structure contains a pointer
109612 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table *p){
109626 ** string will be freed automatically when the table is
109629 static void addModuleArgument(sqlite3 *db, Table *pTable, char *zArg){
109650 ** The parser calls this routine when it first sees a CREATE VIRTUAL TABLE
109656 Token *pName1, /* Name of new table, or database name */
109657 Token *pName2, /* Name of new table or NULL */
109658 Token *pModuleName, /* Name of the module for the virtual table */
109659 int ifNotExists /* No error if the table already exists */
109661 int iDb; /* The database the table is being created in */
109662 Table *pTable; /* The new virtual table */
109682 /* Creating a virtual table invokes the authorization callback twice.
109684 ** sqlite_master table, has already been made by sqlite3StartTable().
109685 ** The second call, to obtain permission to create the table, is made now.
109697 ** virtual table currently under construction in pParse->pTable.
109709 ** The parser calls this routine after the CREATE VIRTUAL TABLE statement
109713 Table *pTab = pParse->pNewTable; /* The table being constructed */
109721 /* If the CREATE VIRTUAL TABLE statement is being entered for the
109722 ** first time (in other words if the virtual table is actually being
109725 ** in the sqlite_master table.
109733 /* Compute the complete text of the CREATE VIRTUAL TABLE statement */
109737 zStmt = sqlite3MPrintf(db, "CREATE VIRTUAL TABLE %T", &pParse->sNameToken);
109740 ** SQLITE_MASTER table. We just need to update that slot with all
109744 ** entry in the sqlite_master table tht was created for this vtab
109750 "SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q "
109763 zWhere = sqlite3MPrintf(db, "name='%q' AND type='table'", pTab->zName);
109769 /* If we are rereading the sqlite_master table create the in-memory
109770 ** record of the table. The xConnect() method is not called until
109771 ** the first time the virtual table is used in an SQL statement. This
109773 ** the required virtual table implementations are registered. */
109775 Table *pOld;
109792 ** of an argument to the module name in a CREATE VIRTUAL TABLE statement.
109802 ** in an argument to the module name in a CREATE VIRTUAL TABLE statement.
109816 ** Invoke a virtual table constructor (either xCreate or xConnect). The
109822 Table *pTab,
109851 /* Invoke the virtual table constructor */
109884 ** columns of the table to see if any of them contain the token "hidden".
109928 ** of the virtual table pTab. If an error occurs, an error code is returned
109931 ** This call is a no-op if table pTab is not a virtual table.
109933 SQLITE_PRIVATE int sqlite3VtabCallConnect(Parse *pParse, Table *pTab){
109944 /* Locate the required virtual table module */
109965 ** more v-table. Return SQLITE_NOMEM if a malloc fails, or SQLITE_OK otherwise.
109986 ** Add the virtual table pVTab to the array sqlite3.aVTrans[]. Space should
109997 ** of the virtual table named zTab in database iDb.
110005 Table *pTab;
110012 /* Locate the required virtual table module */
110040 ** This function is used to set the schema of a virtual table. It is only
110042 ** virtual table module.
110048 Table *pTab;
110103 ** of the virtual table named zTab in database iDb. This occurs
110104 ** when a DROP TABLE is mentioned.
110106 ** This call is a no-op if zTab is not a virtual table.
110110 Table *pTab;
110203 ** If the virtual table pVtab supports the transaction interface
110253 ** as the second argument to the virtual table method invoked.
110257 ** SAVEPOINT_RELEASE, then the xRelease method of each virtual table with
110260 ** If any virtual table method returns an error code other than SQLITE_OK,
110262 ** function immediately. If all calls to virtual table methods are successful,
110301 ** If pExpr is a column in a virtual table, then let the virtual
110302 ** table implementation have an opportunity to overload the function.
110304 ** This routine is used to allow virtual table implementations to
110317 Table *pTab;
110328 /* Check to see the left operand is a column in a virtual table */
110340 /* Call the xFindFunction method on the virtual table implementation
110372 ** Make sure virtual table pTab is contained in the pParse->apVirtualLock[]
110377 SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse *pParse, Table *pTab){
110380 Table **apVtabLock;
110398 ** table update operation currently in progress.
110416 ** of the virtual table being implemented.
110464 ** generating the code that loops through a table looking for applicable
110534 int iTabCur; /* The VDBE cursor used to access the table */
110576 Bitmask maskSelf; /* Bitmask identifying table iTab */
110580 u8 iTab; /* Position in FROM clause of table for this loop */
110922 #define WHERE_IDX_ONLY 0x00000040 /* Use index only - omit table */
110984 ** table and iaCur[1] gets the cursor used by an auxiliary index.
111204 ** There is one cursor per table in the FROM clause. The number of
111434 ** for terms of the form "X <op> <expr>" where X is column iColumn of table
111479 ** where X is a reference to the iColumn of table iCur and <op> is one of
111496 ** the form "X <op> Y" where Y is a column in another table if no terms of
111706 ** a single table T (as shown in example B above) then create a new virtual
111718 ** If all subterms are indexable by a single table T, then set
111721 ** WhereTerm.u.pOrInfo->indexable |= the cursor number for table T
111724 ** "T.C <op> <expr>" where C is any column of table T and
111858 ** something other than == on a column in the single table. The 1-bit
111860 ** "table.column=expr" for some single table. The one bit that is set
111861 ** will correspond to the common table. We still need to check to make
111868 ** Note that terms of the form "table.column1=table.column2" (the
111869 ** same table on both sizes of the ==) cannot be optimized.
111874 int iCursor = -1; /* Table cursor common to all terms */
111877 /* Search for a table and column that appears on one side or the
111878 ** other of the == operator in every subterm. That table and column
111880 ** such table and column. Set okToChngToIN if an appropriate table
111909 /* No candidate table+column was found. This can only occur
111918 /* We have found a candidate table and column. Check to see if that
111919 ** table and column is common to every term in the OR clause */
112011 WhereMaskSet *pMaskSet; /* Set of table index masks */
112049 ** on left table of a LEFT JOIN. Ticket #3015 */
112316 int iBase, /* Cursor for table associated with pIdx */
112352 Table *pTab;
112357 /* If there is more than one table or sub-select in the FROM clause of
112364 /* If any of the expressions is an IPK column on table iBase, then return
112373 /* Loop through all indices on the table, checking each to see if it makes
112467 struct SrcList_item *pSrc, /* Table we are trying to access */
112501 Table *pTable; /* The table being indexed */
112554 ** original table never needs to be accessed. Automatic indices must
112556 ** original table changes and the index and table cannot both be used
112662 ** to this virtual table */
112675 ** virtual table then allocate space for the aOrderBy part of
112751 ** The table object reference passed as the second argument to this function
112752 ** must represent a virtual table. This function invokes the xBestIndex()
112753 ** method of the virtual table with the sqlite3_index_info object that
112764 static int vtabBestIndex(Parse *pParse, Table *pTab, sqlite3_index_info *p){
112788 "table %s: xBestIndex returned an invalid plan", pTab->zName);
113481 ** For example, consider table t1(a,b,c,d,e,f) with index i1(a,b,c).
113513 ** CREATE TABLE t1(a TEXT PRIMARY KEY, b);
113642 ** Argument pLevel describes a strategy for scanning table pTab. This
113644 ** of the subset of table rows scanned by the strategy in the form of an
113660 static char *explainIndexRange(sqlite3 *db, WhereLoop *pLoop, Table *pTab){
113703 ** record is added to the output to describe the table scan strategy in
113708 SrcList *pTabList, /* Table list this loop refers to */
113739 zMsg = sqlite3MAppendf(db, zMsg, "%s TABLE %s", zMsg, pItem->zName);
113778 zMsg = sqlite3MAppendf(db, zMsg, "%s VIRTUAL TABLE INDEX %d:%s", zMsg,
113801 int iCur; /* The VDBE cursor for the table */
113845 /* If this is the right table of a LEFT OUTER JOIN, allocate and
113846 ** initialize a memory cell that records if this table matches any
113847 ** row of the left table of the join.
113867 /* Case 1: The table is a virtual-table. Use the VFilter and VNext
114243 /* Seek the table cursor, if required */
114247 /* pIdx is a covering index. No need to access the main table. */
114289 ** CREATE TABLE t1(a,b,c,d);
114323 ** Added 2014-05-26: If the table is a WITHOUT ROWID table, then
114329 SrcList *pOrTab; /* Shortened table list or OR-clause generation */
114342 Table *pTab = pTabItem->pTab;
114352 /* Set up a new SrcList in pOrTab containing the table being scanned
114448 /* Loop through table entries that match term pOrTerm. */
114481 /* Check if the temp table already contains this key. If so,
114484 ** insert the key into the temp table and proceed with processing
114489 ** the temp table. And if iSet is -1, assume that there is no
114490 ** need to insert the key into the temp table, as it will never
114515 ** contained one or more AND term from a notReady table. The
114516 ** terms from the notReady table could not be tested and will
114546 /* Finish the loop through table entries that match term pOrTerm. */
114568 ** scan of the entire table.
114644 ** at least one row of the right table has matched the left table.
114692 Table *pTab = pItem->pTab;
115189 int iCol; /* Index of the column in the table */
115191 LogEst rLogSize; /* Logarithm of table size */
115379 ** visiting the rows in the main table. */
115450 ** the table is used by an index. Only the first 63 columns are considered.
115479 ** Add all WhereLoop objects for a single table of the join where the table
115480 ** is idenfied by pBuilder->pNew->iTab. That table is guaranteed to be
115481 ** a b-tree table, not a virtual table.
115486 ** For a full scan, assuming the table (or index) contains nRow rows:
115488 ** cost = nRow * 3.0 // full-table scan
115493 ** estimated average size of the index and table records.
115512 ** of a full table scan.
115516 Bitmask mExtra /* Extra prerequesites for using this table */
115529 LogEst rSize; /* number of rows in the table */
115530 LogEst rLogSize; /* Logarithm of the number of rows in the table */
115532 Table *pTab; /* Table being queried */
115552 Index *pFirst; /* First of real indices on the table */
115565 /* The real indices of the table are only considered if the
115598 ** the table being indexed. */
115601 /* TUNING: Each index lookup yields 20 rows in the table. This
115638 /* Full table scan */
115640 /* TUNING: Cost of full table scan is (N*3.0). */
115672 ** index and table rows. If this is a non-covering index scan,
115673 ** also add the cost of visiting table rows (N*3.0). */
115702 ** Add all WhereLoop objects for a table
115703 ** pBuilder->pNew->iTab. That table is guaranteed to be a virtual table.
115713 Table *pTab;
115827 /* Do not attempt to use an IN constraint if the virtual table
115833 /* A virtual table that is constrained by an IN clause may not
115966 ** the planner may elect to "OR" together a full-table scan and an
116057 int iColumn; /* A column number within table iCur */
116086 ** The rowid for a table is always UNIQUE and NOT NULL so whenever the
116110 /* Mark off any ORDER BY term X that is a column in the table of
116171 /* Get the column number in the table (iColumn) and sort order
116699 ** Most queries use only a single table (they are not joins) and have
116717 Table *pTab;
116793 ** The basic idea is to do a nested loop, one loop for each table in
116795 ** same as a SELECT with only a single table in the FROM clause.) For
116816 ** There are Btree cursors associated with each table. t1 uses cursor
116829 ** refer to those indices, a complete table scan can be avoided and the
116921 ** only generate code for the first table in pTabList and assume that
116992 ** its Expr.iRightJoinTable value to find the bitmask of the right table
116993 ** of the join. Subtracting one from the right table bitmask gives a
117167 Table *pTab; /* Table to open */
117168 int iDb; /* Index of database containing table/index */
117219 ** WITHOUT ROWID table. No need for a separate index */
117369 Table *pTab = pTabItem->pTab;
117373 /* For a co-routine, change all OP_Column references to the table of
117419 ** from the index instead of from the table where possible. In some cases
117420 ** this optimization prevents the table from ever being read, which can
117424 ** sqlite3WhereEnd will have created code that references the table
117426 ** that reference the table and converts them into opcodes that
117626 ** table.
117724 ** slots in the yy_action[] table.
117726 ** The action table is constructed as a single large table named yy_action[].
117733 ** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table
117744 ** yy_action[] A single table containing all actions.
117745 ** yy_lookahead[] A table containing the lookahead for each entry in
118212 /* The next table maps tokens into fallback tokens. If a construct
118240 0, /* TABLE => nothing */
118370 ** are required. The following table supplies these names */
118376 "TABLE", "CREATE", "IF", "NOT",
118469 /* 26 */ "create_table ::= createkw temp TABLE ifnotexists nm dbnm",
118549 /* 106 */ "cmd ::= DROP TABLE ifexists fullname",
118747 /* 304 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
118748 /* 305 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column",
118754 /* 311 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm",
119155 /* The following table contains information about every rule that
119590 case 26: /* create_table ::= createkw temp TABLE ifnotexists nm dbnm */
119642 sqlite3ErrorMsg(pParse, "unknown table option: %.*s", yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.z);
119822 case 106: /* cmd ::= DROP TABLE ifexists fullname */
120579 "qualified table names are not allowed on INSERT, UPDATE, and DELETE "
120662 case 304: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
120667 case 305: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column */
120684 case 311: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
121083 ** might be implemented more directly using a hand-written hash table.
121235 testcase( i==19 ); /* TABLE */
121782 /* If the pParse->declareVtab flag is set, do not delete any table
121784 ** will take responsibility for freeing the Table structure.
121799 Table *p = pParse->pZombieTab;
122980 Table *pTab = (Table *)sqliteHashData(p);
123028 ** SQL statements below, as the v-table implementation may be storing
123079 HashElem *i; /* Hash table iterator */
123360 /* SQLITE_LOCKED */ "database table is locked",
123370 /* SQLITE_EMPTY */ "table contains no data",
123407 int count /* Number of times table has been busy */
123571 ** to the hash table.
123712 ** Declare that a function has been overloaded by a virtual table.
124009 ** following table describes the relationship between these two values
124150 Table *pTab; /* A table in the database */
124157 pTab = (Table*)sqliteHashData(k);
125078 ** Return meta information about a specific column of a database table.
125085 const char *zTableName, /* Table name */
125095 Table *pTab = 0;
125113 /* Locate the table in question */
125146 ** 2. The table is not a view and the column name identified an
125178 zErrMsg = sqlite3MPrintf(db, "no such table column: %s.%s", zTableName,
126119 ** the %_segments table in sorted order. This means that when the end
126183 ** The segment directory in table %_segdir stores meta-information for
126223 ** leaf nodes are written in to the %_segments table in order, this
126342 ** When an fts3 table is created, it passes any arguments passed to
126343 ** the tokenizer clause of the CREATE VIRTUAL TABLE statement to the
126347 ** be used for the fts3 table (customized by the tokenizer clause arguments).
126369 ** TABLE statement that created the fts3 table. For example, if
126485 ** This is the header file for the generic hash-table implementation
126487 ** hash table implementation for the full-text indexing module.
126497 /* A complete hash table is an instance of the following structure.
126508 int count; /* Number of entries in this table */
126510 int htsize; /* Number of buckets in the hash table */
126511 struct _fts3ht { /* the hash table */
126517 /* Each element in the hash table is an instance of the following
126524 Fts3HashElem *next, *prev; /* Next and previous elements in the table */
126530 ** There are 2 different modes of operation for a hash table:
126563 ** Macros for looping over all elements of a hash table. The idiom is
126581 ** Number of entries in a hash table
126611 ** Fts3Table.pendingTerms hash table. Normally, the hash table is
126615 ** segment is created and the hash table cleared immediately.
126754 const char *zName; /* virtual table name */
126755 int nColumn; /* number of named columns in virtual table */
126765 ** statements is run and reset within a single virtual table API call.
126774 u8 bHasStat; /* True if %_stat table exists (2==unknown) */
126775 u8 bHasDocsize; /* True if %_docsize table exists */
126779 char *zSegmentsTbl; /* Name of %_segments table */
126780 sqlite3_blob *pSegments; /* Blob handle open on %_segments table */
126788 ** A single FTS4 table may have multiple full-text indexes. For each index
126794 ** pending data structures, including hash table overhead, but not including
126802 Fts3Hash hPending; /* Pending terms table for this index */
126811 ** methods of the virtual table are called at appropriate times. These
126827 ** When the core wants to read from the virtual table, it creates a
126828 ** virtual table cursor (an instance of the following structure) using
126848 sqlite3_int64 nDoc; /* Documents in table */
126867 ** CREATE VIRTUAL TABLE ex1 USING fts3(a,b,c,d);
126876 #define FTS3_FULLSCAN_SEARCH 0 /* Linear scan of %_content table */
126877 #define FTS3_DOCID_SEARCH 1 /* Lookup by rowid on %_content table */
126945 ** where nCol is the number of columns in the queried FTS table. The array
127331 ** The xDisconnect() virtual table method.
127385 ** The xDestroy() virtual table method.
127395 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_content'", zDb, p->zName);
127397 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_segments'", zDb,p->zName);
127398 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_segdir'", zDb, p->zName);
127399 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_docsize'", zDb, p->zName);
127400 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_stat'", zDb, p->zName);
127411 ** Invoke sqlite3_declare_vtab() to declare the schema for the FTS3 table
127430 /* Create a list of user columns for the virtual table */
127436 /* Create the whole "CREATE TABLE" statement to pass to SQLite */
127438 "CREATE TABLE x(%s %Q HIDDEN, docid HIDDEN, %Q HIDDEN)",
127454 ** Create the %_stat table if it does not already exist.
127458 "CREATE TABLE IF NOT EXISTS %Q.'%q_stat'"
127467 ** required by the FTS3 table passed as the only argument. This is done
127471 ** FTS4 table, not an FTS3 table) then also create the %_docsize and
127481 char *zContentCols; /* Columns of %_content table */
127483 /* Create a list of user columns for the content table */
127494 /* Create the content table */
127496 "CREATE TABLE %Q.'%q_content'(%s)",
127504 "CREATE TABLE %Q.'%q_segments'(blockid INTEGER PRIMARY KEY, block BLOB);",
127508 "CREATE TABLE %Q.'%q_segdir'("
127521 "CREATE TABLE %Q.'%q_docsize'(docid INTEGER PRIMARY KEY, size BLOB);",
127660 ** table has the three user-defined columns "a", "b", and "c", the following
127712 ** of columns in the %_content table (one for the docid plus one for each
127717 ** bracket. For example, if zFunc is "zip" and the FTS3 table has three
127780 ** representing the indexes maintained by the current FTS table. FTS tables
127783 ** (if any) specified as part of the CREATE VIRTUAL TABLE statement.
127798 struct Fts3Index **apIndex /* OUT: Array of indexes for this table */
127834 ** This function is called when initializing an FTS4 table that uses the
127836 ** of the new FTS4 table.
127840 ** a table of that name. If found, the output variables are populated
127843 ** *pnCol: Set to the number of columns table xxx has,
127849 ** the name of the corresponding column in table xxx. The array
127854 ** If the table cannot be found, an error code is returned and the output
127861 const char *zTbl, /* Name of content table */
127881 int nCol; /* Number of table columns */
127920 ** methods of the FTS3 virtual table.
127926 ** argv[2] -> table name
127932 void *pAux, /* Hash table containing tokenizers */
127945 int nCol = 0; /* Number of columns in the FTS table */
127948 int nName; /* Bytes required to hold table name */
127951 sqlite3_tokenizer *pTokenizer = 0; /* Tokenizer for this table */
127954 struct Fts3Index *aIndex = 0; /* Array of indexes for this table */
127957 int bNoDocsize = 0; /* True to omit %_docsize table */
127993 ** + Figures out the number of columns the FTSX table will have, and
128116 ** TABLE statement, use all columns from the content table.
128264 /* Check to see if a legacy fts3 table has been "upgraded" by the
128265 ** addition of a %_stat table so that it can use incremental merge.
128276 /* Declare the table schema to SQLite. */
128303 ** The xConnect() and xCreate() methods for the virtual table. All the
128308 void *pAux, /* Pointer to tokenizer hash table */
128318 void *pAux, /* Pointer to tokenizer hash table */
128346 ** 3. Linear scan of %_content table.
128358 /* By default use a full table scan. This is an expensive option,
128489 ** on the xClose method of the virtual table interface.
128510 ** (or the equivalent for a content=xxx table) and set pCsr->pStmt to
128531 ** of the %_content table that contains the last match. Return
128549 ** table is missing a row that is present in the full-text index.
128605 ** table, then there are always 20 bytes of zeroed padding following the
128701 Fts3Table *p, /* Virtual table handle */
128719 char *zBlob = 0; /* Blob read from %_segments table */
129512 Fts3Table *p, /* FTS table handle */
129595 Fts3Table *p, /* FTS3 table handle */
129611 ** made by an fts4aux module, not an FTS table. In this case calling
129669 Fts3Table *p, /* FTS3 table handle */
129701 Fts3Table *p, /* FTS virtual table handle */
129726 Fts3Cursor *pCsr, /* Virtual table cursor handle */
129792 Fts3Table *p, /* Virtual table handle */
129864 ** Advance the cursor to the next row in the %_content table that
129866 ** the next row that matches. For a full-table scan, this will be
129867 ** simply the next row in the %_content table. For a docid lookup,
129920 ** This is the xFilter interface for the virtual table. See
129921 ** the virtual table xFilter method documentation for additional
129924 ** If idxNum==FTS3_FULLSCAN_SEARCH then do a full table scan against
129925 ** the %_content table.
129928 ** in the %_content table.
130013 /* Compile a SELECT statement for this cursor. For a full-table-scan, the
130014 ** statement loops through all rows of the %_content table. For a
130041 ** This is the xEof method of the virtual table. SQLite calls this
130051 ** exposes %_content.docid as the rowid for the virtual table. The
130067 ** (iCol == p->nColumn) -> Magic column with the same name as the table.
130089 /* The extra column whose name is the same as the table.
130122 sqlite3_vtab *pVtab, /* Virtual table handle */
130132 ** hash-table to the database.
130151 ** of blocks from the segments table. But this is not considered overhead
130178 ** If it is currently unknown whether or not the FTS table has an %_stat
130179 ** table (if p->bHasStat==2), attempt to determine this (set p->bHasStat
130221 ** the pending-terms hash-table have already been flushed into the database
130237 ** hash-table. Any changes made to the database are reverted by SQLite.
130365 ** where 't' is the name of an FTS3 table.
130373 Fts3Table *p; /* Virtual table handle */
130419 ** virtual table.
130422 sqlite3_vtab *pVtab, /* Virtual table handle */
130455 ** Implementation of FTS3 xRename method. Rename an fts3 table.
130458 sqlite3_vtab *pVtab, /* Virtual table handle */
130459 const char *zName /* New name of table */
130465 /* At this point it must be known if the %_stat table exists or not.
130469 /* As it happens, the pending terms table is always empty here. This is
130470 ** because an "ALTER TABLE RENAME TABLE" statement inside a transaction
130472 ** flushes the pending terms table. But leave the (no-op) call to
130482 "ALTER TABLE %Q.'%q_content' RENAME TO '%q_content';",
130489 "ALTER TABLE %Q.'%q_docsize' RENAME TO '%q_docsize';",
130495 "ALTER TABLE %Q.'%q_stat' RENAME TO '%q_stat';",
130500 "ALTER TABLE %Q.'%q_segments' RENAME TO '%q_segments';",
130504 "ALTER TABLE %Q.'%q_segdir' RENAME TO '%q_segdir';",
130513 ** Flush the contents of the pending-terms table to disk.
130545 ** Discard the contents of the pending terms table.
130586 ** allocated for the tokenizer hash table.
130648 /* Allocate and initialize the hash-table used to store tokenizers. */
130656 /* Load the built-in tokenizers into the hash table */
130678 /* Create the virtual table wrapper around the hash-table and overload
130717 /* An error has occurred. Delete the hash table and return the error code. */
130782 Fts3Table *pTab, /* FTS Table pointer */
131203 Fts3Table *pTab, /* Virtual table handle */
131494 ** of data that will fit on a single leaf page of an intkey table in
131502 ** data from the %_stat table to calculate it.
131504 ** Entry 0 of the %_stat table is a blob containing (nCol+1) FTS3
131505 ** varints, where nCol is the number of columns in the FTS3 table.
131507 ** the table. The following nCol varints contain the total amount of
131508 ** data stored in all rows of each column of the table, from left
131577 ** table actually contains the same data as the index. To prevent this from
132159 ** 2. After scanning the current FTS table row for the deferred tokens,
132408 ** the FTS table (considering all rows), and
132410 ** 2. For each column, the number of rows in the table for which the
132422 ** values are set to the number of documents in the table. In other
132424 ** column of each row of the table.
132649 ** Initialize API pointer table, if required.
132713 ** Schema of the terms table.
132716 "CREATE TABLE x(term, col, documents, occurrences, languageid HIDDEN)"
132732 char const *zFts3; /* Name of fts3 table */
132737 Fts3auxTable *p; /* Virtual table object to return */
132743 ** CREATE VIRTUAL TABLE xxx USING fts4aux(fts4-table);
132744 ** CREATE VIRTUAL TABLE xxx USING fts4aux(fts4-table-db, fts4-table);
133314 const char **azCol; /* Array of column names for fts3 table */
134155 char **azCol, /* Array of column names for fts3 table */
134206 ** of each column in the target fts3 table, in order from left to right.
134209 ** The iDefaultCol parameter should be passed the index of the table column
134213 ** match any table column.
134218 char **azCol, /* Array of column names for fts3 table */
134304 ** Function to query the hash-table of tokenizers (see README.tokenizers).
134393 ** of a column of the fts3 table that the query expression may refer to.
134517 ** We've modified it slightly to serve as a standalone hash table
134551 /* Turn bulk memory into a hash table object by initializing the
134554 ** "pNew" is a pointer to the hash table that is to be initialized.
134557 ** determines what kind of key the hash table will use. "copyKey" is
134558 ** true if the hash table should make its own private copy of keys and
134572 /* Remove all entries from a hash table. Reclaim all memory.
134573 ** Call this routine to delete a hash table or to reset a hash table
134577 Fts3HashElem *elem; /* For looping over all elements of the table */
134666 /* Link an element into the hash table
134669 Fts3Hash *pH, /* The complete hash table */
134692 /* Resize the hash table so that it cantains "new_size" buckets.
134693 ** "new_size" must be a power of 2. The hash table might fail
134699 struct _fts3ht *new_ht; /* The new hash table */
134719 ** hash table that matches the given key. The hash for this key has
134747 /* Remove a single entry from the hash table given a pointer to that
134801 ** Attempt to locate an element of the hash table pH with a key
134812 /* Insert an element into the hash table pH. The key is pKey,nKey
134822 ** the new data is returned and the hash table is unchanged.
134825 ** element corresponding to "key" is removed from the hash table.
134828 Fts3Hash *pH, /* The hash table to insert into */
134834 int h; /* the hash of the key modulo hash table size */
135584 ** hash table. This function may be called as follows:
135595 ** the string <key-name> must already exist in the has table. Otherwise,
135600 ** to string <key-name> (after the hash-table is updated, if applicable).
135697 Fts3Hash *pHash, /* Tokenizer hash table */
135980 ** the hash table pointed to by argument pHash. The hash table must
135988 ** defined at compilation time, a temporary virtual table (see header
135993 ** of both the scalar and, if created, the virtual table.
136111 ** else we need to reindex. One solution would be a meta-table to
136289 ** This file contains code for the "fts3tokenize" virtual table module.
136290 ** An fts3tokenize virtual table is created as follows:
136292 ** CREATE VIRTUAL TABLE <tbl> USING fts3tokenize(
136296 ** The table created has the following schema:
136298 ** CREATE TABLE <tbl>(input, token, start, end, position)
136304 ** The virtual table module tokenizes this <string>, using the FTS3
136305 ** tokenizer specified by the arguments to the CREATE VIRTUAL TABLE
136326 ** Virtual table structure.
136335 ** Virtual table cursor structure.
136419 ** Schema of the tokenizer table.
136421 #define FTS3_TOK_SCHEMA "CREATE TABLE x(input, token, start, end, position)"
136430 ** argv[2]: table name
136435 void *pHash, /* Hash table of tokenizers */
136659 /* CREATE TABLE x(input, token, start, end, position) */
136776 ** win (reduced IO and CPU) if SQLite stops calling the virtual table xNext()
136941 ** or the pending-terms table being flushed), leaves are written into the
137019 Fts3Table *p, /* Virtual table handle */
137086 ** Read a single entry from the %_segdir table. The entry from absolute
137159 Fts3Table *pTab, /* FTS3 table handle */
137184 Fts3Table *pTab, /* Fts3 table handle */
137205 Fts3Table *pTab, /* Fts3 table handle */
137222 Fts3Table *p, /* The FTS3 table */
137240 ** shared-cache table-lock on the %_segdir table. This is required before
137241 ** writing data to the fts3 table. If this lock is not acquired first, then
137277 ** in the %_segdir table on disk. This function is used to convert three
137279 ** can be used to query the %_segdir table.
137292 Fts3Table *p, /* FTS3 table handle */
137308 ** all rows in the %_segdir table, from oldest to newest. If successful,
137313 ** each FTS3 table.
137315 ** The statement returns the following columns from the %_segdir table:
137324 Fts3Table *p, /* FTS3 table */
137480 Fts3Hash *pHash, /* Pending terms hash table to add entry to */
137509 ** pending-terms hash-table. The docid used is that currently stored in
137515 Fts3Table *p, /* Table into which text will be inserted */
137539 ** zText==0. In this case, add zero token entries to the hash table and
137593 Fts3Table *p, /* Full-text table handle */
137637 ** pendingTerms hash table.
137673 ** apVal[p->nColumn+2] Hidden column with same name as table
137678 Fts3Table *p, /* Full-text table */
137698 ** table. The SQL for this statement is:
137703 ** defined columns in the FTS3 table, plus one for the docid field.
137748 ** Remove all data from the FTS3 table. Clear the hash table containing
137754 /* Discard the contents of the pending-terms hash table. */
137788 Fts3Table *p, /* The FTS table to delete from */
137833 ** This function allocates a new level iLevel index in the segdir table.
137892 ** The %_segments table is declared as follows:
137894 ** CREATE TABLE %_segments(blockid INTEGER PRIMARY KEY, block BLOB)
137896 ** This function reads data from a single row of the %_segments table. The
137900 ** identified table row is. Whether or not paBlob is NULL, *pnBlob is set
137903 ** If an error occurs, or the table does not contain the specified row,
137914 ** on the database file for longer than necessary). Thus, any virtual table
137919 Fts3Table *p, /* FTS3 table handle */
138183 /* A pending-terms seg-reader for an FTS4 table that uses order=desc.
138357 ** the contents of the pending-terms hash table to the database.
138378 ** through each term in the pending-terms table. Or, if isPrefixIter is
138380 ** the pending terms hash table contains the terms "sqlite", "mysql" and
138393 Fts3Table *p, /* Virtual table handle */
138610 ** Insert a record into the %_segments table.
138613 Fts3Table *p, /* Virtual table handle */
138630 ** Find the largest relative level number in the table. If successful, set
138651 ** Insert a record into the %_segdir table.
138654 Fts3Table *p, /* Virtual table handle */
138710 Fts3Table *p, /* Virtual table handle */
138847 Fts3Table *p, /* Virtual table handle */
138916 Fts3Table *p, /* Virtual table handle */
138945 /* Find the next free blockid in the %_segments table */
139058 Fts3Table *p, /* Virtual table handle */
139081 /* The entire tree fits on the root node. Write it to the segdir table. */
139106 ** pRowid would mean the FTS3 table were empty.
139108 ** If successful, *pisEmpty is set to true if the table is empty except for
139116 /* If using the content=xxx option, assume the table is never empty */
139135 ** Segment levels are stored in the 'level' column of the %_segdir table.
139199 ** Delete all entries in the %_segments table associated with the segment
139201 ** of the %_segdir table.
139204 Fts3Table *p, /* FTS table handle */
139236 Fts3Table *p, /* Virtual table handle */
139355 Fts3Table *p, /* Virtual table handle */
139423 Fts3Table *p, /* Virtual table handle */
139455 Fts3Table *p, /* Virtual table handle */
139464 Fts3Table *p, /* Virtual table handle */
139539 Fts3Table *p, /* Virtual table handle */
139777 Fts3Table *p, /* FTS table handle */
139791 /* Loop through all entries in the %_segdir table corresponding to
140050 Fts3Table *p, /* Table into which to insert */
140078 ** Record 0 of the %_stat table contains a blob consisting of N varints,
140079 ** where N is the number of user defined columns in the fts3 table plus
140083 ** Varint 0: Total number of rows in the table.
140086 ** the column for all rows of the table.
140089 ** columns of all rows of the table.
140094 Fts3Table *p, /* Table being updated */
140202 ** The entire FTS index is discarded and rebuilt. If the table is one
140204 ** the current contents of the xxx table. Otherwise, it is rebuilt based
140205 ** on the contents of the %_content table.
140218 /* Compose and prepare an SQL statement to loop through the content table */
140288 Fts3Table *p, /* FTS3 table handle */
140502 Fts3Table *p, /* Fts3 table handle */
140653 Fts3Table *p, /* Fts3 table handle */
140738 Fts3Table *p, /* FTS3 table handle */
140765 ** table. However, this is not permitted in this case. The problem is that
140766 ** space has already been reserved in the %_segments table, and so the
140767 ** start_block and end_block fields of the %_segdir table must be populated.
140776 ** table until we are sure it is needed.
140842 ** Query to see if the entry in the %_segments table with blockid iEnd is
140850 ** is, then a NULL entry has been inserted into the %_segments table
140885 Fts3Table *p, /* Fts3 table handle */
140922 /* Check for the zero-length marker in the %_segments table */
141017 Fts3Table *p, /* FTS Table handle */
141039 ** In the %_segdir table, a segment is defined by the values in three
141062 Fts3Table *p, /* Fts3 table handle */
141098 /* Insert the marker in the %_segments table to make sure nobody tries
141116 ** Remove an entry from the %_segdir table. This involves running the
141127 Fts3Table *p, /* FTS3 table handle */
141151 Fts3Table *p, /* FTS3 table handle */
141274 ** table, and modifying existing entries in both the %_segments and %_segdir
141281 Fts3Table *p, /* FTS3 table handle */
141366 Fts3Table *p, /* FTS table handle */
141433 ** exists, is stored in the rowid==1 row of the %_stat table.
141436 ** table and return SQLITE_OK. Otherwise, if an error occurs, return an
141530 Blob hint = {0, 0, 0}; /* Hint read from %_stat table */
141547 /* Search the %_segdir table for the absolute level with the smallest
141563 /* If the hint read from the %_stat table is not empty, check if the
141587 ** nMin segments and no hint in the %_stat table. No work to do.
141658 /* Write the hint values into the %_stat table for the next incr-merger */
141684 ** INSERT INTO table(table) VALUES('merge=A,B');
141691 Fts3Table *p, /* FTS3 table handle */
141728 ** INSERT INTO table(table) VALUES('automerge=X');
141734 Fts3Table *p, /* FTS3 table handle */
141792 Fts3Table *p, /* FTS3 table handle */
141858 ** content table. If no error occurs and the contents do match, set *pbOk
141887 /* This block calculates the checksum according to the %_content table */
141974 ** 2. By scanning and tokenizing the content table.
141980 Fts3Table *p /* FTS3 table handle */
142066 ** table, not for all rows.
142071 int i; /* Used to iterate through table columns */
142152 Fts3Cursor *pCsr, /* Fts3 table cursor */
142176 ** present in the FTS3 table. If it is, delete it and adjust the contents
142186 int bFound = 0; /* True if *pRowid really is in the table */
142190 int isEmpty = 0; /* Deleting *pRowid leaves the table empty */
142194 /* Deleting this row means the whole table is empty. In this case
142196 ** data in the pendingTerms hash table. */
142217 ** tables. The schema of the virtual table being:
142219 ** CREATE TABLE <table name>(
142221 ** <table name> HIDDEN,
142242 /* At this point it must be known if the %_stat table exists or not.
142308 ** the %_content table. If we hit the duplicate rowid constraint (or any
142370 ** Flush any data in the pending-terms hash table to disk. If successful,
142481 int nCol; /* Number of columns in table */
142931 Fts3Table *pTab, /* FTS3 table snippet comes from */
143151 ** rows of the table. Y is the number of rows for which column iCol contains
143448 sqlite3_int64 nDoc; /* Number of rows in table */
143637 /* Loop through all columns of the table being considered for snippets.
143639 ** columns of the FTS3 table. Otherwise, only column iCol is considered.
143697 int iCol; /* Column of table to populate aTerm for */
143768 /* Loop through the table columns, appending offset information to
143875 Fts3Cursor *pCsr, /* FTS3 table cursor */
144029 ** As part of a tokenchars= or separators= option, the CREATE VIRTUAL TABLE
144030 ** statement has specified that the tokenizer for this table shall consider
144692 ** algorithms packaged as an SQLite virtual table module.
144699 ** The data structure for a single virtual r-tree table is stored in three
144701 ** in the table name is replaced with the user-supplied name of the r-tree
144702 ** table.
144704 ** CREATE TABLE %_node(nodeno INTEGER PRIMARY KEY, data BLOB)
144705 ** CREATE TABLE %_parent(nodeno INTEGER PRIMARY KEY, parentnode INTEGER)
144706 ** CREATE TABLE %_rowid(rowid INTEGER PRIMARY KEY, nodeno INTEGER)
144709 ** table. For each node that is not the root node of the r-tree, there is
144710 ** an entry in the %_parent table associating the node with its parent.
144711 ** And for each row of data in the table, there is an entry in the %_rowid
144712 ** table that maps from the entries rowid to the id of the node that it
144715 ** The root node of an r-tree always exists, even if the r-tree table is
144717 ** table must be the same size as the root node. The content of each node
144772 /* Size of hash table Rtree.aHash. This hash table is not expected to
144778 /* The xBestIndex method of this virtual table requires an estimate of
144779 ** the number of rows in the virtual table to calculate the costs of
144781 ** sqlite_stat1 table (with RTREE_MIN_ROWEST as a hard-coded minimum).
144789 ** An rtree virtual-table object.
144794 int iNodeSize; /* Size in bytes of each node in the node table */
144799 char *zDb; /* Name of database containing r-tree table */
144800 char *zName; /* Name of r-tree table */
144802 i64 nRowEst; /* Estimated number of rows in this table */
144827 RtreeNode *aHash[HASHSIZE]; /* Hash table of in-memory nodes. */
144835 ** If SQLITE_RTREE_INT_ONLY is defined, then this virtual table will
145122 ** in the Rtree.aHash table.
145129 ** Search the node hash table for node iNode. If found, return a pointer
145139 ** Add node pNode to the node hash table.
145150 ** Remove node pNode from the node hash table.
145195 /* Check if the requested node is already in the hash table. If so,
145428 ** the virtual table module xCreate() and xConnect() methods.
145435 ** Rtree virtual table module xCreate method.
145448 ** Rtree virtual table module xConnect method.
145488 ** Rtree virtual table module xDisconnect method.
145496 ** Rtree virtual table module xDestroy method.
145502 "DROP TABLE '%q'.'%q_node';"
145503 "DROP TABLE '%q'.'%q_rowid';"
145504 "DROP TABLE '%q'.'%q_parent';",
145523 ** Rtree virtual table module xOpen method.
145560 ** Rtree virtual table module xClose method.
145574 ** Rtree virtual table module xEof method.
146062 ** Rtree virtual table module xNext method.
146076 ** Rtree virtual table module xRowid method.
146090 ** Rtree virtual table module xColumn method.
146123 ** return SQLITE_OK. If there is no such record in the table, set
146197 ** Rtree virtual table module xFilter method.
146314 ** Rtree virtual table module xBestIndex method. There are three
146315 ** table scan strategies to choose from (in order from most to
146321 ** 2 See below R-tree query or full-table scan.
146523 Rtree *pRtree, /* Rtree table */
146583 Rtree *pRtree, /* Rtree table */
146609 ** Write mapping (iRowid->iNode) to the <rtree>_rowid table.
146619 ** Write mapping (iNode->iPar) to the <rtree>_parent table.
147106 /* Remove the node from the in-memory hash table and link it into
147388 /* Delete the corresponding entry in the <rtree>_rowid table. */
147486 /* Constraint handling. A write operation on an r-tree table may return
147526 ** the table. If so, the constraint has failed. */
147550 ** record to delete from the r-tree table. The following block does
147597 "ALTER TABLE %Q.'%q_node' RENAME TO \"%w_node\";"
147598 "ALTER TABLE %Q.'%q_parent' RENAME TO \"%w_parent\";"
147599 "ALTER TABLE %Q.'%q_rowid' RENAME TO \"%w_rowid\";"
147613 ** of the number of rows in the virtual table. If possible, this is based
147650 rtreeCreate, /* xCreate - create a table */
147651 rtreeConnect, /* xConnect - connect to an existing table */
147653 rtreeDisconnect, /* xDisconnect - Disconnect from a table */
147654 rtreeDestroy, /* xDestroy - Drop a table */
147668 rtreeRename, /* xRename - rename the table */
147685 /* Read and write the xxx_node table */
147690 /* Read and write the xxx_rowid table */
147695 /* Read and write the xxx_parent table */
147707 "CREATE TABLE \"%w\".\"%w_node\"(nodeno INTEGER PRIMARY KEY, data BLOB);"
147708 "CREATE TABLE \"%w\".\"%w_rowid\"(rowid INTEGER PRIMARY KEY, nodeno INTEGER);"
147709 "CREATE TABLE \"%w\".\"%w_parent\"(nodeno INTEGER PRIMARY KEY,"
147772 ** determine the node-size used by the rtree table being created or connected
147777 ** table already exists. In this case the node-size is determined by inspecting
147822 ** methods of the r-tree virtual table.
147826 ** argv[2] -> table name
147832 int argc, const char *const*argv, /* Parameters to CREATE TABLE statement */
147833 sqlite3_vtab **ppVtab, /* OUT: New virtual table */
147845 "Wrong number of columns for an rtree table", /* 1 */
147846 "Too few columns for an rtree table", /* 2 */
147847 "Too many columns for an rtree table" /* 3 */
147881 ** the r-tree table schema.
147887 char *zSql = sqlite3_mprintf("CREATE TABLE x(%s", argv[3]);
148004 ** virtual table module "rtree" and the debugging/analysis scalar