Lines Matching defs:pTab
9881 Table *pTab; /* Source table */
9964 ** is a disk table or the "old.*" pseudo-table, then pTab points to the
10019 Table *pTab; /* Table for TK_COLUMN expressions. */
10185 Table *pTab; /* An SQL table corresponding to zName */
10196 Bitmask colUsed; /* Bit N (1<<N) set if column N of pTab is used */
10450 Table *pTab; /* Table this info block refers to */
10451 int iDb; /* Index in sqlite3.aDb[] of database holding pTab */
68583 Table *pTab;
68604 pTab = sqlite3LocateTable(pParse, 0, zTable, zDb);
68605 if( pTab && IsVirtual(pTab) ){
68606 pTab = 0;
68610 if( pTab && pTab->pSelect ){
68611 pTab = 0;
68615 if( !pTab ){
68626 /* Now search pTab for the exact column. */
68627 for(iCol=0; iCol<pTab->nCol; iCol++) {
68628 if( sqlite3StrICmp(pTab->aCol[iCol].zName, zColumn)==0 ){
68632 if( iCol==pTab->nCol ){
68654 for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){
68664 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
68685 int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
68696 sqlite3VdbeChangeP2(v, 1, pTab->pSchema->schema_cookie);
68697 sqlite3VdbeChangeP3(v, 1, pTab->pSchema->iGeneration);
68707 sqlite3VdbeChangeP2(v, 2, pTab->tnum);
68709 sqlite3VdbeChangeP4(v, 2, pTab->zName, P4_TRANSIENT);
68713 ** parameter of the other to pTab->tnum. */
68715 sqlite3VdbeChangeP2(v, 3 + flags, pTab->tnum);
68725 sqlite3VdbeChangeP4(v, 3+flags, SQLITE_INT_TO_PTR(pTab->nCol+1),P4_INT32);
68726 sqlite3VdbeChangeP2(v, 7, pTab->nCol);
69642 ** pExpr->pTab Points to the Table structure of X.Y (even if
69683 pExpr->pTab = 0;
69693 Table *pTab;
69697 pTab = pItem->pTab;
69698 assert( pTab!=0 && pTab->zName!=0 );
69699 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
69700 assert( pTab->nCol>0 );
69706 char *zTabName = pTab->zName;
69717 pExpr->pTab = pTab;
69718 pSchema = pTab->pSchema;
69721 for(j=0, pCol=pTab->aCol; j<pTab->nCol; j++, pCol++){
69726 pExpr->pTab = pTab;
69728 pSchema = pTab->pSchema;
69730 pExpr->iColumn = j==pTab->iPKey ? -1 : (i16)j;
69763 Table *pTab = 0;
69767 pTab = pParse->pTriggerTab;
69770 pTab = pParse->pTriggerTab;
69773 if( pTab ){
69775 pSchema = pTab->pSchema;
69777 for(iCol=0; iCol<pTab->nCol; iCol++){
69778 Column *pCol = &pTab->aCol[iCol];
69780 if( iCol==pTab->iPKey ){
69786 if( iCol>=pTab->nCol && sqlite3IsRowid(zCol) ){
69789 if( iCol<pTab->nCol ){
69803 pExpr->pTab = pTab;
69873 pExpr->pTab = 0;
69944 p->pTab = pItem->pTab;
69946 if( p->pTab->iPKey==iCol ){
70003 pExpr->pTab = pItem->pTab;
70643 ** Expr.pTab Points to the Table object for X.Y
70783 && pExpr->pTab!=0
70785 /* op==TK_REGISTER && pExpr->pTab!=0 happens when pExpr was originally
70789 assert( pExpr->pTab && j<pExpr->pTab->nCol );
70790 return pExpr->pTab->aCol[j].affinity;
70837 if( p->pTab!=0 && (
70840 /* op==TK_REGISTER && p->pTab!=0 happens when pExpr was originally
70846 zColl = p->pTab->aCol[j].zColl;
71635 Table *pTab;
71645 pTab = pNewItem->pTab = pOldItem->pTab;
71646 if( pTab ){
71647 pTab->nRef++;
72083 Table *pTab;
72099 pTab = pSrc->a[0].pTab;
72100 if( NEVER(pTab==0) ) return 0;
72101 assert( pTab->pSelect==0 ); /* FROM clause is not a view */
72102 if( IsVirtual(pTab) ) return 0; /* FROM clause not a virtual table */
72183 Table *pTab = p->pSrc->a[0].pTab; /* Table <table>. */
72184 int iDb; /* Database idx for pTab */
72187 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
72189 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
72203 sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead);
72220 int affinity_ok = (pTab->aCol[iCol].affinity==aff||aff==SQLITE_AFF_NONE);
72222 for(pIdx=pTab->pIndex; pIdx && eType==0 && affinity_ok; pIdx=pIdx->pNext){
72241 if( prNotFound && !pTab->aCol[iCol].notNull ){
72866 Table *pTab, /* The table containing the value */
72871 if( iCol<0 || iCol==pTab->iPKey ){
72874 int op = IsVirtual(pTab) ? OP_VColumn : OP_Column;
72878 sqlite3ColumnDefault(v, pTab, iCol, regOut);
72884 ** table pTab and store the column value in a register. An effort
72888 ** There must be an open cursor to pTab in iTable when this routine
72893 Table *pTab, /* Description of the table we are reading from */
72910 sqlite3ExprCodeGetColumnOfTable(v, pTab, iTable, iColumn, iReg);
73038 inReg = sqlite3ExprCodeGetColumn(pParse, pExpr->pTab,
73447 Table *pTab = pExpr->pTab;
73448 int p1 = pExpr->iTable * (pTab->nCol+1) + 1 + pExpr->iColumn;
73451 assert( pExpr->iColumn>=-1 && pExpr->iColumn<pTab->nCol );
73452 assert( pTab->iPKey<0 || pExpr->iColumn!=pTab->iPKey );
73453 assert( p1>=0 && p1<(pTab->nCol*2+2) );
73458 (pExpr->iColumn<0 ? "rowid" : pExpr->pTab->aCol[pExpr->iColumn].zName),
73466 && pTab->aCol[pExpr->iColumn].affinity==SQLITE_AFF_REAL
74307 pCol->pTab = pExpr->pTab;
74772 ** tables that have foreign key constraints that refer to table pTab (i.e.
74773 ** constraints for which pTab is the parent table) from the sqlite_master
74776 static char *whereForeignKeys(Parse *pParse, Table *pTab){
74779 for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
74788 ** temporary triggers on table pTab from the sqlite_temp_master table. If
74789 ** table pTab has no temporary triggers, or is itself stored in the
74792 static char *whereTempTriggers(Parse *pParse, Table *pTab){
74802 if( pTab->pSchema!=pTempSchema ){
74804 for(pTrig=sqlite3TriggerList(pParse, pTab); pTrig; pTrig=pTrig->pNext){
74820 ** pTab from the database, including triggers and temporary triggers.
74823 ** pTab->zName if this function is being called to code part of an
74826 static void reloadTableSchema(Parse *pParse, Table *pTab, const char *zName){
74829 int iDb; /* Index of database containing pTab */
74837 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
74842 for(pTrig=sqlite3TriggerList(pParse, pTab); pTrig; pTrig=pTrig->pNext){
74850 sqlite3VdbeAddOp4(v, OP_DropTable, iDb, 0, 0, pTab->zName, 0);
74861 if( (zWhere=whereTempTriggers(pParse, pTab))!=0 ){
74894 Table *pTab; /* Table being renamed */
74911 pTab = sqlite3LocateTable(pParse, 0, pSrc->a[0].zName, pSrc->a[0].zDatabase);
74912 if( !pTab ) goto exit_rename_table;
74913 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
74933 if( SQLITE_OK!=isSystemTable(pParse, pTab->zName) ){
74941 if( pTab->pSelect ){
74942 sqlite3ErrorMsg(pParse, "view %s may not be altered", pTab->zName);
74949 if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, 0) ){
74955 if( sqlite3ViewGetColumnNames(pParse, pTab) ){
74958 if( IsVirtual(pTab) ){
74959 pVTab = sqlite3GetVTable(db, pTab);
74993 zTabName = pTab->zName;
75001 if( (zWhere=whereForeignKeys(pParse, pTab))!=0 ){
75043 zDb, zName, pTab->zName);
75052 if( (zWhere=whereTempTriggers(pParse, pTab))!=0 ){
75065 for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
75067 if( pFrom!=pTab ){
75075 reloadTableSchema(pParse, pTab, zName);
75119 Table *pTab; /* Table being altered */
75139 pTab = sqlite3FindTable(db, zTab, zDb);
75140 assert( pTab );
75144 if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, 0) ){
75223 reloadTableSchema(pParse, pTab, pTab->zName);
75243 Table *pTab;
75254 pTab = sqlite3LocateTable(pParse, 0, pSrc->a[0].zName, pSrc->a[0].zDatabase);
75255 if( !pTab ) goto exit_begin_add_column;
75258 if( IsVirtual(pTab) ){
75265 if( pTab->pSelect ){
75269 if( SQLITE_OK!=isSystemTable(pParse, pTab->zName) ){
75273 assert( pTab->addColOffset>0 );
75274 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
75287 pNew->nCol = pTab->nCol;
75292 pNew->zName = sqlite3MPrintf(db, "sqlite_altertab_%s", pTab->zName);
75297 memcpy(pNew->aCol, pTab->aCol, sizeof(Column)*pNew->nCol);
75307 pNew->addColOffset = pTab->addColOffset;
75428 Table *pTab, /* Table whose indices are to be analyzed */
75441 int iDb; /* Index of database containing pTab */
75460 if( v==0 || NEVER(pTab==0) ){
75463 if( pTab->tnum==0 ){
75467 if( sqlite3_strnicmp(pTab->zName, "sqlite_", 7)==0 ){
75472 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
75476 if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0,
75483 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
75486 sqlite3VdbeAddOp4(v, OP_String8, 0, regTabname, 0, pTab->zName, 0);
75487 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
75510 ** first index in the pTab->pIndex list, then register regLast has
75512 if( pTab->pIndex==pIdx ){
75671 if( pTab->pIndex==0 ){
75672 sqlite3VdbeAddOp3(v, OP_OpenRead, iIdxCur, pTab->tnum, iDb);
75673 VdbeComment((v, "%s", pTab->zName));
75718 Table *pTab = (Table*)sqliteHashData(k);
75719 analyzeOneTable(pParse, pTab, 0, iStatCur, iMem);
75727 ** in pTab that should be analyzed.
75729 static void analyzeTable(Parse *pParse, Table *pTab, Index *pOnlyIdx){
75733 assert( pTab!=0 );
75735 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
75742 openStatTable(pParse, iDb, iStatCur, pTab->zName, "tbl");
75744 analyzeOneTable(pParse, pTab, pOnlyIdx, iStatCur, pParse->nMem+1);
75765 Table *pTab;
75793 }else if( (pTab = sqlite3LocateTable(pParse, 0, z, 0))!=0 ){
75794 analyzeTable(pParse, pTab, 0);
75808 }else if( (pTab = sqlite3LocateTable(pParse, 0, z, zDb))!=0 ){
75809 analyzeTable(pParse, pTab, 0);
76729 Table *pTab = 0; /* The table being read */
76745 pTab = pParse->pTriggerTab;
76750 pTab = pTabList->a[iSrc].pTab;
76756 if( NEVER(pTab==0) ) return;
76759 assert( iCol<pTab->nCol );
76760 zCol = pTab->aCol[iCol].zName;
76761 }else if( pTab->iPKey>=0 ){
76762 assert( pTab->iPKey<pTab->nCol );
76763 zCol = pTab->aCol[pTab->iPKey].zName;
76768 if( SQLITE_IGNORE==sqlite3AuthReadCol(pParse, pTab->zName, zCol, iDb) ){
77983 Table *pTab = pParse->pNewTable;
77986 if( pTab==0 || IN_DECLARE_VTAB ) goto primary_key_exit;
77987 if( pTab->tabFlags & TF_HasPrimaryKey ){
77989 "table \"%s\" has more than one primary key", pTab->zName);
77992 pTab->tabFlags |= TF_HasPrimaryKey;
77994 iCol = pTab->nCol - 1;
77995 pTab->aCol[iCol].isPrimKey = 1;
77998 for(iCol=0; iCol<pTab->nCol; iCol++){
77999 if( sqlite3StrICmp(pList->a[i].zName, pTab->aCol[iCol].zName)==0 ){
78003 if( iCol<pTab->nCol ){
78004 pTab->aCol[iCol].isPrimKey = 1;
78009 if( iCol>=0 && iCol<pTab->nCol ){
78010 zType = pTab->aCol[iCol].zType;
78014 pTab->iPKey = iCol;
78015 pTab->keyConf = (u8)onError;
78017 pTab->tabFlags |= autoInc*TF_Autoincrement;
78046 Table *pTab = pParse->pNewTable;
78047 if( pTab && !IN_DECLARE_VTAB ){
78048 pTab->pCheck = sqlite3ExprAnd(db, pTab->pCheck, pCheckExpr);
78327 sSrc.a[0].pTab = p;
78682 Table *pTab = sqliteHashData(i);
78683 if( pTab->pSelect ){
78684 sqliteDeleteColumnNames(db, pTab);
78685 pTab->aCol = 0;
78686 pTab->nCol = 0;
78722 Table *pTab = sqliteHashData(pElem);
78723 if( pTab->tnum==iFrom ){
78724 pTab->tnum = iTo;
78766 ** Write VDBE code to erase table pTab and all associated indices on disk.
78771 static void destroyTable(Parse *pParse, Table *pTab){
78774 int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
78775 destroyRootPage(pParse, pTab->tnum, iDb);
78776 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
78796 int iTab = pTab->tnum;
78806 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
78808 assert( pIdx->pSchema==pTab->pSchema );
78816 int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
78829 Table *pTab;
78840 pTab = sqlite3LocateTable(pParse, isView,
78844 if( pTab==0 ){
78848 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
78851 /* If pTab is a virtual table, call ViewGetColumnNames() to ensure
78854 if( IsVirtual(pTab) && sqlite3ViewGetColumnNames(pParse, pTab) ){
78873 }else if( IsVirtual(pTab) ){
78875 zArg2 = sqlite3GetVTable(db, pTab)->pMod->zName;
78884 if( sqlite3AuthCheck(pParse, code, pTab->zName, zArg2, zDb) ){
78887 if( sqlite3AuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0, zDb) ){
78892 if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){
78893 sqlite3ErrorMsg(pParse, "table %s may not be dropped", pTab->zName);
78901 if( isView && pTab->pSelect==0 ){
78902 sqlite3ErrorMsg(pParse, "use DROP TABLE to delete table %s", pTab->zName);
78905 if( !isView && pTab->pSelect ){
78906 sqlite3ErrorMsg(pParse, "use DROP VIEW to delete view %s", pTab->zName);
78921 if( IsVirtual(pTab) ){
78925 sqlite3FkDropTable(pParse, pName, pTab);
78931 pTrigger = sqlite3TriggerList(pParse, pTab);
78933 assert( pTrigger->pSchema==pTab->pSchema ||
78945 if( pTab->tabFlags & TF_Autoincrement ){
78948 pDb->zName, pTab->zName
78962 pDb->zName, SCHEMA_TABLE(iDb), pTab->zName);
78967 "DELETE FROM %Q.sqlite_stat1 WHERE tbl=%Q", pDb->zName, pTab->zName
78971 if( !isView && !IsVirtual(pTab) ){
78972 destroyTable(pParse, pTab);
78978 if( IsVirtual(pTab) ){
78979 sqlite3VdbeAddOp4(v, OP_VDestroy, iDb, 0, 0, pTab->zName, 0);
78981 sqlite3VdbeAddOp4(v, OP_DropTable, iDb, 0, 0, pTab->zName, 0);
79129 Table *pTab;
79131 if( (pTab = pParse->pNewTable)==0 || (pFKey = pTab->pFKey)==0 ) return;
79149 Table *pTab = pIndex->pTable; /* The table that is indexed */
79150 int iTab = pParse->nTab++; /* Btree cursor used for pTab */
79169 sqlite3TableLock(pParse, iDb, pTab->tnum, 1, pTab->zName);
79185 sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead);
79245 Table *pTab = 0; /* Table to be indexed */
79290 pTab = sqlite3SrcListLookup(pParse, pTblName);
79291 if( pName2->n==0 && pTab && pTab->pSchema==db->aDb[1].pSchema ){
79304 pTab = sqlite3LocateTable(pParse, 0, pTblName->a[0].zName,
79306 if( !pTab || db->mallocFailed ) goto exit_create_index;
79307 assert( db->aDb[iDb].pSchema==pTab->pSchema );
79310 pTab = pParse->pNewTable;
79311 if( !pTab ) goto exit_create_index;
79312 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
79316 assert( pTab!=0 );
79318 if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0
79319 && sqlite3StrNICmp(&pTab->zName[7],"altertab_",9)!=0 ){
79320 sqlite3ErrorMsg(pParse, "table %s may not be indexed", pTab->zName);
79324 if( pTab->pSelect ){
79330 if( IsVirtual(pTab) ){
79373 for(pLoop=pTab->pIndex, n=1; pLoop; pLoop=pLoop->pNext, n++){}
79374 zName = sqlite3MPrintf(db, "sqlite_autoindex_%s_%d", pTab->zName, n);
79390 if( sqlite3AuthCheck(pParse, i, zName, pTab->zName, zDb) ){
79401 nullId.z = pTab->aCol[pTab->nCol-1].zName;
79448 pIndex->pTable = pTab;
79479 for(j=0, pTabCol=pTab->aCol; j<pTab->nCol; j++, pTabCol++){
79482 if( j>=pTab->nCol ){
79484 pTab->zName, zColName);
79504 zColl = pTab->aCol[j].zColl;
79518 if( pTab==pParse->pNewTable ){
79541 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
79649 pTab->zName,
79675 if( onError!=OE_Replace || pTab->pIndex==0
79676 || pTab->pIndex->onError==OE_Replace){
79677 pIndex->pNext = pTab->pIndex;
79678 pTab->pIndex = pIndex;
79680 Index *pOther = pTab->pIndex;
79775 Table *pTab = pIndex->pTable;
79782 if( sqlite3AuthCheck(pParse, code, pIndex->zName, pTab->zName, zDb) ){
80075 sqlite3DeleteTable(db, pItem->pTab);
80452 ** Recompute all indices of pTab that use the collating sequence pColl.
80453 ** If pColl==0 then recompute all indices of pTab.
80456 static void reindexTable(Parse *pParse, Table *pTab, char const *zColl){
80457 Index *pIndex; /* An index associated with pTab */
80459 for(pIndex=pTab->pIndex; pIndex; pIndex=pIndex->pNext){
80461 int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
80480 Table *pTab; /* A table in the database */
80486 pTab = (Table*)sqliteHashData(k);
80487 reindexTable(pParse, pTab, zColl);
80511 Table *pTab; /* A table in the database */
80512 Index *pIndex; /* An index associated with pTab */
80544 pTab = sqlite3FindTable(db, z, zDb);
80545 if( pTab ){
80546 reindexTable(pParse, pTab, 0);
81022 Table *pTab = sqliteHashData(pElem);
81023 sqlite3DeleteTable(0, pTab);
81084 ** pSrc->a[0].pTab Pointer to the Table object
81090 Table *pTab;
81092 pTab = sqlite3LocateTable(pParse, 0, pItem->zName, pItem->zDatabase);
81093 sqlite3DeleteTable(pParse->db, pItem->pTab);
81094 pItem->pTab = pTab;
81095 if( pTab ){
81096 pTab->nRef++;
81099 pTab = 0;
81101 return pTab;
81109 SQLITE_PRIVATE int sqlite3IsReadOnly(Parse *pParse, Table *pTab, int viewOk){
81120 if( ( IsVirtual(pTab)
81121 && sqlite3GetVTable(pParse->db, pTab)->pMod->pModule->xUpdate==0 )
81122 || ( (pTab->tabFlags & TF_Readonly)!=0
81126 sqlite3ErrorMsg(pParse, "table %s may not be modified", pTab->zName);
81131 if( !viewOk && pTab->pSelect ){
81132 sqlite3ErrorMsg(pParse,"cannot modify %s because it is a view",pTab->zName);
81286 Table *pTab; /* The table from which records will be deleted */
81287 const char *zDb; /* Name of database holding pTab */
81292 int iCur; /* VDBE Cursor number for pTab */
81317 pTab = sqlite3SrcListLookup(pParse, pTabList);
81318 if( pTab==0 ) goto delete_from_cleanup;
81324 pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0);
81325 isView = pTab->pSelect!=0;
81335 /* If pTab is really a view, make sure it has been initialized.
81337 if( sqlite3ViewGetColumnNames(pParse, pTab) ){
81341 if( sqlite3IsReadOnly(pParse, pTab, (pTrigger?1:0)) ){
81344 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
81347 rcauth = sqlite3AuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0, zDb);
81358 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
81365 sqlite3AuthContextPush(pParse, &sContext, pTab->zName);
81382 sqlite3MaterializeView(pParse, pTab, pWhere, iCur);
81408 if( rcauth==SQLITE_OK && pWhere==0 && !pTrigger && !IsVirtual(pTab)
81409 && 0==sqlite3FkRequired(pParse, pTab, 0, 0)
81412 sqlite3VdbeAddOp4(v, OP_Clear, pTab->tnum, iDb, memCnt,
81413 pTab->zName, P4_STATIC);
81414 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
81415 assert( pIdx->pSchema==pTab->pSchema );
81433 regRowid = sqlite3ExprCodeGetColumn(pParse, pTab, -1, iCur, iRowid);
81450 sqlite3OpenTableAndIndices(pParse, pTab, iCur, OP_OpenWrite);
81457 if( IsVirtual(pTab) ){
81458 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
81459 sqlite3VtabMakeWritable(pParse, pTab);
81466 sqlite3GenerateRowDelete(pParse, pTab, iCur, iRowid, count, pTrigger, OE_Default);
81474 if( !isView && !IsVirtual(pTab) ){
81475 for(i=1, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
81523 ** 1. A read/write cursor pointing to pTab, the table containing the row
81526 ** 2. Read/write cursors for all indices of pTab must be open as
81537 Table *pTab, /* Table containing the row to be deleted */
81559 if( sqlite3FkRequired(pParse, pTab, 0, 0) || pTrigger ){
81566 pParse, pTrigger, 0, 0, TRIGGER_BEFORE|TRIGGER_AFTER, pTab, onconf
81568 mask |= sqlite3FkOldmask(pParse, pTab);
81570 pParse->nMem += (1 + pTab->nCol);
81575 for(iCol=0; iCol<pTab->nCol; iCol++){
81577 sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, iCol, iOld+iCol+1);
81583 TK_DELETE, 0, TRIGGER_BEFORE, pTab, iOld, onconf, iLabel
81595 sqlite3FkCheck(pParse, pTab, iOld, 0);
81598 /* Delete the index and table entries. Skip this step if pTab is really
81601 if( pTab->pSelect==0 ){
81602 sqlite3GenerateRowIndexDelete(pParse, pTab, iCur, 0);
81605 sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_TRANSIENT);
81612 sqlite3FkActions(pParse, pTab, 0, iOld);
81616 TK_DELETE, 0, TRIGGER_AFTER, pTab, iOld, onconf, iLabel
81632 ** 1. A read/write cursor pointing to pTab, the table containing the row
81635 ** 2. Read/write cursors for all indices of pTab must be open as
81643 Table *pTab, /* Table containing the row to be deleted */
81651 for(i=1, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
81660 ** regOut. The key with be for index pIdx which is an index on pTab.
81661 ** iCur is the index of a cursor open on the pTab table and pointing to
81678 Table *pTab = pIdx->pTable;
81687 if( idx==pTab->iPKey ){
81691 sqlite3ColumnDefault(v, pTab, idx, -1);
83608 int iDb, /* Index of database housing pTab */
83609 Table *pTab, /* Parent table of FK pFKey */
83610 Index *pIdx, /* Unique index on parent key columns in pTab */
83615 int isIgnore /* If true, pretend pTab contains all NULL values */
83640 ** column of the parent table (table pTab). */
83656 if( pTab==pFKey->pFrom && nIncr==1 ){
83660 sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenRead);
83682 if( pTab==pFKey->pFrom && nIncr==1 ){
83752 Table *pTab,
83767 assert( !pIdx || pIdx->pTable==pTab );
83795 pCol = &pTab->aCol[iCol];
83796 if( pTab->iPKey==iCol ) iCol = -1;
83817 if( pTab==pFKey->pFrom && nIncr>0 ){
83861 ** constraints for which table pTab is the parent table. For example,
83873 SQLITE_PRIVATE FKey *sqlite3FkReferences(Table *pTab){
83874 int nName = sqlite3Strlen30(pTab->zName);
83875 return (FKey *)sqlite3HashFind(&pTab->pSchema->fkeyHash, pTab->zName, nName);
83898 ** This function is called to generate code that runs when table pTab is
83901 ** table pTab.
83914 SQLITE_PRIVATE void sqlite3FkDropTable(Parse *pParse, SrcList *pName, Table *pTab){
83916 if( (db->flags&SQLITE_ForeignKeys) && !IsVirtual(pTab) && !pTab->pSelect ){
83921 if( sqlite3FkReferences(pTab)==0 ){
83928 for(p=pTab->pFKey; p; p=p->pNextFrom){
83957 ** table pTab to generate VDBE code to perform foreign key constraint
83961 ** first register in an array of (pTab->nCol+1) registers containing the
83967 ** first register of an array of (pTab->nCol+1) registers containing the new
83977 Table *pTab, /* Row is being deleted from this table */
83983 int iDb; /* Index of database containing pTab */
83984 const char *zDb; /* Name of database containing pTab */
83993 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
83996 /* Loop through all the foreign key constraints for which pTab is the
83998 for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){
84029 if( aiCol[i]==pTab->iPKey ){
84067 for(pFKey = sqlite3FkReferences(pTab); pFKey; pFKey=pFKey->pNextTo){
84079 if( locateFkeyIndex(pParse, pTab, pFKey, &pIdx, &aiCol) ){
84091 pItem->pTab = pFKey->pFrom;
84093 pItem->pTab->nRef++;
84097 fkScanChildren(pParse, pSrc, pTab, pIdx, pFKey, aiCol, regNew, -1);
84106 pTab, pIdx, pFKey, aiCol, regOld, 1);
84119 ** row contained in table pTab.
84123 Table *pTab /* Table being modified */
84129 for(p=pTab->pFKey; p; p=p->pNextFrom){
84132 for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
84134 locateFkeyIndex(pParse, pTab, p, &pIdx, 0);
84145 ** row contained in table pTab. If the operation is a DELETE, then
84147 ** to an array of size N, where N is the number of columns in table pTab.
84159 Table *pTab, /* Table being modified */
84168 return (sqlite3FkReferences(pTab) || pTab->pFKey);
84176 for(p=pTab->pFKey; p; p=p->pNextFrom){
84180 if( iChildKey==pTab->iPKey && chngRowid ) return 1;
84185 for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
84189 for(iKey=0; iKey<pTab->nCol; iKey++){
84190 Column *pCol = &pTab->aCol[iKey];
84193 if( iKey==pTab->iPKey && chngRowid ) return 1;
84205 ** compiled on table pTab, which is the parent table of foreign-key pFKey.
84216 ** For example, if pFKey is the foreign key and pTab is table "p" in
84234 Table *pTab, /* Table being updated or deleted from */
84259 if( locateFkeyIndex(pParse, pTab, pFKey, &pIdx, &aiCol) ) return 0;
84272 tToCol.z = pIdx ? pTab->aCol[pIdx->aiColumn[i]].zName : "oid";
84404 pTrigger->pSchema = pTab->pSchema;
84405 pTrigger->pTabSchema = pTab->pSchema;
84419 Table *pTab, /* Table being updated or deleted from */
84424 ** refer to table pTab. If there is an action associated with the FK
84429 for(pFKey = sqlite3FkReferences(pTab); pFKey; pFKey=pFKey->pNextTo){
84430 Trigger *pAction = fkActionTrigger(pParse, pTab, pFKey, pChanges);
84432 sqlite3CodeRowTriggerDirect(pParse, pAction, pTab, regOld, OE_Abort, 0);
84442 ** table pTab. Remove the deleted foreign keys from the Schema.fkeyHash
84445 SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){
84449 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) );
84450 for(pFKey=pTab->pFKey; pFKey; pFKey=pNext){
84459 sqlite3HashInsert(&pTab->pSchema->fkeyHash, z, sqlite3Strlen30(z), p);
84507 Table *pTab, /* The table to be opened */
84511 if( IsVirtual(pTab) ) return;
84514 sqlite3TableLock(p, iDb, pTab->tnum, (opcode==OP_OpenWrite)?1:0, pTab->zName);
84515 sqlite3VdbeAddOp3(v, opcode, iCur, pTab->tnum, iDb);
84516 sqlite3VdbeChangeP4(v, -1, SQLITE_INT_TO_PTR(pTab->nCol), P4_INT32);
84517 VdbeComment((v, "%s", pTab->zName));
84551 Table *pTab = pIdx->pTable;
84559 pIdx->zColAff[n] = pTab->aCol[pIdx->aiColumn[n]].affinity;
84570 ** string for table pTab. A column affinity string has one character
84582 SQLITE_PRIVATE void sqlite3TableAffinityStr(Vdbe *v, Table *pTab){
84590 if( !pTab->zColAff ){
84595 zColAff = (char *)sqlite3DbMallocRaw(0, pTab->nCol+1);
84601 for(i=0; i<pTab->nCol; i++){
84602 zColAff[i] = pTab->aCol[i].affinity;
84604 zColAff[pTab->nCol] = '\0';
84606 pTab->zColAff = zColAff;
84609 sqlite3VdbeChangeP4(v, -1, pTab->zColAff, P4_TRANSIENT);
84613 ** Return non-zero if the table pTab in database iDb or any of its indices
84616 ** a statement of the form "INSERT INTO <iDb, pTab> SELECT ..." can
84619 static int readsTable(Parse *p, int iStartAddr, int iDb, Table *pTab){
84624 VTable *pVTab = IsVirtual(pTab) ? sqlite3GetVTable(p->db, pTab) : 0;
84633 if( tnum==pTab->tnum ){
84636 for(pIndex=pTab->pIndex; pIndex; pIndex=pIndex->pNext){
84655 ** Locate or create an AutoincInfo structure associated with table pTab
84662 ** first use of table pTab. On 2nd and subsequent uses, the original
84667 ** (1) Register to hold the name of the pTab table.
84668 ** (2) Register to hold the maximum ROWID of pTab.
84669 ** (3) Register to hold the rowid in sqlite_sequence of pTab
84676 int iDb, /* Index of the database holding pTab */
84677 Table *pTab /* The table we are writing to */
84680 if( pTab->tabFlags & TF_Autoincrement ){
84685 while( pInfo && pInfo->pTab!=pTab ){ pInfo = pInfo->pNext; }
84691 pInfo->pTab = pTab;
84726 sqlite3VdbeAddOp4(v, OP_String8, 0, memId-1, 0, p->pTab->zName, 0);
84925 Table *pTab; /* The table to insert into. aka TABLE */
84933 int baseCur = 0; /* VDBE Cursor number for pTab */
84958 Trigger *pTrigger; /* List of triggers on pTab, if required */
84973 pTab = sqlite3SrcListLookup(pParse, pTabList);
84974 if( pTab==0 ){
84977 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
84981 if( sqlite3AuthCheck(pParse, SQLITE_INSERT, pTab->zName, 0, zDb) ){
84989 pTrigger = sqlite3TriggersExist(pParse, pTab, TK_INSERT, 0, &tmask);
84990 isView = pTab
85002 /* If pTab is really a view, make sure it has been initialized.
85003 ** ViewGetColumnNames() is a no-op if pTab is not a view (or virtual
85006 if( sqlite3ViewGetColumnNames(pParse, pTab) ){
85014 if( sqlite3IsReadOnly(pParse, pTab, tmask) ){
85035 if( pColumn==0 && xferOptimization(pParse, pTab, pSelect, onError, iDb) ){
85045 regAutoinc = autoIncBegin(pParse, iDb, pTab);
85112 if( pTrigger || readsTable(pParse, addrSelect, iDb, pTab) ){
85167 if( IsVirtual(pTab) ){
85168 for(i=0; i<pTab->nCol; i++){
85169 nHidden += (IsHiddenColumn(&pTab->aCol[i]) ? 1 : 0);
85172 if( pColumn==0 && nColumn && nColumn!=(pTab->nCol-nHidden) ){
85175 pTabList, 0, pTab->nCol-nHidden, nColumn);
85192 ** key in the original table is pTab->iPKey.)
85199 for(j=0; j<pTab->nCol; j++){
85200 if( sqlite3StrICmp(pColumn->a[i].zName, pTab->aCol[j].zName)==0 ){
85202 if( j==pTab->iPKey ){
85208 if( j>=pTab->nCol ){
85226 keyColumn = pTab->iPKey;
85241 nIdx = sqlite3OpenTableAndIndices(pParse, pTab, baseCur, OP_OpenWrite);
85282 pParse->nMem += pTab->nCol + 1;
85283 if( IsVirtual(pTab) ){
85293 int regCols = sqlite3GetTempRange(pParse, pTab->nCol+1);
85320 assert( !IsVirtual(pTab) );
85324 for(i=0; i<pTab->nCol; i++){
85333 sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regCols+i+1);
85348 sqlite3VdbeAddOp2(v, OP_Affinity, regCols+1, pTab->nCol);
85349 sqlite3TableAffinityStr(v, pTab);
85354 pTab, regCols-pTab->nCol-1, onError, endOfLoop);
85356 sqlite3ReleaseTempRange(pParse, regCols, pTab->nCol+1);
85365 if( IsVirtual(pTab) ){
85378 if( ALWAYS(pOp) && pOp->opcode==OP_Null && !IsVirtual(pTab) ){
85391 if( !IsVirtual(pTab) ){
85401 }else if( IsVirtual(pTab) ){
85413 for(i=0; i<pTab->nCol; i++){
85415 if( i==pTab->iPKey ){
85424 if( IsHiddenColumn(&pTab->aCol[i]) ){
85425 assert( IsVirtual(pTab) );
85437 sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, iRegStore);
85451 if( IsVirtual(pTab) ){
85452 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
85453 sqlite3VtabMakeWritable(pParse, pTab);
85454 sqlite3VdbeAddOp4(v, OP_VUpdate, 1, pTab->nCol+2, regIns, pVTab, P4_VTAB);
85460 sqlite3GenerateConstraintChecks(pParse, pTab, baseCur, regIns, aRegIdx,
85463 sqlite3FkCheck(pParse, pTab, 0, regIns);
85465 pParse, pTab, baseCur, regIns, aRegIdx, 0, appendFlag, isReplace==0
85479 pTab, regData-2-pTab->nCol, onError, endOfLoop);
85495 if( !IsVirtual(pTab) && !isView ){
85498 for(idx=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, idx++){
85614 ** The calling routine must open a read/write cursor for pTab with
85615 ** cursor number "baseCur". All indices of pTab must also have open
85622 Table *pTab, /* the table into which we are inserting */
85623 int baseCur, /* Index of a read/write cursor pointing at pTab */
85646 assert( pTab->pSelect==0 ); /* This table is not a VIEW */
85647 nCol = pTab->nCol;
85653 if( i==pTab->iPKey ){
85656 onError = pTab->aCol[i].notNull;
85663 if( onError==OE_Replace && pTab->aCol[i].pDflt==0 ){
85677 pTab->zName, pTab->aCol[i].zName);
85688 sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regData+i);
85698 if( pTab->pCheck && (pParse->db->flags & SQLITE_IgnoreChecks)==0 ){
85701 sqlite3ExprIfTrue(pParse, pTab->pCheck, allOk, SQLITE_JUMPIFNULL);
85718 onError = pTab->keyConf;
85766 pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0);
85768 if( pTrigger || sqlite3FkRequired(pParse, pTab, 0, 0) ){
85771 pParse, pTab, baseCur, regRowid, 0, pTrigger, OE_Replace
85773 }else if( pTab->pIndex ){
85775 sqlite3GenerateRowIndexDelete(pParse, pTab, baseCur, 0);
85796 for(iCur=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, iCur++){
85806 if( idx==pTab->iPKey ){
85857 char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
85879 pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0);
85882 pParse, pTab, baseCur, regR, 0, pTrigger, OE_Replace
85908 Table *pTab, /* the table into which we are inserting */
85909 int baseCur, /* Index of a read/write cursor pointing at pTab */
85926 assert( pTab->pSelect==0 ); /* This table is not a VIEW */
85927 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){}
85937 sqlite3VdbeAddOp3(v, OP_MakeRecord, regData, pTab->nCol, regRec);
85938 sqlite3TableAffinityStr(v, pTab);
85939 sqlite3ExprCacheAffinityChange(pParse, regData, pTab->nCol);
85954 sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_TRANSIENT);
85968 Table *pTab, /* Table to be opened */
85977 if( IsVirtual(pTab) ) return 0;
85978 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
85981 sqlite3OpenTable(pParse, baseCur, iDb, pTab, op);
85982 for(i=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
85984 assert( pIdx->pSchema==pTab->pSchema );
88400 Table *pTab;
88402 pTab = sqlite3FindTable(db, zRight, zDb);
88403 if( pTab ){
88415 sqlite3ViewGetColumnNames(pParse, pTab);
88416 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
88439 Table *pTab;
88444 pTab = pIdx->pTable;
88454 assert( pTab->nCol>cnum );
88455 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pTab->aCol[cnum].zName, 0);
88463 Table *pTab;
88465 pTab = sqlite3FindTable(db, zRight, zDb);
88466 if( pTab ){
88468 pIdx = pTab->pIndex;
88526 Table *pTab;
88528 pTab = sqlite3FindTable(db, zRight, zDb);
88529 if( pTab ){
88531 pFK = pTab->pFKey;
88554 pTab->aCol[pFK->aCol[j].iFrom].zName, 0);
88654 Table *pTab = sqliteHashData(x);
88656 sqlite3VdbeAddOp2(v, OP_Integer, pTab->tnum, 2+cnt);
88658 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
88684 Table *pTab = sqliteHashData(x);
88688 if( pTab->pIndex==0 ) continue;
88692 sqlite3OpenTableAndIndices(pParse, pTab, 1, OP_OpenRead);
88696 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
88723 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
89200 Table *pTab;
89265 pTab = sqlite3FindTable(db, zMasterName, db->aDb[iDb].zName);
89266 if( ALWAYS(pTab) ){
89267 pTab->tabFlags |= TF_Readonly;
90106 static int columnIndex(Table *pTab, const char *zCol){
90108 for(i=0; i<pTab->nCol; i++){
90109 if( sqlite3StrICmp(pTab->aCol[i].zName, zCol)==0 ) return i;
90128 int *piCol /* Write index of pSrc->a[*piTab].pTab->aCol[] here */
90135 iCol = columnIndex(pSrc->a[i].pTab, zCol);
90175 assert( pSrc->a[iLeft].pTab );
90176 assert( pSrc->a[iRight].pTab );
90252 Table *pLeftTab = pLeft->pTab;
90253 Table *pRightTab = pRight->pTab;
90919 Table *pTab = 0; /* Table structure column is extracted from */
90921 int iCol = pExpr->iColumn; /* Index of column in pTab */
90924 while( pNC && !pTab ){
90928 pTab = pTabList->a[j].pTab;
90935 if( pTab==0 ){
90956 assert( pTab && pExpr->pTab==pTab );
90974 }else if( ALWAYS(pTab->pSchema) ){
90977 if( iCol<0 ) iCol = pTab->iPKey;
90978 assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
90983 zType = pTab->aCol[iCol].zType;
90984 zOriginCol = pTab->aCol[iCol].zName;
90986 zOriginTab = pTab->zName;
90988 int iDb = sqlite3SchemaToIndex(pNC->pParse->db, pTab->pSchema);
91096 Table *pTab;
91103 pTab = pTabList->a[j].pTab;
91104 if( iCol<0 ) iCol = pTab->iPKey;
91105 assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
91109 zCol = pTab->aCol[iCol].zName;
91116 zName = sqlite3MPrintf(db, "%s.%s", pTab->zName, zCol);
91171 Table *pTab; /* Table associated with this expression */
91173 if( pColExpr->op==TK_COLUMN && ALWAYS(pColExpr->pTab!=0) ){
91176 pTab = pColExpr->pTab;
91177 if( iCol<0 ) iCol = pTab->iPKey;
91179 iCol>=0 ? pTab->aCol[iCol].zName : "rowid");
91271 Table *pTab;
91282 pTab = sqlite3DbMallocZero(db, sizeof(Table) );
91283 if( pTab==0 ){
91289 pTab->nRef = 1;
91290 pTab->zName = 0;
91291 pTab->nRowEst = 1000000;
91292 selectColumnsFromExprList(pParse, pSelect->pEList, &pTab->nCol, &pTab->aCol);
91293 selectAddColumnTypeAndCollation(pParse, pTab->nCol, pTab->aCol, pSelect);
91294 pTab->iPKey = -1;
91296 sqlite3DeleteTable(db, pTab);
91299 return pTab;
92807 ** complete, since there may still exist Expr.pTab entries that
92810 ** pSubitem->pTab is always non-NULL by test restrictions and tests above.
92812 if( ALWAYS(pSubitem->pTab!=0) ){
92813 Table *pTabToDel = pSubitem->pTab;
92821 pSubitem->pTab = 0;
93009 Table *pTab;
93019 pTab = p->pSrc->a[0].pTab;
93021 assert( pTab && !pTab->pSelect && pExpr );
93023 if( IsVirtual(pTab) ) return 0;
93028 return pTab;
93039 if( pFrom->pTab && pFrom->zIndex ){
93040 Table *pTab = pFrom->pTab;
93043 for(pIdx=pTab->pIndex;
93064 ** (2) Fill in the pTabList->a[].pTab fields in the SrcList that
93109 Table *pTab;
93110 if( pFrom->pTab!=0 ){
93121 assert( pFrom->pTab==0 );
93123 pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
93124 if( pTab==0 ) return WRC_Abort;
93125 pTab->nRef = 1;
93126 pTab->zName = sqlite3MPrintf(db, "sqlite_subquery_%p_", (void*)pTab);
93128 selectColumnsFromExprList(pParse, pSel->pEList, &pTab->nCol, &pTab->aCol);
93129 pTab->iPKey = -1;
93130 pTab->nRowEst = 1000000;
93131 pTab->tabFlags |= TF_Ephemeral;
93135 assert( pFrom->pTab==0 );
93136 pFrom->pTab = pTab =
93138 if( pTab==0 ) return WRC_Abort;
93139 pTab->nRef++;
93141 if( pTab->pSelect || IsVirtual(pTab) ){
93143 if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort;
93145 pFrom->pSelect = sqlite3SelectDup(db, pTab->pSelect, 0);
93219 Table *pTab = pFrom->pTab;
93222 zTabName = pTab->zName;
93229 for(j=0; j<pTab->nCol; j++){
93231 char *zName = pTab->aCol[j].zName;
93240 if( IsHiddenColumn(&pTab->aCol[j]) ){
93241 assert(IsVirtual(pTab));
93362 Table *pTab = pFrom->pTab;
93363 if( ALWAYS(pTab!=0) && (pTab->tabFlags & TF_Ephemeral)!=0 ){
93368 selectAddColumnTypeAndCollation(pParse, pTab->nCol, pTab->aCol, pSel);
93549 ** count(*) query ("SELECT count(*) FROM pTab").
93554 Table *pTab, /* Table being queried */
93559 pTab->zName,
93562 pTab->nRowEst
93729 pItem->pTab->nRowEst = (unsigned)pSub->nSelectRow;
94015 pCol->pTab, pCol->iColumn, pCol->iTable, r1);
94131 Table *pTab;
94132 if( (pTab = isSimpleCount(p, &sAggInfo))!=0 ){
94146 const int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
94151 int iRoot = pTab->tnum; /* Root page of scanned b-tree */
94154 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
94167 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
94172 if( pBest && pBest->nColumn<pTab->nCol ){
94184 explainSimpleCount(pParse, pTab, pBest);
94352 if( pItem->pTab ){
94353 sqlite3DebugPrintf("(table: %s)", pItem->pTab->zName);
94620 ** Given table pTab, return a list of all the triggers attached to
94623 ** All of the triggers on pTab that are in the same database as pTab
94624 ** are already attached to pTab->pTrigger. But there might be additional
94625 ** triggers on pTab in the TEMP schema. This routine prepends all
94626 ** TEMP triggers on pTab to the beginning of the pTab->pTrigger list
94630 ** that fire off of pTab. The list will include any TEMP triggers on
94631 ** pTab as well as the triggers lised in pTab->pTrigger.
94633 SQLITE_PRIVATE Trigger *sqlite3TriggerList(Parse *pParse, Table *pTab){
94641 if( pTmpSchema!=pTab->pSchema ){
94646 if( pTrig->pTabSchema==pTab->pSchema
94647 && 0==sqlite3StrICmp(pTrig->table, pTab->zName)
94649 pTrig->pNext = (pList ? pList : pTab->pTrigger);
94655 return (pList ? pList : pTab->pTrigger);
94679 Table *pTab; /* Table that the trigger fires off of */
94685 int iTabDb; /* Index of the database holding pTab */
94715 pTab = sqlite3SrcListLookup(pParse, pTableName);
94716 if( db->init.busy==0 && pName2->n==0 && pTab
94717 && pTab->pSchema==db->aDb[1].pSchema ){
94728 pTab = sqlite3SrcListLookup(pParse, pTableName);
94729 if( !pTab ){
94744 if( IsVirtual(pTab) ){
94768 if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){
94777 if( pTab->pSelect && tr_tm!=TK_INSTEAD ){
94782 if( !pTab->pSelect && tr_tm==TK_INSTEAD ){
94787 iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
94795 if( sqlite3AuthCheck(pParse, code, zName, pTab->zName, zDbTrig) ){
94820 pTrigger->pTabSchema = pTab->pSchema;
94903 Table *pTab;
94905 pTab = sqlite3HashFind(&pLink->pTabSchema->tblHash, pLink->table, n);
94906 assert( pTab!=0 );
94907 pLink->pNext = pTab->pTrigger;
94908 pTab->pTrigger = pLink;
95183 Table *pTab = tableOfTrigger(pTrigger);
95185 for(pp=&pTab->pTrigger; *pp!=pTrigger; pp=&((*pp)->pNext));
95212 ** Return a list of all triggers on table pTab if there exists at least
95219 Table *pTab, /* The table the contains the triggers */
95229 pList = sqlite3TriggerList(pParse, pTab);
95231 assert( pList==0 || IsVirtual(pTab)==0 );
95391 Table *pTab, /* The table pTrigger is attached to */
95404 assert( pTrigger->zName==0 || pTab==tableOfTrigger(pTrigger) );
95429 pSubParse->pTriggerTab = pTab;
95443 pTab->zName
95503 Table *pTab, /* The table trigger pTrigger is attached to */
95509 assert( pTrigger->zName==0 || pTab==tableOfTrigger(pTrigger) );
95522 pPrg = codeRowTrigger(pParse, pTrigger, pTab, orconf);
95530 ** table pTab. The reg, orconf and ignoreJump parameters passed to this
95537 Table *pTab, /* The table to code triggers from */
95544 pPrg = getRowTrigger(pParse, p, pTab, orconf);
95568 ** on table pTab. The operation to code triggers for (INSERT, UPDATE or DELETE)
95574 ** operation on pTab, this function is a no-op.
95578 ** in the trigger program. If N is the number of columns in table pTab
95579 ** (a copy of pTab->nCol), then registers are populated as follows:
95584 ** reg+1 OLD.* value of left-most column of pTab
95586 ** reg+N OLD.* value of right-most column of pTab
95588 ** reg+N+2 OLD.* value of left-most column of pTab
95590 ** reg+N+N+1 NEW.* value of right-most column of pTab
95608 Trigger *pTrigger, /* List of triggers on table pTab */
95612 Table *pTab, /* The table to code triggers from */
95638 sqlite3CodeRowTriggerDirect(pParse, p, pTab, reg, orconf, ignoreJump);
95670 Trigger *pTrigger, /* List of triggers on table pTab */
95674 Table *pTab, /* The table to code triggers from */
95687 pPrg = getRowTrigger(pParse, p, pTab, orconf);
95721 Table *pTab, /* The virtual table */
95724 int *aXRef, /* Mapping from columns of pTab to entries in pChanges */
95731 ** i-th column of table pTab. This routine sets the P4 parameter of the
95759 SQLITE_PRIVATE void sqlite3ColumnDefault(Vdbe *v, Table *pTab, int i, int iReg){
95760 assert( pTab!=0 );
95761 if( !pTab->pSelect ){
95764 Column *pCol = &pTab->aCol[i];
95765 VdbeComment((v, "%s.%s", pTab->zName, pCol->zName));
95766 assert( i<pTab->nCol );
95773 if( iReg>=0 && pTab->aCol[i].affinity==SQLITE_AFF_REAL ){
95795 Table *pTab; /* The table to be updated */
95801 int iCur; /* VDBE Cursor number of pTab */
95818 Trigger *pTrigger; /* List of triggers on pTab, if required */
95840 pTab = sqlite3SrcListLookup(pParse, pTabList);
95841 if( pTab==0 ) goto update_cleanup;
95842 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
95848 pTrigger = sqlite3TriggersExist(pParse, pTab, TK_UPDATE, pChanges, &tmask);
95849 isView = pTab->pSelect!=0;
95861 if( sqlite3ViewGetColumnNames(pParse, pTab) ){
95864 if( sqlite3IsReadOnly(pParse, pTab, tmask) ){
95867 aXRef = sqlite3DbMallocRaw(db, sizeof(int) * pTab->nCol );
95869 for(i=0; i<pTab->nCol; i++) aXRef[i] = -1;
95877 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
95897 for(j=0; j<pTab->nCol; j++){
95898 if( sqlite3StrICmp(pTab->aCol[j].zName, pChanges->a[i].zName)==0 ){
95899 if( j==pTab->iPKey ){
95907 if( j>=pTab->nCol ){
95920 rc = sqlite3AuthCheck(pParse, SQLITE_UPDATE, pTab->zName,
95921 pTab->aCol[j].zName, db->aDb[iDb].zName);
95931 hasFK = sqlite3FkRequired(pParse, pTab, aXRef, chngRowid);
95938 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){}
95943 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
95967 if( IsVirtual(pTab) ){
95968 updateVirtualTable(pParse, pTabList, pTab, pChanges, pRowidExpr, aXRef,
95980 pParse->nMem += pTab->nCol;
95986 pParse->nMem += pTab->nCol;
95990 sqlite3AuthContextPush(pParse, &sContext, pTab->zName);
95998 sqlite3MaterializeView(pParse, pTab, pWhere, iCur);
96042 if( !okOnePass ) sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenWrite);
96047 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
96054 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
96091 u32 oldmask = (hasFK ? sqlite3FkOldmask(pParse, pTab) : 0);
96093 pTrigger, pChanges, 0, TRIGGER_BEFORE|TRIGGER_AFTER, pTab, onError
96095 for(i=0; i<pTab->nCol; i++){
96097 sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, i, regOld+i);
96121 pParse, pTrigger, pChanges, 1, TRIGGER_BEFORE, pTab, onError
96123 for(i=0; i<pTab->nCol; i++){
96124 if( i==pTab->iPKey ){
96139 sqlite3ColumnDefault(v, pTab, i, regNew+i);
96148 sqlite3VdbeAddOp2(v, OP_Affinity, regNew, pTab->nCol);
96149 sqlite3TableAffinityStr(v, pTab);
96151 TRIGGER_BEFORE, pTab, regOldRowid, onError, addr);
96166 for(i=0; i<pTab->nCol; i++){
96167 if( aXRef[i]<0 && i!=pTab->iPKey ){
96169 sqlite3ColumnDefault(v, pTab, i, regNew+i);
96178 sqlite3GenerateConstraintChecks(pParse, pTab, iCur, regNewRowid,
96183 sqlite3FkCheck(pParse, pTab, regOldRowid, 0);
96188 sqlite3GenerateRowIndexDelete(pParse, pTab, iCur, aRegIdx);
96197 sqlite3FkCheck(pParse, pTab, 0, regNewRowid);
96201 sqlite3CompleteInsertion(pParse, pTab, iCur, regNewRowid, aRegIdx, 1, 0, 0);
96207 sqlite3FkActions(pParse, pTab, pChanges, regOldRowid);
96218 TRIGGER_AFTER, pTab, regOldRowid, onError, addr);
96227 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
96295 Table *pTab, /* The virtual table */
96298 int *aXRef, /* Mapping from columns of pTab to entries in pChanges */
96310 const char *pVTab = (const char*)sqlite3GetVTable(db, pTab);
96321 assert( pTab->iPKey<0 );
96322 for(i=0; i<pTab->nCol; i++){
96326 pExpr = sqlite3Expr(db, TK_ID, pTab->aCol[i].zName);
96337 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, ephemTab, pTab->nCol+1+(pRowid!=0));
96347 pParse->nMem += pTab->nCol+1;
96351 for(i=0; i<pTab->nCol; i++){
96354 sqlite3VtabMakeWritable(pParse, pTab);
96355 sqlite3VdbeAddOp4(v, OP_VUpdate, 0, pTab->nCol+2, iReg, pVTab, P4_VTAB);
96812 ** pTab is a pointer to a Table structure representing a virtual-table.
96816 SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3 *db, Table *pTab){
96818 assert( IsVirtual(pTab) );
96819 for(pVtab=pTab->pVTable; pVtab && pVtab->db!=db; pVtab=pVtab->pNext);
97035 Table *pTab = pParse->pNewTable; /* The table being constructed */
97038 if( pTab==0 ) return;
97041 if( pTab->nModuleArg<1 ) return;
97069 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
97075 pTab->zName,
97076 pTab->zName,
97085 zWhere = sqlite3MPrintf(db, "name='%q' AND type='table'", pTab->zName);
97088 pTab->zName, sqlite3Strlen30(pTab->zName) + 1);
97098 Schema *pSchema = pTab->pSchema;
97099 const char *zName = pTab->zName;
97102 pOld = sqlite3HashInsert(&pSchema->tblHash, zName, nName, pTab);
97105 assert( pTab==pOld ); /* Malloc must have failed inside HashInsert() */
97144 Table *pTab,
97151 const char *const*azArg = (const char *const*)pTab->azModuleArg;
97152 int nArg = pTab->nModuleArg;
97154 char *zModuleName = sqlite3MPrintf(db, "%s", pTab->zName);
97170 db->pVTab = pTab;
97191 *pzErr = sqlite3MPrintf(db, zFormat, pTab->zName);
97197 ** into the linked list headed by pTab->pVTable. Then loop through the
97201 pVTable->pNext = pTab->pVTable;
97202 pTab->pVTable = pVTable;
97204 for(iCol=0; iCol<pTab->nCol; iCol++){
97205 char *zType = pTab->aCol[iCol].zType;
97230 pTab->aCol[iCol].isHidden = 1;
97243 ** of the virtual table pTab. If an error occurs, an error code is returned
97246 ** This call is a no-op if table pTab is not a virtual table.
97248 SQLITE_PRIVATE int sqlite3VtabCallConnect(Parse *pParse, Table *pTab){
97254 assert( pTab );
97255 if( (pTab->tabFlags & TF_Virtual)==0 || sqlite3GetVTable(db, pTab) ){
97260 zMod = pTab->azModuleArg[0];
97264 const char *zModule = pTab->azModuleArg[0];
97269 rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xConnect, &zErr);
97313 Table *pTab;
97317 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
97318 assert( pTab && (pTab->tabFlags & TF_Virtual)!=0 && !pTab->pVTable );
97321 zMod = pTab->azModuleArg[0];
97332 rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xCreate, pzErr);
97337 if( rc==SQLITE_OK && ALWAYS(sqlite3GetVTable(db, pTab)) ){
97338 rc = addToVTrans(db, sqlite3GetVTable(db, pTab));
97353 Table *pTab;
97357 pTab = db->pVTab;
97358 if( !pTab ){
97363 assert( (pTab->tabFlags & TF_Virtual)!=0 );
97379 if( !pTab->aCol ){
97380 pTab->aCol = pParse->pNewTable->aCol;
97381 pTab->nCol = pParse->pNewTable->nCol;
97415 Table *pTab;
97417 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
97418 if( ALWAYS(pTab!=0 && pTab->pVTable!=0) ){
97419 VTable *p = vtabDisconnectAll(db, pTab);
97426 assert( pTab->pVTable==p && p->pNext==0 );
97428 pTab->pVTable = 0;
97573 Table *pTab;
97587 pTab = pExpr->pTab;
97588 if( NEVER(pTab==0) ) return pDef;
97589 if( (pTab->tabFlags & TF_Virtual)==0 ) return pDef;
97590 pVtab = sqlite3GetVTable(db, pTab)->pVtab;
97628 ** Make sure virtual table pTab is contained in the pParse->apVirtualLock[]
97629 ** array so that an OP_VBegin will get generated for it. Add pTab to the
97630 ** array if it is missing. If pTab is already in the array, this routine
97633 SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse *pParse, Table *pTab){
97638 assert( IsVirtual(pTab) );
97640 if( pTab==pToplevel->apVtabLock[i] ) return;
97646 pToplevel->apVtabLock[pToplevel->nVtabLock++] = pTab;
99060 ** pOrderBy is an ORDER BY clause from a SELECT statement. pTab is the
99062 ** the table has a cursor number of "base". pIdx is an index on pTab.
99374 aff = pSrc->pTab->aCol[pTerm->u.leftColumn].affinity;
99417 pTable = pSrc->pTab;
99489 pTable = pSrc->pTab;
99621 WHERETRACE(("Recomputing index info for %s...\n", pSrc->pTab->zName));
99719 static int vtabBestIndex(Parse *pParse, Table *pTab, sqlite3_index_info *p){
99720 sqlite3_vtab *pVtab = sqlite3GetVTable(pParse->db, pTab)->pVtab;
99724 WHERETRACE(("xBestIndex for %s\n", pTab->zName));
99744 "table %s: xBestIndex returned an invalid plan", pTab->zName);
99778 Table *pTab = pSrc->pTab;
99816 assert( pTab->azModuleArg && pTab->azModuleArg[0] );
99817 assert( sqlite3GetVTable(pParse->db, pTab) );
99861 if( vtabBestIndex(pParse, pTab, pIdxInfo) ){
100389 sPk.pTable = pSrc->pTab;
100390 aiRowEstPk[0] = pSrc->pTab->nRowEst;
100392 pFirst = pSrc->pTab->pIndex;
100742 pSrc->pTab->zName, (pIdx ? pIdx->zName : "ipk"),
100797 ** Find the query plan for accessing table pSrc->pTab. Write the
100812 if( IsVirtual(pSrc->pTab) ){
101106 ** Argument pLevel describes a strategy for scanning table pTab. This
101124 static char *explainIndexRange(sqlite3 *db, WhereLevel *pLevel, Table *pTab){
101129 Column *aCol = pTab->aCol;
101195 char *zWhere = explainIndexRange(db, pLevel, pItem->pTab);
101794 r = sqlite3ExprCodeGetColumn(pParse, pTabItem->pTab, -1, iCur,
102126 if( ALWAYS(pTabList->a[i].pTab) && IsVirtual(pTabList->a[i].pTab) ){
102249 assert( pTabItem->pTab );
102251 if( IsVirtual(pTabItem->pTab) ){
102383 Table *pTab; /* Table to open */
102387 pTab = pTabItem->pTab;
102390 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
102391 if( (pTab->tabFlags & TF_Ephemeral)!=0 || pTab->pSelect ){
102396 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
102404 sqlite3OpenTable(pParse, pTabItem->iCursor, iDb, pTab, op);
102405 testcase( pTab->nCol==BMS-1 );
102406 testcase( pTab->nCol==BMS );
102407 if( !pWInfo->okOnePass && pTab->nCol<BMS ){
102413 assert( n<=pTab->nCol );
102416 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
102427 assert( pIx->pSchema==pTab->pSchema );
102464 if( z==0 ) z = pTabItem->pTab->zName;
102578 Table *pTab = pTabItem->pTab;
102579 assert( pTab!=0 );
102580 if( (pTab->tabFlags & TF_Ephemeral)==0
102581 && pTab->pSelect==0
109534 Table *pTab = 0;
109553 pTab = sqlite3FindTable(db, zTableName, zDbName);
109554 if( !pTab || pTab->pSelect ){
109555 pTab = 0;
109561 iCol = pTab->iPKey;
109563 pCol = &pTab->aCol[iCol];
109566 for(iCol=0; iCol<pTab->nCol; iCol++){
109567 pCol = &pTab->aCol[iCol];
109572 if( iCol==pTab->nCol ){
109573 pTab = 0;
109593 autoinc = pTab->iPKey==iCol && (pTab->tabFlags & TF_Autoincrement)!=0;
109615 if( SQLITE_OK==rc && !pTab ){
115789 ** Evaluate the full-text expression pExpr against FTS3 table pTab. Store
120182 Fts3Table *pTab, /* FTS3 table handle */
120192 rc = fts3SqlStmt(pTab, eStmt, &pStmt, 0);
120212 Fts3Table *pTab, /* Fts3 table handle */
120215 return fts3SelectDocsize(pTab, SQL_SELECT_DOCTOTAL, 0, ppStmt);
120219 Fts3Table *pTab, /* Fts3 table handle */
120223 return fts3SelectDocsize(pTab, SQL_SELECT_DOCSIZE, iDocid, ppStmt);
123218 Fts3Table *pTab, /* FTS3 table snippet comes from */
123249 pMod = (sqlite3_tokenizer_module *)pTab->pTokenizer->pModule;
123254 rc = pMod->xOpen(pTab->pTokenizer, zDoc, nDoc, &pC);
123258 pC->pTokenizer = pTab->pTokenizer;
123292 Fts3Table *pTab = (Fts3Table *)pCsr->base.pVtab;
123317 pMod = (sqlite3_tokenizer_module *)pTab->pTokenizer->pModule;
123318 rc = pMod->xOpen(pTab->pTokenizer, zDoc, nDoc, &pC);
123322 pC->pTokenizer = pTab->pTokenizer;
123344 rc = fts3SnippetShift(pTab, nSnippet, &zDoc[iBegin], n, &iPos, &hlmask);
123534 Fts3Table *pTab,
123540 || (cArg==FTS3_MATCHINFO_NDOC && pTab->bHasStat)
123541 || (cArg==FTS3_MATCHINFO_AVGLENGTH && pTab->bHasStat)
123542 || (cArg==FTS3_MATCHINFO_LENGTH && pTab->bHasDocsize)
123578 Fts3Table *pTab,
123588 int rc = sqlite3Fts3SelectDoctotal(pTab, ppStmt);
123772 Fts3Table *pTab = (Fts3Table *)pCsr->base.pVtab;
123789 rc = fts3MatchinfoSelectDoctotal(pTab, &pSelect, &nDoc, 0);
123799 rc = fts3MatchinfoSelectDoctotal(pTab, &pSelect, &nDoc, &a);
123815 rc = sqlite3Fts3SelectDocsize(pTab, pCsr->iPrevId, &pSelectDocsize);
123844 rc = fts3MatchinfoSelectDoctotal(pTab, &pSelect, &pInfo->nDoc, 0);
123872 Fts3Table *pTab = (Fts3Table *)pCsr->base.pVtab;
123878 sInfo.nCol = pTab->nColumn;
123944 Fts3Table *pTab = (Fts3Table *)pCsr->base.pVtab;
123989 for(iRead=0; iRead<pTab->nColumn; iRead++){
124024 sqlite3Fts3SegmentsClose(pTab);
124085 Fts3Table *pTab = (Fts3Table *)pCsr->base.pVtab;
124086 sqlite3_tokenizer_module const *pMod = pTab->pTokenizer->pModule;
124118 for(iCol=0; iCol<pTab->nColumn; iCol++){
124151 rc = pMod->xOpen(pTab->pTokenizer, zDoc, nDoc, &pC);
124153 pC->pTokenizer = pTab->pTokenizer;
124204 sqlite3Fts3SegmentsClose(pTab);
124222 Fts3Table *pTab = (Fts3Table *)pCsr->base.pVtab;
124230 if( fts3MatchinfoCheck(pTab, zArg[i], &zErr) ){
124248 sqlite3Fts3SegmentsClose(pTab);