Home | History | Annotate | Download | only in dist

Lines Matching defs:Table

618 #define SQLITE_LOCKED       6   /* A table in the database is locked */
1923 ** the use of covering indices for full table scans in the query optimizer.
1927 ** The ability to disable the use of covering indices for full table scans
2105 ** the table has a column of type [INTEGER PRIMARY KEY] then that column
2109 ** most recent successful [INSERT] into a rowid table or [virtual table]
2116 ** ^(If an [INSERT] occurs within a trigger or within a [virtual table]
2118 ** row as long as the trigger or virtual table method is running.
2119 ** But once the trigger or virtual table method ends, the value returned
2121 ** table method began.)^
2308 ** an attempt is made to access a database table associated with
2310 ** or process has the table locked.
2367 ** for a specified amount of time when a table is locked. ^The handler
2392 ** Definition: A <b>result table</b> is memory data structure created by the
2393 ** [sqlite3_get_table()] interface. A result table records the
2396 ** The table conceptually has a number of rows and columns. But
2397 ** these numbers are not part of the result table itself. These
2401 ** A result table is an array of pointers to zero-terminated UTF-8 strings.
2408 ** A result table might consist of one or more memory allocations.
2409 ** It is not safe to pass a result table directly to [sqlite3_free()].
2410 ** A result table should be deallocated using [sqlite3_free_table()].
2412 ** ^(As an example of the result table format, suppose a query result
2424 ** result table has 8 entries. Suppose the result table is stored
2440 ** string of its 2nd parameter and returns a result table to the
2444 ** it must pass the result table pointer to sqlite3_free_table() in order to
2526 ** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES('%q')", zText);
2554 ** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES(%Q)", zText);
2566 ** table and column names into a constructed SQL statement.
2702 ** select random [ROWID | ROWIDs] when inserting new records into a table that
2757 ** a NULL value in place of the table column that would have
2760 ** columns of a table.
2843 #define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */
2844 #define SQLITE_CREATE_TABLE 2 /* Table Name NULL */
2845 #define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */
2846 #define SQLITE_CREATE_TEMP_TABLE 4 /* Table Name NULL */
2847 #define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */
2849 #define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */
2851 #define SQLITE_DELETE 9 /* Table Name NULL */
2852 #define SQLITE_DROP_INDEX 10 /* Index Name Table Name */
2853 #define SQLITE_DROP_TABLE 11 /* Table Name NULL */
2854 #define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */
2855 #define SQLITE_DROP_TEMP_TABLE 13 /* Table Name NULL */
2856 #define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */
2858 #define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */
2860 #define SQLITE_INSERT 18 /* Table Name NULL */
2862 #define SQLITE_READ 20 /* Table Name Column Name */
2865 #define SQLITE_UPDATE 23 /* Table Name Column Name */
2868 #define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */
2870 #define SQLITE_ANALYZE 28 /* Table Name NULL */
2871 #define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */
2872 #define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */
3124 ** <table border="1" align=center cellpadding=5>
3149 ** </table>
3357 ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
3363 ** <dd>The maximum number of columns in a table definition or in the
3592 ** that can be stored in a database table. SQLite uses dynamic typing
3883 ** ^These routines provide a means to determine the database, table, and
3884 ** table column that is the origin of a particular result column in
3886 ** ^The name of the database or table or column can be returned as
3888 ** the database name, the _table_ routines return the table name, and
3897 ** database, table, and column.
3907 ** occurs. ^Otherwise, they return the name of the attached database, table,
3938 ** returned result set of that [SELECT] is a table column (not an
3939 ** expression or subquery) then the declared type of the table
3946 ** CREATE TABLE t1(c1 VARIANT);
4175 ** conversion automatically. ^(The following table details the conversions
4179 ** <table border="1">
4198 ** </table>
4201 ** The table above makes reference to standard C library functions atoi()
4204 ** used in the table for brevity and because they are familiar to most
5287 ** a rowid table.
5292 ** row is updated, inserted or deleted in a rowid table.
5299 ** database and table name containing the affected row.
5466 ** CAPI3REF: Extract Metadata About A Column Of A Table
5470 ** information about column C of table T in database D
5478 ** table and returns SQLITE_OK if the table exists and SQLITE_ERROR if it
5484 ** table or NULL.)^ ^If it is NULL, then all attached databases are searched
5485 ** for the table using the same algorithm used by the database engine to
5486 ** resolve unqualified table references.
5488 ** ^The third and fourth parameters to this function are the table and column
5496 ** <table border="1">
5504 ** </table>
5511 ** ^If the specified table is actually a view, an [error code] is returned.
5513 ** ^If the specified column is "rowid", "oid" or "_rowid_" and the table
5514 ** is not a [WITHOUT ROWID] table and an
5535 const char *zTableName, /* Table name */
5661 ** The interface to the virtual-table mechanism is currently considered
5665 ** When the virtual-table mechanism stabilizes, we will declare the
5670 ** Structures used by the virtual table interface
5678 ** CAPI3REF: Virtual Table Object
5679 ** KEYWORDS: sqlite3_module {virtual table module}
5681 ** This structure, sometimes called a "virtual table module",
5685 ** ^A virtual table module is created by filling in a persistent
5729 ** CAPI3REF: Virtual Table Indexing Information
5733 ** of the [virtual table] interface to
5735 ** method of a [virtual table module]. The fields under **Inputs** are the
5755 ** relevant to the particular virtual table being queried.
5765 ** virtual table and is not checked again by SQLite.)^
5778 ** to a linear scan of an SQLite table with N rows. A cost of log(N)
5780 ** binary search on a unique indexed field of an SQLite table with N rows.
5786 ** structure for SQLite version 3.8.2. If a virtual table extension is
5801 } *aConstraint; /* Table of WHERE clause constraints */
5822 ** CAPI3REF: Virtual Table Constraint Operator Codes
5827 ** a query that uses a [virtual table].
5837 ** CAPI3REF: Register A Virtual Table Implementation
5840 ** ^These routines are used to register a new [virtual table module] name.
5842 ** creating a new [virtual table] using the module and before using a
5843 ** preexisting [virtual table] for the module.
5848 ** the implementation of the [virtual table module]. ^The fourth
5850 ** into the [xCreate] and [xConnect] methods of the virtual table module
5851 ** when a new virtual table is be being created or reinitialized.
5877 ** CAPI3REF: Virtual Table Instance Object
5880 ** Every [virtual table module] implementation uses a subclass
5882 ** of the [virtual table]. Each subclass will
5895 const sqlite3_module *pModule; /* The module for this virtual table */
5898 /* Virtual table implementations will typically add additional fields */
5902 ** CAPI3REF: Virtual Table Cursor Object
5903 ** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor}
5905 ** Every [virtual table module] implementation uses a subclass of the
5907 ** [virtual table] and are used
5908 ** to loop through the virtual table. Cursors are created using the
5919 sqlite3_vtab *pVtab; /* Virtual table of this cursor */
5920 /* Virtual table implementations will typically add additional fields */
5924 ** CAPI3REF: Declare The Schema Of A Virtual Table
5927 ** [virtual table module] call this interface
5934 ** CAPI3REF: Overload A Function For A Virtual Table
5938 ** using the [xFindFunction] method of the [virtual table module].
5948 ** by a [virtual table].
5953 ** The interface to the virtual-table mechanism defined above (back up
5958 ** When the virtual-table mechanism stabilizes, we will declare the
5982 ** in row iRow, column zColumn, table zTable in database zDb;
6008 ** <li> ^(Table zTable does not exist within database zDb)^,
6009 ** <li> ^(Table zTable is a WITHOUT ROWID table)^,
6011 ** <li> ^(Row iRow is not present in the table)^,
6064 ** to a different row of the same database table. ^The new row is identified
6066 ** changed. ^The database, table and column on which the blob handle is open
6072 ** the nominated column.)^ ^If the new row is not present in the table, or if
6846 ** statements. For example, if the number of table steps greatly exceeds
6847 ** the number of table searches or result rows, that would tend to indicate
6848 ** that the prepared statement is using a full table scan rather than
6875 ** a table as part of a full table scan. Large numbers for this counter
7040 ** <table border=1 width=85% align=center>
7047 ** </table>
7378 ** shared-cache table, and more than one other connection currently holds
7379 ** a read-lock on the same table, then SQLite arbitrarily selects one of
7439 ** <b>The "DROP TABLE" Exception</b>
7443 TABLE" or "DROP INDEX" statement,
7448 ** invoked immediately. If the application then re-attempts the "DROP TABLE"
7454 ** the special "DROP TABLE/INDEX" case, the extended error code is just
7721 ** CAPI3REF: Virtual Table Interface Configuration
7724 ** of a [virtual table] implementation to configure
7725 ** various facets of the virtual table interface.
7728 ** xCreate virtual table method then the behavior is undefined.
7737 ** CAPI3REF: Virtual Table Configuration Options
7740 ** [sqlite3_vtab_config()] interface that [virtual table] implementations
7747 ** where X is an integer. If X is zero, then the [virtual table] whose
7755 ** If X is non-zero, then the virtual table implementation guarantees
7765 ** Virtual table implementations that are required to handle OR REPLACE
7768 ** CONFLICT policy is REPLACE, the virtual table implementation should
7778 ** CAPI3REF: Determine The Virtual Table Conflict Policy
7781 ** of a [virtual table] implementation for an INSERT or UPDATE operation. ^The
7785 ** [virtual table].
7794 ** inform a [virtual table] implementation what the [ON CONFLICT] mode
7838 ** to a zero-terminated UTF-8 string containing the name of the index or table
8070 ** limits the size of a row in a table or index.
8082 ** * Columns in a table
8092 ** not have more than a dozen or so columns in any table. And if
8154 ** the main database table and for temporary tables.
8568 ** This is the header file for the generic hash-table implementation
8578 /* A complete hash table is an instance of the following structure.
8586 ** All elements of the hash table are on a single doubly-linked list.
8595 ** Hash.ht table is never allocated because if there are few elements
8596 ** in the table, it is faster to do a linear search than to manage
8597 ** the hash table.
8600 unsigned int htsize; /* Number of buckets in the hash table */
8601 unsigned int count; /* Number of entries in this table */
8603 struct _ht { /* the hash table */
8609 /* Each element in the hash table is an instance of the following
8616 HashElem *next, *prev; /* Next and previous elements in the table */
8630 ** Macros for looping over all elements of a hash table. The idiom is
8648 ** Number of entries in a hash table
8998 ** table or index. This is an unsigned integer type. For 99.9% of
9203 ** Name of the master database table. The master database table
9204 ** is a special table that holds the names and attributes of all
9211 ** The root-page of the master database table.
9216 ** The name of the schema table.
9322 typedef struct Table Table;
9446 ** Every SQLite table must have either BTREE_INTKEY or BTREE_BLOBKEY set.
9447 ** With BTREE_INTKEY, the table key is a 64-bit integer and arbitrary data
9453 #define BTREE_INTKEY 1 /* Table has only 64-bit signed integer keys */
9454 #define BTREE_BLOBKEY 2 /* Table has keys only - no data */
9511 Btree*, /* BTree containing table to open */
10893 Hash fkeyHash; /* All foreign keys by referenced table name */
10894 Table *pSeqTab; /* The sqlite_sequence table used by AUTOINCREMENT */
10966 ** A hash table for function definitions.
10972 FuncDef *a[23]; /* Hash table for functions */
11047 int newTnum; /* Rootpage of table being initialized */
11051 u8 imposterTable; /* Building an imposter table */
11099 FuncDefHash aFunc; /* Hash table of connection functions */
11142 #define SQLITE_InternChanges 0x00000002 /* Uncommitted Hash table changes */
11225 ** hash table. When multiple functions have the same name, the hash table
11352 ** Each SQLite module (virtual table definition) is defined by an
11354 ** hash table.
11364 ** information about each column of an SQL table is held in an instance
11382 #define COLFLAG_HIDDEN 0x0002 /* A hidden column in a virtual table */
11450 ** An object of this type is created for each virtual table present in
11456 ** instance of the sqlite3_vtab* handle used to access the virtual table
11462 ** then be used by the virtual table implementation to access real tables
11465 ** connection as that used to execute SQL operations on the virtual table.
11467 ** All VTable objects that correspond to a single table in a shared
11469 ** the Table.pVTable member variable of the corresponding Table object.
11471 ** table, it searches the list for the VTable that corresponds to the
11475 ** When an in-memory Table object is deleted (for example when the
11478 ** immediately. Instead, they are moved from the Table.pVTable list to
11492 sqlite3 *db; /* Database connection associated with this table */
11502 ** The schema for each SQL table and view is represented in memory
11505 struct Table {
11506 char *zName; /* Name of the table or view */
11508 Index *pIndex; /* List of SQL indexes on this table. */
11510 FKey *pFKey; /* Linked list of all foreign keys in this table */
11515 int tnum; /* Root BTree page for this table */
11517 i16 nCol; /* Number of columns in this table */
11518 u16 nRef; /* Number of pointers to this Table */
11519 LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */
11520 LogEst szTabRow; /* Estimated size of each table row in bytes */
11522 LogEst costMult; /* Cost multiplier for using this table */
11527 int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */
11535 Schema *pSchema; /* Schema that contains this table */
11536 Table *pNextZombie; /* Next on the Parse.pZombieTab list */
11540 ** Allowed values for Table.tabFlags.
11543 ** followed by non-hidden columns. Example: "CREATE VIRTUAL TABLE x USING
11548 #define TF_Readonly 0x01 /* Read-only system table */
11549 #define TF_Ephemeral 0x02 /* An ephemeral table */
11550 #define TF_HasPrimaryKey 0x04 /* Table has a primary key */
11552 #define TF_Virtual 0x10 /* Is a virtual table */
11558 ** Test to see whether or not a table is a virtual table. This is
11560 ** table support is omitted from the build.
11570 /* Does the table have a rowid */
11576 ** A foreign key is associated with two tables. The "from" table is
11577 ** the table that contains the REFERENCES clause that creates the foreign
11578 ** key. The "to" table is the table that is named in the REFERENCES clause.
11581 ** CREATE TABLE ex1(
11586 ** For foreign key "fk1", the from-table is "ex1" and the to-table is "ex2".
11589 ** from-table == child-table
11590 ** to-table == parent-table
11593 ** which is attached to the from-table. The to-table need not exist when
11594 ** the from-table is created. The existence of the to-table is not checked.
11596 ** The list of all parents for child Table X is held at X.pFKey.
11598 ** A list of all children for a table named Z (which might not even exist)
11602 Table *pFrom; /* Table containing the REFERENCES clause (aka: Child) */
11604 char *zTo; /* Name of table that the key points to (aka: Parent) */
11637 ** referenced table row is propagated into the row that holds the
11683 ** Records are used to store the content of a table row and to store
11709 ** The columns of the table that are to be indexed are described
11711 ** we have the following table and index:
11713 ** CREATE TABLE Ex1(c1 int, c2 int, c3 text);
11716 ** In the Table structure describing Ex1, nCol==3 because there are
11717 ** three columns in the table. In the Index structure describing
11735 Table *pTable; /* The SQL table being indexed */
11737 Index *pNext; /* The next index associated with the same table */
11768 #define SQLITE_IDXTYPE_PRIMARYKEY 2 /* Is the PRIMARY KEY for the table */
11777 ** Each sample stored in the sqlite_stat3 table is represented in memory
11819 ** than the source table */
11821 int sortingIdxPTab; /* Cursor number of pseudo-table */
11826 Table *pTab; /* Source table */
11827 int iTable; /* Cursor number of the source table */
11828 int iColumn; /* Column number within the source table */
11841 int iDistinct; /* Ephemeral table used to enforce DISTINCT */
11888 ** An expression of the form ID or ID.ID refers to a column in a table.
11890 ** the integer cursor number of a VDBE cursor pointing to that table and
11906 ** If the Expr is of type OP_Column, and the table it is selecting from
11907 ** is a disk table or the "old.*" pseudo-table, then pTab points to the
11908 ** corresponding table definition.
11954 int iTable; /* TK_COLUMN: cursor number of table holding column
11961 i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */
11966 Table *pTab; /* Table for TK_COLUMN expressions. */
12047 ** of the result column in the form: DATABASE.TABLE.COLUMN. This later
12058 unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */
12090 ** column names after a table name in an INSERT statement. In the statement
12094 ** If "a" is the k-th column of table "t", then IdList.a[0].idx==k.
12099 int idx; /* Index in some Table.aCol[] of a column named zName */
12126 ** Each table or subquery in the FROM clause is a separate element of
12130 ** can also be used to describe a particular table such as the table that
12132 ** such a table must be a simple name: ID. But in SQLite, the table can
12133 ** now be identified by a database name, a dot, then the table name: ID.ID.
12135 ** The jointype starts out showing the join type between the current table
12136 ** and the next table on the list. The parser builds the list this way.
12138 ** jointype expresses the join between the table and the previous table.
12140 ** In the colUsed field, the high-order bit (bit 63) is set if the table
12148 char *zDatabase; /* Name of database holding this table */
12149 char *zName; /* Name of the table */
12151 Table *pTab; /* An SQL table corresponding to zName */
12152 Select *pSelect; /* A SELECT statement used in place of a table name */
12164 int iCursor; /* The VDBE cursor number used to access this table */
12194 #define WHERE_OMIT_OPEN_CLOSE 0x0010 /* Table cursors are already open */
12196 #define WHERE_ONETABLE_ONLY 0x0040 /* Only code the 1st table in pTabList */
12212 ** A NameContext defines a context in which to resolve table and column
12216 ** to the table being operated on by INSERT, UPDATE, or DELETE. The
12308 #define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */
12348 ** row of result as the key in table pDest->iSDParm.
12352 ** SRT_EphemTab Create an temporary table pDest->iSDParm and store
12356 ** the table first.
12364 ** SRT_Table Store results in temporary table pDest->iSDParm.
12365 ** SRT_Fifo This is like SRT_EphemTab except that the table
12370 ** SRT_DistFifo Store results in a temporary table pDest->iSDParm.
12371 ** But also use temporary table pDest->iSDParm+1 as
12417 ** tables, the following information is attached to the Table.u.autoInc.p
12418 ** pointer of each autoincrement table to record some side information that
12419 ** the code generator needs. We have to keep per-table autoincrement
12426 Table *pTab; /* Table this info block refers to */
12495 ** used to store the set of table-locks required by the statement being
12523 int iPartIdxTab; /* Table corresponding to a partial index */
12529 int iTable; /* Table cursor number */
12530 i16 iColumn; /* Table column number */
12541 int regRowid; /* Register holding rowid of CREATE TABLE entry */
12550 TableLock *aTableLock; /* Required table locks for shared-cache mode */
12556 Table *pTriggerTab; /* Table triggers are being coded for */
12557 int addrCrTab; /* Address of OP_CreateTable opcode on CREATE TABLE */
12591 Table *pNewTable; /* A table being constructed by CREATE TABLE */
12598 Table **apVtabLock; /* Pointer to virtual tables needing locking */
12600 Table *pZombieTab; /* List of Table objects to delete after code gen */
12644 * 1. In the "trigHash" hash table (part of the sqlite3* that represents the
12646 * 2. All triggers associated with a single table form a linked list, using the
12649 * struct Table.
12656 char *table; /* The table or view to which the trigger applies */
12663 Schema *pTabSchema; /* Schema containing the table */
12665 Trigger *pNext; /* Next trigger associated with the table */
12695 * zTarget -> Dequoted name of the table to insert into.
12703 * zTarget -> Dequoted name of the table to delete from.
12708 * zTarget -> Dequoted name of the table to update.
12721 char *zTarget; /* Target table for DELETE, UPDATE, INSERT */
12885 ** (common table expressions) created by a single WITH clause.
13121 SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse*,Select*);
13123 SQLITE_PRIVATE Index *sqlite3PrimaryKeyIndex(Table*);
13162 SQLITE_PRIVATE int sqlite3ViewGetColumnNames(Parse*,Table*);
13171 SQLITE_PRIVATE void sqlite3CodeDropTable(Parse*, Table*, int, int);
13172 SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3*, Table*);
13202 SQLITE_PRIVATE Table *sqlite3SrcListLookup(Parse*, SrcList*);
13203 SQLITE_PRIVATE int sqlite3IsReadOnly(Parse*, Table*, int);
13204 SQLITE_PRIVATE void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int);
13219 SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8);
13220 SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int);
13239 SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3*,const char*, const char*);
13240 SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*);
13241 SQLITE_PRIVATE Table *sqlite3LocateTableItem(Parse*,int isView,struct SrcList_item *);
13274 SQLITE_PRIVATE void sqlite3GenerateRowDelete(Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8);
13275 SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*);
13278 SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(Parse*,Table*,int*,int,int,int,int,
13280 SQLITE_PRIVATE void sqlite3CompleteInsertion(Parse*,Table*,int,int,int,int*,int,int,int);
13281 SQLITE_PRIVATE int sqlite3OpenTableAndIndices(Parse*, Table*, int, int, u8*, int*, int*);
13287 SQLITE_PRIVATE void sqlite3RowidConstraint(Parse*, int, Table*);
13308 SQLITE_PRIVATE void sqlite3MaterializeView(Parse*, Table*, Expr*, int);
13317 SQLITE_PRIVATE Trigger *sqlite3TriggersExist(Parse *, Table*, int, ExprList*, int *pMask);
13318 SQLITE_PRIVATE Trigger *sqlite3TriggerList(Parse *, Table *);
13319 SQLITE_PRIVATE void sqlite3CodeRowTrigger(Parse*, Trigger *, int, ExprList*, int, Table *,
13321 SQLITE_PRIVATE void sqlite3CodeRowTriggerDirect(Parse *, Trigger *, Table *, int, int, int);
13322 void sqliteViewTriggers(Parse*, Table*, Expr*, int, ExprList*);
13331 SQLITE_PRIVATE u32 sqlite3TriggerColmask(Parse*,Trigger*,ExprList*,int,int,Table*,int);
13406 SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe*, Table*, int);
13477 SQLITE_PRIVATE void sqlite3ResolveSelfReference(Parse*,Table*,int,Expr*,ExprList*);
13479 SQLITE_PRIVATE void sqlite3ColumnDefault(Vdbe *, Table *, int, int);
13571 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table*);
13572 SQLITE_PRIVATE void sqlite3VtabDisconnect(sqlite3 *db, Table *p);
13581 SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3*, Table*);
13584 SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*);
13590 SQLITE_PRIVATE int sqlite3VtabCallConnect(Parse*, Table*);
13625 SQLITE_PRIVATE void sqlite3FkCheck(Parse*, Table*, int, int, int*, int);
13626 SQLITE_PRIVATE void sqlite3FkDropTable(Parse*, SrcList *, Table*);
13627 SQLITE_PRIVATE void sqlite3FkActions(Parse*, Table*, ExprList*, int, int*, int);
13628 SQLITE_PRIVATE int sqlite3FkRequired(Parse*, Table*, int*, int);
13629 SQLITE_PRIVATE u32 sqlite3FkOldmask(Parse*, Table*);
13630 SQLITE_PRIVATE FKey *sqlite3FkReferences(Table *);
13639 SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *, Table*);
13640 SQLITE_PRIVATE int sqlite3FkLocateIndex(Parse*,Table*,FKey*,Index**,int**);
13669 #define IN_INDEX_ROWID 1 /* Search the rowid of the table */
13673 #define IN_INDEX_NOOP 5 /* No table available. Use comparisons */
13851 ** The following 256 byte lookup table is used to support SQLites built-in
14006 ** Hash table for global functions - functions common to all
14007 ** database connections. After initialization, this table is
14559 ** A pseudo-table is a single-row table implemented by registers.
14566 Btree *pBt; /* Separate file holding temporary table */
14578 Bool isEphemeral:1; /* True for an ephemeral table */
14580 Bool isTable:1; /* True if a table requiring integer keys */
14581 Bool isOrdered:1; /* True if the underlying table is BTREE_UNORDERED */
14583 sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
14808 char *zName; /* Name of table or index */
15246 sqlite3DeleteTable(db, (Table *)sqliteHashData(p));
16883 ** fatal. For example, if a malloc fails while resizing a hash table, this
16885 ** hash table will continue to function normally. So a malloc failure
16886 ** during a hash table resize is a benign fault.
18037 ** small chunk list, or into the large chunk hash table.
18208 ** chunk table or in the large chunk hash table. This is
21412 ** The following table is searched linearly, so it is good to put the
22943 ** This lookup table is used to help decode the first byte of
24821 /* Turn bulk memory into a hash table object by initializing the
24824 ** "pNew" is a pointer to the hash table that is to be initialized.
24834 /* Remove all entries from a hash table. Reclaim all memory.
24835 ** Call this routine to delete a hash table or to reset a hash table
24839 HashElem *elem; /* For looping over all elements of the table */
24868 /* Link pNew element into the hash table pH. If pEntry!=0 then also
24872 Hash *pH, /* The complete hash table */
24899 /* Resize the hash table so that it cantains "new_size" buckets.
24901 ** The hash table might fail to resize if sqlite3_malloc() fails or
24906 struct _ht *new_ht; /* The new hash table */
24916 /* The inability to allocates space for a larger hash table is
24921 ** use the actual amount of space allocated for the hash table (which
24942 ** hash table that matches the given key. The hash for this key is
24976 /* Remove a single entry from the hash table given a pointer to that
25010 /* Attempt to locate an element of the hash table pH with a key
25024 /* Insert an element into the hash table pH. The key is pKey
25033 ** the new data is returned and the hash table is unchanged.
25036 ** element corresponding to "key" is removed from the hash table.
25039 unsigned int h; /* the hash of the key modulo hash table size */
38882 ** But sometimes (for example when during a DROP of a large table) most
38920 /* Number of u32 values in hash table. */
38922 /* Maximum number of entries in hash table before
38945 ** a hash table that will hold up to BITVEC_MXHASH distinct values.
38966 u32 aHash[BITVEC_NINT]; /* Hash table representation */
39096 ** that BitvecClear can use to rebuilt its hash table.
40024 /* Hash table of all pages. The following variables may only be accessed
40030 PgHdr1 **apHash; /* Hash table for fast lookup by key */
40043 PgHdr1 *pNext; /* Next in hash table chain */
40325 ** This function is used to resize the hash table used by the cache passed
40400 ** Remove the page supplied as an argument from the hash table
40768 /* Step 1: Search the hash table for an existing entry. */
44300 ** in this case. But for things like temporary table (which will be
49084 ** database page number associated with each wal frame, and a hash-table
49099 ** Even without using the hash table, the last frame for page P
49106 ** The hash table consists of HASHTABLE_NSLOT 16-bit unsigned integers.
49108 ** hash table for each page number in the mapping section, so the hash
49109 ** table is never more than half full. The expected number of collisions
49110 ** prior to finding a match is 1. Each entry of the hash table is an
49115 ** K will be (mxFrame%HASHTABLE_NPAGE).) Unused slots of the hash table
49118 ** To look for page P in the hash table, first compute a hash iKey on
49123 ** Then start scanning entries of the hash table, starting with iKey
49124 ** (wrapping around to the beginning when the end of the hash table is
49127 ** wrap-around.) Because the hash table is never more than half full,
49151 ** Both readers can use the same hash table and mapping section to get
49152 ** the correct result. There may be entries in the hash table with
49154 ** slots in the hash table and so the first reader will get an answer as
49155 ** if no values greater than K0 had ever been inserted into the hash table
49160 ** When a rollback occurs, the value of K is decreased. Hash table entries
49162 ** from the hash table at this point.
49373 ** Each page of the wal-index mapping contains a hash-table made up of
49407 ** is a hash-table following every HASHTABLE_NPAGE page numbers in the
49418 ** The block of page numbers associated with the first hash-table in a
49420 ** hash-table on each aligned 32KB page of the wal-index.
49745 ** Return pointers to the hash table and page number array stored on
49749 ** Set output variable *paHash to point to the start of the hash table
49751 ** number of the first frame indexed by this hash table. If a
49752 ** slot in the hash table is set to N, it refers to frame number
49756 ** first frame indexed by the hash table, frame (*piZero+1).
49760 int iHash, /* Find the iHash'th table */
49791 ** Return the number of the wal-index page that contains the hash-table
49819 ** Remove entries from the hash table that point to WAL slots greater
49825 ** At most only the hash table containing pWal->hdr.mxFrame needs to be
49831 volatile ht_slot *aHash = 0; /* Pointer to hash table to clear */
49832 volatile u32 *aPgno = 0; /* Page number array for hash table */
49845 /* Obtain pointers to the hash-table and page-number array containing
49847 ** that the page said hash-table and array reside on is already mapped.
49853 /* Zero all hash-table entries that correspond to frame numbers greater
49872 ** via the hash table even after the cleanup.
49896 volatile ht_slot *aHash = 0; /* Hash table */
49901 ** page number array and hash table entry.
49904 int iKey; /* Hash table key */
49905 int idx; /* Value to write to hash-table slot */
49911 /* If this is the first entry to be added to this hash-table, zero the
49912 ** entire hash table and aPgno[] array before proceeding.
49923 ** the hash-table before writing any new entries.
49930 /* Write the aPgno[] array entry and the hash-table slot. */
49939 /* Verify that the number of entries in the hash table exactly equals
49944 int nEntry = 0; /* Number of entries in the hash table */
49950 ** via the hash table. This turns out to be a really, really expensive
51306 /* Search the hash table or tables for an entry matching page number
51308 ** hash table (each hash table indexes up to HASHTABLE_NPAGE frames).
51312 ** table). This means the value just read from the hash
51322 ** if we had exclusive access to the hash-table:
51325 ** This condition filters out normal hash-table collisions.
51329 ** table after the current read-transaction had started.
51332 volatile ht_slot *aHash; /* Pointer to hash table */
52375 u8 intKey; /* True if table b-trees. False for index b-trees */
52376 u8 intKeyLeaf; /* True if the leaf of an intKey table */
52410 ** is opened on the table with root page BtShared.iTable. Locks are removed
52416 Pgno iTable; /* Root page of table */
52493 ** table (because there exists one or more read-locks on the table),
52527 u16 maxLeaf; /* Maximum local payload in a LEAFDATA table */
52528 u16 minLeaf; /* Minimum local payload in a LEAFDATA table */
52637 ** because the table is empty or because BtreeCursorFirst() has not been
52649 ** The table that this cursor was opened on still exists, but has been
52693 ** The pointer map is a lookup table that identifies the parent page for
52956 ** a statement since we will be comparing table and column names
53171 ** shared-cache table level locks. If the library is compiled with the
53191 ** table with root page iRoot. Return 1 if it does and 0 if not.
53193 ** For example, when writing to a table with root-page iRoot via
53200 ** the corresponding table. This makes things a bit more complicated,
53201 ** as this module treats each table as a separate structure. To determine
53202 ** the table corresponding to the index being written, this
53205 ** Instead of a lock on the table/index rooted at page iRoot, the caller may
53206 ** hold a write-lock on the schema table (root page 1). This is also
53238 /* Figure out the root-page that the lock should be held on. For table
53241 ** table. */
53261 ** write-lock on the schema table, or (if the client is reading) a
53282 ** table or index rooted at iRoot because other shared connections are
53283 ** simultaneously reading that same table or index.
53287 ** the iRoot table. Except, if the other Btree object has the
53291 ** For example, before writing to any part of the table or index
53312 ** (READ_LOCK or WRITE_LOCK) on the table with root-page iTab. Return
53352 ** may hold a WRITE_LOCK on any table in this file (since there can
53372 ** Add a lock on the table with root-page iTable to the shared-btree used
53400 ** table, and that lock is obtained in BtreeBeginTrans(). */
53408 /* First search the list for an existing lock on this table. */
53417 ** with table iTable, allocate one and link it into the list.
53445 ** Release all the table locks (locks obtained via calls to
53544 ** This function is called before modifying the contents of a table
53549 ** table is about to be deleted. In this case invalidate all incrblob
53550 ** cursors open on any row within the table with root-page pgnoRoot.
53684 /* If this is an intKey table, then the above call to BtreeKeySize()
53687 ** table, then malloc space for and store the pCur->nKey bytes of key
53719 ** the table with root-page iRoot. "Saving the cursor position" means that
53723 ** table, for example in BtreeDelete() or BtreeInsert().
54585 ** table b-tree page. */
54588 ** table b-tree page. */
54672 ** possible for a root page of a table that contains no rows) then the
55348 ** The call to sqlite3BtreeRollback() drops any table-locks held by
56882 ** cursors open with wrFlag==0 on the same table. Otherwise
56899 int iTable, /* Root page of table to open */
56910 ** b-tree database, the connection is holding the required table locks,
56952 int iTable, /* Root page of table to open */
57070 ** that is currently pointing to a row in a (non-empty) table.
57083 ** For a table with the INTKEY flag set, this routine returns the key
57251 ** invalidated if some other cursor writes to the same table, or if
57257 ** * Creating a table (may require moving an overflow page).
57457 ** in the table.
57504 ** table btrees (pPage->intKey==1). The number of bytes of available
57649 ** If the table has a virtual root page, then the cursor is moved to point
57650 ** to the virtual root page instead of the actual root page. A table has a
57652 ** single child page. This can only happen with the table rooted at page 1.
57663 ** indicating a table b-tree, or if the caller did specify a KeyInfo
57702 ** NULL, the caller expects a table b-tree. If this is not the case,
57708 ** in such a way that page pRoot is linked into a second b-tree table
57784 /* Move the cursor to the first entry in the table. Return SQLITE_OK
57786 ** or set *pRes to 1 if the table is empty.
57807 /* Move the cursor to the last entry in the table. Return SQLITE_OK
57809 ** or set *pRes to 1 if the table is empty.
57870 ** is smaller than intKey/pIdxKey or if the table is empty
57883 i64 intKey, /* The table key */
57944 ** be the right kind (index or table) of b-tree page. Otherwise
58084 ** Return TRUE if the cursor is not pointing at an entry of the table.
58087 ** past the last entry in the table or sqlite3BtreePrev() moves past
58088 ** the first entry. TRUE is also returned if the table is empty.
58091 /* TODO: What if the cursor is in CURSOR_REQUIRESEEK but all table entries
60090 ** of the table is closer to a linear scan through the file. That in turn
60598 ** define what table the record should be inserted into. The cursor
60601 ** For an INTKEY table, only the nKey value of the key is used. pKey is
60602 ** ignored. For a ZERODATA table, the pData and nData are both ignored.
60618 BtCursor *pCur, /* Insert data into the table of this cursor */
60649 ** intkey table, the caller should be inserting integer keys with a
60653 /* Save the positions of any other cursors open on this table.
60656 ** example, when inserting data into a table with auto-generated integer
60668 /* If this is an insert into a table b-tree, invalidate any incrblob
60691 TRACE(("INSERT: table=%d nkey=%lld ndata=%d page=%d %s\n",
60741 ** entry in the table, and the next row inserted has an integer key
60808 /* Save the positions of any other cursors open on this table before
60816 /* If this is a delete operation to remove a row from a table b-tree,
60880 ** Create a new BTree table. Write into *piTable the page
60881 ** number for the root page of the new table.
60895 int ptfFlags; /* Page-type flage for the root page of new table */
60911 /* Creating a new table may probably require moving an existing database
60919 ** root page of the new table should go. meta[3] is the largest root-page
60945 ** the new table (assuming an error did not occur). But we were
61045 BtShared *pBt, /* The BTree that contains the table */
61098 ** Delete all information from a single table in the database. iTable is
61099 ** the page number of the root of the table. After this routine returns,
61103 ** read cursors on the table. Open write cursors are moved to the
61104 ** root of the table.
61106 ** If pnChange is not NULL, then table iTable must be an intkey table. The
61108 ** entries in the table.
61119 /* Invalidate all incrblob cursors open on table iTable (assuming iTable
61120 ** is the root of a table b-tree - if it is not, the following call is
61130 ** Delete all information from the single table that pCur is open on.
61132 ** This routine only work for pCur on an ephemeral table.
61139 ** Erase all information in a table and add the root of the table to
61140 ** the freelist. Except, the root of the principle table (the one on
61144 ** cursors on the table.
61166 /* It is illegal to drop a table if any cursors are open on the
61199 /* If the table being dropped is the table with the largest root-page
61208 /* The table being dropped does not have the largest root-page
61922 ** a table. nRoot is the number of entries in aRoot.
62149 ** sqlite_master table. Otherwise SQLITE_OK.
62164 ** Obtain a lock on the table whose root page is iTab. The
62190 ** INTKEY table currently pointing at a valid table entry.
62213 /* Save the positions of all other cursors open on this table. This is
62217 ** Note that pCsr must be open on a INTKEY table and saveCursorPosition()
62218 ** and hence saveAllCursors() cannot fail on a BTREE_INTKEY table, hence
62227 ** (c) the connection holds a write-lock on the table (if required),
62229 ** (e) the cursor points at a valid row of an intKey table.
64382 ** on a table column definition, and hence only when pCtx==0. This
64511 ** sqlite_stat3 table to the record format SQLite uses internally.
64625 ** in the sqlite_stat4 table.
65413 const char *zName /* Name of table or index being scanned */
66080 ** to 6.6 percent. The test case is inserting 1000 rows into a table
67653 ** the blob of data that it corresponds to. In a table record, all serial
67658 ** The following table describes the various storage classes for data:
68057 ** This function compares two index or table record keys in the same way
68375 ** This function compares the two table rows or index records
69982 ** 3 The name of the table that the column derives from
69983 ** 4 The name of the table column that the result column derives from
70085 ** Return the name of the table from which a result column derives.
70101 ** Return the name of the table column from which a result column derives.
70938 int nField, /* Number of fields in the table or index */
70940 int isBtreeCursor /* True for B-Tree. False for pseudo-table or vtab */
73137 ** If the OPFLAG_CLEARCACHE bit is set on P5 and P1 is a pseudo-table cursor,
73139 ** The first OP_Column against a pseudo-table after the value of the content
73177 assert( pC->pVtabCursor==0 ); /* OP_Column never called on virtual table */
73437 ** use as a data record in a database table or as a key
73594 ** Store the number of entries (an integer value) in the table or index
73967 ** are queried from within xNext() and other v-table methods using
73970 ** v-table would have to be ready for the sqlite3_vtab structure itself
73972 ** a v-table method.
74057 ** Open a read-only cursor for the database table whose root page is
74081 ** value, it is set to the number of columns in the table.
74102 ** Open a read/write cursor named P1 on the table or index whose root
74110 ** value, it is set to the number of columns in the table, or to the
74111 ** largest index of any column of the table that is actually used.
74114 ** in read/write mode. For a given table, there can be one or more read-only
74197 testcase( nField==0 ); /* Table with INTEGER PRIMARY KEY and nothing else */
74222 ** Open a new cursor P1 to a transient table.
74225 ** table is deleted automatically when the cursor is closed.
74227 ** P2 is the number of columns in the ephemeral table.
74228 ** The cursor points to a BTree table if P4==0 and to a BTree index
74270 ** opening it. If a transient table is required, just use the
74271 ** automatically created table with root-page 1 (an BLOB_INTKEY table).
74339 ** Open a new cursor that points to a fake table that contains a single
74344 ** A pseudo-table created by this opcode is used to hold a single
74347 ** is the only cursor opcode that works with a pseudo-table.
74350 ** the pseudo-table.
74381 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
74399 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
74417 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
74435 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
74590 /* res might be negative because the table is empty. Check to
74607 ** P1 is an open table cursor and P2 is a rowid integer. Arrange
74774 ** P1 is the index of a cursor open on an SQL table btree (with integer
74840 ** Get a new integer record number (a.k.a "rowid") used as the key to a table.
74842 ** table that cursor P1 points to. The new record number is written
74854 VdbeCursor *pC; /* Cursor of table to get the new rowid */
74878 ** it already exists in the table. If it does not exist, we have
74949 ** an AUTOINCREMENT table. */
74974 ** Write an entry into the table of cursor P1. A new entry is
74998 ** Parameter P4 may point to a string containing the table-name, or
75022 VdbeCursor *pC; /* Cursor to table into which insert is written */
75026 const char *zTbl; /* Table name - used by the opdate hook */
75088 ** record in the table. If it is left pointing at the next record, then
75095 ** P1 must not be pseudo-table. It has to be a real table with
75098 ** If P4 is not NULL, then it is the name of the table that P1 is
75187 ** a register that is the source for a pseudo-table cursor created using
75188 ** OpenPseudo. That pseudo-table cursor is the one that is identified by
75214 ** of a real table, not a pseudo-table.
75225 ** of a real table, not a pseudo-table.
75298 ** Store in register P2 an integer which is the key of the table entry that
75301 ** P1 can be either an ordinary table or a virtual table. There used to
75303 ** one opcode now works for both table types.
75367 ** will refer to the last entry in the database table or index.
75368 ** If the table or index is empty and P2>0, then jump immediately to P2.
75369 ** If P2 is 0 or if the table or index is not empty, fall through
75427 ** will refer to the first entry in the database table or index.
75428 ** If the table or index is empty, jump immediately to P2.
75429 ** If the table or index is not empty, fall through to the following
75468 ** table or index. If there are no more key/value pairs then fall through
75476 ** The P1 cursor must be for a real table, not a pseudo-table. P1 must have
75500 ** table or index. If there is no previous key/value pairs then fall through
75509 ** The P1 cursor must be for a real table, not a pseudo-table. If P1 is
75680 ** the rowid of the table entry to which this index entry points.
75808 ** Delete an entire database table or index whose root page in the database
75811 ** The table being destroyed is in the main database file if P3==0. If
75812 ** P3==1 then the table to be clear is in the auxiliary database file
75813 ** that is used to store tables create using CREATE TEMPORARY TABLE.
75820 ** movement was required (because the table being dropped was already
75857 ** Delete all contents of the database table or index whose root page
75859 ** remove the table or index from the database file.
75861 ** The table being clear is in the main database file if P2==0. If
75862 ** P2==1 then the table to be clear is in the auxiliary database file
75863 ** that is used to store tables create using CREATE TEMPORARY TABLE.
75865 ** If the P3 value is non-zero, then the table referred to must be an
75866 ** intkey table (an SQL table, not an index). In this case the row change
75867 ** count is incremented by the number of rows in the table being cleared.
75869 ** also incremented by the number of rows in the table being cleared.
75895 ** Delete all contents from the ephemeral table or sorter
75919 ** Allocate a new table in the main database file if P1==0 or in the
75921 ** P1>1. Write the root page number of the new table into
75924 ** The difference between a table and an index is this: A table must
75935 ** P1>1. Write the root page number of the new table into
75966 ** Read and parse all entries from the SQLITE_MASTER table of database P1
76022 ** Read the sqlite_stat1 table for database P1 and load the content
76023 ** of that table into the internal index hash table. This will cause
76036 ** the table named P4 in database P1. This is called after a table
76836 ** Obtain a lock on a particular table. This instruction is only used when
76843 ** P2 contains the root-page of the table to lock.
76845 ** P4 contains a pointer to the name of the table being locked. This is only
76858 sqlite3SetString(&p->zErrMsg, db, "database table is locked: %s", z);
76869 ** xBegin method for that table.
76872 ** within a callback to a virtual table xSync() method. If it is, the error
76887 ** P2 is a register that holds the name of a virtual table in database
76888 ** P1. Call the xCreate method for that table.
76892 const char *zTab; /* Name of the virtual table */
76915 ** P4 is the name of a virtual table in database P1. Call the xDestroy method
76916 ** of that table.
76929 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
76931 ** table and stores that cursor in P1.
76980 ** This opcode invokes the xFilter method on the virtual table specified
77040 ** the row of the virtual-table that the
77083 ** Advance virtual table P1 to the next row in its result set and
77084 ** jump to instruction P2. Or, if the virtual table has reached
77107 ** some other method is next invoked on the save virtual table cursor.
77126 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
77158 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
77168 ** row. This can be NULL to have the virtual table select the new
77469 int iCol; /* Table column this handle is open on */
77550 const char *zTable, /* The table containing the blob */
77560 ** db/table/row entry. The reason for using a vdbe program instead
77592 Table *pTab;
77626 sqlite3ErrorMsg(pParse, "cannot open virtual table: %s", zTable);
77630 sqlite3ErrorMsg(pParse, "cannot open table without rowid: %s", zTable);
77717 /* Make sure a mutex is held on the table to be accessed */
77737 ** think that the table has one more column than it really
77877 ** database table.
80821 ** Table of methods for JournalFile sqlite3_file object.
81109 ** Table of methods for MemJournal sqlite3_file object.
81330 ** table and column.
81469 ** Subqueries stores the original database, table and column names for their
81470 ** result sets in ExprList.a[].zSpan, in the form "DATABASE.TABLE.COLUMN".
81506 ** pExpr->iTable Set to the cursor number for the table obtained
81508 ** pExpr->pTab Points to the Table structure of X.Y (even if
81510 ** pExpr->iColumn Set to the column number within the table.
81517 ** can be used. The zTable variable is the name of the table (the "Y"). This
81519 ** means that the form of the name is Z and that columns from any table
81527 const char *zDb, /* Name of the database containing table, or NULL */
81528 const char *zTab, /* Name of table containing column, or NULL */
81535 int cntTab = 0; /* Number of matching table names */
81543 Table *pTab = 0; /* Table hold the row */
81619 ** is for the right-hand table of a NATURAL JOIN or is in a
81716 ** SELECT a+b AS x FROM table WHERE x<10;
81797 /* If a column from a table in pSrcList is referenced, then record
81968 /* A table name and column name: ID.ID
81969 ** Or a database, table and column: ID.ID.ID
82666 ** table columns and result-set columns. At the same time, do error
82670 ** To resolve table columns references we look for nodes (or subtrees) of the
82676 ** Y: The name of a table in a FROM clause. Or in a trigger
82679 ** Z: The name of a column in table Y.
82684 ** Expr.pTab Points to the Table object for X.Y
82693 ** Table-name and function resolution occurs on the substituted expression
82780 ** Resolve names in expressions that can only reference a single table:
82792 Table *pTab, /* The table being referenced */
82849 ** CREATE TABLE t1(a);
83853 Table *pTab;
84099 ** in a CREATE TABLE statement. The Walker.eCode value is 5 when parsing
84146 ** of the sqlite_master table */
84201 ** for any single row of the table with cursor iCur. In other words, the
84203 ** table other than iCur.
84360 Table *pTab;
84379 if( IsVirtual(pTab) ) return 0; /* FROM clause not a virtual table */
84397 ** Generate code that checks the left-most column of index table iCur to see if
84444 ** IN_INDEX_ROWID - The cursor was opened on a database table.
84448 ** populated epheremal table.
84455 ** SELECT <column> FROM <table>
84458 ** an ephemeral table might need to be generated from the RHS and then
84459 ** pX->iTable made to point to the ephemeral table instead of an
84460 ** existing table.
84464 ** IN_INDEX_MEMBERSHIP, then the generated table will be used for a
84471 ** An epheremal table must be used unless the selected <column> is guaranteed
84476 ** for fast set membership tests) then an epheremal table must
84503 int eType = 0; /* Type of RHS table. IN_INDEX_* */
84504 int iTab = pParse->nTab++; /* Cursor of the RHS table */
84511 /* Check to see if an existing table or index can be used to
84513 ** ephemeral table.
84518 Table *pTab; /* Table <table>. */
84531 /* Code an OP_Transaction and OP_TableLock for <table>. */
84553 ** be used in place of a temp-table, it must be ordered according
84589 ** then it is not worth creating an ephemeral table to evaluate
84602 /* Could not find an existing table or index to use as the RHS b-tree.
84603 ** We will have to generate an ephemeral table to do the job.
84639 ** to some integer key column of a table B-Tree. In this case, use an
84699 ** expression it is handled the same way. An ephemeral table is
84719 ** table allocated and opened above.
84747 ** store it in the temporary table. If <expr> is a column, then use
84782 /* Evaluate the expression and insert it into the temp table */
84894 /* Compute the RHS. After this step, the table with cursor
84977 /* In this case, the RHS is the ROWID of table b-tree
85122 ** particular table is stored in a particular register.
85256 ** Generate code to extract the value of the iCol-th column of a table.
85260 Table *pTab, /* The table containing the value */
85261 int iTabCur, /* The table cursor. Or the PK cursor for WITHOUT ROWID */
85282 ** table pTab and store the column value in a register. An effort
85291 Table *pTab, /* Description of the table we are reading from */
85292 int iColumn, /* Index of the table column */
85293 int iTable, /* The cursor pointing to the table */
85743 ** a virtual table column.
85747 ** see if it is a column in a virtual table. This is done because
85840 ** new.* pseudo-table, or 0 for the old.* pseudo-table. Expr.iColumn
85841 ** is set to the column of the pseudo-table to read, or to -1 to
85846 ** to reference another column of the old.* pseudo-table, where
85848 ** set to (n+1), where n is the number of columns in each pseudo-table.
85849 ** For a reference to any other column in the new.* pseudo-table, p1
85851 ** example, if the table on which triggers are being fired is
85854 ** CREATE TABLE t1(a, b);
85862 Table *pTab = pExpr->pTab;
86320 ** new.* pseudo-table, or 0 for the old.* pseudo-table. Expr.iColumn
86321 ** is set to the column of the pseudo-table to read, or to -1 to
86894 ** Expr.iTable<0 then assume a table number given by iTab.
86921 ** to count references to table columns in the arguments of an
87034 /* If we reach this point, it means that pExpr refers to a table
87259 ** that implements the ALTER TABLE command.
87264 ** ALTER TABLE logic from the build.
87271 ** ALTER TABLE command. The first argument is the text of a CREATE TABLE or
87272 ** CREATE INDEX command. The second is a table name. The table name in
87273 ** the CREATE TABLE or CREATE INDEX statement is replaced with the third
87276 ** sqlite_rename_table('CREATE TABLE abc(a, b, c)', 'def')
87277 ** -> 'CREATE TABLE def(a, b, c)'
87300 /* The principle used to locate the table name in the CREATE TABLE
87301 ** statement is that the table name is the first non-space token that
87333 ** generated by the ALTER TABLE ... RENAME command to modify the definition
87334 ** of any foreign key constraints that use the table being renamed as the
87335 ** parent table. It is passed three arguments:
87337 ** 1) The complete text of the CREATE TABLE statement being modified,
87338 ** 2) The old name of the table being renamed, and
87339 ** 3) The new name of the table being renamed.
87341 ** It returns the new CREATE TABLE statement. For example:
87343 ** sqlite_rename_parent('CREATE TABLE t1(a REFERENCES t2)', 't2', 't3')
87344 ** -> 'CREATE TABLE t1(a REFERENCES t3)'
87398 ** ALTER TABLE command. The first argument is the text of a CREATE TRIGGER
87399 ** statement. The second is a table name. The table name in the CREATE
87402 ** TRIGGER, not CREATE INDEX and CREATE TABLE.
87422 /* The principle used to locate the table name in the CREATE TRIGGER
87423 ** statement is that the table name is the first token that is immediately
87431 /* Ran out of input before finding the table name. Return NULL. */
87453 ** Note that ON cannot be a database, table or column name, so
87463 /* Variable tname now contains the token that is the old table-name
87474 ** Register built-in functions used to help implement ALTER TABLE
87525 ** tables that have foreign key constraints that refer to table pTab (i.e.
87526 ** constraints for which pTab is the parent table) from the sqlite_master
87527 ** table.
87529 static char *whereForeignKeys(Parse *pParse, Table *pTab){
87541 ** temporary triggers on table pTab from the sqlite_temp_master table. If
87542 ** table pTab has no temporary triggers, or is itself stored in the
87545 static char *whereTempTriggers(Parse *pParse, Table *pTab){
87550 /* If the table is not located in the temp-db (in which case NULL is
87572 ** Generate code to drop and reload the internal representation of table
87574 ** Argument zName is the name of the table in the database schema at
87577 ** "ALTER TABLE RENAME TO" statement.
87579 static void reloadTableSchema(Parse *pParse, Table *pTab, const char *zName){
87594 /* Drop any table triggers from the internal schema. */
87602 /* Drop the table and index from the internal schema. */
87605 /* Reload the table, index and permanent trigger schemas. */
87611 /* Now, if the table is not stored in the temp database, reload any temp
87621 ** Parameter zName is the name of a table that is about to be altered
87622 ** (either with ALTER TABLE ... RENAME TO or ALTER TABLE ... ADD COLUMN).
87623 ** If the table is a system table, this function leaves an error message
87626 ** Or, if zName is not a system table, zero is returned.
87630 sqlite3ErrorMsg(pParse, "table %s may not be altered", zName);
87637 ** Generate code to implement the "ALTER TABLE xxx RENAME TO yyy"
87642 SrcList *pSrc, /* The table to rename. */
87643 Token *pName /* The new table name. */
87645 int iDb; /* Database that contains the table */
87647 Table *pTab; /* Table being renamed */
87651 const char *zTabName; /* Original name of the table */
87670 /* Get a NULL terminated version of the new table name. */
87674 /* Check that a table or index named 'zName' does not already exist
87679 "there is already another table or index with this name: %s", zName);
87683 /* Make sure it is not a system table being altered, or a reserved name
87684 ** that the table is being renamed to.
87720 ** Then modify the schema cookie (since the ALTER TABLE modifies the
87721 ** schema). Open a statement transaction if the table is a virtual
87722 ** table.
87731 /* If this is a virtual table, invoke the xRename() function if
87733 ** of any resources used by the v-table implementation (including other
87734 ** SQLite tables) that are identified by the name of the virtual table.
87751 /* If foreign-key support is enabled, rewrite the CREATE TABLE
87753 ** for which the renamed table is the parent table. */
87764 /* Modify the sqlite_master table to use the new table name. */
87776 "WHEN type='table' THEN %Q "
87781 "(type='table' OR type='index' OR type='trigger');",
87790 /* If the sqlite_sequence table exists in this database, then update
87791 ** it with the new table name.
87801 /* If there are TEMP triggers on this table, modify the sqlite_temp_master
87802 ** table. Don't do this if the table being ALTERed is itself located in
87819 Table *pFrom = p->pFrom;
87827 /* Drop and reload the internal table schema. */
87864 ** This function is called after an "ALTER TABLE ... ADD" statement
87868 ** The Table structure pParse->pNewTable was extended to include
87872 Table *pNew; /* Copy of pParse->pNewTable */
87873 Table *pTab; /* Table being altered */
87876 const char *zTab; /* Table name */
87953 /* Modify the CREATE TABLE statement. */
87965 "WHERE type = 'table' AND name = %Q",
87979 /* Reload the schema of the modified table. */
87984 ** This function is called by the parser after the table-name in
87985 ** an "ALTER TABLE <table-name> ADD" statement is parsed. Argument
87986 ** pSrc is the full-name of the table being altered.
87988 ** This routine makes a (partial) copy of the Table structure
87989 ** for the table being altered and sets Parse.pNewTable to point
87992 ** the copy. The copy of the Table structure is deleted by tokenize.c
87996 ** coding the "ALTER TABLE ... ADD" statement.
87999 Table *pNew;
88000 Table *pTab;
88007 /* Look up the table being altered. */
88033 /* Put a copy of the Table struct in Parse.pNewTable for the
88037 ** table because user table are not allowed to have the "sqlite_"
88040 pNew = (Table*)sqlite3DbMallocZero(db, sizeof(Table));
88100 ** CREATE TABLE sqlite_stat1(tbl, idx, stat);
88101 ** CREATE TABLE sqlite_stat2(tbl, idx, sampleno, sample);
88102 ** CREATE TABLE sqlite_stat3(tbl, idx, nEq, nLt, nDLt, sample);
88103 ** CREATE TABLE sqlite_stat4(tbl, idx, nEq, nLt, nDLt, sample);
88106 ** The sqlite_stat2 table is not created or used unless the SQLite version
88108 ** with SQLITE_ENABLE_STAT2. The sqlite_stat2 table is deprecated.
88109 ** The sqlite_stat2 table is superseded by sqlite_stat3, which is only
88124 ** name in the idx column. The tbl column is the name of the table to
88128 ** number of rows in the table, except for partial indices.) The second
88145 ** rows in the table identified by sqlite_stat1.tbl.
88151 ** 3.6.18 and 3.7.8. The "stat2" table contains additional information
88153 ** the "idx" column and the "tbl" column is the name of the table to which
88155 ** table for each index.
88170 ** writes the sqlite_stat2 table. This version of SQLite only supports
88181 ** As with sqlite_stat2, the sqlite_stat4 table contains histogram data
88186 ** The sqlite_stat4 table contains multiple entries for each index.
88187 ** The idx column names the index and the tbl column is the table of the
88214 ** The sqlite_stat3 table is like sqlite_stat4 except that it only
88240 ** The sqlite_stat1 table is always relevant. sqlite_stat2 is now
88246 ** Argument zWhere may be a pointer to a buffer containing a table name,
88248 ** the sqlite_statN tables associated with the named table are deleted.
88249 ** If zWhere==0, then code is generated to delete all stat table entries.
88254 int iStatCur, /* Open the sqlite_stat1 table on this cursor */
88255 const char *zWhere, /* Delete entries for this table or index */
88291 Table *pStat;
88294 /* The sqlite_statN table does not exist. Create it. Note that a
88295 ** side-effect of the CREATE TABLE statement is to leave the rootpage
88296 ** of the new table in register pParse->regRoot. This is important
88299 "CREATE TABLE %Q.%s(%s)", pDb->zName, zTab, aTable[i].zCols
88305 /* The table already exists. If zWhere is not NULL, delete all entries
88306 ** associated with the table zWhere. If zWhere is NULL, delete the
88307 ** entire contents of the table. */
88317 /* The sqlite_stat[134] table already exists. Delete all rows. */
88352 i64 iRowid; /* Rowid in main table of the key */
88362 tRowcnt nRow; /* Number of rows in the entire table */
88458 ** WITHOUT ROWID table, N is the number of PRIMARY KEY columns, not the
88459 ** total number of columns in the table.
88465 ** PRIMARY KEY of the table. The covering index that implements the
88466 ** original WITHOUT ROWID table as N==K as a special case.
88643 ** iCol occurs many times in the table. However, if we have already
88869 #define STAT_GET_STAT1 0 /* "stat" column of stat1 table */
88886 ** stat1 table entry information.
88908 ** table for this index.
89032 ** a single table.
89036 Table *pTab, /* Table whose indices are to be analyzed */
89038 int iStatCur, /* Index of VdbeCursor that writes the sqlite_stat1 table */
89045 int iTabCur; /* Table cursor */
89050 u8 needTableCnt = 1; /* True to count the table */
89058 int regTabname = iMem++; /* Register containing table name */
89087 /* Establish a read-lock on the table at the shared-cache level.
89088 ** Open a read-only cursor on the table. Also allocate a cursor number
89156 ** the sqlite_stat4 table. */
89168 ** (or for a WITHOUT ROWID table, the number of PK columns),
89281 /* Add the entry to the stat1 table. */
89289 /* Add the entries to the stat3 or stat4 table. */
89387 Table *pTab = (Table*)sqliteHashData(k);
89394 ** Generate code that will do an analysis of a single table in
89398 static void analyzeTable(Parse *pParse, Table *pTab, Index *pOnlyIdx){
89427 ** Form 3 analyzes all indices associated with the named table.
89434 Table *pTab;
89454 /* Form 2: Analyze the database or table named */
89470 /* Form 3: Analyze the fully qualified table name */
89566 ** sqlite_stat1 table.
89568 ** argv[0] = name of the table
89573 ** the table.
89578 Table *pTable;
89692 ** occur in the stat4 table for this index. Set sumEq to the sum of
89714 ** Look up an index by name. Or, if the name of a WITHOUT ROWID table
89715 ** is supplied instead, find the PRIMARY KEY index for that table.
89724 Table *pTab = sqlite3FindTable(db, zName, zDb);
89731 ** Load the content from either the sqlite_stat4 or sqlite_stat3 table
89781 ** loaded from the stat4 table. In this case ignore stat3 data. */
89831 ** the sqlite_stat4 table. In this case ignore stat3 data. */
89897 ** If the sqlite_stat1 table is not present in the database, SQLITE_ERROR
89899 ** during compilation and the sqlite_stat3/4 table is present, no data is
89903 ** sqlite_stat4 table is not present in the database, SQLITE_ERROR is
89905 ** table (if it is present) before returning.
89931 /* Check to make sure the sqlite_stat1 table exists */
89938 /* Load new statistics out of the sqlite_stat1 table */
89949 /* Load the statistics from the sqlite_stat4 table. */
90421 ** a specific database to all table references where the database name
90618 ** the table and the column that are being accessed. The auth function
90656 ** table zTab in database zDb. This function assumes that an authorization
90665 const char *zTab, /* Table name */
90692 ** The pExpr should be a TK_COLUMN expression. The table referred to
90693 ** is in pTabList or else it is the NEW or OLD table of a trigger.
90704 SrcList *pTabList /* All table that pExpr might refer to */
90707 Table *pTab = 0; /* The table being read */
90708 const char *zCol; /* Name of the column of the table */
90709 int iSrc; /* Index in pTabList->a[] of table being read */
90711 int iCol; /* Index of column in table */
90717 ** temporary table. */
90838 ** CREATE TABLE
90839 ** DROP TABLE
90863 int iDb; /* The database containing the table to be locked */
90864 int iTab; /* The root page of the table to be locked */
90866 const char *zName; /* Name of the table */
90870 ** Record the fact that we want to lock a table at run-time.
90872 ** The table to be locked has root page iTab and is found in database iDb.
90881 int iDb, /* Index of the database containing the table to lock */
90882 int iTab, /* Root page number of the table to be locked */
90884 const char *zName /* Name of the table to be locked */
90916 ** Code an OP_TableLock instruction for each table locked by the
91026 ** obtain the required table-locks. This is a no-op unless the
91110 ** Return TRUE if zTable is the name of the system table that stores the
91120 ** table given the name of that table and (optionally) the name of the
91121 ** database containing the table. Return NULL if not found.
91123 ** If zDatabase is 0, all databases are searched for the table and the
91124 ** first matching table is returned. (No checking for duplicate table
91130 SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){
91131 Table *p = 0;
91137 /* Only the admin user is allowed to know that the sqlite_user table
91155 ** table given the name of that table and (optionally) the name of the
91156 ** database containing the table. Return NULL if not found. Also leave an
91163 SQLITE_PRIVATE Table *sqlite3LocateTable(
91165 int isView, /* True if looking for a VIEW rather than a TABLE */
91166 const char *zName, /* Name of the table we are looking for */
91169 Table *p;
91179 const char *zMsg = isView ? "no such view" : "no such table";
91197 ** Locate the table identified by *p.
91205 SQLITE_PRIVATE Table *sqlite3LocateTableItem(
91228 ** table and the first matching index is returned. (No checking
91268 ** unlike that index from its Table then remove the index from
91269 ** the index hash table and free all memory structures associated
91381 ** Delete memory allocated for the column names of a table or view (the
91382 ** Table.aCol[] array).
91384 static void sqliteDeleteColumnNames(sqlite3 *db, Table *pTable){
91402 ** Table. No changes are made to disk by this routine.
91405 ** the table data structure from the hash table. But it does destroy
91407 ** the table.
91409 ** The db parameter is optional. It is needed if the Table object
91410 ** contains lookaside memory. (Table objects in the schema do not use
91411 ** lookaside memory, but some ephemeral Table objects do.) Or the
91413 ** used by the Table object.
91415 SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
91421 /* Do not delete the table until the reference count reaches zero. */
91431 /* Delete all indices associated with this table. */
91446 /* Delete any foreign keys attached to this table. */
91449 /* Delete the Table structure itself.
91468 ** Unlink the given table from the hash tables and the delete the
91469 ** table structure with all its indices and foreign keys.
91472 Table *p;
91479 testcase( zTabName[0]==0 ); /* Zero-length table names are allowed */
91511 ** Open the sqlite_master table stored in database number iDb for
91512 ** writing. The table is opened using cursor 0.
91559 /* The table or view or trigger name is passed to this routine via tokens
91560 ** pName1 and pName2. If the table name was fully qualified, for example:
91562 ** CREATE TABLE xxx.yyy (...);
91565 ** the table name is not fully qualified, i.e.:
91567 ** CREATE TABLE yyy(...);
91572 ** pName2) that stores the unqualified table name. The index of the
91605 ** unqualified name for a new schema object (table, index, view or
91621 ** Return the PRIMARY KEY index of a table
91623 SQLITE_PRIVATE Index *sqlite3PrimaryKeyIndex(Table *pTab){
91630 ** Return the column of index pIdx that corresponds to table
91642 ** Begin constructing a new table representation in memory. This is
91644 ** to a CREATE TABLE statement. In particular, this routine is called
91645 ** after seeing tokens "CREATE" and "TABLE" and the table name. The isTemp
91646 ** flag is true if the table should be stored in the auxiliary database
91649 ** CREATE and TABLE.
91651 ** The new table record is initialized and put in pParse->pNewTable.
91652 ** As more of the CREATE TABLE statement is parsed, additional action
91654 ** At the end of the CREATE TABLE statement, the sqlite3EndTable() routine
91655 ** is called to complete the construction of the new table record.
91659 Token *pName1, /* First part of the name of the table or view */
91660 Token *pName2, /* Second part of the name of the table or view */
91661 int isTemp, /* True if this is a TEMP table */
91663 int isVirtual, /* True if this is a VIRTUAL table */
91664 int noErr /* Do nothing if table already exists */
91666 Table *pTable;
91667 char *zName = 0; /* The name of the new table */
91670 int iDb; /* Database number to create the table in */
91671 Token *pName; /* Unqualified name of the table to create */
91673 /* The table or view name to create is passed to this routine via tokens
91674 ** pName1 and pName2. If the table name was fully qualified, for example:
91676 ** CREATE TABLE xxx.yyy (...);
91679 ** the table name is not fully qualified, i.e.:
91681 ** CREATE TABLE yyy(...);
91686 ** pName2) that stores the unqualified table name. The variable iDb is
91687 ** set to the index of the database that the table or view is to be
91693 /* If creating a temp table, the name may not be qualified. Unless
91695 sqlite3ErrorMsg(pParse, "temporary table name must be unqualified");
91734 /* Make sure the new table name does not collide with an existing
91735 ** index or table name in the same database. Issue an error message if
91749 sqlite3ErrorMsg(pParse, "table %T already exists", pName);
91762 pTable = sqlite3DbMallocZero(db, sizeof(Table));
91777 /* If this is the magic sqlite_sequence table used by autoincrement,
91778 ** then record a pointer to this table in the main database structure
91779 ** so that INSERT can find the table easily.
91788 /* Begin generating the code that will insert the table record into
91789 ** the SQLITE_MASTER table. Note in particular that we must go ahead
91790 ** and allocate the record number for the table entry now. Before any
91792 ** indices to be created and the table record must come before the
91793 ** indices. Hence, the record number for the table must be allocated
91825 /* This just creates a place-holder record in the sqlite_master table.
91830 ** The root page number of the new table is left in reg pParse->regRoot.
91873 ** Add a new column to the table currently being constructed.
91876 ** in a CREATE TABLE statement. sqlite3StartTable() gets called
91881 Table *p;
91926 ** parsing a CREATE TABLE statement. A "NOT NULL" constraint has
91931 Table *p;
91942 ** substrings in the following table. If one of the substrings is
91945 ** the table take priority. For example, if zType is 'BLOBINT',
91959 ** If none of the substrings in the above table are found,
92026 ** parsing a CREATE TABLE statement. The pFirst token is the first
92034 Table *p;
92048 ** of the table currently under construction.
92054 ** parsing a CREATE TABLE statement.
92057 Table *p;
92082 ** Designate the PRIMARY KEY for the table. pList is a list of names
92084 ** most recently added column of the table is the primary key.
92086 ** A table can have at most one primary key. If the table already has
92091 ** then we will try to use that column as the rowid. Set the Table.iPKey
92092 ** field of the table under construction to be the index of the
92093 ** INTEGER PRIMARY KEY column. Table.iPKey is set to -1 if there is
92106 Table *pTab = pParse->pNewTable;
92113 "table \"%s\" has more than one primary key", pTab->zName);
92167 ** Add a new CHECK constraint to the table currently under construction.
92174 Table *pTab = pParse->pNewTable;
92191 ** Set the collation function of the most recently parsed table column
92195 Table *p;
92340 ** Generate a CREATE TABLE statement appropriate for the given
92341 ** table. Memory to hold the text of the statement is obtained
92344 static char *createTableStmt(sqlite3 *db, Table *p){
92369 sqlite3_snprintf(n, zStmt, "CREATE TABLE ");
92434 ** Estimate the total row width for a table.
92436 static void estimateTableWidth(Table *pTab){
92470 ** This routine runs at the end of parsing a CREATE TABLE statement that
92473 ** are appropriate for a WITHOUT ROWID table instead of a rowid table.
92479 ** (2) Bypass the creation of the sqlite_master table entry
92481 ** identified by the sqlite_master table entry of the table itself.
92483 ** schema to the rootpage from the main table.
92485 ** (5) Add all table columns to the PRIMARY KEY Index object
92492 static void convertToWithoutRowidTable(Parse *pParse, Table *pTab){
92501 ** root-page for the table into an OP_CreateIndex opcode. The index
92510 ** table entry.
92517 /* Locate the PRIMARY KEY index. Or, if this table was originally
92518 ** an INTEGER PRIMARY KEY table, create a new PRIMARY KEY index.
92561 /* The root page of the PRIMARY KEY is the table root page */
92590 /* Add all table columns to the PRIMARY KEY index
92611 ** a CREATE TABLE statement.
92613 ** The table structure that other action routines have been building
92617 ** An entry for the table is made in the master table on disk, unless
92618 ** this is a temporary table or db->init.busy==1. When db->init.busy==1
92619 ** it means we are reading the sqlite_master table because we just
92620 ** connected to the database or because the sqlite_master table has
92621 ** recently changed, so the entry for this table already exists in
92622 ** the sqlite_master table. We do not want to create it again.
92625 ** was called to create a table generated from a
92626 ** "CREATE TABLE ... AS SELECT ..." statement. The column names of
92627 ** the new table will match the result set of the SELECT.
92632 Token *pEnd, /* The ')' before options in the CREATE TABLE */
92633 u8 tabOpts, /* Extra table options. Usually 0. */
92636 Table *p; /* The new table */
92638 int iDb; /* Database in which the table lives */
92639 Index *pIdx; /* An implied index of the table */
92650 ** "sqlite_master" or "sqlite_temp_master" table on the disk.
92652 ** for the table from the db->init.newTnum field. (The page number
92667 sqlite3ErrorMsg(pParse, "PRIMARY KEY missing on table %s", p->zName);
92684 /* Estimate the average row size for the table and for all implied indices */
92690 /* If not initializing, then create a record for the new table
92691 ** in the SQLITE_MASTER table of the database.
92693 ** If this is a TEMPORARY table, write the entry into the auxiliary
92699 char *zType; /* "view" or "table" */
92700 char *zType2; /* "VIEW" or "TABLE" */
92701 char *zStmt; /* Text of the CREATE TABLE or CREATE VIEW statement */
92709 ** Initialize zType for the new view or table.
92712 /* A regular table */
92713 zType = "table";
92714 zType2 = "TABLE";
92723 /* If this is a CREATE TABLE xx AS SELECT ..., execute the SELECT
92724 ** statement to populate the new table. The root-page number for the
92725 ** new table is in register pParse->regRoot.
92729 ** by the new table.
92731 ** A shared-cache write-lock is not required to write to the new table,
92738 Table *pSelTab;
92772 ** SQLITE_MASTER table. We just need to update that slot with all
92791 /* Check to see if we need to create an sqlite_sequence table for
92799 "CREATE TABLE %Q.sqlite_sequence(name,seq)",
92812 /* Add the table to the in-memory representation of the database.
92815 Table *pOld;
92855 Table *p;
92911 /* Use sqlite3EndTable() to add the view to the SQLITE_MASTER table */
92919 ** The Table structure pTable is really a VIEW. Fill in the names of
92923 SQLITE_PRIVATE int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){
92924 Table *pSelTab; /* A fake table from which we get the result set */
92957 ** CREATE TABLE main.ex1(a);
92967 /* If we get this far, it means we need to compute the table names.
93023 Table *pTab = sqliteHashData(i);
93038 ** used by SQLite when the btree layer moves a table root page. The
93039 ** root-page of a table or index in database iDb has changed from iFrom
93042 ** Ticket #1728: The symbol table might still contain information
93045 ** have the same rootpage number as the real table or index that is
93048 ** or tables and not the table/index that is actually being moved.
93063 Table *pTab = sqliteHashData(pElem);
93079 ** Write code to erase the table with root-page iTable from database iDb.
93080 ** Also write code to modify the sqlite_master table and internal schema
93081 ** if a root-page of another table is moved by the btree-layer whilst
93091 ** is non-zero, then it is the root page number of a table moved to
93092 ** location iTable. The following code modifies the sqlite_master table to
93107 ** Write VDBE code to erase table pTab and all associated indices on disk.
93109 ** in case a root-page belonging to another table is moved by the btree layer
93112 static void destroyTable(Parse *pParse, Table *pTab){
93123 ** table and index root-pages in order, starting with the numerically
93168 ** after a DROP INDEX or DROP TABLE command.
93174 const char *zName /* Name of index or table */
93191 ** Generate code to drop a table.
93193 SQLITE_PRIVATE void sqlite3CodeDropTable(Parse *pParse, Table *pTab, int iDb, int isView){
93209 /* Drop all triggers associated with the table being dropped. Code
93222 /* Remove any entries of the sqlite_sequence table associated with
93223 ** the table being dropped. This is done before the table is dropped
93224 ** at the btree level, in case the sqlite_sequence table needs to
93235 /* Drop all SQLITE_MASTER table and index entries that refer to the
93236 ** table. The program name loops through the master table and deletes
93237 ** every row that refers to a table of the same name as the one being
93239 table in another
93249 /* Remove the table entry from SQLite's internal schema and modify
93261 ** This routine is called to do the work of a DROP TABLE statement.
93262 ** pName is the name of the table to be dropped.
93265 Table *pTab;
93287 /* If pTab is a virtual table, call ViewGetColumnNames() to ensure
93330 sqlite3ErrorMsg(pParse, "table %s may not be dropped", pTab->zName);
93335 /* Ensure DROP TABLE is not used on a view, and DROP VIEW is not used
93336 ** on a table.
93339 sqlite3ErrorMsg(pParse, "use DROP TABLE to delete table %s", pTab->zName);
93348 /* Generate code to remove the table from the master table
93364 ** This routine is called to create a new foreign key on the table
93366 ** in the current table point to the foreign key. If pFromCol==0 then
93368 ** the table referred to (a.k.a the "parent" table). pToCol is a list
93369 ** of tables in the parent pTo table. flags contains all
93373 ** An FKey structure is created and added to the table currently
93381 ExprList *pFromCol, /* Columns in this table that point to other table */
93382 Token *pTo, /* Name of the other table */
93383 ExprList *pToCol, /* Columns in the other table */
93390 Table *p = pParse->pNewTable;
93403 " should reference only one column of table %T",
93411 "columns in the referenced table");
93481 /* Link the foreign key to the table as the last step.
93502 Table *pTab;
93522 Table *pTab = pIndex->pTable; /* The table that is indexed */
93543 /* Require a write-lock on the table to perform this operation */
93560 /* Open the table. Loop through all rows of the table, inserting index
93637 ** Create a new index for an SQL table. pName1.pName2 is the name of the index
93638 ** and pTblList is the name of the table that is to be indexed. Both will
93641 ** as the table to be indexed. pParse->pNewTable is a table that is
93642 ** currently being constructed by a CREATE TABLE statement.
93646 ** to the table currently under construction.
93656 SrcList *pTblName, /* Table to index. Use pParse->pNewTable if 0 */
93665 Table *pTab = 0; /* Table to be indexed */
93673 Db *pDb; /* The specific table containing the indexed database */
93677 const Column *pTabCol; /* A column in the table */
93691 ** Find the table
93696 ** to search for the table. 'Fix' the table name to this db
93697 ** before looking up the table.
93705 /* If the index name was unqualified, check if the table
93706 ** is a temp table. If so, set the database to 1. Do not do this
93728 "cannot create a TEMP index on non-TEMP table \"%s\"",
93750 sqlite3ErrorMsg(pParse, "table %s may not be indexed", pTab->zName);
93768 ** index or table with the same name.
93771 ** sqlite_master table (because some other process changed the schema) and
93772 ** one of the index names collides with the name of a temporary table or
93788 sqlite3ErrorMsg(pParse, "there is already a table named %s", zName);
93828 ** key out of the last column added to the table under construction.
93886 /* Scan the names of the columns of the table to be indexed and
93905 sqlite3ErrorMsg(pParse, "table %s has no column named %s",
93960 ** CREATE TABLE t(x PRIMARY KEY, y);
93961 ** CREATE TABLE t(x, y, UNIQUE(x, y));
93963 ** Either way, check to see if the table already has such an index. If
93995 ** constraint specified somewhere in the CREATE TABLE statement.
94015 /* Link the new Index structure to its table and to the other
94034 /* If this is the initial CREATE INDEX statement (or CREATE TABLE if the
94037 ** the index in the sqlite_master table and populate the index with
94039 ** table to parse the schema, or if this index is the PRIMARY KEY index
94040 ** of a WITHOUT ROWID table.
94043 ** or UNIQUE index in a CREATE TABLE statement. Since the table
94100 /* When adding an index to the list of indices for a table, make
94139 ** number of rows in the table that match any particular value of the
94159 ** number of rows in the table. Or 10, if the estimated number of rows
94160 ** in the table is less than that. */
94212 Table *pTab = pIndex->pTable;
94225 /* Generate code to remove the index and from the master table */
94406 ** Append a new table name to the given SrcList. Create a new SrcList if
94414 ** If pDatabase is not null, it means that the table has an optional
94415 ** database name prefix. Like this: "database.table". The pDatabase
94416 ** points to the table name and the pTable points to the database name.
94417 ** The SrcList.a[].zName field is filled with the table name which might
94426 ** Then B is a table name and the database name is unspecified. If called
94431 ** Then C is the table name and B is the database name. If C is defined
94442 Token *pTable, /* Table to append */
94443 Token *pDatabase /* Database of the table */
94514 ** are the name of the table and database named in the FROM clause term.
94528 Token *pTable, /* Name of the table to add to the FROM clause */
94531 Select *pSubquery, /* A subquery used in place of a table name */
94783 ** inserting multiple rows in a table, or inserting a row and index entries.)
94846 Table *pTab = pIdx->pTable;
94870 Table *pTab /* The table with the non-unique rowid */
94910 static void reindexTable(Parse *pParse, Table *pTab, char const *zColl){
94934 Table *pTab; /* A table in the database */
94940 pTab = (Table*)sqliteHashData(k);
94958 ** indices associated with the named table.
94963 char *z; /* Name of a table or index */
94965 Table *pTab; /* A table in the database */
94969 Token *pObjName; /* Name of the table or index to be reindexed */
95061 Token *pName, /* Name of the common-table */
95062 ExprList *pArglist, /* Optional column name list for the table */
95063 Select *pQuery /* Query used to initialize the table */
95076 sqlite3ErrorMsg(pParse, "duplicate WITH table name: %s", zName);
95262 ** Locate and return an entry from the db.aCollSeq hash table. If the entry
95266 ** Each pointer stored in the sqlite3.aCollSeq hash table contains an
95299 ** to the hash table).
95410 FuncDefHash *pHash, /* Hash table to search */
95425 ** Insert a new FuncDef into a FuncDefHash hash table.
95428 FuncDefHash *pHash, /* The hash table into which to insert */
95525 ** new entry to the hash table and return it.
95567 Table *pTab = sqliteHashData(pElem);
95622 ** the name of a single table, as one might find in an INSERT, DELETE,
95623 ** or UPDATE statement. Look up that table in the symbol table and
95624 ** return a pointer. Set an error message and return NULL if the table
95629 ** pSrc->a[0].pTab Pointer to the Table object
95633 SQLITE_PRIVATE Table *sqlite3SrcListLookup(Parse *pParse, SrcList *pSrc){
95635 Table *pTab;
95650 ** Check to make sure the given table is writable. If it is not
95654 SQLITE_PRIVATE int sqlite3IsReadOnly(Parse *pParse, Table *pTab, int viewOk){
95655 /* A table is not writable under the following circumstances:
95657 ** 1) It is a virtual table and no implementation of the xUpdate method
95659 ** 2) It is a system table (i.e. sqlite_master), this call is not
95671 sqlite3ErrorMsg(pParse, "table %s may not be modified", pTab->zName);
95687 ** Evaluate a view and store its result in an ephemeral table. The
95689 ** set of rows in the view that are to be added to the ephemeral table.
95693 Table *pView, /* View definition */
95695 int iCur /* Cursor number for ephemeral table */
95821 SrcList *pTabList, /* The table from which we should delete things */
95825 Table *pTab; /* The table from which records will be deleted */
95829 Index *pIdx; /* For looping over indices of the table */
95830 int iTabCur; /* Cursor number for the table */
95843 Index *pPk; /* The PRIMARY KEY index on the table */
95848 int iEphCur = 0; /* Ephemeral table holding all primary key values */
95853 int addrEphOpen = 0; /* Instruction to open the Ephemeral table */
95857 Trigger *pTrigger; /* List of table triggers, if required */
95867 /* Locate the table which we want to delete. This table has to be
95870 ** an SrcList* parameter instead of just a Table* parameter.
95875 /* Figure out if we have any triggers and if the table being
95909 /* Assign cursor numbers to the table and all its indices.
95933 ** an ephemeral table.
95961 ** It is easier just to erase the whole table. Prior to version 3.6.5,
95981 /* For a rowid table, initialize the RowSet to an empty set */
95987 /* For a WITHOUT ROWID table, create an ephemeral table used to
96065 /* Unless this is a view, open cursors for the table we are
96127 /* Close the cursors open on the table and its indexes. */
96136 /* Update the sqlite_sequence table by storing the content of the
96173 ** single table to be deleted. Both the original table entry and
96179 ** store for the table. (This will be either the table itself,
96180 ** in the case of a rowid table, or the PRIMARY KEY index in the case
96181 ** of a WITHOUT ROWID table.)
96193 Table *pTab, /* Table containing the row to be deleted */
96240 /* Populate the OLD.* pseudo-table register array. These values will be
96269 ** refer to this table (i.e. constraints attached to other tables)
96274 /* Delete the index and table entries. Skip this step if pTab is really
96304 ** index entries associated with a single row of a single table, pTab
96309 ** btree for the table pTab. (This will be either the table itself
96322 Table *pTab, /* Table containing the row to be deleted */
96323 int iDataCur, /* Cursor of table holding data. */
96354 ** iCur is the index of a cursor open on the pTab table and pointing to
96355 ** the entry that needs indexing. If pTab is a WITHOUT ROWID table, then
96379 ** on a table with multiple indices, and especially with the ROWID or
96394 Table *pTab = pIdx->pTable;
96417 ** might be stored in the table as an integer (using a compact
96903 ** routines in the function table. The noopFunc macro provides this.
98132 ** to the global function hash table. This occurs at start-time (as
98297 ** I.1) For each FK for which the table is the child table, search
98298 ** the parent table for a match. If none is found increment the
98301 ** I.2) For each FK for which the table is the parent table,
98302 ** search the child table for rows that correspond to the new
98303 ** row in the parent table. Decrement the counter for each row
98308 ** D.1) For each FK for which the table is the child table,
98309 ** search the parent table for a row that corresponds to the
98310 ** deleted row in the child table. If such a row is not found,
98313 ** D.2) For each FK for which the table is the parent table, search
98314 ** the child table for rows that correspond to the deleted row
98315 ** in the parent table. For each found increment the counter.
98343 ** TODO: How should dropping a table be handled? How should renaming a
98344 ** table be handled?
98379 ** CREATE TABLE t1(a, b INTEGER PRIMARY KEY, c);
98390 ** table are collectively subject to a UNIQUE or PRIMARY KEY constraint.
98391 ** Given that pParent is the parent table for foreign key constraint pFKey,
98402 ** array is the index of the child table column that is mapped by the FK
98403 ** constraint to the parent table column stored in the left-most column
98405 ** child table column that corresponds to the second left-most column of
98416 ** foreign key definition, and the parent table does not have a
98420 ** foreign key definition, and the PRIMARY KEY of the parent table
98422 ** the child table.
98430 Table *pParent, /* Parent table of FK constraint pFKey */
98432 Index **ppIdx, /* OUT: Unique index on parent table */
98446 ** maps to the INTEGER PRIMARY KEY of table pParent. If so, leave *ppIdx
98457 ** mapped to the primary key of table pParent, or
98480 ** the PRIMARY KEY of table pParent. The PRIMARY KEY index may be
98491 ** map to an explicit list of columns in table pParent. Check if this
98539 ** child table of foreign key constraint pFKey. If an SQL UPDATE is executed
98540 ** on the child table of pFKey, this function is invoked twice for each row
98545 ** row in the parent table that corresponds to the row being inserted into
98546 ** or deleted from the child table. If the parent row can be found, no
98548 ** found in the parent table:
98566 Table *pTab, /* Parent table of FK pFKey */
98569 int *aiCol, /* Map from parent key columns to child table columns */
98570 int regData, /* Address of array containing child table row */
98583 ** Check if any of the key columns in the child table row are NULL. If
98585 ** search for a matching row in the parent table. */
98598 ** column of the parent table (table pTab). */
98611 /* If the parent table is the same as the child table, and we are about
98637 /* If the parent table is the same as the child table, and we are about
98677 ** one row into the table, raise a constraint immediately instead of
98697 ** to column iCol of table pTab.
98705 Table *pTab, /* The table whose content is at r[regBase]... */
98706 int regBase, /* Contents of table pTab */
98732 ** Return an Expr object that refers to column iCol of table pTab which
98737 Table *pTab, /* The table whose column is desired */
98738 int iCursor, /* The open cursor on the table */
98752 ** from the parent table of foreign key constraint pFKey and, if pFKey is
98753 ** deferred, when a row is inserted into the same table. When generating
98762 ** table that correspond to the parent table row being deleted or inserted.
98784 SrcList *pSrc, /* The child table to be scanned */
98785 Table *pTab, /* The parent table */
98788 int *aiCol, /* Map from pIdx cols to child table cols */
98819 Expr *pLeft; /* Value from parent table row */
98820 Expr *pRight; /* Column ref to child table */
98822 i16 iCol; /* Index of column in child table */
98823 const char *zCol; /* Name of column in child table */
98835 /* If the child table is the same as the parent table, then add terms
98848 Expr *pLeft; /* Value from parent table row */
98849 Expr *pRight; /* Column ref to child table */
98894 ** FKey.pNextTo) holding all children of table pTab. For example,
98897 ** CREATE TABLE t1(a PRIMARY KEY);
98898 ** CREATE TABLE t2(b REFERENCES t1(a);
98900 ** Calling this function with table "t1" as an argument returns a pointer
98901 ** to the FKey structure representing the foreign key constraint on table
98904 ** table).
98906 SQLITE_PRIVATE FKey *sqlite3FkReferences(Table *pTab){
98930 ** This function is called to generate code that runs when table pTab is
98933 ** table pTab.
98937 ** (a) The table is the parent table of a FK constraint, or
98938 ** (b) The table is the child table of a deferred FK constraint and it is
98943 ** the table from the database. Triggers are disabled while running this
98946 SQLITE_PRIVATE void sqlite3FkDropTable(Parse *pParse, SrcList *pName, Table *pTab){
98954 /* Search for a deferred foreign key constraint for which this table
98955 ** is the child table. If one cannot be found, return without
98997 ** for which pTab is the child table. An UPDATE statement against pTab
98998 ** is currently being processed. For each column of the table that is
99008 Table *pTab, /* Table being updated */
99024 ** for which pTab is the parent table. An UPDATE statement against pTab
99025 ** is currently being processed. For each column of the table that is
99035 Table *pTab,
99078 ** table pTab to generate VDBE code to perform foreign key constraint
99092 ** the original record is deleted from the table using the calling convention
99098 Table *pTab, /* Row is being deleted from this table */
99120 ** child table (the table that the foreign key definition is part of). */
99122 Table *pTo; /* Parent table of foreign key pFKey */
99137 /* Find the parent table of this foreign key. Also find a unique index
99138 ** on the parent key columns in the parent table. If either of these
99150 /* If isIgnoreErrors is true, then a table is being dropped. In this
99151 ** case SQLite runs a "DELETE FROM xxx" on the table being dropped
99153 ** If the parent table of an FK constraint on the current table is
99155 ** FK counter for each row of the current table with non-NULL keys.
99182 ** values read from the parent table are NULL. */
99192 /* Take a shared-cache advisory read-lock on the parent table. Allocate
99194 ** in the parent table. */
99199 /* A row is being removed from the child table. Search for the parent.
99205 /* A row is being added to the child table. If a parent row cannot
99219 /* Loop through all the foreign key constraints that refer to this table.
99234 /* Inserting a single row into a parent table cannot cause (or fix)
99245 /* Create a SrcList structure containing the child table. We need the
99246 ** child table as a SrcList for sqlite3WhereBegin() */
99275 ** child table to fire. In these cases the fk constraint counters
99293 ** row contained in table pTab.
99297 Table *pTab /* Table being modified */
99320 ** row contained in table pTab. If the operation is a DELETE, then
99322 ** to an array of size N, where N is the number of columns in table pTab.
99326 ** UPDATE statement modifies the rowid fields of the table.
99334 Table *pTab, /* Table being modified */
99341 ** table in question is either the child or parent table for any
99365 ** compiled on table pTab, which is the parent table of foreign-key pFKey.
99376 ** For example, if pFKey is the foreign key and pTab is table "p" in
99379 ** CREATE TABLE p(pk PRIMARY KEY);
99380 ** CREATE TABLE c(ck REFERENCES p ON DELETE CASCADE);
99394 Table *pTab, /* Table being updated or deleted from */
99408 char const *zFrom; /* Name of child table */
99411 int *aiCol = 0; /* child table cols -> parent key cols */
99425 Token tFromCol; /* Name of column in child table */
99426 Token tToCol; /* Name of column in parent table */
99427 int iFromCol; /* Idx of column in child table */
99442 ** parent table are used for the comparison. */
99580 Table *pTab, /* Table being updated or deleted from */
99587 ** refer to table pTab. If there is an action associated with the FK
99607 ** table pTab. Remove the deleted foreign keys from the Schema.fkeyHash
99608 ** hash table.
99610 SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){
99617 /* Remove the FK from the fkeyHash hash table. */
99668 ** (1) acquire a lock for table pTab then
99671 ** If pTab is a WITHOUT ROWID table, then it is the PRIMARY KEY index
99672 ** for that table that is actually opened.
99676 int iCur, /* The cursor number of the table */
99678 Table *pTab, /* The table to be opened */
99703 ** the table, according to the affinity of the column:
99731 Table *pTab = pIdx->pTable;
99749 ** Compute the affinity string for table pTab, if it has not already been
99768 SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe *v, Table *pTab, int iReg){
99798 ** Return non-zero if the table pTab in database iDb or any of its indices
99801 ** run without using a temporary table for the results of the SELECT.
99803 static int readsTable(Parse *p, int iDb, Table *pTab){
99839 ** Locate or create an AutoincInfo structure associated with table pTab
99843 ** There is at most one AutoincInfo structure per table even if the
99844 ** same table is autoincremented multiple times due to inserts within
99846 ** first use of table pTab. On 2nd and subsequent uses, the original
99851 ** (1) Register to hold the name of the pTab table.
99861 Table *pTab /* The table we are writing to */
99877 pToplevel->nMem++; /* Register to hold name of table */
99893 Db *pDb; /* Database only autoinc table */
99943 ** table (either directly or through triggers) needs to call this
99984 Table *pDest, /* The table we are inserting into */
99993 ** insert into TABLE (IDLIST) values(EXPRLIST),(EXPRLIST),...
99994 ** insert into TABLE (IDLIST) select
99995 ** insert into TABLE (IDLIST) default values
99997 ** The IDLIST following the table name is always optional. If omitted,
99998 ** then a list of all (non-hidden) columns for the table is substituted.
100013 ** open write cursor to <table> and its indices
100015 ** write the resulting record into <table>
100020 ** INSERT INTO <table> SELECT ...
100023 ** in other words if the SELECT pulls all columns from a single table
100031 ** open a write cursor to <table>
100033 ** transfer all records in <table2> over to <table>
100035 ** foreach index on <table>
100036 ** open a write cursor on the <table> index
100043 ** and the SELECT clause does not read from <table> at any time.
100055 ** B: open write cursor to <table> and its indices
100057 ** insert the select result into <table> from R..R+n
100062 ** values from a SELECT but the data is being inserted into a table
100064 ** we have to use an intermediate table to store the results of
100076 ** B: open temp table
100078 ** insert row from R..R+n into temp table
100080 ** M: open write cursor to <table> and its indices
100081 ** rewind temp table
100082 ** C: loop over rows of intermediate table
100083 ** transfer values form intermediate table into <table>
100089 SrcList *pTabList, /* Name of table into which we are inserting */
100095 Table *pTab; /* The table to insert into. aka TABLE */
100096 char *zTab; /* Name of the table into which we are inserting */
100097 const char *zDb; /* Name of the database holding this table */
100100 Index *pIdx; /* For looping over indices of the table */
100102 int nHidden = 0; /* Number of hidden columns if TABLE is virtual */
100111 int iDb; /* Index of database holding TABLE */
100112 Db *pDb; /* The database containing table being inserted into */
100113 u8 useTempTable = 0; /* Store SELECT results in intermediate table */
100115 u8 withoutRowid; /* 0 for normal table. 1 for WITHOUT ROWID table */
100116 u8 bIdListInOrder; /* True if IDLIST is in table order */
100151 /* Locate the table into which we will be inserting new information.
100169 /* Figure out if we have any triggers and if the table being
100193 /* Cannot insert into a read-only table.
100223 /* If this is an AUTOINCREMENT table, look up the sequence number in the
100224 ** sqlite_sequence table and store it in memory cell regAutoinc.
100240 ** all elements of the IDLIST really are columns of the table and
100243 ** If the table has an INTEGER PRIMARY KEY column and that column
100247 ** is appears in the original table. (The index of the INTEGER
100248 ** PRIMARY KEY in the original table is pTab->iPKey.)
100271 sqlite3ErrorMsg(pParse, "table %S has no column named %s",
100307 ** should be written into a temporary table (template 4). Set to
100309 ** the destination table (template 3).
100311 ** A temp table must be used if the table being updated is also one
100313 ** temp table in the case of row triggers.
100321 ** and add it to a transient table srcTab. The code generated
100324 ** B: open temp table
100326 ** insert row from R..R+n into temp table
100331 int regTempRowid; /* Register to hold temp table ROWID */
100364 /* If there is no IDLIST term but the table has an integer primary
100366 ** column index in the original table definition.
100373 ** of columns to be inserted into the table.
100382 "table %S has %d columns but %d values were supplied",
100398 /* If this is not a view, open the table and and all indices */
100417 ** rewind temp table, if empty goto D
100418 ** C: loop over rows of intermediate table
100419 ** transfer values form intermediate table into <table>
100430 ** insert the select result into <table> from R..R+n
100467 /* Cannot have triggers on a virtual table. If it were possible,
100494 ** If this is a real table, attempt conversions as required by the
100495 ** table column affinities.
100654 /* Update the sqlite_sequence table by storing the content of the
100696 ** on table pTab.
100702 ** case of a WITHOUT ROWID table. The second register in the range will
100703 ** contain the content of the first table column. The third register will
100704 ** contain the content of the second table column. And so forth.
100712 ** rowid for a normal table or the PRIMARY KEY for a WITHOUT ROWID table)
100714 ** the iDataCur content table is guaranteed to be unchanged by the UPDATE.
100719 ** that the table is a WITHOUT ROWID table and has no rowid. On an INSERT,
100730 ** table and all applicable indices (that is to say, all indices for which
100731 ** aRegIdx[] is not zero). iDataCur is the cursor for the main table when
100732 ** inserting or updating a rowid table, or the cursor for the PRIMARY KEY
100733 ** index when operating on a WITHOUT ROWID table. iIdxCur is the cursor
100779 Table *pTab, /* The table being inserted or updated */
100781 int iDataCur, /* Canonical data cursor (main table or PK index) */
100811 assert( pTab->pSelect==0 ); /* This table is not a VIEW */
100816 ** pPk index or 1 for a rowid table. In other words, nPkField is the
100817 ** number of fields in the true primary key of the table. */
100903 ** exist in the table.
100939 /* Check to see if the new rowid already exists in the table. Skip
100957 /* If there are DELETE triggers on this table and the
100959 ** remove the conflicting row from the table. This will fire
100960 ** the triggers and remove both the table and index b-tree entries.
100963 ** flag is not set, but the table has one or more indexes, call
100965 ** only. The table b-tree entry will be replaced by the new entry
100977 ** table.
101012 ** WITHOUT ROWID table.
101059 ** of a WITHOUT ROWID table and there has been no change the
101110 ** table, only conflict if the new PRIMARY KEY values are actually
101189 Table *pTab, /* the table into which we are inserting */
101202 int regRec; /* Register holding assembled record for the table */
101208 assert( pTab->pSelect==0 ); /* This table is not a VIEW */
101251 ** Allocate cursors for the pTab table and all its indices and generate
101255 ** the table itself, but the PRIMARY KEY index in the case of a WITHOUT
101256 ** ROWID table) is returned in *piDataCur. The first index cursor is
101263 ** For a rowid table, *piDataCur will be exactly one less than *piIdxCur.
101264 ** For a WITHOUT ROWID table, *piDataCur will be somewhere in the range
101268 ** If pTab is a virtual table, then this routine is a no-op and the
101273 Table *pTab, /* Table to be opened */
101275 int iBase, /* Use this for the table cursor, if there is one */
101276 u8 *aToOpen, /* If not NULL: boolean for each table and index */
101402 ** Sometimes the xfer optimization will only work if the destination table
101405 ** does a test to see if the destination table is empty and jumps over the
101415 Table *pDest, /* The table we are inserting into */
101422 Table *pSrc; /* The table in the FROM clause of SELECT */
101441 ** attached to it. Proceeding may generate a false "no such table: xxx"
101450 return 0; /* tab1 must not be a virtual table */
101502 return 0; /* FROM clause does not contain a real table */
101505 return 0; /* tab1 and tab2 may not be the same table */
101512 return 0; /* tab2 must not be a virtual table */
101561 /* Disallow the transfer optimization if the destination table constains
101578 ** table (tab1) is initially empty.
101599 ** only if the destination table is initially empty. Unless the
101602 ** table is always empty.
101663 ** that the destination table is empty. If all indexed columns use
103172 ** object. This ensures that the aPragmaName[] table is arranged in
103967 /* Locate the pragma in the lookup table */
104605 ** PRAGMA table_info(<table>)
104607 ** Return a single row for each column of the named table. The columns of
104617 Table *pTab;
104670 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "table", SQLITE_STATIC);
104675 Table *pTab = sqliteHashData(i);
104697 Table *pTab;
104744 Table *pTab;
104809 Table *pTab;
104821 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "table", SQLITE_STATIC);
104857 Table *pTab; /* Child table contain "REFERENCES" keyword */
104858 Table *pParent; /* Parent table that child points to */
104859 Index *pIdx; /* Index in the parent table */
104862 HashElem *k; /* Loop counter: Next table in schema */
104877 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "table", SQLITE_STATIC);
104888 pTab = (Table*)sqliteHashData(k);
105071 Table *pTab = sqliteHashData(x);
105103 Table *pTab = sqliteHashData(x);
105154 /* Verify that an index entry exists for the current table row */
105322 ** creating or dropping a table or index). The schema version is used by
105638 ** argv[1] = root page number for table or index. 0 for trigger or view.
105661 /* Call the parser to process a CREATE TABLE, INDEX or VIEW.
105664 ** structures that describe the table, index, or view.
105696 ** constraint for a CREATE TABLE. The index should have already
105697 ** been created when we processed the CREATE TABLE. All we have
105703 /* This can occur if there exists an index on a TEMP table which
105705 ** the permanent table is hidden by the TEMP table, we can also
105706 ** safely ignore the index on the permanent table.
105730 Table *pTab;
105740 ** The master database table has a structure like this
105743 "CREATE TABLE sqlite_master(\n"
105753 "CREATE TEMP TABLE sqlite_temp_master(\n"
105772 ** initialized. zMasterName is the name of the master table.
105888 ** file_format==2 Version 3.1.3. // ALTER TABLE ADD COLUMN
105948 ** purpose of this is to allow access to the sqlite_master table
106099 ** expr.c is trying to resolve a reference to a transient table (i.e. one
106330 ** locked the sqlite3_master table, return SQLITE_LOCKED. If any other error
106525 int tabTnct; /* Ephemeral table used for DISTINCT processing */
106733 ** Return the index of a column in a table. Return -1 if the column
106734 ** is not contained in the table.
106736 static int columnIndex(Table *pTab, const char *zCol){
106746 ** table that has a column named zCol.
106748 ** When found, set *piTab and *piCol to the table index and column index
106784 ** where tab1 is the iSrc'th table in SrcList pSrc and tab2 is the
106791 int iLeft, /* Index of first table to join in pSrc */
106792 int iColLeft, /* Index of column in first table */
106793 int iRight, /* Index of second table in pSrc */
106794 int iColRight, /* Index of column in second table */
106834 ** expression depends on table iRightJoinTable even if that table is not
106864 ** The left most table is the first entry in Select.pSrc. The right-most
106865 ** table is the last entry. The join operator is held in the entry to
106875 struct SrcList_item *pLeft; /* Left table being joined */
106876 struct SrcList_item *pRight; /* Right table being joined */
106882 Table *pLeftTab = pLeft->pTab;
106883 Table *pRightTab = pRight->pTab;
106899 char *zName; /* Name of column in the right table */
106900 int iLeft; /* Matching left table */
106901 int iLeftCol; /* Matching column in the left table */
106939 int iLeft; /* Table on the left with matching column name */
107012 KeyInfo *pKI; /* Original KeyInfo on the sorter table */
107111 ** (example: "a IN (SELECT * FROM table)") but it has more than 1 result
107145 int srcTab, /* Pull data from this table */
107185 ** there are columns in the table on the left. The error will be caught
107268 ** table iParm.
107282 ** the temporary table iParm.
107306 ** output table as well. */
107329 ** item into the set table with bogus data.
107624 int bUseTmp /* True if a temp table was used */
107776 ** original CREATE TABLE statement if the expression is a column. The
107821 /* The expression is a column. Locate the table the column is being
107822 ** extracted from in NameContext.pSrcList. This table may be real
107823 ** database table or a subquery.
107825 Table *pTab = 0; /* Table structure column is extracted from */
107848 ** CREATE TABLE t1(col INTEGER);
107864 /* The "table" is actually a sub-select or a view in the FROM clause
107881 /* A real table */
108015 Table *pTab;
108052 ** column names for a table that would hold the expression list.
108097 Table *pTab; /* Table associated with this expression */
108167 Table *pTab, /* Add column type information to this table */
108203 ** Given a SELECT statement, generate a Table structure that describes
108206 SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse *pParse, Select *pSelect){
108207 Table *pTab;
108218 pTab = sqlite3DbMallocZero(db, sizeof(Table) );
108398 ** <recursive-table> AS (<setup-query> UNION [ALL] <recursive-query>)
108403 ** There is exactly one reference to the recursive-table in the FROM clause
108407 ** into a Queue table. Rows are extracted from the Queue table one by
108409 ** extracted row (now in the iCurrent table) becomes the content of the
108410 ** recursive-table for a recursive-query run. The output of the recursive-query
108411 ** is added back into the Queue table. Then another row is extracted from Queue
108412 ** and the iteration continues until the Queue table is empty.
108415 ** inserted into the Queue table. The iDistinct table keeps a copy of all rows
108419 ** If the query has an ORDER BY, then entries in the Queue table are kept in
108421 ** an ORDER BY, the Queue table is just a FIFO.
108436 int nCol = p->pEList->nExpr; /* Number of columns in the recursive table */
108441 int iCurrent = 0; /* The Current table */
108442 int regCurrent; /* Register holding Current table */
108443 int iQueue; /* The Queue table */
108446 SelectDest destQueue; /* SelectDest targetting the Queue table */
108467 /* Locate the cursor number of the Current table */
108476 ** the Distinct table must be exactly one greater than Queue in order
108498 VdbeComment((v, "Queue table"));
108537 ** the value for the recursive-table. Store the results in the Queue.
108695 /* Create the destination temporary table if necessary
108777 int unionTab; /* Cursor number of the temporary table holding result */
108788 /* We can reuse a temporary table generated by a SELECT to our
108795 /* We will need to create our own temporary table to hold the
108847 /* Convert the data in the temporary table into whatever form
108895 /* Code the SELECTs to our left into temporary table "tab1".
108904 /* Code the current SELECT into temporary table "tab2"
109087 ** item into the set table with bogus data.
109572 ** a column in table number iTable with a copy of the iColumn-th
109580 ** changes to pExpr so that it refers directly to the source table
109586 int iTable, /* Table to be substituted */
109615 int iTable, /* Table to be substituted */
109627 int iTable, /* Table to be replaced */
109661 ** subquery first and store the results in a temporary table, then
109662 ** run the outer query on that temporary table. This requires two
109663 ** passes over the data. Furthermore, because the temporary table
109674 ** exist on the table t1, a complete scan of the data might be
109700 ** table sqlite_once that consists of a single row containing a
109804 int iParent; /* VDBE cursor number of the pSub result set temp table */
110020 /* Delete the transient table structure associated with the
110031 /* Defer deleting the Table object associated with the
110039 Table *pTabToDel = pSubitem->pTab;
110260 ** where table is a database table, not a sub-select or view. If the query
110261 ** does match this pattern, then a pointer to the Table object representing
110264 static Table *isSimpleCount(Select *p, AggInfo *pAggInfo){
110265 Table *pTab;
110297 Table *pTab = pFrom->pTab;
110387 ** WITH contexts, from inner to outermost. If the table identified by
110388 ** FROM clause element pItem is really a common-table-expression (CTE)
110389 ** then return a pointer to the CTE definition for that table. Otherwise
110463 Table *pTab;
110480 pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
110514 pParse, "multiple references to recursive table: %s", pCte->zName
110529 sqlite3ErrorMsg(pParse, "table %s has %d values for %d columns",
110561 ** sqlite3SelectExpand() when walking a SELECT tree to resolve table
110595 ** for instances of the "*" operator or the TABLE.* operator.
110596 ** If found, expand each "*" to be every column in every table
110597 ** and TABLE.* to be every column in TABLE.
110628 /* Look up every table named in the FROM clause of the select. If
110629 ** an entry of the FROM clause is a subquery instead of a table or view,
110630 ** then create a transient table structure to describe the subquery.
110633 Table *pTab;
110656 pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
110667 /* An ordinary table or view name in the FROM clause */
110680 /* We reach here if the named table is a really a view */
110703 ** all columns in all tables. And for every TABLE.* insert the names
110704 ** of all columns in TABLE. The parser inserted a special expression
110754 /* This expression is a "*" or a "TABLE.*" and needs to be
110756 int tableSeen = 0; /* Set to 1 when TABLE matches */
110757 char *zTName = 0; /* text of name of TABLE */
110764 Table *pTab = pFrom->pTab;
110809 ** table to the right of the join */
110814 ** using clause from the table on the right. */
110857 sqlite3ErrorMsg(pParse, "no such table: %s", zTName);
110925 ** information to the Table structure that represents the result set
110928 ** The Table structure that represents the result set was constructed
110945 Table *pTab = pFrom->pTab;
110962 ** the Table structures of all FROM-clause subqueries in a
110984 ** * Ephemeral Table objects are created for all FROM-clause subqueries.
110986 ** * Wildcards "*" and "TABLE.*" in result sets are expanded.
111158 Table *pTab, /* Table being queried */
111163 char *zEqp = sqlite3MPrintf(pParse->db, "SCAN TABLE %s%s%s",
111339 /* Generate a subroutine that will fill an ephemeral table with
111410 ** The second form is preferred as a single index (or temp-table) may be
111412 ** written the query must use a temp-table for at least one of the ORDER
111413 ** BY and DISTINCT, and an index or separate temp-table for the other.
111447 /* If the output is destined for a temporary table, open that table.
111645 ** we do not have to sort. The OP_OpenEphemeral table will be
111708 /* If the index or temporary table used by the GROUP BY sort
111710 ** clause, cancel the ephemeral table open coded earlier.
111823 Table *pTab;
111825 /* If isSimpleCount() returns a pointer to a Table structure, then
111830 ** where the Table structure returned represents table <tbl>.
111833 ** OP_Count instruction is executed either on the intkey table that
111834 ** contains the data for table <tbl> or on one of its indexes. It
112094 /************** Begin file table.c *******************************************/
112133 ** This routine is called once for each row in the result table. Its job
112208 ** Instead, the entire table should be passed to sqlite3_free_table() when
112214 char ***pazResult, /* Write the result table here */
112295 /************** End of table.c ***********************************************/
112329 ** Given table pTab, return a list of all the triggers attached to
112330 ** the table. The list is connected by Trigger.pNext pointers.
112342 SQLITE_PRIVATE Trigger *sqlite3TriggerList(Parse *pParse, Table *pTab){
112356 && 0==sqlite3StrICmp(pTrig->table, pTab->zName)
112382 SrcList *pTableName,/* The name of the table/view the trigger applies to */
112388 Table *pTab; /* Table that the trigger fires off of */
112432 /* If the trigger name was unqualified, and the table is a temp table,
112434 ** If sqlite3SrcListLookup() returns 0, indicating the table does not
112443 /* Ensure the table name matches database name and that the table exists */
112452 /* The table does not exist. */
112455 ** Normally, whenever a table is dropped, all associated triggers are
112456 ** dropped too. But if a TEMP trigger is created on a non-TEMP table
112457 ** and the table is dropped by a different database connection, the
112460 ** "orphaned trigger" - a trigger whose associated table is missing.
112488 /* Do not create a trigger on a system table */
112490 sqlite3ErrorMsg(pParse, "cannot create trigger on system table");
112504 " trigger on table: %S", pTableName, 0);
112538 pTrigger->table = sqlite3DbStrDup(db, pTableName->a[0].zName);
112601 /* Make an entry in the sqlite_master table */
112609 pTrig->table, z);
112624 Table *pTab;
112625 pTab = sqlite3HashFind(&pLink->pTabSchema->tblHash, pLink->table);
112690 Token *pTableName, /* Name of the table into which we insert */
112719 Token *pTableName, /* Name of the table to be updated */
112744 Token *pTableName, /* The table from which rows are deleted */
112765 sqlite3DbFree(db, pTrigger->table);
112818 ** Return a pointer to the Table structure for the table that a trigger
112821 static Table *tableOfTrigger(Trigger *pTrigger){
112822 return sqlite3HashFind(&pTrigger->pTabSchema->tblHash, pTrigger->table);
112830 Table *pTable;
112897 Table *pTab = tableOfTrigger(pTrigger);
112926 ** Return a list of all triggers on table pTab if there exists at least
112928 ** performed on the table, and, if that operation is an UPDATE, if at
112933 Table *pTab, /* The table the contains the triggers */
113106 Table *pTab, /* The table pTrigger is attached to */
113220 Table *pTab, /* The table trigger pTrigger is attached to */
113247 ** table pTab. The reg, orconf and ignoreJump parameters passed to this
113254 Table *pTab, /* The table to code triggers from */
113285 ** on table pTab. The operation to code triggers for (INSERT, UPDATE or DELETE)
113295 ** in the trigger program. If N is the number of columns in table pTab
113325 Trigger *pTrigger, /* List of triggers on table pTab */
113329 Table *pTab, /* The table to code triggers from */
113342 /* Sanity checking: The schema for the trigger and for the table are
113343 ** always defined. The trigger must be in the same schema as the table
113361 ** Triggers may access values stored in the old.* or new.* pseudo-table.
113368 ** table may be accessed using an [old|new].<col> reference. Bit 1 is set if
113370 ** are more than 32 columns in the table, and at least one of the columns
113377 ** applies to the old.* table. If 1, the new.* table.
113387 Trigger *pTrigger, /* List of triggers on table pTab */
113391 Table *pTab, /* The table to code triggers from */
113437 SrcList *pSrc, /* The virtual table to be modified */
113438 Table *pTab, /* The virtual table */
113449 ** i-th column of table pTab. This routine sets the P4 parameter of the
113453 ** column definition. This was either supplied by the user when the table
113454 ** was created, or added later to the table definition by an ALTER TABLE
113455 ** command. If the latter, then the row-records in the table btree on disk
113461 ** Column definitions created by an ALTER TABLE command may only have
113464 ** when the ALTER TABLE is executed and one of the literal values written
113465 ** into the sqlite_master table.)
113477 SQLITE_PRIVATE void sqlite3ColumnDefault(Vdbe *v, Table *pTab, int i, int iReg){
113507 SrcList *pTabList, /* The table in which we should change things */
113513 Table *pTab; /* The table to be updated */
113526 ** an expression for the i-th column of the table.
113529 u8 chngPk; /* PRIMARY KEY changed in a WITHOUT ROWID table */
113530 u8 chngRowid; /* Rowid changed in a normal table */
113535 int iDb; /* Database containing the table being updated */
113547 int iEph = 0; /* Ephemeral table holding all primary key values */
113555 int regNew; /* Content of the NEW.* table in triggers */
113556 int regOld = 0; /* Content of OLD.* table in triggers */
113567 /* Locate the table which we want to update.
113573 /* Figure out if we have any triggers and if the table being
113597 /* Allocate a cursors for the main database table and for all indices.
113689 /* There is one entry in the aRegIdx[] array for each index on the table
113746 ** an ephemeral table.
113908 ** table and index records, and as the values for any new.* references
114059 /* Update the sqlite_sequence table by storing the content of the
114098 ** Generate code for an UPDATE of a virtual table.
114100 ** The strategy is that we create an ephemeral table that contains
114107 ** Then we loop over this ephemeral table and for each row in
114108 ** the ephemeral table call VUpdate.
114110 ** When finished, drop the ephemeral table.
114114 ** it out of the ephemeral table before calling VUpdate.
114118 SrcList *pSrc, /* The virtual table to be modified */
114119 Table *pTab, /* The virtual table */
114130 int ephemTab; /* Table holding the result of the SELECT */
114157 /* Create the ephemeral table into which the update results will
114165 /* fill the ephemeral table
114170 /* Generate code to scan the ephemeral table and call VUpdate. */
114426 "SELECT 'CREATE TABLE vacuum_db.' || substr(sql,14) "
114427 " FROM sqlite_master WHERE type='table' AND name!='sqlite_sequence'"
114450 "WHERE type = 'table' AND name!='sqlite_sequence' "
114457 /* Copy over the sequence table
114475 ** from the SQLITE_MASTER table.
114482 " OR (type='table' AND rootpage=0)"
114584 ** Before a virtual table xCreate() or xConnect() method is invoked, the
114591 VTable *pVTable; /* The virtual table being constructed */
114592 Table *pTab; /* The Table object to which the virtual table belongs */
114644 ** External API function used to create a new virtual-table module.
114659 ** External API function used to create a new virtual-table module.
114675 ** Lock the virtual table so that it cannot be disconnected.
114679 ** If a disconnect is attempted while a virtual table is locked,
114688 ** pTab is a pointer to a Table structure representing a virtual-table.
114690 ** this virtual-table, if one has been created, or NULL otherwise.
114692 SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3 *db, Table *pTab){
114700 ** Decrement the ref-count on a virtual table object. When the ref-count
114721 ** Table p is a virtual table. This function moves all elements in the
114727 static VTable *vtabDisconnectAll(sqlite3 *db, Table *p){
114733 ** that contains table p is held by the caller. See header comments
114760 ** Table *p is a virtual table. This function removes the VTable object
114761 ** for table *p associated with database connection db from the linked
114767 SQLITE_PRIVATE void sqlite3VtabDisconnect(sqlite3 *db, Table *p){
114786 ** Disconnect all the virtual table objects in the sqlite3.pDisconnect list.
114798 ** associated with the database the virtual table is stored in is held
114799 ** or, if the virtual table is stored in a non-sharable database, then
114823 ** Clear any and all virtual-table information from the Table record.
114824 ** This routine is called, for example, just before deleting the Table
114827 ** Since it is a virtual-table, the Table structure contains a pointer
114836 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table *p){
114850 ** string will be freed automatically when the table is
114853 static void addModuleArgument(sqlite3 *db, Table *pTable, char *zArg){
114874 ** The parser calls this routine when it first sees a CREATE VIRTUAL TABLE
114880 Token *pName1, /* Name of new table, or database name */
114881 Token *pName2, /* Name of new table or NULL */
114882 Token *pModuleName, /* Name of the module for the virtual table */
114883 int ifNotExists /* No error if the table already exists */
114885 int iDb; /* The database the table is being created in */
114886 Table *pTable; /* The new virtual table */
114911 /* Creating a virtual table invokes the authorization callback twice.
114913 ** sqlite_master table, has already been made by sqlite3StartTable().
114914 ** The second call, to obtain permission to create the table, is made now.
114926 ** virtual table currently under construction in pParse->pTable.
114938 ** The parser calls this routine after the CREATE VIRTUAL TABLE statement
114942 Table *pTab = pParse->pNewTable; /* The table being constructed */
114950 /* If the CREATE VIRTUAL TABLE statement is being entered for the
114951 ** first time (in other words if the virtual table is actually being
114954 ** in the sqlite_master table.
114963 /* Compute the complete text of the CREATE VIRTUAL TABLE statement */
114967 zStmt = sqlite3MPrintf(db, "CREATE VIRTUAL TABLE %T", &pParse->sNameToken);
114970 ** SQLITE_MASTER table. We just need to update that slot with all
114974 ** entry in the sqlite_master table tht was created for this vtab
114980 "SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q "
114993 zWhere = sqlite3MPrintf(db, "name='%q' AND type='table'", pTab->zName);
115001 /* If we are rereading the sqlite_master table create the in-memory
115002 ** record of the table. The xConnect() method is not called until
115003 ** the first time the virtual table is used in an SQL statement. This
115005 ** the required virtual table implementations are registered. */
115007 Table *pOld;
115023 TABLE statement.
115033 ** in an argument to the module name in a CREATE VIRTUAL TABLE statement.
115047 ** Invoke a virtual table constructor (either xCreate or xConnect). The
115053 Table *pTab,
115068 /* Check that the virtual-table is not already being initialized */
115094 /* Invoke the virtual table constructor */
115131 ** columns of the table to see if any of them contain the token "hidden".
115181 ** of the virtual table pTab. If an error occurs, an error code is returned
115184 ** This call is a no-op if table pTab is not a virtual table.
115186 SQLITE_PRIVATE int sqlite3VtabCallConnect(Parse *pParse, Table *pTab){
115197 /* Locate the required virtual table module */
115218 ** more v-table. Return SQLITE_NOMEM if a malloc fails, or SQLITE_OK otherwise.
115239 ** Add the virtual table pVTab to the array sqlite3.aVTrans[]. Space should
115250 ** of the virtual table named zTab in database iDb.
115258 Table *pTab;
115265 /* Locate the required virtual table module */
115293 ** This function is used to set the schema of a virtual table. It is only
115295 ** virtual table module.
115301 Table *pTab;
115363 ** of the virtual table named zTab in database iDb. This occurs
115364 ** when a DROP TABLE is mentioned.
115366 ** This call is a no-op if zTab is not a virtual table.
115370 Table *pTab;
115467 ** If the virtual table pVtab supports the transaction interface
115517 ** as the second argument to the virtual table method invoked.
115521 ** SAVEPOINT_RELEASE, then the xRelease method of each virtual table with
115524 ** If any virtual table method returns an error code other than SQLITE_OK,
115526 ** function immediately. If all calls to virtual table methods are successful,
115565 ** If pExpr is a column in a virtual table, then let the virtual
115566 ** table implementation have an opportunity to overload the function.
115568 ** This routine is used to allow virtual table implementations to
115581 Table *pTab;
115592 /* Check to see the left operand is a column in a virtual table */
115604 /* Call the xFindFunction method on the virtual table implementation
115636 ** Make sure virtual table pTab is contained in the pParse->apVirtualLock[]
115641 SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse *pParse, Table *pTab){
115644 Table **apVtabLock;
115662 ** table update operation currently in progress.
115683 ** of the virtual table being implemented.
115733 ** generating the code that loops through a table looking for applicable
115803 int iTabCur; /* The VDBE cursor used to access the table */
115850 Bitmask maskSelf; /* Bitmask identifying table iTab */
115854 u8 iTab; /* Position in FROM clause of table for this loop */
116199 #define WHERE_IDX_ONLY 0x00000040 /* Use index only - omit table */
116262 ** table and iaCur[1] gets the cursor used by an auxiliary index.
116484 ** There is one cursor per table in the FROM clause. The number of
116709 ** for terms of the form "X <op> <expr>" where X is column iColumn of table
116754 ** where X is a reference to the iColumn of table iCur and <op> is one of
116771 ** the form "X <op> Y" where Y is a column in another table if no terms of
117068 ** a single table T (as shown in example B above) then create a new virtual
117090 ** If all subterms are indexable by a single table T, then set
117093 ** WhereTerm.u.pOrInfo->indexable |= the cursor number for table T
117096 ** "T.C <op> <expr>" where C is any column of table T and
117244 ** something other than == on a column in the single table. The 1-bit
117246 ** "table.column=expr" for some single table. The one bit that is set
117247 ** will correspond to the common table. We still need to check to make
117254 ** Note that terms of the form "table.column1=table.column2" (the
117255 ** same table on both sizes of the ==) cannot be optimized.
117260 int iCursor = -1; /* Table cursor common to all terms */
117263 /* Search for a table and column that appears on one side or the
117264 ** other of the == operator in every subterm. That table and column
117266 ** such table and column. Set okToChngToIN if an appropriate table
117295 /* No candidate table+column was found. This can only occur
117304 /* We have found a candidate table and column. Check to see if that
117305 ** table and column is common to every term in the OR clause */
117396 WhereMaskSet *pMaskSet; /* Set of table index masks */
117434 ** on left table of a LEFT JOIN. Ticket #3015 */
117714 int iBase, /* Cursor for table associated with pIdx */
117750 Table *pTab;
117755 /* If there is more than one table or sub-select in the FROM clause of
117762 /* If any of the expressions is an IPK column on table iBase, then return
117771 /* Loop through all indices on the table, checking each to see if it makes
117865 struct SrcList_item *pSrc, /* Table we are trying to access */
117899 Table *pTable; /* The table being indexed */
117931 || pLoop->prereq!=0 ); /* table of a LEFT JOIN */
117967 ** original table never needs to be accessed. Automatic indices must
117969 ** original table changes and the index and table cannot both be used
118085 ** to this virtual table */
118098 ** virtual table then allocate space for the aOrderBy part of
118174 ** The table object reference passed as the second argument to this function
118175 ** must represent a virtual table. This function invokes the xBestIndex()
118176 ** method of the virtual table with the sqlite3_index_info object that
118187 static int vtabBestIndex(Parse *pParse, Table *pTab, sqlite3_index_info *p){
118211 "table %s: xBestIndex returned an invalid plan", pTab->zName);
119051 ** For example, consider table t1(a,b,c,d,e,f) with index i1(a,b,c).
119083 ** CREATE TABLE t1(a TEXT PRIMARY KEY, b);
119212 ** Argument pLevel describes a strategy for scanning table pTab. This
119213 ** function appends text to pStr that describes the subset of table
119225 static void explainIndexRange(StrAccum *pStr, WhereLoop *pLoop, Table *pTab){
119261 ** is added to the output to describe the table scan strategy in pLevel.
119268 SrcList *pTabList, /* Table list this loop refers to */
119303 sqlite3XPrintf(&str, 0, " TABLE %s", pItem->zName);
119351 sqlite3XPrintf(&str, 0, " VIRTUAL TABLE INDEX %d:%s",
119441 int iCur; /* The VDBE cursor for the table */
119485 /* If this is the right table of a LEFT OUTER JOIN, allocate and
119486 ** initialize a memory cell that records if this table matches any
119487 ** row of the left table of the join.
119507 /* Case 1: The table is a virtual-table. Use the VFilter and VNext
119900 /* Seek the table cursor, if required */
119904 /* pIdx is a covering index. No need to access the main table. */
119946 ** CREATE TABLE t1(a,b,c,d);
119980 ** Added 2014-05-26: If the table is a WITHOUT ROWID table, then
119986 SrcList *pOrTab; /* Shortened table list or OR-clause generation */
119999 Table *pTab = pTabItem->pTab;
120009 /* Set up a new SrcList in pOrTab containing the table being scanned
120106 /* Loop through table entries that match term pOrTerm. */
120142 /* Check if the temp table already contains this key. If so,
120145 ** insert the key into the temp table and proceed with processing
120150 ** the temp table. And if iSet is -1, assume that there is no
120151 ** need to insert the key into the temp table, as it will never
120176 ** contained one or more AND term from a notReady table. The
120177 ** terms from the notReady table could not be tested and will
120207 /* Finish the loop through table entries that match term pOrTerm. */
120229 ** scan of the entire table.
120316 ** at least one row of the right table has matched the left table.
120369 Table *pTab = pItem->pTab;
120800 ** table statistics.
120809 ** of rows in the table. In other words, assume that x==EXPR will filter
120818 LogEst nRow /* Number of rows in the entire table */
120901 int iCol; /* Index of the column in the table */
120903 LogEst rSize; /* Number of rows in the table */
120904 LogEst rLogSize; /* Logarithm of table size */
121079 ** visiting the rows in the main table. */
121186 ** the table is used by an index. Only the first 63 columns are considered.
121220 ** Add all WhereLoop objects for a single table of the join where the table
121221 ** is idenfied by pBuilder->pNew->iTab. That table is guaranteed to be
121222 ** a b-tree table, not a virtual table.
121227 ** For a full scan, assuming the table (or index) contains nRow rows:
121229 ** cost = nRow * 3.0 // full-table scan
121234 ** estimated average size of the index and table records.
121253 ** of a full table scan.
121257 Bitmask mExtra /* Extra prerequesites for using this table */
121270 LogEst rSize; /* number of rows in the table */
121271 LogEst rLogSize; /* Logarithm of the number of rows in the table */
121273 Table *pTab; /* Table being queried */
121293 Index *pFirst; /* First of real indices on the table */
121306 /* The real indices of the table are only considered if the
121340 ** the table being indexed and where X is 7 (LogEst=28) for normal
121351 /* TUNING: Each index lookup yields 20 rows in the table. This
121389 /* Full table scan */
121391 /* TUNING: Cost of full table scan is (N*3.0). */
121423 ** index and table rows. If this is a non-covering index scan,
121424 ** also add the cost of visiting table rows (N*3.0). */
121453 ** Add all WhereLoop objects for a table of the join identified by
121454 ** pBuilder->pNew->iTab. That table is guaranteed to be a virtual table.
121464 Table *pTab;
121578 /* Do not attempt to use an IN constraint if the virtual table
121584 /* A virtual table that is constrained by an IN clause may not
121729 ** the planner may elect to "OR" together a full-table scan and an
121821 int iColumn; /* A column number within table iCur */
121850 ** The rowid for a table is always UNIQUE and NOT NULL so whenever the
121874 /* Mark off any ORDER BY term X that is a column in the table of
121935 /* Get the column number in the table (iColumn) and sort order
122466 ** Most queries use only a single table (they are not joins) and have
122484 Table *pTab;
122559 ** The basic idea is to do a nested loop, one loop for each table in
122561 ** same as a SELECT with only a single table in the FROM clause.) For
122582 ** There are Btree cursors associated with each table. t1 uses cursor
122595 ** refer to those indices, a complete table scan can be avoided and the
122687 ** only generate code for the first table in pTabList and assume that
122758 ** its Expr.iRightJoinTable value to find the bitmask of the right table
122759 ** of the join. Subtracting one from the right table bitmask gives a
122925 Table *pTab; /* Table to open */
122926 int iDb; /* Index of database containing table/index */
122977 ** WITHOUT ROWID table. No need for a separate index */
123150 Table *pTab = pTabItem->pTab;
123154 /* For a co-routine, change all OP_Column references to the table of
123200 ** from the index instead of from the table where possible. In some cases
123201 ** this optimization prevents the table from ever being read, which can
123205 ** sqlite3WhereEnd will have created code that references the table
123207 ** that reference the table and converts them into opcodes that
123429 ** table.
123527 ** slots in the yy_action[] table.
123529 ** The action table is constructed as a single large table named yy_action[].
123536 ** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table
123547 ** yy_action[] A single table containing all actions.
123548 ** yy_lookahead[] A table containing the lookahead for each entry in
124015 /* The next table maps tokens into fallback tokens. If a construct
124043 0, /* TABLE => nothing */
124173 ** are required. The following table supplies these names */
124179 "TABLE", "CREATE", "IF", "NOT",
124272 /* 26 */ "create_table ::= createkw temp TABLE ifnotexists nm dbnm",
124352 /* 106 */ "cmd ::= DROP TABLE ifexists fullname",
124550 /* 304 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
124551 /* 305 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column",
124557 /* 311 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm",
124958 /* The following table contains information about every rule that
125393 case 26: /* create_table ::= createkw temp TABLE ifnotexists nm dbnm */
125445 sqlite3ErrorMsg(pParse, "unknown table option: %.*s", yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.z);
125625 case 106: /* cmd ::= DROP TABLE ifexists fullname */
126397 "qualified table names are not allowed on INSERT, UPDATE, and DELETE "
126480 case 304: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
126485 case 305: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column */
126502 case 311: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
126901 ** might be implemented more directly using a hand-written hash table.
127053 testcase( i==19 ); /* TABLE */
127604 /* If the pParse->declareVtab flag is set, do not delete any table
127606 ** will take responsibility for freeing the Table structure.
127621 Table *p = pParse->pZombieTab;
128579 ** full table scans in the query optimizer. */
128948 Table *pTab = (Table *)sqliteHashData(p);
128996 ** SQL statements below, as the v-table implementation may be storing
129047 HashElem *i; /* Hash table iterator */
129167 ** but are "saved" in case the table pages are moved around.
129335 /* SQLITE_LOCKED */ "database table is locked",
129345 /* SQLITE_EMPTY */ "table contains no data",
129382 int count /* Number of times table has been busy */
129564 ** to the hash table.
129715 ** Declare that a function has been overloaded by a virtual table.
130072 ** following table describes the relationship between these two values
131180 table.
131186 const char *zTableName, /* Table name */
131196 Table *pTab = 0;
131220 /* Locate the table in question */
131229 /* Query for existance of table only */
131255 ** 2. The table is not a view and the column name identified an
131287 zErrMsg = sqlite3MPrintf(db, "no such table column: %s.%s", zTableName,
131668 ** table should connect.
131671 ** run a single CREATE TABLE statement to construct the imposter table in
132266 ** the %_segments table in sorted order. This means that when the end
132330 ** The segment directory in table %_segdir stores meta-information for
132370 ** leaf nodes are written in to the %_segments table in order, this
132489 ** When an fts3 table is created, it passes any arguments passed to
132490 ** the tokenizer clause of the CREATE VIRTUAL TABLE statement to the
132494 ** be used for the fts3 table (customized by the tokenizer clause arguments).
132516 ** TABLE statement that created the fts3 table. For example, if
132632 ** This is the header file for the generic hash-table implementation
132634 ** hash table implementation for the full-text indexing module.
132644 /* A complete hash table is an instance of the following structure.
132655 int count; /* Number of entries in this table */
132657 int htsize; /* Number of buckets in the hash table */
132658 struct _fts3ht { /* the hash table */
132664 /* Each element in the hash table is an instance of the following
132671 Fts3HashElem *next, *prev; /* Next and previous elements in the table */
132677 ** There are 2 different modes of operation for a hash table:
132710 ** Macros for looping over all elements of a hash table. The idiom is
132728 ** Number of entries in a hash table
132758 ** Fts3Table.pendingTerms hash table. Normally, the hash table is
132762 ** segment is created and the hash table cleared immediately.
132906 const char *zName; /* virtual table name */
132907 int nColumn; /* number of named columns in virtual table */
132917 ** statements is run and reset within a single virtual table API call.
132926 u8 bHasStat; /* True if %_stat table exists (2==unknown) */
132927 u8 bHasDocsize; /* True if %_docsize table exists */
132931 char *zSegmentsTbl; /* Name of %_segments table */
132932 sqlite3_blob *pSegments; /* Blob handle open on %_segments table */
132940 ** A single FTS4 table may have multiple full-text indexes. For each index
132946 ** pending data structures, including hash table overhead, but not including
132954 Fts3Hash hPending; /* Pending terms table for this index */
132963 ** methods of the virtual table are called at appropriate times. These
132979 ** When the core wants to read from the virtual table, it creates a
132980 ** virtual table cursor (an instance of the following structure) using
133000 sqlite3_int64 nDoc; /* Documents in table */
133019 ** CREATE VIRTUAL TABLE ex1 USING fts3(a,b,c,d);
133028 #define FTS3_FULLSCAN_SEARCH 0 /* Linear scan of %_content table */
133029 #define FTS3_DOCID_SEARCH 1 /* Lookup by rowid on %_content table */
133102 ** where nCol is the number of columns in the queried FTS table. The array
133496 ** The xDisconnect() virtual table method.
133561 ** The xDestroy() virtual table method.
133571 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_content'", zDb, p->zName);
133573 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_segments'", zDb,p->zName);
133574 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_segdir'", zDb, p->zName);
133575 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_docsize'", zDb, p->zName);
133576 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_stat'", zDb, p->zName);
133587 ** Invoke sqlite3_declare_vtab() to declare the schema for the FTS3 table
133606 /* Create a list of user columns for the virtual table */
133612 /* Create the whole "CREATE TABLE" statement to pass to SQLite */
133614 "CREATE TABLE x(%s %Q HIDDEN, docid HIDDEN, %Q HIDDEN)",
133630 ** Create the %_stat table if it does not already exist.
133634 "CREATE TABLE IF NOT EXISTS %Q.'%q_stat'"
133643 ** required by the FTS3 table passed as the only argument. This is done
133647 ** FTS4 table, not an FTS3 table) then also create the %_docsize and
133657 char *zContentCols; /* Columns of %_content table */
133659 /* Create a list of user columns for the content table */
133670 /* Create the content table */
133672 "CREATE TABLE %Q.'%q_content'(%s)",
133680 "CREATE TABLE %Q.'%q_segments'(blockid INTEGER PRIMARY KEY, block BLOB);",
133684 "CREATE TABLE %Q.'%q_segdir'("
133697 "CREATE TABLE %Q.'%q_docsize'(docid INTEGER PRIMARY KEY, size BLOB);",
133836 ** table has the three user-defined columns "a", "b", and "c", the following
133888 ** of columns in the %_content table (one for the docid plus one for each
133893 ** bracket. For example, if zFunc is "zip" and the FTS3 table has three
133961 ** representing the indexes maintained by the current FTS table. FTS tables
133964 ** (if any) specified as part of the CREATE VIRTUAL TABLE statement.
133979 struct Fts3Index **apIndex /* OUT: Array of indexes for this table */
134021 ** This function is called when initializing an FTS4 table that uses the
134023 ** of the new FTS4 table.
134027 ** a table of that name. If found, the output variables are populated
134030 ** *pnCol: Set to the number of columns table xxx has,
134036 ** the name of the corresponding column in table xxx. The array
134041 ** If the table cannot be found, an error code is returned and the output
134048 const char *zTbl, /* Name of content table */
134072 int nCol; /* Number of table columns */
134111 ** methods of the FTS3 virtual table.
134117 ** argv[2] -> table name
134123 void *pAux, /* Hash table containing tokenizers */
134136 int nCol = 0; /* Number of columns in the FTS table */
134139 int nName; /* Bytes required to hold table name */
134142 sqlite3_tokenizer *pTokenizer = 0; /* Tokenizer for this table */
134145 struct Fts3Index *aIndex = 0; /* Array of indexes for this table */
134148 int bNoDocsize = 0; /* True to omit %_docsize table */
134184 ** + Figures out the number of columns the FTSX table will have, and
134307 ** TABLE statement, use all columns from the content table.
134455 /* Check to see if a legacy fts3 table has been "upgraded" by the
134456 ** addition of a %_stat table so that it can use incremental merge.
134467 /* Declare the table schema to SQLite. */
134494 ** The xConnect() and xCreate() methods for the virtual table. All the
134499 void *pAux, /* Pointer to tokenizer hash table */
134509 void *pAux, /* Pointer to tokenizer hash table */
134537 ** 3. Linear scan of %_content table.
134549 /* By default use a full table scan. This is an expensive option,
134680 ** on the xClose method of the virtual table interface.
134701 ** (or the equivalent for a content=xxx table) and set pCsr->pStmt to
134722 ** of the %_content table that contains the last match. Return
134740 ** table is missing a row that is present in the full-text index.
134796 ** table, then there are always 20 bytes of zeroed padding following the
134892 Fts3Table *p, /* Virtual table handle */
134910 char *zBlob = 0; /* Blob read from %_segments table */
135716 Fts3Table *p, /* FTS table handle */
135813 Fts3Table *p, /* FTS3 table handle */
135829 ** made by an fts4aux module, not an FTS table. In this case calling
135887 Fts3Table *p, /* FTS3 table handle */
135919 Fts3Table *p, /* FTS virtual table handle */
135944 Fts3Cursor *pCsr, /* Virtual table cursor handle */
136010 Fts3Table *p, /* Virtual table handle */
136082 ** Advance the cursor to the next row in the %_content table that
136084 ** the next row that matches. For a full-table scan, this will be
136085 ** simply the next row in the %_content table. For a docid lookup,
136138 ** This is the xFilter interface for the virtual table. See
136139 ** the virtual table xFilter method documentation for additional
136142 ** If idxNum==FTS3_FULLSCAN_SEARCH then do a full table scan against
136143 ** the %_content table.
136146 ** in the %_content table.
136232 /* Compile a SELECT statement for this cursor. For a full-table-scan, the
136233 ** statement loops through all rows of the %_content table. For a
136267 ** This is the xEof method of the virtual table. SQLite calls this
136277 ** exposes %_content.docid as the rowid for the virtual table. The
136293 ** (iCol == p->nColumn) -> Magic column with the same name as the table.
136315 table.
136348 sqlite3_vtab *pVtab, /* Virtual table handle */
136358 ** hash-table to the database.
136377 ** of blocks from the segments table. But this is not considered overhead
136404 ** If it is currently unknown whether or not the FTS table has an %_stat
136405 ** table (if p->bHasStat==2), attempt to determine this (set p->bHasStat
136447 ** the pending-terms hash-table have already been flushed into the database
136463 ** hash-table. Any changes made to the database are reverted by SQLite.
136613 ** where 't' is the name of an FTS3 table.
136621 Fts3Table *p; /* Virtual table handle */
136667 ** virtual table.
136670 sqlite3_vtab *pVtab, /* Virtual table handle */
136703 ** Implementation of FTS3 xRename method. Rename an fts3 table.
136706 sqlite3_vtab *pVtab, /* Virtual table handle */
136707 const char *zName /* New name of table */
136713 /* At this point it must be known if the %_stat table exists or not.
136717 /* As it happens, the pending terms table is always empty here. This is
136718 ** because an "ALTER TABLE RENAME TABLE" statement inside a transaction
136720 ** flushes the pending terms table. But leave the (no-op) call to
136730 "ALTER TABLE %Q.'%q_content' RENAME TO '%q_content';",
136737 "ALTER TABLE %Q.'%q_docsize' RENAME TO '%q_docsize';",
136743 "ALTER TABLE %Q.'%q_stat' RENAME TO '%q_stat';",
136748 "ALTER TABLE %Q.'%q_segments' RENAME TO '%q_segments';",
136752 "ALTER TABLE %Q.'%q_segdir' RENAME TO '%q_segdir';",
136761 ** Flush the contents of the pending-terms table to disk.
136793 ** Discard the contents of the pending terms table.
136834 ** allocated for the tokenizer hash table.
136896 /* Allocate and initialize the hash-table used to store tokenizers. */
136904 /* Load the built-in tokenizers into the hash table */
136926 /* Create the virtual table wrapper around the hash-table and overload
136965 /* An error has occurred. Delete the hash table and return the error code. */
137032 Fts3Table *pTab, /* FTS Table pointer */
137457 Fts3Table *pTab, /* Virtual table handle */
137750 ** of data that will fit on a single leaf page of an intkey table in
137758 ** data from the %_stat table to calculate it.
137760 ** Entry 0 of the %_stat table is a blob containing (nCol+1) FTS3
137761 ** varints, where nCol is the number of columns in the FTS3 table.
137763 ** the table. The following nCol varints contain the total amount of
137764 ** data stored in all rows of each column of the table, from left
137833 ** table actually contains the same data as the index. To prevent this from
138435 ** 2. After scanning the current FTS table row for the deferred tokens,
138685 ** the FTS table (considering all rows), and
138687 ** 2. For each column, the number of rows in the table for which the
138699 ** values are set to the number of documents in the table. In other
138701 ** column of each row of the table.
138901 ** Initialize API pointer table, if required.
138965 ** Schema of the terms table.
138968 "CREATE TABLE x(term, col, documents, occurrences, languageid HIDDEN)"
138984 char const *zFts3; /* Name of fts3 table */
138989 Fts3auxTable *p; /* Virtual table object to return */
138995 ** CREATE VIRTUAL TABLE xxx USING fts4aux(fts4-table);
138996 ** CREATE VIRTUAL TABLE xxx USING fts4aux(fts4-table-db, fts4-table);
139566 const char **azCol; /* Array of column names for fts3 table */
140407 char **azCol, /* Array of column names for fts3 table */
140458 ** of each column in the target fts3 table, in order from left to right.
140461 ** The iDefaultCol parameter should be passed the index of the table column
140465 ** match any table column.
140470 char **azCol, /* Array of column names for fts3 table */
140556 ** Function to query the hash-table of tokenizers (see README.tokenizers).
140645 ** of a column of the fts3 table that the query expression may refer to.
140769 ** We've modified it slightly to serve as a standalone hash table
140803 /* Turn bulk memory into a hash table object by initializing the
140806 ** "pNew" is a pointer to the hash table that is to be initialized.
140809 ** determines what kind of key the hash table will use. "copyKey" is
140810 ** true if the hash table should make its own private copy of keys and
140824 /* Remove all entries from a hash table. Reclaim all memory.
140825 ** Call this routine to delete a hash table or to reset a hash table
140829 Fts3HashElem *elem; /* For looping over all elements of the table */
140918 /* Link an element into the hash table
140921 Fts3Hash *pH, /* The complete hash table */
140944 /* Resize the hash table so that it cantains "new_size" buckets.
140945 ** "new_size" must be a power of 2. The hash table might fail
140951 struct _fts3ht *new_ht; /* The new hash table */
140971 ** hash table that matches the given key. The hash for this key has
140999 /* Remove a single entry from the hash table given a pointer to that
141053 ** Attempt to locate an element of the hash table pH with a key
141064 /* Insert an element into the hash table pH. The key is pKey,nKey
141074 ** the new data is returned and the hash table is unchanged.
141077 ** element corresponding to "key" is removed from the hash table.
141080 Fts3Hash *pH, /* The hash table to insert into */
141086 int h; /* the hash of the key modulo hash table size */
141836 ** hash table. This function may be called as follows:
141847 ** the string <key-name> must already exist in the has table. Otherwise,
141852 ** to string <key-name> (after the hash-table is updated, if applicable).
141951 table */
142238 ** the hash table pointed to by argument pHash. The hash table must
142246 ** defined at compilation time, a temporary virtual table (see header
142251 ** of both the scalar and, if created, the virtual table.
142369 ** else we need to reindex. One solution would be a meta-table to
142547 ** This file contains code for the "fts3tokenize" virtual table module.
142548 ** An fts3tokenize virtual table is created as follows:
142550 ** CREATE VIRTUAL TABLE <tbl> USING fts3tokenize(
142554 ** The table created has the following schema:
142556 ** CREATE TABLE <tbl>(input, token, start, end, position)
142562 ** The virtual table module tokenizes this <string>, using the FTS3
142563 ** tokenizer specified by the arguments to the CREATE VIRTUAL TABLE
142584 ** Virtual table structure.
142593 ** Virtual table cursor structure.
142677 ** Schema of the tokenizer table.
142679 #define FTS3_TOK_SCHEMA "CREATE TABLE x(input, token, start, end, position)"
142688 ** argv[2]: table name
142693 void *pHash, /* Hash table of tokenizers */
142917 /* CREATE TABLE x(input, token, start, end, position) */
143034 ** win (reduced IO and CPU) if SQLite stops calling the virtual table xNext()
143199 ** or the pending-terms table being flushed), leaves are written into the
143277 Fts3Table *p, /* Virtual table handle */
143344 ** Read a single entry from the %_segdir table. The entry from absolute
143417 Fts3Table *pTab, /* FTS3 table handle */
143442 Fts3Table *pTab, /* Fts3 table handle */
143463 Fts3Table *pTab, /* Fts3 table handle */
143480 Fts3Table *p, /* The FTS3 table */
143498 ** shared-cache table-lock on the %_segdir table. This is required before
143499 ** writing data to the fts3 table. If this lock is not acquired first, then
143535 ** in the %_segdir table on disk. This function is used to convert three
143537 ** can be used to query the %_segdir table.
143550 Fts3Table *p, /* FTS3 table handle */
143566 ** all rows in the %_segdir table, from oldest to newest. If successful,
143571 ** each FTS3 table.
143573 ** The statement returns the following columns from the %_segdir table:
143582 Fts3Table *p, /* FTS3 table */
143738 Fts3Hash *pHash, /* Pending terms hash table to add entry to */
143767 ** pending-terms hash-table. The docid used is that currently stored in
143773 Fts3Table *p, /* Table into which text will be inserted */
143797 ** zText==0. In this case, add zero token entries to the hash table and
143851 Fts3Table *p, /* Full-text table handle */
143895 ** pendingTerms hash table.
143931 ** apVal[p->nColumn+2] Hidden column with same name as table
143936 Fts3Table *p, /* Full-text table */
143956 ** table. The SQL for this statement is:
143961 ** defined columns in the FTS3 table, plus one for the docid field.
144006 ** Remove all data from the FTS3 table. Clear the hash table containing
144012 /* Discard the contents of the pending-terms hash table. */
144046 Fts3Table *p, /* The FTS table to delete from */
144091 ** This function allocates a new level iLevel index in the segdir table.
144150 ** The %_segments table is declared as follows:
144152 ** CREATE TABLE %_segments(blockid INTEGER PRIMARY KEY, block BLOB)
144154 ** This function reads data from a single row of the %_segments table. The
144158 ** identified table row is. Whether or not paBlob is NULL, *pnBlob is set
144161 ** If an error occurs, or the table does not contain the specified row,
144172 ** on the database file for longer than necessary). Thus, any virtual table
144177 Fts3Table *p, /* FTS3 table handle */
144441 /* A pending-terms seg-reader for an FTS4 table that uses order=desc.
144615 ** the contents of the pending-terms hash table to the database.
144639 ** through each term in the pending-terms table. Or, if isPrefixIter is
144641 ** the pending terms hash table contains the terms "sqlite", "mysql" and
144654 Fts3Table *p, /* Virtual table handle */
144871 ** Insert a record into the %_segments table.
144874 Fts3Table *p, /* Virtual table handle */
144891 ** Find the largest relative level number in the table. If successful, set
144912 ** Insert a record into the %_segdir table.
144915 Fts3Table *p, /* Virtual table handle */
144971 Fts3Table *p, /* Virtual table handle */
145108 Fts3Table *p, /* Virtual table handle */
145177 Fts3Table *p, /* Virtual table handle */
145206 /* Find the next free blockid in the %_segments table */
145319 Fts3Table *p, /* Virtual table handle */
145342 /* The entire tree fits on the root node. Write it to the segdir table. */
145367 ** pRowid would mean the FTS3 table were empty.
145369 ** If successful, *pisEmpty is set to true if the table is empty except for
145377 /* If using the content=xxx option, assume the table is never empty */
145396 ** Segment levels are stored in the 'level' column of the %_segdir table.
145460 ** Delete all entries in the %_segments table associated with the segment
145462 ** of the %_segdir table.
145465 Fts3Table *p, /* FTS table handle */
145497 Fts3Table *p, /* Virtual table handle */
145616 Fts3Table *p, /* Virtual table handle */
145684 Fts3Table *p, /* Virtual table handle */
145716 Fts3Table *p, /* Virtual table handle */
145725 Fts3Table *p, /* Virtual table handle */
145800 Fts3Table *p, /* Virtual table handle */
146038 Fts3Table *p, /* FTS table handle */
146052 /* Loop through all entries in the %_segdir table corresponding to
146311 Fts3Table *p, /* Table into which to insert */
146339 ** Record 0 of the %_stat table contains a blob consisting of N varints,
146340 ** where N is the number of user defined columns in the fts3 table plus
146344 ** Varint 0: Total number of rows in the table.
146347 ** the column for all rows of the table.
146350 ** columns of all rows of the table.
146355 Fts3Table *p, /* Table being updated */
146464 ** The entire FTS index is discarded and rebuilt. If the table is one
146466 ** the current contents of the xxx table. Otherwise, it is rebuilt based
146467 ** on the contents of the %_content table.
146480 /* Compose and prepare an SQL statement to loop through the content table */
146550 Fts3Table *p, /* FTS3 table handle */
146764 Fts3Table *p, /* Fts3 table handle */
146915 Fts3Table *p, /* Fts3 table handle */
147000 Fts3Table *p, /* FTS3 table handle */
147027 ** table. However, this is not permitted in this case. The problem is that
147028 ** space has already been reserved in the %_segments table, and so the
147029 ** start_block and end_block fields of the %_segdir table must be populated.
147038 ** table until we are sure it is needed.
147104 ** Query to see if the entry in the %_segments table with blockid iEnd is
147112 ** is, then a NULL entry has been inserted into the %_segments table
147147 Fts3Table *p, /* Fts3 table handle */
147184 /* Check for the zero-length marker in the %_segments table */
147279 Fts3Table *p, /* FTS Table handle */
147301 ** In the %_segdir table, a segment is defined by the values in three
147324 Fts3Table *p, /* Fts3 table handle */
147360 /* Insert the marker in the %_segments table to make sure nobody tries
147378 ** Remove an entry from the %_segdir table. This involves running the
147389 Fts3Table *p, /* FTS3 table handle */
147413 Fts3Table *p, /* FTS3 table handle */
147536 ** table, and modifying existing entries in both the %_segments and %_segdir
147543 Fts3Table *p, /* FTS3 table handle */
147628 Fts3Table *p, /* FTS table handle */
147695 ** exists, is stored in the rowid==1 row of the %_stat table.
147698 ** table and return SQLITE_OK. Otherwise, if an error occurs, return an
147792 Blob hint = {0, 0, 0}; /* Hint read from %_stat table */
147809 /* Search the %_segdir table for the absolute level with the smallest
147825 /* If the hint read from the %_stat table is not empty, check if the
147849 ** nMin segments and no hint in the %_stat table. No work to do.
147920 /* Write the hint values into the %_stat table for the next incr-merger */
147946 ** INSERT INTO table(table) VALUES('merge=A,B');
147953 Fts3Table *p, /* FTS3 table handle */
147990 ** INSERT INTO table(table) VALUES('automerge=X');
147996 Fts3Table *p, /* FTS3 table handle */
148054 Fts3Table *p, /* FTS3 table handle */
148120 ** content table. If no error occurs and the contents do match, set *pbOk
148150 /* This block calculates the checksum according to the %_content table */
148236 ** 2. By scanning and tokenizing the content table.
148242 Fts3Table *p /* FTS3 table handle */
148328 ** table, not for all rows.
148333 int i; /* Used to iterate through table columns */
148414 Fts3Cursor *pCsr, /* Fts3 table cursor */
148438 ** present in the FTS3 table. If it is, delete it and adjust the contents
148448 int bFound = 0; /* True if *pRowid really is in the table */
148452 int isEmpty = 0; /* Deleting *pRowid leaves the table empty */
148456 /* Deleting this row means the whole table is empty. In this case
148458 ** data in the pendingTerms hash table. */
148479 ** tables. The schema of the virtual table being:
148481 ** CREATE TABLE <table name>(
148483 ** <table name> HIDDEN,
148504 /* At this point it must be known if the %_stat table exists or not.
148570 ** the %_content table. If we hit the duplicate rowid constraint (or any
148632 ** Flush any data in the pending-terms hash table to disk. If successful,
148744 int nCol; /* Number of columns in table */
149196 Fts3Table *pTab, /* FTS3 table snippet comes from */
149420 ** rows of the table. Y is the number of rows for which column iCol contains
149767 sqlite3_int64 nDoc; /* Number of rows in table */
149960 /* Loop through all columns of the table being considered for snippets.
149962 ** columns of the FTS3 table. Otherwise, only column iCol is considered.
150020 int iCol; /* Column of table to populate aTerm for */
150091 /* Loop through the table columns, appending offset information to
150198 Fts3Cursor *pCsr, /* FTS3 table cursor */
150352 ** As part of a tokenchars= or separators= option, the CREATE VIRTUAL TABLE
150353 ** statement has specified that the tokenizer for this table shall consider
151015 ** algorithms packaged as an SQLite virtual table module.
151022 ** The data structure for a single virtual r-tree table is stored in three
151024 ** in the table name is replaced with the user-supplied name of the r-tree
151025 ** table.
151027 ** CREATE TABLE %_node(nodeno INTEGER PRIMARY KEY, data BLOB)
151028 ** CREATE TABLE %_parent(nodeno INTEGER PRIMARY KEY, parentnode INTEGER)
151029 ** CREATE TABLE %_rowid(rowid INTEGER PRIMARY KEY, nodeno INTEGER)
151032 ** table. For each node that is not the root node of the r-tree, there is
151033 ** an entry in the %_parent table associating the node with its parent.
151034 ** And for each row of data in the table, there is an entry in the %_rowid
151035 ** table that maps from the entries rowid to the id of the node that it
151038 ** The root node of an r-tree always exists, even if the r-tree table is
151040 ** table must be the same size as the root node. The content of each node
151095 /* Size of hash table Rtree.aHash. This hash table is not expected to
151101 /* The xBestIndex method of this virtual table requires an estimate of
151102 ** the number of rows in the virtual table to calculate the costs of
151104 ** sqlite_stat1 table (with RTREE_MIN_ROWEST as a hard-coded minimum).
151112 ** An rtree virtual-table object.
151117 int iNodeSize; /* Size in bytes of each node in the node table */
151122 char *zDb; /* Name of database containing r-tree table */
151123 char *zName; /* Name of r-tree table */
151125 i64 nRowEst; /* Estimated number of rows in this table */
151150 RtreeNode *aHash[HASHSIZE]; /* Hash table of in-memory nodes. */
151158 ** If SQLITE_RTREE_INT_ONLY is defined, then this virtual table will
151444 ** in the Rtree.aHash table.
151451 ** Search the node hash table for node iNode. If found, return a pointer
151461 ** Add node pNode to the node hash table.
151472 ** Remove node pNode from the node hash table.
151517 /* Check if the requested node is already in the hash table. If so,
151749 ** the virtual table module xCreate() and xConnect() methods.
151756 ** Rtree virtual table module xCreate method.
151769 ** Rtree virtual table module xConnect method.
151809 ** Rtree virtual table module xDisconnect method.
151817 ** Rtree virtual table module xDestroy method.
151823 "DROP TABLE '%q'.'%q_node';"
151824 "DROP TABLE '%q'.'%q_rowid';"
151825 "DROP TABLE '%q'.'%q_parent';",
151844 ** Rtree virtual table module xOpen method.
151881 ** Rtree virtual table module xClose method.
151895 ** Rtree virtual table module xEof method.
152383 ** Rtree virtual table module xNext method.
152397 ** Rtree virtual table module xRowid method.
152411 ** Rtree virtual table module xColumn method.
152444 ** return SQLITE_OK. If there is no such record in the table, set
152518 ** Rtree virtual table module xFilter method.
152635 ** Rtree virtual table module xBestIndex method. There are three
152636 ** table scan strategies to choose from (in order from most to
152642 ** 2 See below R-tree query or full-table scan.
152844 Rtree *pRtree, /* Rtree table */
152904 Rtree *pRtree, /* Rtree table */
152930 ** Write mapping (iRowid->iNode) to the <rtree>_rowid table.
152940 ** Write mapping (iNode->iPar) to the <rtree>_parent table.
153427 /* Remove the node from the in-memory hash table and link it into
153709 /* Delete the corresponding entry in the <rtree>_rowid table. */
153809 /* Constraint handling. A write operation on an r-tree table may return
153826 ** with "column" that are interpreted as table constraints.
153827 ** Example: CREATE VIRTUAL TABLE bad USING rtree(x,y,CHECK(y>5));
153857 ** the table. If so, the constraint has failed. */
153881 ** record to delete from the r-tree table. The following block does
153928 "ALTER TABLE %Q.'%q_node' RENAME TO \"%w_node\";"
153929 "ALTER TABLE %Q.'%q_parent' RENAME TO \"%w_parent\";"
153930 "ALTER TABLE %Q.'%q_rowid' RENAME TO \"%w_rowid\";"
153944 ** of the number of rows in the virtual table. If possible, this is based
153981 rtreeCreate, /* xCreate - create a table */
153982 rtreeConnect, /* xConnect - connect to an existing table */
153984 rtreeDisconnect, /* xDisconnect - Disconnect from a table */
153985 rtreeDestroy, /* xDestroy - Drop a table */
153999 rtreeRename, /* xRename - rename the table */
154016 /* Read and write the xxx_node table */
154021 /* Read and write the xxx_rowid table */
154026 /* Read and write the xxx_parent table */
154038 "CREATE TABLE \"%w\".\"%w_node\"(nodeno INTEGER PRIMARY KEY, data BLOB);"
154039 "CREATE TABLE \"%w\".\"%w_rowid\"(rowid INTEGER PRIMARY KEY, nodeno INTEGER);"
154040 "CREATE TABLE \"%w\".\"%w_parent\"(nodeno INTEGER PRIMARY KEY,"
154103 ** determine the node-size used by the rtree table being created or connected
154108 ** table already exists. In this case the node-size is determined by inspecting
154153 ** methods of the r-tree virtual table.
154157 ** argv[2] -> table name
154163 int argc, const char *const*argv, /* Parameters to CREATE TABLE statement */
154164 sqlite3_vtab **ppVtab, /* OUT: New virtual table */
154176 "Wrong number of columns for an rtree table", /* 1 */
154177 "Too few columns for an rtree table", /* 2 */
154178 "Too many columns for an rtree table" /* 3 */
154212 ** the r-tree table schema.
154218 char *zSql = sqlite3_mprintf("CREATE TABLE x(%s", argv[3]);
154335 ** virtual table module "rtree" and the debugging/analysis scalar
155259 ** This file contains an implementation of the "dbstat" virtual table.
155261 ** The dbstat virtual table is used to extract low-level formatting
155302 "CREATE TABLE xx( " \
155303 " name STRING, /* Name of table or index */" \
155378 ** Connect to or create a statvfs virtual table.
155418 ** Disconnect from or destroy a statvfs virtual table.
155426 ** There is no "best-index". This virtual table always does a linear
155470 "SELECT 'sqlite_master' AS name, 1 AS rootpage, 'table' AS type"
155536 if( flags==0x0D ){ /* Table leaf node */
155597 /* A table interior node. nPayload==0. */
155774 case 0x05: /* table internal */
155778 case 0x0D: /* table leaf */
155867 ** Invoke this routine to register the "dbstat" virtual table module