您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ sqlite3VdbeAddOp3函数代码示例

51自学网 2021-06-03 08:14:40
  C++
这篇教程C++ sqlite3VdbeAddOp3函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中sqlite3VdbeAddOp3函数的典型用法代码示例。如果您正苦于以下问题:C++ sqlite3VdbeAddOp3函数的具体用法?C++ sqlite3VdbeAddOp3怎么用?C++ sqlite3VdbeAddOp3使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了sqlite3VdbeAddOp3函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: sqlite3GenerateIndexKey

/*** Generate code that will assemble an index key and put it in register** regOut.  The key with be for index pIdx which is an index on pTab.** iCur is the index of a cursor open on the pTab table and pointing to** the entry that needs indexing.**** Return a register number which is the first in a block of** registers that holds the elements of the index key.  The** block of registers has already been deallocated by the time** this routine returns.*/int sqlite3GenerateIndexKey(  Parse *pParse,     /* Parsing context */  Index *pIdx,       /* The index for which to generate a key */  int iCur,          /* Cursor number for the pIdx->pTable table */  int regOut,        /* Write the new index key to this register */  int doMakeRec      /* Run the OP_MakeRecord instruction if true */){  Vdbe *v = pParse->pVdbe;  int j;  Table *pTab = pIdx->pTable;  int regBase;  int nCol;  nCol = pIdx->nColumn;  regBase = sqlite3GetTempRange(pParse, nCol+1);  sqlite3VdbeAddOp2(v, OP_Rowid, iCur, regBase+nCol);  for(j=0; j<nCol; j++){    int idx = pIdx->aiColumn[j];    if( idx==pTab->iPKey ){      sqlite3VdbeAddOp2(v, OP_SCopy, regBase+nCol, regBase+j);    }else{      sqlite3VdbeAddOp3(v, OP_Column, iCur, idx, regBase+j);      sqlite3ColumnDefault(v, pTab, idx, -1);    }  }  if( doMakeRec ){    sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol+1, regOut);    sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v, pIdx), 0);  }  sqlite3ReleaseTempRange(pParse, regBase, nCol+1);  return regBase;}
开发者ID:Sheridan,项目名称:sqlite,代码行数:43,


示例2: sqlite3UpsertDoUpdate

/*** Generate bytecode that does an UPDATE as part of an upsert.**** If pIdx is NULL, then the UNIQUE constraint that failed was the IPK.** In this case parameter iCur is a cursor open on the table b-tree that** currently points to the conflicting table row. Otherwise, if pIdx** is not NULL, then pIdx is the constraint that failed and iCur is a** cursor points to the conflicting row.*/void sqlite3UpsertDoUpdate(  Parse *pParse,        /* The parsing and code-generating context */  Upsert *pUpsert,      /* The ON CONFLICT clause for the upsert */  Table *pTab,          /* The table being updated */  Index *pIdx,          /* The UNIQUE constraint that failed */  int iCur              /* Cursor for pIdx (or pTab if pIdx==NULL) */){  Vdbe *v = pParse->pVdbe;  sqlite3 *db = pParse->db;  SrcList *pSrc;            /* FROM clause for the UPDATE */  int iDataCur;  assert( v!=0 );  assert( pUpsert!=0 );  VdbeNoopComment((v, "Begin DO UPDATE of UPSERT"));  iDataCur = pUpsert->iDataCur;  if( pIdx && iCur!=iDataCur ){    if( HasRowid(pTab) ){      int regRowid = sqlite3GetTempReg(pParse);      sqlite3VdbeAddOp2(v, OP_IdxRowid, iCur, regRowid);      sqlite3VdbeAddOp3(v, OP_SeekRowid, iDataCur, 0, regRowid);      VdbeCoverage(v);      sqlite3ReleaseTempReg(pParse, regRowid);    }else{      Index *pPk = sqlite3PrimaryKeyIndex(pTab);      int nPk = pPk->nKeyCol;      int iPk = pParse->nMem+1;      int i;      pParse->nMem += nPk;      for(i=0; i<nPk; i++){        int k;        assert( pPk->aiColumn[i]>=0 );        k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[i]);        sqlite3VdbeAddOp3(v, OP_Column, iCur, k, iPk+i);        VdbeComment((v, "%s.%s", pIdx->zName,                    pTab->aCol[pPk->aiColumn[i]].zName));      }      sqlite3VdbeVerifyAbortable(v, OE_Abort);      i = sqlite3VdbeAddOp4Int(v, OP_Found, iDataCur, 0, iPk, nPk);      VdbeCoverage(v);      sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_CORRUPT, OE_Abort, 0,             "corrupt database", P4_STATIC);      sqlite3VdbeJumpHere(v, i);    }  }  /* pUpsert does not own pUpsertSrc - the outer INSERT statement does.  So  ** we have to make a copy before passing it down into sqlite3Update() */  pSrc = sqlite3SrcListDup(db, pUpsert->pUpsertSrc, 0);  sqlite3Update(pParse, pSrc, pUpsert->pUpsertSet,      pUpsert->pUpsertWhere, OE_Abort, 0, 0, pUpsert);  pUpsert->pUpsertSet = 0;    /* Will have been deleted by sqlite3Update() */  pUpsert->pUpsertWhere = 0;  /* Will have been deleted by sqlite3Update() */  VdbeNoopComment((v, "End DO UPDATE of UPSERT"));}
开发者ID:SCALE-GmbH,项目名称:sqlcipher,代码行数:63,


示例3: sqlite3GenerateIndexKey

/*** Generate code that will assemble an index key and stores it in register** regOut.  The key with be for index pIdx which is an index on pTab.** iCur is the index of a cursor open on the pTab table and pointing to** the entry that needs indexing.  If pTab is a WITHOUT ROWID table, then** iCur must be the cursor of the PRIMARY KEY index.**** Return a register number which is the first in a block of** registers that holds the elements of the index key.  The** block of registers has already been deallocated by the time** this routine returns.**** If *piPartIdxLabel is not NULL, fill it in with a label and jump** to that label if pIdx is a partial index that should be skipped.** A partial index should be skipped if its WHERE clause evaluates** to false or null.  If pIdx is not a partial index, *piPartIdxLabel** will be set to zero which is an empty label that is ignored by** sqlite3VdbeResolveLabel().*/int sqlite3GenerateIndexKey(  Parse *pParse,       /* Parsing context */  Index *pIdx,         /* The index for which to generate a key */  int iDataCur,        /* Cursor number from which to take column data */  int regOut,          /* Put the new key into this register if not 0 */  int prefixOnly,      /* Compute only a unique prefix of the key */  int *piPartIdxLabel  /* OUT: Jump to this label to skip partial index */){  Vdbe *v = pParse->pVdbe;  int j;  Table *pTab = pIdx->pTable;  int regBase;  int nCol;  Index *pPk;  if( piPartIdxLabel ){    if( pIdx->pPartIdxWhere ){      *piPartIdxLabel = sqlite3VdbeMakeLabel(v);      pParse->iPartIdxTab = iDataCur;      sqlite3ExprIfFalse(pParse, pIdx->pPartIdxWhere, *piPartIdxLabel,                          SQLITE_JUMPIFNULL);    }else{      *piPartIdxLabel = 0;    }  }  nCol = (prefixOnly && pIdx->uniqNotNull) ? pIdx->nKeyCol : pIdx->nColumn;  regBase = sqlite3GetTempRange(pParse, nCol);  pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);  for(j=0; j<nCol; j++){    i16 idx = pIdx->aiColumn[j];    if( pPk ) idx = sqlite3ColumnOfIndex(pPk, idx);    if( idx<0 || idx==pTab->iPKey ){      sqlite3VdbeAddOp2(v, OP_Rowid, iDataCur, regBase+j);    }else{      sqlite3VdbeAddOp3(v, OP_Column, iDataCur, idx, regBase+j);      sqlite3ColumnDefault(v, pTab, pIdx->aiColumn[j], -1);    }  }  if( regOut ){    const char *zAff;    if( pTab->pSelect     || OptimizationDisabled(pParse->db, SQLITE_IdxRealAsInt)    ){      zAff = 0;    }else{      zAff = sqlite3IndexAffinityStr(v, pIdx);    }    sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regOut);    sqlite3VdbeChangeP4(v, -1, zAff, P4_TRANSIENT);  }  sqlite3ReleaseTempRange(pParse, regBase, nCol);  return regBase;}
开发者ID:xluoly,项目名称:raw-os_sqlite,代码行数:72,


示例4: sqlite3GenerateIndexKey

/*** Generate code that will assemble an index key and put it in register** regOut.  The key with be for index pIdx which is an index on pTab.** iCur is the index of a cursor open on the pTab table and pointing to** the entry that needs indexing.**** Return a register number which is the first in a block of** registers that holds the elements of the index key.  The** block of registers has already been deallocated by the time** this routine returns.**** If *piPartIdxLabel is not NULL, fill it in with a label and jump** to that label if pIdx is a partial index that should be skipped.** A partial index should be skipped if its WHERE clause evaluates** to false or null.  If pIdx is not a partial index, *piPartIdxLabel** will be set to zero which is an empty label that is ignored by** sqlite3VdbeResolveLabel().*/int sqlite3GenerateIndexKey(  Parse *pParse,       /* Parsing context */  Index *pIdx,         /* The index for which to generate a key */  int iCur,            /* Cursor number for the pIdx->pTable table */  int regOut,          /* Write the new index key to this register */  int doMakeRec,       /* Run the OP_MakeRecord instruction if true */  int *piPartIdxLabel  /* OUT: Jump to this label to skip partial index */){  Vdbe *v = pParse->pVdbe;  int j;  Table *pTab = pIdx->pTable;  int regBase;  int nCol;  if( piPartIdxLabel ){    if( pIdx->pPartIdxWhere ){      *piPartIdxLabel = sqlite3VdbeMakeLabel(v);      pParse->iPartIdxTab = iCur;      sqlite3ExprIfFalse(pParse, pIdx->pPartIdxWhere, *piPartIdxLabel,                          SQLITE_JUMPIFNULL);    }else{      *piPartIdxLabel = 0;    }  }  nCol = pIdx->nColumn;  regBase = sqlite3GetTempRange(pParse, nCol+1);  sqlite3VdbeAddOp2(v, OP_Rowid, iCur, regBase+nCol);  for(j=0; j<nCol; j++){    int idx = pIdx->aiColumn[j];    if( idx==pTab->iPKey ){      sqlite3VdbeAddOp2(v, OP_SCopy, regBase+nCol, regBase+j);    }else{      sqlite3VdbeAddOp3(v, OP_Column, iCur, idx, regBase+j);      sqlite3ColumnDefault(v, pTab, idx, -1);    }  }  if( doMakeRec ){    const char *zAff;    if( pTab->pSelect     || OptimizationDisabled(pParse->db, SQLITE_IdxRealAsInt)    ){      zAff = 0;    }else{      zAff = sqlite3IndexAffinityStr(v, pIdx);    }    sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol+1, regOut);    sqlite3VdbeChangeP4(v, -1, zAff, P4_TRANSIENT);  }  sqlite3ReleaseTempRange(pParse, regBase, nCol+1);  return regBase;}
开发者ID:AdrianHuang,项目名称:rt-thread-for-vmm,代码行数:69,


示例5: sqlite3CodeRowTriggerDirect

/* ** Generate code for the trigger program associated with trigger p on ** table pTab. The reg, orconf and ignoreJump parameters passed to this ** function are the same as those described in the header function for ** sqlite3CodeRowTrigger() */SQLITE_PRIVATE void sqlite3CodeRowTriggerDirect(                                                Parse *pParse,       /* Parse context */                                                Trigger *p,          /* Trigger to code */                                                Table *pTab,         /* The table to code triggers from */                                                int reg,             /* Reg array containing OLD.* and NEW.* values */                                                int orconf,          /* ON CONFLICT policy */                                                int ignoreJump       /* Instruction to jump to for RAISE(IGNORE) */){    Vdbe *v = sqlite3GetVdbe(pParse); /* Main VM */    TriggerPrg *pPrg;    pPrg = getRowTrigger(pParse, p, pTab, orconf);    assert( pPrg || pParse->nErr || pParse->db->mallocFailed );        /* Code the OP_Program opcode in the parent VDBE. P4 of the OP_Program     ** is a pointer to the sub-vdbe containing the trigger program.  */    if( pPrg ){        int bRecursive = (p->zName && 0==(pParse->db->flags&SQLITE_RecTriggers));                sqlite3VdbeAddOp3(v, OP_Program, reg, ignoreJump, ++pParse->nMem);        sqlite3VdbeChangeP4(v, -1, (const char *)pPrg->pProgram, P4_SUBPROGRAM);        VdbeComment(                    (v, "Call: %s.%s", (p->zName?p->zName:"fkey"), onErrorText(orconf)));                /* Set the P5 operand of the OP_Program instruction to non-zero if         ** recursive invocation of this trigger program is disallowed. Recursive         ** invocation is disallowed if (a) the sub-program is really a trigger,         ** not a foreign key action, and (b) the flag to enable recursive triggers         ** is clear.  */        sqlite3VdbeChangeP5(v, (u8)bRecursive);    }}
开发者ID:pchernev,项目名称:Objective-C-iOS-Categories,代码行数:37,


示例6: sqlite3GenerateRowIndexDelete

/*** This routine generates VDBE code that causes the deletion of all** index entries associated with a single row of a single table, pTab**** Preconditions:****   1.  A read/write cursor "iDataCur" must be open on the canonical storage**       btree for the table pTab.  (This will be either the table itself**       for rowid tables or to the primary key index for WITHOUT ROWID**       tables.)****   2.  Read/write cursors for all indices of pTab must be open as**       cursor number iIdxCur+i for the i-th index.  (The pTab->pIndex**       index is the 0-th index.)****   3.  The "iDataCur" cursor must be already be positioned on the row**       that is to be deleted.*/void sqlite3GenerateRowIndexDelete(  Parse *pParse,     /* Parsing and code generating context */  Table *pTab,       /* Table containing the row to be deleted */  int iDataCur,      /* Cursor of table holding data. */  int iIdxCur,       /* First index cursor */  int *aRegIdx,      /* Only delete if aRegIdx!=0 && aRegIdx[i]>0 */  int iIdxNoSeek     /* Do not delete from this cursor */){  int i;             /* Index loop counter */  int r1 = -1;       /* Register holding an index key */  int iPartIdxLabel; /* Jump destination for skipping partial index entries */  Index *pIdx;       /* Current index */  Index *pPrior = 0; /* Prior index */  Vdbe *v;           /* The prepared statement under construction */  Index *pPk;        /* PRIMARY KEY index, or NULL for rowid tables */  v = pParse->pVdbe;  pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);  for(i=0, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){    assert( iIdxCur+i!=iDataCur || pPk==pIdx );    if( aRegIdx!=0 && aRegIdx[i]==0 ) continue;    if( pIdx==pPk ) continue;    if( iIdxCur+i==iIdxNoSeek ) continue;    VdbeModuleComment((v, "GenRowIdxDel for %s", pIdx->zName));    r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 1,        &iPartIdxLabel, pPrior, r1);    sqlite3VdbeAddOp3(v, OP_IdxDelete, iIdxCur+i, r1,        pIdx->uniqNotNull ? pIdx->nKeyCol : pIdx->nColumn);    sqlite3ResolvePartIdxLabel(pParse, iPartIdxLabel);    pPrior = pIdx;  }}
开发者ID:chinesemanbobo,项目名称:PPDemo,代码行数:50,


示例7: sqlite3GenerateIndexKey

/*** Generate code that will assemble an index key and stores it in register** regOut.  The key with be for index pIdx which is an index on pTab.** iCur is the index of a cursor open on the pTab table and pointing to** the entry that needs indexing.  If pTab is a WITHOUT ROWID table, then** iCur must be the cursor of the PRIMARY KEY index.**** Return a register number which is the first in a block of** registers that holds the elements of the index key.  The** block of registers has already been deallocated by the time** this routine returns.**** If *piPartIdxLabel is not NULL, fill it in with a label and jump** to that label if pIdx is a partial index that should be skipped.** The label should be resolved using sqlite3ResolvePartIdxLabel().** A partial index should be skipped if its WHERE clause evaluates** to false or null.  If pIdx is not a partial index, *piPartIdxLabel** will be set to zero which is an empty label that is ignored by** sqlite3ResolvePartIdxLabel().**** The pPrior and regPrior parameters are used to implement a cache to** avoid unnecessary register loads.  If pPrior is not NULL, then it is** a pointer to a different index for which an index key has just been** computed into register regPrior.  If the current pIdx index is generating** its key into the same sequence of registers and if pPrior and pIdx share** a column in common, then the register corresponding to that column already** holds the correct value and the loading of that register is skipped.** This optimization is helpful when doing a DELETE or an INTEGRITY_CHECK ** on a table with multiple indices, and especially with the ROWID or** PRIMARY KEY columns of the index.*/int sqlite3GenerateIndexKey(  Parse *pParse,       /* Parsing context */  Index *pIdx,         /* The index for which to generate a key */  int iDataCur,        /* Cursor number from which to take column data */  int regOut,          /* Put the new key into this register if not 0 */  int prefixOnly,      /* Compute only a unique prefix of the key */  int *piPartIdxLabel, /* OUT: Jump to this label to skip partial index */  Index *pPrior,       /* Previously generated index key */  int regPrior         /* Register holding previous generated key */){  Vdbe *v = pParse->pVdbe;  int j;  int regBase;  int nCol;  if( piPartIdxLabel ){    if( pIdx->pPartIdxWhere ){      *piPartIdxLabel = sqlite3VdbeMakeLabel(v);      pParse->iSelfTab = iDataCur + 1;      sqlite3ExprIfFalseDup(pParse, pIdx->pPartIdxWhere, *piPartIdxLabel,                             SQLITE_JUMPIFNULL);      pParse->iSelfTab = 0;    }else{      *piPartIdxLabel = 0;    }  }  nCol = (prefixOnly && pIdx->uniqNotNull) ? pIdx->nKeyCol : pIdx->nColumn;  regBase = sqlite3GetTempRange(pParse, nCol);  if( pPrior && (regBase!=regPrior || pPrior->pPartIdxWhere) ) pPrior = 0;  for(j=0; j<nCol; j++){    if( pPrior     && pPrior->aiColumn[j]==pIdx->aiColumn[j]     && pPrior->aiColumn[j]!=XN_EXPR    ){      /* This column was already computed by the previous index */      continue;    }    sqlite3ExprCodeLoadIndexColumn(pParse, pIdx, iDataCur, j, regBase+j);    /* If the column affinity is REAL but the number is an integer, then it    ** might be stored in the table as an integer (using a compact    ** representation) then converted to REAL by an OP_RealAffinity opcode.    ** But we are getting ready to store this value back into an index, where    ** it should be converted by to INTEGER again.  So omit the OP_RealAffinity    ** opcode if it is present */    sqlite3VdbeDeletePriorOpcode(v, OP_RealAffinity);  }  if( regOut ){    sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regOut);    if( pIdx->pTable->pSelect ){      const char *zAff = sqlite3IndexAffinityStr(pParse->db, pIdx);      sqlite3VdbeChangeP4(v, -1, zAff, P4_TRANSIENT);    }  }  sqlite3ReleaseTempRange(pParse, regBase, nCol);  return regBase;}
开发者ID:cris-auts,项目名称:linux_c_study,代码行数:87,


示例8: sqlite3MinimumFileFormat

/*** Generate code to make sure the file format number is at least minFormat.** The generated code will increase the file format number if necessary.*/void sqlite3MinimumFileFormat(Parse *pParse, int iDb, int minFormat){  Vdbe *v;  v = sqlite3GetVdbe(pParse);  /* The VDBE should have been allocated before this routine is called.  ** If that allocation failed, we would have quit before reaching this  ** point */  if( ALWAYS(v) ){    int r1 = sqlite3GetTempReg(pParse);    int r2 = sqlite3GetTempReg(pParse);    int j1;    sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, r1, BTREE_FILE_FORMAT);    sqlite3VdbeUsesBtree(v, iDb);    sqlite3VdbeAddOp2(v, OP_Integer, minFormat, r2);    j1 = sqlite3VdbeAddOp3(v, OP_Ge, r2, 0, r1);    sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, r2);    sqlite3VdbeJumpHere(v, j1);    sqlite3ReleaseTempReg(pParse, r1);    sqlite3ReleaseTempReg(pParse, r2);  }}
开发者ID:Adoni,项目名称:WiEngine,代码行数:24,


示例9: sqlite3OpenTable

/*** Generate code that will open a table for reading.*/void sqlite3OpenTable(  Parse *p,       /* Generate code into this VDBE */  int iCur,       /* The cursor number of the table */  int iDb,        /* The database index in sqlite3.aDb[] */  Table *pTab,    /* The table to be opened */  int opcode      /* OP_OpenRead or OP_OpenWrite */){  Vdbe *v;  if( IsVirtual(pTab) ) return;  v = sqlite3GetVdbe(p);  assert( opcode==OP_OpenWrite || opcode==OP_OpenRead );  sqlite3TableLock(p, iDb, pTab->tnum, (opcode==OP_OpenWrite)?1:0, pTab->zName);  sqlite3VdbeAddOp2(v, OP_SetNumColumns, 0, pTab->nCol);  sqlite3VdbeAddOp3(v, opcode, iCur, pTab->tnum, iDb);  VdbeComment((v, "%s", pTab->zName));}
开发者ID:kfengbest,项目名称:GenericDB,代码行数:19,


示例10: sqlite3GenerateRowIndexDelete

/*** This routine generates VDBE code that causes the deletion of all** index entries associated with a single row of a single table.**** The VDBE must be in a particular state when this routine is called.** These are the requirements:****   1.  A read/write cursor pointing to pTab, the table containing the row**       to be deleted, must be opened as cursor number "iCur".****   2.  Read/write cursors for all indices of pTab must be open as**       cursor number iCur+i for the i-th index.****   3.  The "iCur" cursor must be pointing to the row that is to be**       deleted.*/void sqlite3GenerateRowIndexDelete(  Parse *pParse,     /* Parsing and code generating context */  Table *pTab,       /* Table containing the row to be deleted */  int iCur,          /* Cursor number for the table */  int *aRegIdx       /* Only delete if aRegIdx!=0 && aRegIdx[i]>0 */){  int i;  Index *pIdx;  int r1;  for(i=1, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){    if( aRegIdx!=0 && aRegIdx[i-1]==0 ) continue;    r1 = sqlite3GenerateIndexKey(pParse, pIdx, iCur, 0, 0);    sqlite3VdbeAddOp3(pParse->pVdbe, OP_IdxDelete, iCur+i, r1,pIdx->nColumn+1);  }}
开发者ID:Mars-Wu,项目名称:djyos,代码行数:32,


示例11: sqlite3GenerateRowDelete

/*** This routine generates VDBE code that causes a single row of a** single table to be deleted.**** The VDBE must be in a particular state when this routine is called.** These are the requirements:****   1.  A read/write cursor pointing to pTab, the table containing the row**       to be deleted, must be opened as cursor number "base".****   2.  Read/write cursors for all indices of pTab must be open as**       cursor number base+i for the i-th index.****   3.  The record number of the row to be deleted must be stored in**       memory cell iRowid.**** This routine pops the top of the stack to remove the record number** and then generates code to remove both the table record and all index** entries that point to that record.*/void sqlite3GenerateRowDelete(  Parse *pParse,     /* Parsing context */  Table *pTab,       /* Table containing the row to be deleted */  int iCur,          /* Cursor number for the table */  int iRowid,        /* Memory cell that contains the rowid to delete */  int count          /* Increment the row change counter */){  int addr;  Vdbe *v;  v = pParse->pVdbe;  addr = sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, iRowid);  sqlite3GenerateRowIndexDelete(pParse, pTab, iCur, 0);  sqlite3VdbeAddOp2(v, OP_Delete, iCur, (count?OPFLAG_NCHANGE:0));  if( count ){    sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_STATIC);  }  sqlite3VdbeJumpHere(v, addr);}
开发者ID:kfengbest,项目名称:GenericDB,代码行数:39,


示例12: updateVirtualTable

/*** Generate code for an UPDATE of a virtual table.**** There are two possible strategies - the default and the special ** "onepass" strategy. Onepass is only used if the virtual table ** implementation indicates that pWhere may match at most one row.**** The default strategy is to create an ephemeral table that contains** for each row to be changed:****   (A)  The original rowid of that row.**   (B)  The revised rowid for the row.**   (C)  The content of every column in the row.**** Then loop through the contents of this ephemeral table executing a** VUpdate for each row. When finished, drop the ephemeral table.**** The "onepass" strategy does not use an ephemeral table. Instead, it** stores the same values (A, B and C above) in a register array and** makes a single invocation of VUpdate.*/static void updateVirtualTable(  Parse *pParse,       /* The parsing context */  SrcList *pSrc,       /* The virtual table to be modified */  Table *pTab,         /* The virtual table */  ExprList *pChanges,  /* The columns to change in the UPDATE statement */  Expr *pRowid,        /* Expression used to recompute the rowid */  int *aXRef,          /* Mapping from columns of pTab to entries in pChanges */  Expr *pWhere,        /* WHERE clause of the UPDATE statement */  int onError          /* ON CONFLICT strategy */){  Vdbe *v = pParse->pVdbe;  /* Virtual machine under construction */  int ephemTab;             /* Table holding the result of the SELECT */  int i;                    /* Loop counter */  sqlite3 *db = pParse->db; /* Database connection */  const char *pVTab = (const char*)sqlite3GetVTable(db, pTab);  WhereInfo *pWInfo;  int nArg = 2 + pTab->nCol;      /* Number of arguments to VUpdate */  int regArg;                     /* First register in VUpdate arg array */  int regRec;                     /* Register in which to assemble record */  int regRowid;                   /* Register for ephem table rowid */  int iCsr = pSrc->a[0].iCursor;  /* Cursor used for virtual table scan */  int aDummy[2];                  /* Unused arg for sqlite3WhereOkOnePass() */  int bOnePass;                   /* True to use onepass strategy */  int addr;                       /* Address of OP_OpenEphemeral */  /* Allocate nArg registers to martial the arguments to VUpdate. Then  ** create and open the ephemeral table in which the records created from  ** these arguments will be temporarily stored. */  assert( v );  ephemTab = pParse->nTab++;  addr= sqlite3VdbeAddOp2(v, OP_OpenEphemeral, ephemTab, nArg);  regArg = pParse->nMem + 1;  pParse->nMem += nArg;  regRec = ++pParse->nMem;  regRowid = ++pParse->nMem;  /* Start scanning the virtual table */  pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0,0,WHERE_ONEPASS_DESIRED,0);  if( pWInfo==0 ) return;  /* Populate the argument registers. */  sqlite3VdbeAddOp2(v, OP_Rowid, iCsr, regArg);  if( pRowid ){    sqlite3ExprCode(pParse, pRowid, regArg+1);  }else{    sqlite3VdbeAddOp2(v, OP_Rowid, iCsr, regArg+1);  }  for(i=0; i<pTab->nCol; i++){    if( aXRef[i]>=0 ){      sqlite3ExprCode(pParse, pChanges->a[aXRef[i]].pExpr, regArg+2+i);    }else{      sqlite3VdbeAddOp3(v, OP_VColumn, iCsr, i, regArg+2+i);    }  }  bOnePass = sqlite3WhereOkOnePass(pWInfo, aDummy);  if( bOnePass ){    /* If using the onepass strategy, no-op out the OP_OpenEphemeral coded    ** above. Also, if this is a top-level parse (not a trigger), clear the    ** multi-write flag so that the VM does not open a statement journal */    sqlite3VdbeChangeToNoop(v, addr);    if( sqlite3IsToplevel(pParse) ){      pParse->isMultiWrite = 0;    }  }else{    /* Create a record from the argument register contents and insert it into    ** the ephemeral table. */    sqlite3VdbeAddOp3(v, OP_MakeRecord, regArg, nArg, regRec);    sqlite3VdbeAddOp2(v, OP_NewRowid, ephemTab, regRowid);    sqlite3VdbeAddOp3(v, OP_Insert, ephemTab, regRec, regRowid);  }  if( bOnePass==0 ){    /* End the virtual table scan */    sqlite3WhereEnd(pWInfo);    /* Begin scannning through the ephemeral table. *///.........这里部分代码省略.........
开发者ID:hoangdoanh,项目名称:sqlite,代码行数:101,


示例13: sqlite3GenerateRowDelete

/*** This routine generates VDBE code that causes a single row of a** single table to be deleted.**** The VDBE must be in a particular state when this routine is called.** These are the requirements:****   1.  A read/write cursor pointing to pTab, the table containing the row**       to be deleted, must be opened as cursor number $iCur.****   2.  Read/write cursors for all indices of pTab must be open as**       cursor number base+i for the i-th index.****   3.  The record number of the row to be deleted must be stored in**       memory cell iRowid.**** This routine generates code to remove both the table record and all ** index entries that point to that record.*/void sqlite3GenerateRowDelete(  Parse *pParse,     /* Parsing context */  Table *pTab,       /* Table containing the row to be deleted */  int iCur,          /* Cursor number for the table */  int iRowid,        /* Memory cell that contains the rowid to delete */  int count,         /* If non-zero, increment the row change counter */  Trigger *pTrigger, /* List of triggers to (potentially) fire */  int onconf         /* Default ON CONFLICT policy for triggers */){  Vdbe *v = pParse->pVdbe;        /* Vdbe */  int iOld = 0;                   /* First register in OLD.* array */  int iLabel;                     /* Label resolved to end of generated code */  /* Vdbe is guaranteed to have been allocated by this stage. */  assert( v );  /* Seek cursor iCur to the row to delete. If this row no longer exists   ** (this can happen if a trigger program has already deleted it), do  ** not attempt to delete it or fire any DELETE triggers.  */  iLabel = sqlite3VdbeMakeLabel(v);  sqlite3VdbeAddOp3(v, OP_NotExists, iCur, iLabel, iRowid);   /* If there are any triggers to fire, allocate a range of registers to  ** use for the old.* references in the triggers.  */  if( sqlite3FkRequired(pParse, pTab, 0, 0) || pTrigger ){    u32 mask;                     /* Mask of OLD.* columns in use */    int iCol;                     /* Iterator used while populating OLD.* */    /* TODO: Could use temporary registers here. Also could attempt to    ** avoid copying the contents of the rowid register.  */    mask = sqlite3TriggerColmask(        pParse, pTrigger, 0, 0, TRIGGER_BEFORE|TRIGGER_AFTER, pTab, onconf    );    mask |= sqlite3FkOldmask(pParse, pTab);    iOld = pParse->nMem+1;    pParse->nMem += (1 + pTab->nCol);    /* Populate the OLD.* pseudo-table register array. These values will be     ** used by any BEFORE and AFTER triggers that exist.  */    sqlite3VdbeAddOp2(v, OP_Copy, iRowid, iOld);    for(iCol=0; iCol<pTab->nCol; iCol++){      if( mask==0xffffffff || mask&(1<<iCol) ){        sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, iCol, iOld+iCol+1);      }    }    /* Invoke BEFORE DELETE trigger programs. */    sqlite3CodeRowTrigger(pParse, pTrigger,         TK_DELETE, 0, TRIGGER_BEFORE, pTab, iOld, onconf, iLabel    );    /* Seek the cursor to the row to be deleted again. It may be that    ** the BEFORE triggers coded above have already removed the row    ** being deleted. Do not attempt to delete the row a second time, and     ** do not fire AFTER triggers.  */    sqlite3VdbeAddOp3(v, OP_NotExists, iCur, iLabel, iRowid);    /* Do FK processing. This call checks that any FK constraints that    ** refer to this table (i.e. constraints attached to other tables)     ** are not violated by deleting this row.  */    sqlite3FkCheck(pParse, pTab, iOld, 0);  }  /* Delete the index and table entries. Skip this step if pTab is really  ** a view (in which case the only effect of the DELETE statement is to  ** fire the INSTEAD OF triggers).  */   if( pTab->pSelect==0 ){    sqlite3GenerateRowIndexDelete(pParse, pTab, iCur, 0);    sqlite3VdbeAddOp2(v, OP_Delete, iCur, (count?OPFLAG_NCHANGE:0));    if( count ){      sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_TRANSIENT);    }  }  /* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to  ** handle rows (possibly in other tables) that refer via a foreign key  ** to the row just deleted. */   sqlite3FkActions(pParse, pTab, 0, iOld);  /* Invoke AFTER DELETE trigger programs. */  sqlite3CodeRowTrigger(pParse, pTrigger, //.........这里部分代码省略.........
开发者ID:Mars-Wu,项目名称:djyos,代码行数:101,


示例14: sqlite3DeleteFrom

//.........这里部分代码省略.........   && 0==sqlite3FkRequired(pParse, pTab, 0, 0)  ){    assert( !isView );    sqlite3VdbeAddOp4(v, OP_Clear, pTab->tnum, iDb, memCnt,                      pTab->zName, P4_STATIC);    for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){      assert( pIdx->pSchema==pTab->pSchema );      sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb);    }  }else#endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */  /* The usual case: There is a WHERE clause so we have to scan through  ** the table and pick which records to delete.  */  {    int iRowSet = ++pParse->nMem;   /* Register for rowset of rows to delete */    int iRowid = ++pParse->nMem;    /* Used for storing rowid values. */    int regRowid;                   /* Actual register containing rowids */    /* Collect rowids of every row to be deleted.    */    sqlite3VdbeAddOp2(v, OP_Null, 0, iRowSet);    pWInfo = sqlite3WhereBegin(        pParse, pTabList, pWhere, 0, 0, WHERE_DUPLICATES_OK, 0    );    if( pWInfo==0 ) goto delete_from_cleanup;    regRowid = sqlite3ExprCodeGetColumn(pParse, pTab, -1, iCur, iRowid, 0);    sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, regRowid);    if( db->flags & SQLITE_CountRows ){      sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);    }    sqlite3WhereEnd(pWInfo);    /* Delete every item whose key was written to the list during the    ** database scan.  We have to delete items after the scan is complete    ** because deleting an item can change the scan order.  */    end = sqlite3VdbeMakeLabel(v);    /* Unless this is a view, open cursors for the table we are     ** deleting from and all its indices. If this is a view, then the    ** only effect this statement has is to fire the INSTEAD OF     ** triggers.  */    if( !isView ){      sqlite3OpenTableAndIndices(pParse, pTab, iCur, OP_OpenWrite);    }    addr = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, end, iRowid);    /* Delete the row */#ifndef SQLITE_OMIT_VIRTUALTABLE    if( IsVirtual(pTab) ){      const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);      sqlite3VtabMakeWritable(pParse, pTab);      sqlite3VdbeAddOp4(v, OP_VUpdate, 0, 1, iRowid, pVTab, P4_VTAB);      sqlite3VdbeChangeP5(v, OE_Abort);      sqlite3MayAbort(pParse);    }else#endif    {      int count = (pParse->nested==0);    /* True to count changes */      sqlite3GenerateRowDelete(pParse, pTab, iCur, iRowid, count, pTrigger, OE_Default);    }    /* End of the delete loop */    sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);    sqlite3VdbeResolveLabel(v, end);    /* Close the cursors open on the table and its indexes. */    if( !isView && !IsVirtual(pTab) ){      for(i=1, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){        sqlite3VdbeAddOp2(v, OP_Close, iCur + i, pIdx->tnum);      }      sqlite3VdbeAddOp1(v, OP_Close, iCur);    }  }  /* Update the sqlite_sequence table by storing the content of the  ** maximum rowid counter values recorded while inserting into  ** autoincrement tables.  */  if( pParse->nested==0 && pParse->pTriggerTab==0 ){    sqlite3AutoincrementEnd(pParse);  }  /* Return the number of rows that were deleted. If this routine is   ** generating code because of a call to sqlite3NestedParse(), do not  ** invoke the callback function.  */  if( (db->flags&SQLITE_CountRows) && !pParse->nested && !pParse->pTriggerTab ){    sqlite3VdbeAddOp2(v, OP_ResultRow, memCnt, 1);    sqlite3VdbeSetNumCols(v, 1);    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows deleted", SQLITE_STATIC);  }delete_from_cleanup:  sqlite3AuthContextPop(&sContext);  sqlite3SrcListDelete(db, pTabList);  sqlite3ExprDelete(db, pWhere);  return;}
开发者ID:Mars-Wu,项目名称:djyos,代码行数:101,


示例15: analyzeOneTable

/*** Generate code to do an analysis of all indices associated with** a single table.*/static void analyzeOneTable(  Parse *pParse,   /* Parser context */  Table *pTab,     /* Table whose indices are to be analyzed */  Index *pOnlyIdx, /* If not NULL, only analyze this one index */  int iStatCur,    /* Index of VdbeCursor that writes the sqlite_stat1 table */  int iMem         /* Available memory locations begin here */){  sqlite3 *db = pParse->db;    /* Database handle */  Index *pIdx;                 /* An index to being analyzed */  int iIdxCur;                 /* Cursor open on index being analyzed */  Vdbe *v;                     /* The virtual machine being built up */  int i;                       /* Loop counter */  int topOfLoop;               /* The top of the loop */  int endOfLoop;               /* The end of the loop */  int jZeroRows = -1;          /* Jump from here if number of rows is zero */  int iDb;                     /* Index of database containing pTab */  int regTabname = iMem++;     /* Register containing table name */  int regIdxname = iMem++;     /* Register containing index name */  int regSampleno = iMem++;    /* Register containing next sample number */  int regCol = iMem++;         /* Content of a column analyzed table */  int regRec = iMem++;         /* Register holding completed record */  int regTemp = iMem++;        /* Temporary use register */  int regRowid = iMem++;       /* Rowid for the inserted record */#ifdef SQLITE_ENABLE_STAT2  int addr = 0;                /* Instruction address */  int regTemp2 = iMem++;       /* Temporary use register */  int regSamplerecno = iMem++; /* Index of next sample to record */  int regRecno = iMem++;       /* Current sample index */  int regLast = iMem++;        /* Index of last sample to record */  int regFirst = iMem++;       /* Index of first sample to record */#endif  v = sqlite3GetVdbe(pParse);  if( v==0 || NEVER(pTab==0) ){    return;  }  if( pTab->tnum==0 ){    /* Do not gather statistics on views or virtual tables */    return;  }  if( memcmp(pTab->zName, "sqlite_", 7)==0 ){    /* Do not gather statistics on system tables */    return;  }  assert( sqlite3BtreeHoldsAllMutexes(db) );  iDb = sqlite3SchemaToIndex(db, pTab->pSchema);  assert( iDb>=0 );  assert( sqlite3SchemaMutexHeld(db, iDb, 0) );#ifndef SQLITE_OMIT_AUTHORIZATION  if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0,      db->aDb[iDb].zName ) ){    return;  }#endif  /* Establish a read-lock on the table at the shared-cache level. */  sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);  iIdxCur = pParse->nTab++;  sqlite3VdbeAddOp4(v, OP_String8, 0, regTabname, 0, pTab->zName, 0);  for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){    int nCol;    KeyInfo *pKey;    if( pOnlyIdx && pOnlyIdx!=pIdx ) continue;    nCol = pIdx->nColumn;    pKey = sqlite3IndexKeyinfo(pParse, pIdx);    if( iMem+1+(nCol*2)>pParse->nMem ){      pParse->nMem = iMem+1+(nCol*2);    }    /* Open a cursor to the index to be analyzed. */    assert( iDb==sqlite3SchemaToIndex(db, pIdx->pSchema) );    sqlite3VdbeAddOp4(v, OP_OpenRead, iIdxCur, pIdx->tnum, iDb,        (char *)pKey, P4_KEYINFO_HANDOFF);    VdbeComment((v, "%s", pIdx->zName));    /* Populate the register containing the index name. */    sqlite3VdbeAddOp4(v, OP_String8, 0, regIdxname, 0, pIdx->zName, 0);#ifdef SQLITE_ENABLE_STAT2    /* If this iteration of the loop is generating code to analyze the    ** first index in the pTab->pIndex list, then register regLast has    ** not been populated. In this case populate it now.  */    if( pTab->pIndex==pIdx ){      sqlite3VdbeAddOp2(v, OP_Integer, SQLITE_INDEX_SAMPLES, regSamplerecno);      sqlite3VdbeAddOp2(v, OP_Integer, SQLITE_INDEX_SAMPLES*2-1, regTemp);      sqlite3VdbeAddOp2(v, OP_Integer, SQLITE_INDEX_SAMPLES*2, regTemp2);      sqlite3VdbeAddOp2(v, OP_Count, iIdxCur, regLast);      sqlite3VdbeAddOp2(v, OP_Null, 0, regFirst);      addr = sqlite3VdbeAddOp3(v, OP_Lt, regSamplerecno, 0, regLast);      sqlite3VdbeAddOp3(v, OP_Divide, regTemp2, regLast, regFirst);      sqlite3VdbeAddOp3(v, OP_Multiply, regLast, regTemp, regLast);//.........这里部分代码省略.........
开发者ID:sunyangkobe,项目名称:db_research,代码行数:101,


示例16: openStatTable

/*** This routine generates code that opens the sqlite_stat1 table for** writing with cursor iStatCur. If the library was built with the** SQLITE_ENABLE_STAT2 macro defined, then the sqlite_stat2 table is** opened for writing using cursor (iStatCur+1)**** If the sqlite_stat1 tables does not previously exist, it is created.** Similarly, if the sqlite_stat2 table does not exist and the library** is compiled with SQLITE_ENABLE_STAT2 defined, it is created. **** Argument zWhere may be a pointer to a buffer containing a table name,** or it may be a NULL pointer. If it is not NULL, then all entries in** the sqlite_stat1 and (if applicable) sqlite_stat2 tables associated** with the named table are deleted. If zWhere==0, then code is generated** to delete all stat table entries.*/static void openStatTable(  Parse *pParse,          /* Parsing context */  int iDb,                /* The database we are looking in */  int iStatCur,           /* Open the sqlite_stat1 table on this cursor */  const char *zWhere,     /* Delete entries for this table or index */  const char *zWhereType  /* Either "tbl" or "idx" */){  static const struct {    const char *zName;    const char *zCols;  } aTable[] = {    { "sqlite_stat1", "tbl,idx,stat" },#ifdef SQLITE_ENABLE_STAT2    { "sqlite_stat2", "tbl,idx,sampleno,sample" },#endif  };  int aRoot[] = {0, 0};  u8 aCreateTbl[] = {0, 0};  int i;  sqlite3 *db = pParse->db;  Db *pDb;  Vdbe *v = sqlite3GetVdbe(pParse);  if( v==0 ) return;  assert( sqlite3BtreeHoldsAllMutexes(db) );  assert( sqlite3VdbeDb(v)==db );  pDb = &db->aDb[iDb];  for(i=0; i<ArraySize(aTable); i++){    const char *zTab = aTable[i].zName;    Table *pStat;    if( (pStat = sqlite3FindTable(db, zTab, pDb->zName))==0 ){      /* The sqlite_stat[12] table does not exist. Create it. Note that a       ** side-effect of the CREATE TABLE statement is to leave the rootpage       ** of the new table in register pParse->regRoot. This is important       ** because the OpenWrite opcode below will be needing it. */      sqlite3NestedParse(pParse,          "CREATE TABLE %Q.%s(%s)", pDb->zName, zTab, aTable[i].zCols      );      aRoot[i] = pParse->regRoot;      aCreateTbl[i] = 1;    }else{      /* The table already exists. If zWhere is not NULL, delete all entries       ** associated with the table zWhere. If zWhere is NULL, delete the      ** entire contents of the table. */      aRoot[i] = pStat->tnum;      sqlite3TableLock(pParse, iDb, aRoot[i], 1, zTab);      if( zWhere ){        sqlite3NestedParse(pParse,           "DELETE FROM %Q.%s WHERE %s=%Q", pDb->zName, zTab, zWhereType, zWhere        );      }else{        /* The sqlite_stat[12] table already exists.  Delete all rows. */        sqlite3VdbeAddOp2(v, OP_Clear, aRoot[i], iDb);      }    }  }  /* Open the sqlite_stat[12] tables for writing. */  for(i=0; i<ArraySize(aTable); i++){    sqlite3VdbeAddOp3(v, OP_OpenWrite, iStatCur+i, aRoot[i], iDb);    sqlite3VdbeChangeP4(v, -1, (char *)3, P4_INT32);    sqlite3VdbeChangeP5(v, aCreateTbl[i]);  }}
开发者ID:sunyangkobe,项目名称:db_research,代码行数:82,


示例17: sqlite3Update

//.........这里部分代码省略.........    ** Open every index that needs updating.  Note that if any    ** index could potentially invoke a REPLACE conflict resolution     ** action, then we need to open all indices because we might need    ** to be deleting some records.    */    if( !okOnePass ) sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenWrite);     if( onError==OE_Replace ){      openAll = 1;    }else{      openAll = 0;      for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){        if( pIdx->onError==OE_Replace ){          openAll = 1;          break;        }      }    }    for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){      if( openAll || aRegIdx[i]>0 ){        KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx);        sqlite3VdbeAddOp4(v, OP_OpenWrite, iCur+i+1, pIdx->tnum, iDb,                       (char*)pKey, P4_KEYINFO_HANDOFF);        assert( pParse->nTab>iCur+i+1 );      }    }  }  /* Top of the update loop */  if( okOnePass ){    int a1 = sqlite3VdbeAddOp1(v, OP_NotNull, regOldRowid);    addr = sqlite3VdbeAddOp0(v, OP_Goto);    sqlite3VdbeJumpHere(v, a1);  }else{    addr = sqlite3VdbeAddOp3(v, OP_RowSetRead, regRowSet, 0, regOldRowid);  }  /* Make cursor iCur point to the record that is being updated. If  ** this record does not exist for some reason (deleted by a trigger,  ** for example, then jump to the next iteration of the RowSet loop.  */  sqlite3VdbeAddOp3(v, OP_NotExists, iCur, addr, regOldRowid);  /* If the record number will change, set register regNewRowid to  ** contain the new value. If the record number is not being modified,  ** then regNewRowid is the same register as regOldRowid, which is  ** already populated.  */  assert( chngRowid || pTrigger || hasFK || regOldRowid==regNewRowid );  if( chngRowid ){    sqlite3ExprCode(pParse, pRowidExpr, regNewRowid);    sqlite3VdbeAddOp1(v, OP_MustBeInt, regNewRowid);  }  /* If there are triggers on this table, populate an array of registers   ** with the required old.* column data.  */  if( hasFK || pTrigger ){    u32 oldmask = (hasFK ? sqlite3FkOldmask(pParse, pTab) : 0);    oldmask |= sqlite3TriggerColmask(pParse,         pTrigger, pChanges, 0, TRIGGER_BEFORE|TRIGGER_AFTER, pTab, onError    );    for(i=0; i<pTab->nCol; i++){      if( aXRef[i]<0 || oldmask==0xffffffff || (oldmask & (1<<i)) ){        sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, i, regOld+i);      }else{        sqlite3VdbeAddOp2(v, OP_Null, 0, regOld+i);      }    }    if( chngRowid==0 ){
开发者ID:Sheridan,项目名称:sqlite,代码行数:67,


示例18: sqlite3Update

//.........这里部分代码省略.........    if( !okOnePass ) sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenWrite);     if( onError==OE_Replace ){      openAll = 1;    }else{      openAll = 0;      for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){        if( pIdx->onError==OE_Replace ){          openAll = 1;          break;        }      }    }    for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){      if( openAll || aRegIdx[i]>0 ){        KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx);        sqlite3VdbeAddOp4(v, OP_OpenWrite, iCur+i+1, pIdx->tnum, iDb,                       (char*)pKey, P4_KEYINFO_HANDOFF);        assert( pParse->nTab>iCur+i+1 );      }    }  }    /* Jump back to this point if a trigger encounters an IGNORE constraint. */  if( triggers_exist ){    sqlite3VdbeResolveLabel(v, addr);  }  /* Top of the update loop */  if( okOnePass ){    int a1 = sqlite3VdbeAddOp1(v, OP_NotNull, regOldRowid);    addr = sqlite3VdbeAddOp0(v, OP_Goto);    sqlite3VdbeJumpHere(v, a1);  }else{    addr = sqlite3VdbeAddOp3(v, OP_RowSetRead, regRowSet, 0, regOldRowid);  }  if( triggers_exist ){    int regRowid;    int regRow;    int regCols;    /* Make cursor iCur point to the record that is being updated.    */    sqlite3VdbeAddOp3(v, OP_NotExists, iCur, addr, regOldRowid);    /* Generate the OLD table    */    regRowid = sqlite3GetTempReg(pParse);    regRow = sqlite3GetTempReg(pParse);    sqlite3VdbeAddOp2(v, OP_Rowid, iCur, regRowid);    if( !old_col_mask ){      sqlite3VdbeAddOp2(v, OP_Null, 0, regRow);    }else{      sqlite3VdbeAddOp2(v, OP_RowData, iCur, regRow);    }    sqlite3VdbeAddOp3(v, OP_Insert, oldIdx, regRow, regRowid);    /* Generate the NEW table    */    if( chngRowid ){      sqlite3ExprCodeAndCache(pParse, pRowidExpr, regRowid);      sqlite3VdbeAddOp1(v, OP_MustBeInt, regRowid);    }else{      sqlite3VdbeAddOp2(v, OP_Rowid, iCur, regRowid);    }    regCols = sqlite3GetTempRange(pParse, pTab->nCol);
开发者ID:DoganA,项目名称:nightingale-deps,代码行数:67,


示例19: codeAttach

static void codeAttach(  Parse *pParse,         int type,              FuncDef const *pFunc,  Expr *pAuthArg,        Expr *pFilename,       Expr *pDbname,         Expr *pKey           ){  int rc;  NameContext sName;  Vdbe *v;  sqlite3* db = pParse->db;  int regArgs;  memset(&sName, 0, sizeof(NameContext));  sName.pParse = pParse;  if(       SQLITE_OK!=(rc = resolveAttachExpr(&sName, pFilename)) ||      SQLITE_OK!=(rc = resolveAttachExpr(&sName, pDbname)) ||      SQLITE_OK!=(rc = resolveAttachExpr(&sName, pKey))  ){    pParse->nErr++;    goto attach_end;  }#ifndef SQLITE_OMIT_AUTHORIZATION  if( pAuthArg ){    char *zAuthArg;    if( pAuthArg->op==TK_STRING ){      zAuthArg = pAuthArg->u.zToken;    }else{      zAuthArg = 0;    }    rc = sqlite3AuthCheck(pParse, type, zAuthArg, 0, 0);    if(rc!=SQLITE_OK ){      goto attach_end;    }  }#endif   v = sqlite3GetVdbe(pParse);  regArgs = sqlite3GetTempRange(pParse, 4);  sqlite3ExprCode(pParse, pFilename, regArgs);  sqlite3ExprCode(pParse, pDbname, regArgs+1);  sqlite3ExprCode(pParse, pKey, regArgs+2);  assert( v || db->mallocFailed );  if( v ){    sqlite3VdbeAddOp3(v, OP_Function, 0, regArgs+3-pFunc->nArg, regArgs+3);    assert( pFunc->nArg==-1 || (pFunc->nArg&0xff)==pFunc->nArg );    sqlite3VdbeChangeP5(v, (u8)(pFunc->nArg));    sqlite3VdbeChangeP4(v, -1, (char *)pFunc, P4_FUNCDEF);    sqlite3VdbeAddOp1(v, OP_Expire, (type==SQLITE_ATTACH));  }  attach_end:  sqlite3ExprDelete(db, pFilename);  sqlite3ExprDelete(db, pDbname);  sqlite3ExprDelete(db, pKey);}
开发者ID:qtekfun,项目名称:htcDesire820Kernel,代码行数:64,


示例20: sqlite3DeleteFrom

//.........这里部分代码省略.........    /* Unless this is a view, open cursors for the table we are     ** deleting from and all its indices. If this is a view, then the    ** only effect this statement has is to fire the INSTEAD OF     ** triggers.    */    if( !isView ){      int iAddrOnce = 0;      if( eOnePass==ONEPASS_MULTI ){        iAddrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);      }      testcase( IsVirtual(pTab) );      sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, OPFLAG_FORDELETE,                                 iTabCur, aToOpen, &iDataCur, &iIdxCur);      assert( pPk || IsVirtual(pTab) || iDataCur==iTabCur );      assert( pPk || IsVirtual(pTab) || iIdxCur==iDataCur+1 );      if( eOnePass==ONEPASS_MULTI ) sqlite3VdbeJumpHere(v, iAddrOnce);    }      /* Set up a loop over the rowids/primary-keys that were found in the    ** where-clause loop above.    */    if( eOnePass!=ONEPASS_OFF ){      assert( nKey==nPk );  /* OP_Found will use an unpacked key */      if( !IsVirtual(pTab) && aToOpen[iDataCur-iTabCur] ){        assert( pPk!=0 || pTab->pSelect!=0 );        sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey);        VdbeCoverage(v);      }    }else if( pPk ){      addrLoop = sqlite3VdbeAddOp1(v, OP_Rewind, iEphCur); VdbeCoverage(v);      sqlite3VdbeAddOp2(v, OP_RowKey, iEphCur, iKey);      assert( nKey==0 );  /* OP_Found will use a composite key */    }else{      addrLoop = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, 0, iKey);      VdbeCoverage(v);      assert( nKey==1 );    }        /* Delete the row */#ifndef SQLITE_OMIT_VIRTUALTABLE    if( IsVirtual(pTab) ){      const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);      sqlite3VtabMakeWritable(pParse, pTab);      sqlite3VdbeAddOp4(v, OP_VUpdate, 0, 1, iKey, pVTab, P4_VTAB);      sqlite3VdbeChangeP5(v, OE_Abort);      assert( eOnePass==ONEPASS_OFF || eOnePass==ONEPASS_SINGLE );      sqlite3MayAbort(pParse);      if( eOnePass==ONEPASS_SINGLE && sqlite3IsToplevel(pParse) ){        pParse->isMultiWrite = 0;      }    }else#endif    {      int count = (pParse->nested==0);    /* True to count changes */      int iIdxNoSeek = -1;      if( bComplex==0 && aiCurOnePass[1]!=iDataCur ){        iIdxNoSeek = aiCurOnePass[1];      }      sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,          iKey, nKey, count, OE_Default, eOnePass, iIdxNoSeek);    }      /* End of the loop over all rowids/primary-keys. */    if( eOnePass!=ONEPASS_OFF ){      sqlite3VdbeResolveLabel(v, addrBypass);      sqlite3WhereEnd(pWInfo);
开发者ID:chinesemanbobo,项目名称:PPDemo,代码行数:67,


示例21: sqlite3AlterFinishAddColumn

//.........这里部分代码省略.........  assert( sqlite3BtreeHoldsAllMutexes(db) );  iDb = sqlite3SchemaToIndex(db, pNew->pSchema);  zDb = db->aDb[iDb].zName;  zTab = &pNew->zName[16];  /* Skip the "sqlite_altertab_" prefix on the name */  pCol = &pNew->aCol[pNew->nCol-1];  pDflt = pCol->pDflt;  pTab = sqlite3FindTable(db, zTab, zDb);  assert( pTab );#ifndef SQLITE_OMIT_AUTHORIZATION  /* Invoke the authorization callback. */  if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, 0) ){    return;  }#endif  /* If the default value for the new column was specified with a  ** literal NULL, then set pDflt to 0. This simplifies checking  ** for an SQL NULL default below.  */  if( pDflt && pDflt->op==TK_NULL ){    pDflt = 0;  }  /* Check that the new column is not specified as PRIMARY KEY or UNIQUE.  ** If there is a NOT NULL constraint, then the default value for the  ** column must not be NULL.  */  if( pCol->colFlags & COLFLAG_PRIMKEY ){    sqlite3ErrorMsg(pParse, "Cannot add a PRIMARY KEY column");    return;  }  if( pNew->pIndex ){    sqlite3ErrorMsg(pParse, "Cannot add a UNIQUE column");    return;  }  if( (db->flags&SQLITE_ForeignKeys) && pNew->pFKey && pDflt ){    sqlite3ErrorMsg(pParse,        "Cannot add a REFERENCES column with non-NULL default value");    return;  }  if( pCol->notNull && !pDflt ){    sqlite3ErrorMsg(pParse,        "Cannot add a NOT NULL column with default value NULL");    return;  }  /* Ensure the default expression is something that sqlite3ValueFromExpr()  ** can handle (i.e. not CURRENT_TIME etc.)  */  if( pDflt ){    sqlite3_value *pVal = 0;    int rc;    rc = sqlite3ValueFromExpr(db, pDflt, SQLITE_UTF8, SQLITE_AFF_BLOB, &pVal);    assert( rc==SQLITE_OK || rc==SQLITE_NOMEM );    if( rc!=SQLITE_OK ){      assert( db->mallocFailed == 1 );      return;    }    if( !pVal ){      sqlite3ErrorMsg(pParse, "Cannot add a column with non-constant default");      return;    }    sqlite3ValueFree(pVal);  }  /* Modify the CREATE TABLE statement. */  zCol = sqlite3DbStrNDup(db, (char*)pColDef->z, pColDef->n);  if( zCol ){    char *zEnd = &zCol[pColDef->n-1];    int savedDbFlags = db->flags;    while( zEnd>zCol && (*zEnd==';' || sqlite3Isspace(*zEnd)) ){      *zEnd-- = '/0';    }    db->flags |= SQLITE_PreferBuiltin;    sqlite3NestedParse(pParse,        "UPDATE /"%w/".%s SET "          "sql = substr(sql,1,%d) || ', ' || %Q || substr(sql,%d) "        "WHERE type = 'table' AND name = %Q",      zDb, SCHEMA_TABLE(iDb), pNew->addColOffset, zCol, pNew->addColOffset+1,      zTab    );    sqlite3DbFree(db, zCol);    db->flags = savedDbFlags;  }  /* If the default value of the new column is NULL, then the file  ** format to 2. If the default value of the new column is not NULL,  ** the file format be 3.  Back when this feature was first added  ** in 2006, we went to the trouble to upgrade the file format to the  ** minimum support values.  But 10-years on, we can assume that all  ** extent versions of SQLite support file-format 4, so we always and  ** unconditionally upgrade to 4.  */  sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT,                    SQLITE_MAX_FILE_FORMAT);  /* Reload the schema of the modified table. */  reloadTableSchema(pParse, pTab, pTab->zName);}
开发者ID:arizwanp,项目名称:intel_sgx,代码行数:101,


示例22: sqlite3DeleteFrom

//.........这里部分代码省略.........  /* If we are trying to delete from a view, realize that view into  ** a ephemeral table.  */#if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)  if( isView ){    sqlite3MaterializeView(pParse, pTab, pWhere, iCur);  }#endif  /* Resolve the column names in the WHERE clause.  */  memset(&sNC, 0, sizeof(sNC));  sNC.pParse = pParse;  sNC.pSrcList = pTabList;  if( sqlite3ResolveExprNames(&sNC, pWhere) ){    goto delete_from_cleanup;  }  /* Initialize the counter of the number of rows deleted, if  ** we are counting rows.  */  if( db->flags & SQLITE_CountRows ){    memCnt = ++pParse->nMem;    sqlite3VdbeAddOp2(v, OP_Integer, 0, memCnt);  }#ifndef SQLITE_OMIT_TRUNCATE_OPTIMIZATION  /* Special case: A DELETE without a WHERE clause deletes everything.  ** It is easier just to erase the whole table.  Note, however, that  ** this means that the row change count will be incorrect.  */  if( rcauth==SQLITE_OK && pWhere==0 && !triggers_exist && !IsVirtual(pTab) ){    assert( !isView );    sqlite3VdbeAddOp3(v, OP_Clear, pTab->tnum, iDb, memCnt);    if( !pParse->nested ){      sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_STATIC);    }    for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){      assert( pIdx->pSchema==pTab->pSchema );      sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb);    }  }else#endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */  /* The usual case: There is a WHERE clause so we have to scan through  ** the table and pick which records to delete.  */  {    int iRowid = ++pParse->nMem;    /* Used for storing rowid values. */    int iRowSet = ++pParse->nMem;   /* Register for rowset of rows to delete */    /* Begin the database scan    */    pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0);    if( pWInfo==0 ) goto delete_from_cleanup;    /* Remember the rowid of every item to be deleted.    */    sqlite3VdbeAddOp2(v, IsVirtual(pTab) ? OP_VRowid : OP_Rowid, iCur, iRowid);    sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iRowid);    if( db->flags & SQLITE_CountRows ){      sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);    }    /* End the database scan loop.    */    sqlite3WhereEnd(pWInfo);
开发者ID:kfengbest,项目名称:GenericDB,代码行数:67,


示例23: sqlite3Update

//.........这里部分代码省略.........  /* Start the view context. */  if( isView ){    sqlite3AuthContextPush(pParse, &sContext, pTab->zName);  }  /* If we are trying to update a view, realize that view into  ** an ephemeral table.  */#if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)  if( isView ){    sqlite3MaterializeView(pParse, pTab, pWhere, iDataCur);  }#endif  /* Resolve the column names in all the expressions in the  ** WHERE clause.  */  if( sqlite3ResolveExprNames(&sNC, pWhere) ){    goto update_cleanup;  }#ifndef SQLITE_OMIT_VIRTUALTABLE  /* Virtual tables must be handled separately */  if( IsVirtual(pTab) ){    updateVirtualTable(pParse, pTabList, pTab, pChanges, pRowidExpr, aXRef,                       pWhere, onError);    goto update_cleanup;  }#endif  /* Begin the database scan  */  if( HasRowid(pTab) ){    sqlite3VdbeAddOp3(v, OP_Null, 0, regRowSet, regOldRowid);    pWInfo = sqlite3WhereBegin(        pParse, pTabList, pWhere, 0, 0, WHERE_ONEPASS_DESIRED, iIdxCur    );    if( pWInfo==0 ) goto update_cleanup;    okOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);      /* Remember the rowid of every item to be updated.    */    sqlite3VdbeAddOp2(v, OP_Rowid, iDataCur, regOldRowid);    if( !okOnePass ){      sqlite3VdbeAddOp2(v, OP_RowSetAdd, regRowSet, regOldRowid);    }      /* End the database scan loop.    */    sqlite3WhereEnd(pWInfo);  }else{    int iPk;         /* First of nPk memory cells holding PRIMARY KEY value */    i16 nPk;         /* Number of components of the PRIMARY KEY */    int addrOpen;    /* Address of the OpenEphemeral instruction */    assert( pPk!=0 );    nPk = pPk->nKeyCol;    iPk = pParse->nMem+1;    pParse->nMem += nPk;    regKey = ++pParse->nMem;    iEph = pParse->nTab++;    sqlite3VdbeAddOp2(v, OP_Null, 0, iPk);    addrOpen = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iEph, nPk);    sqlite3VdbeSetP4KeyInfo(pParse, pPk);    pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0,                                WHERE_ONEPASS_DESIRED, iIdxCur);
开发者ID:hoangdoanh,项目名称:sqlite,代码行数:67,


示例24: fkLookupParent

/*** This function is called when a row is inserted into or deleted from the ** child table of foreign key constraint pFKey. If an SQL UPDATE is executed ** on the child table of pFKey, this function is invoked twice for each row** affected - once to "delete" the old row, and then again to "insert" the** new row.**** Each time it is called, this function generates VDBE code to locate the** row in the parent table that corresponds to the row being inserted into ** or deleted from the child table. If the parent row can be found, no ** special action is taken. Otherwise, if the parent row can *not* be** found in the parent table:****   Operation | FK type   | Action taken**   --------------------------------------------------------------------------**   INSERT      immediate   Increment the "immediate constraint counter".****   DELETE      immediate   Decrement the "immediate constraint counter".****   INSERT      deferred    Increment the "deferred constraint counter".****   DELETE      deferred    Decrement the "deferred constraint counter".**** These operations are identified in the comment at the top of this file ** (fkey.c) as "I.1" and "D.1".*/static void fkLookupParent(  Parse *pParse,        /* Parse context */  int iDb,              /* Index of database housing pTab */  Table *pTab,          /* Parent table of FK pFKey */  Index *pIdx,          /* Unique index on parent key columns in pTab */  FKey *pFKey,          /* Foreign key constraint */  int *aiCol,           /* Map from parent key columns to child table columns */  int regData,          /* Address of array containing child table row */  int nIncr,            /* Increment constraint counter by this */  int isIgnore          /* If true, pretend pTab contains all NULL values */){  int i;                                    /* Iterator variable */  Vdbe *v = sqlite3GetVdbe(pParse);         /* Vdbe to add code to */  int iCur = pParse->nTab - 1;              /* Cursor number to use */  int iOk = sqlite3VdbeMakeLabel(v);        /* jump here if parent key found */  /* If nIncr is less than zero, then check at runtime if there are any  ** outstanding constraints to resolve. If there are not, there is no need  ** to check if deleting this row resolves any outstanding violations.  **  ** Check if any of the key columns in the child table row are NULL. If   ** any are, then the constraint is considered satisfied. No need to   ** search for a matching row in the parent table.  */  if( nIncr<0 ){    sqlite3VdbeAddOp2(v, OP_FkIfZero, pFKey->isDeferred, iOk);  }  for(i=0; i<pFKey->nCol; i++){    int iReg = aiCol[i] + regData + 1;    sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iOk);  }  if( isIgnore==0 ){    if( pIdx==0 ){      /* If pIdx is NULL, then the parent key is the INTEGER PRIMARY KEY      ** column of the parent table (table pTab).  */      int iMustBeInt;               /* Address of MustBeInt instruction */      int regTemp = sqlite3GetTempReg(pParse);        /* Invoke MustBeInt to coerce the child key value to an integer (i.e.       ** apply the affinity of the parent key). If this fails, then there      ** is no matching parent key. Before using MustBeInt, make a copy of      ** the value. Otherwise, the value inserted into the child key column      ** will have INTEGER affinity applied to it, which may not be correct.  */      sqlite3VdbeAddOp2(v, OP_SCopy, aiCol[0]+1+regData, regTemp);      iMustBeInt = sqlite3VdbeAddOp2(v, OP_MustBeInt, regTemp, 0);        /* If the parent table is the same as the child table, and we are about      ** to increment the constraint-counter (i.e. this is an INSERT operation),      ** then check if the row being inserted matches itself. If so, do not      ** increment the constraint-counter.  */      if( pTab==pFKey->pFrom && nIncr==1 ){        sqlite3VdbeAddOp3(v, OP_Eq, regData, iOk, regTemp);      }        sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenRead);      sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, regTemp);      sqlite3VdbeAddOp2(v, OP_Goto, 0, iOk);      sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);      sqlite3VdbeJumpHere(v, iMustBeInt);      sqlite3ReleaseTempReg(pParse, regTemp);    }else{      int nCol = pFKey->nCol;      int regTemp = sqlite3GetTempRange(pParse, nCol);      int regRec = sqlite3GetTempReg(pParse);      KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx);        sqlite3VdbeAddOp3(v, OP_OpenRead, iCur, pIdx->tnum, iDb);      sqlite3VdbeChangeP4(v, -1, (char*)pKey, P4_KEYINFO_HANDOFF);      for(i=0; i<nCol; i++){        sqlite3VdbeAddOp2(v, OP_Copy, aiCol[i]+1+regData, regTemp+i);      }        /* If the parent table is the same as the child table, and we are about      ** to increment the constraint-counter (i.e. this is an INSERT operation),//.........这里部分代码省略.........
开发者ID:77songsong,项目名称:sqlite3,代码行数:101,


示例25: updateVirtualTable

static void updateVirtualTable(  Parse *pParse,         SrcList *pSrc,         Table *pTab,           ExprList *pChanges,    Expr *pRowid,          int *aXRef,            Expr *pWhere         ){  Vdbe *v = pParse->pVdbe;    ExprList *pEList = 0;       Select *pSelect = 0;        Expr *pExpr;                int ephemTab;               int i;                      int addr;                   int iReg;                   sqlite3 *db = pParse->db;   const char *pVTab = (const char*)sqlite3GetVTable(db, pTab);  SelectDest dest;  pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ID, "_rowid_"));  if( pRowid ){    pEList = sqlite3ExprListAppend(pParse, pEList,                                   sqlite3ExprDup(db, pRowid, 0));  }  assert( pTab->iPKey<0 );  for(i=0; i<pTab->nCol; i++){    if( aXRef[i]>=0 ){      pExpr = sqlite3ExprDup(db, pChanges->a[aXRef[i]].pExpr, 0);    }else{      pExpr = sqlite3Expr(db, TK_ID, pTab->aCol[i].zName);    }    pEList = sqlite3ExprListAppend(pParse, pEList, pExpr);  }  pSelect = sqlite3SelectNew(pParse, pEList, pSrc, pWhere, 0, 0, 0, 0, 0, 0);    assert( v );  ephemTab = pParse->nTab++;  sqlite3VdbeAddOp2(v, OP_OpenEphemeral, ephemTab, pTab->nCol+1+(pRowid!=0));  sqlite3VdbeChangeP5(v, BTREE_UNORDERED);  sqlite3SelectDestInit(&dest, SRT_Table, ephemTab);  sqlite3Select(pParse, pSelect, &dest);    iReg = ++pParse->nMem;  pParse->nMem += pTab->nCol+1;  addr = sqlite3VdbeAddOp2(v, OP_Rewind, ephemTab, 0);  sqlite3VdbeAddOp3(v, OP_Column,  ephemTab, 0, iReg);  sqlite3VdbeAddOp3(v, OP_Column, ephemTab, (pRowid?1:0), iReg+1);  for(i=0; i<pTab->nCol; i++){    sqlite3VdbeAddOp3(v, OP_Column, ephemTab, i+1+(pRowid!=0), iReg+2+i);  }  sqlite3VtabMakeWritable(pParse, pTab);  sqlite3VdbeAddOp4(v, OP_VUpdate, 0, pTab->nCol+2, iReg, pVTab, P4_VTAB);  sqlite3MayAbort(pParse);  sqlite3VdbeAddOp2(v, OP_Next, ephemTab, addr+1);  sqlite3VdbeJumpHere(v, addr);  sqlite3VdbeAddOp2(v, OP_Close, ephemTab, 0);    sqlite3SelectDelete(db, pSelect);  }
开发者ID:qtekfun,项目名称:htcDesire820Kernel,代码行数:64,


示例26: updateVirtualTable

/*** Generate code for an UPDATE of a virtual table.**** The strategy is that we create an ephemerial table that contains** for each row to be changed:****   (A)  The original rowid of that row.**   (B)  The revised rowid for the row. (note1)**   (C)  The content of every column in the row.**** Then we loop over this ephemeral table and for each row in** the ephermeral table call VUpdate.**** When finished, drop the ephemeral table.**** (note1) Actually, if we know in advance that (A) is always the same** as (B) we only store (A), then duplicate (A) when pulling** it out of the ephemeral table before calling VUpdate.*/static void updateVirtualTable(  Parse *pParse,       /* The parsing context */  SrcList *pSrc,       /* The virtual table to be modified */  Table *pTab,         /* The virtual table */  ExprList *pChanges,  /* The columns to change in the UPDATE statement */  Expr *pRowid,        /* Expression used to recompute the rowid */  int *aXRef,          /* Mapping from columns of pTab to entries in pChanges */  Expr *pWhere         /* WHERE clause of the UPDATE statement */){  Vdbe *v = pParse->pVdbe;  /* Virtual machine under construction */  ExprList *pEList = 0;     /* The result set of the SELECT statement */  Select *pSelect = 0;      /* The SELECT statement */  Expr *pExpr;              /* Temporary expression */  int ephemTab;             /* Table holding the result of the SELECT */  int i;                    /* Loop counter */  int addr;                 /* Address of top of loop */  int iReg;                 /* First register in set passed to OP_VUpdate */  sqlite3 *db = pParse->db; /* Database connection */  const char *pVTab = (const char*)sqlite3GetVTable(db, pTab);  SelectDest dest;  /* Construct the SELECT statement that will find the new values for  ** all updated rows.   */  pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ID, "_rowid_"));  if( pRowid ){    pEList = sqlite3ExprListAppend(pParse, pEList,                                   sqlite3ExprDup(db, pRowid, 0));  }  assert( pTab->iPKey<0 );  for(i=0; i<pTab->nCol; i++){    if( aXRef[i]>=0 ){      pExpr = sqlite3ExprDup(db, pChanges->a[aXRef[i]].pExpr, 0);    }else{      pExpr = sqlite3Expr(db, TK_ID, pTab->aCol[i].zName);    }    pEList = sqlite3ExprListAppend(pParse, pEList, pExpr);  }  pSelect = sqlite3SelectNew(pParse, pEList, pSrc, pWhere, 0, 0, 0, 0, 0, 0);    /* Create the ephemeral table into which the update results will  ** be stored.  */  assert( v );  ephemTab = pParse->nTab++;  sqlite3VdbeAddOp2(v, OP_OpenEphemeral, ephemTab, pTab->nCol+1+(pRowid!=0));  sqlite3VdbeChangeP5(v, BTREE_UNORDERED);  /* fill the ephemeral table   */  sqlite3SelectDestInit(&dest, SRT_Table, ephemTab);  sqlite3Select(pParse, pSelect, &dest);  /* Generate code to scan the ephemeral table and call VUpdate. */  iReg = ++pParse->nMem;  pParse->nMem += pTab->nCol+1;  addr = sqlite3VdbeAddOp2(v, OP_Rewind, ephemTab, 0);  sqlite3VdbeAddOp3(v, OP_Column,  ephemTab, 0, iReg);  sqlite3VdbeAddOp3(v, OP_Column, ephemTab, (pRowid?1:0), iReg+1);  for(i=0; i<pTab->nCol; i++){    sqlite3VdbeAddOp3(v, OP_Column, ephemTab, i+1+(pRowid!=0), iReg+2+i);  }  sqlite3VtabMakeWritable(pParse, pTab);  sqlite3VdbeAddOp4(v, OP_VUpdate, 0, pTab->nCol+2, iReg, pVTab, P4_VTAB);  sqlite3MayAbort(pParse);  sqlite3VdbeAddOp2(v, OP_Next, ephemTab, addr+1);  sqlite3VdbeJumpHere(v, addr);  sqlite3VdbeAddOp2(v, OP_Close, ephemTab, 0);  /* Cleanup */  sqlite3SelectDelete(db, pSelect);  }
开发者ID:Sheridan,项目名称:sqlite,代码行数:91,


示例27: codeAttach

/*** This procedure generates VDBE code for a single invocation of either the** sqlite_detach() or sqlite_attach() SQL user functions.*/static void codeAttach(  Parse *pParse,       /* The parser context */  int type,            /* Either SQLITE_ATTACH or SQLITE_DETACH */  FuncDef *pFunc,      /* FuncDef wrapper for detachFunc() or attachFunc() */  Expr *pAuthArg,      /* Expression to pass to authorization callback */  Expr *pFilename,     /* Name of database file */  Expr *pDbname,       /* Name of the database to use internally */  Expr *pKey           /* Database key for encryption extension */){  int rc;  NameContext sName;  Vdbe *v;  sqlite3* db = pParse->db;  int regArgs;  memset(&sName, 0, sizeof(NameContext));  sName.pParse = pParse;  if(       SQLITE_OK!=(rc = resolveAttachExpr(&sName, pFilename)) ||      SQLITE_OK!=(rc = resolveAttachExpr(&sName, pDbname)) ||      SQLITE_OK!=(rc = resolveAttachExpr(&sName, pKey))  ){    pParse->nErr++;    goto attach_end;  }#ifndef SQLITE_OMIT_AUTHORIZATION  if( pAuthArg ){    char *zAuthArg = pAuthArg->u.zToken;    if( NEVER(zAuthArg==0) ){      goto attach_end;    }    rc = sqlite3AuthCheck(pParse, type, zAuthArg, 0, 0);    if(rc!=SQLITE_OK ){      goto attach_end;    }  }#endif /* SQLITE_OMIT_AUTHORIZATION */  v = sqlite3GetVdbe(pParse);  regArgs = sqlite3GetTempRange(pParse, 4);  sqlite3ExprCode(pParse, pFilename, regArgs);  sqlite3ExprCode(pParse, pDbname, regArgs+1);  sqlite3ExprCode(pParse, pKey, regArgs+2);  assert( v || db->mallocFailed );  if( v ){    sqlite3VdbeAddOp3(v, OP_Function, 0, regArgs+3-pFunc->nArg, regArgs+3);    assert( pFunc->nArg==-1 || (pFunc->nArg&0xff)==pFunc->nArg );    sqlite3VdbeChangeP5(v, (u8)(pFunc->nArg));    sqlite3VdbeChangeP4(v, -1, (char *)pFunc, P4_FUNCDEF);    /* Code an OP_Expire. For an ATTACH statement, set P1 to true (expire this    ** statement only). For DETACH, set it to false (expire all existing    ** statements).    */    sqlite3VdbeAddOp1(v, OP_Expire, (type==SQLITE_ATTACH));  }  attach_end:  sqlite3ExprDelete(db, pFilename);  sqlite3ExprDelete(db, pDbname);  sqlite3ExprDelete(db, pKey);}
开发者ID:FarazShaikh,项目名称:LikewiseSMB2,代码行数:70,


示例28: sqlite3Update

//.........这里部分代码省略.........    regRowCount = ++pParse->nMem;    sqlite3VdbeAddOp2(v, OP_Integer, 0, regRowCount);  }  if( !isView ){    if( !okOnePass ) sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenWrite);     if( onError==OE_Replace ){      openAll = 1;    }else{      openAll = 0;      for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){        if( pIdx->onError==OE_Replace ){          openAll = 1;          break;        }      }    }    for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){      if( openAll || aRegIdx[i]>0 ){        KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx);        sqlite3VdbeAddOp4(v, OP_OpenWrite, iCur+i+1, pIdx->tnum, iDb,                       (char*)pKey, P4_KEYINFO_HANDOFF);        assert( pParse->nTab>iCur+i+1 );      }    }  }    if( okOnePass ){    int a1 = sqlite3VdbeAddOp1(v, OP_NotNull, regOldRowid);    addr = sqlite3VdbeAddOp0(v, OP_Goto);    sqlite3VdbeJumpHere(v, a1);  }else{    addr = sqlite3VdbeAddOp3(v, OP_RowSetRead, regRowSet, 0, regOldRowid);  }  sqlite3VdbeAddOp3(v, OP_NotExists, iCur, addr, regOldRowid);  assert( chngRowid || pTrigger || hasFK || regOldRowid==regNewRowid );  if( chngRowid ){    sqlite3ExprCode(pParse, pRowidExpr, regNewRowid);    sqlite3VdbeAddOp1(v, OP_MustBeInt, regNewRowid);  }  if( hasFK || pTrigger ){    u32 oldmask = (hasFK ? sqlite3FkOldmask(pParse, pTab) : 0);    oldmask |= sqlite3TriggerColmask(pParse,         pTrigger, pChanges, 0, TRIGGER_BEFORE|TRIGGER_AFTER, pTab, onError    );    for(i=0; i<pTab->nCol; i++){      if( aXRef[i]<0 || oldmask==0xffffffff || (i<32 && (oldmask & (1<<i))) ){        sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, i, regOld+i);      }else{        sqlite3VdbeAddOp2(v, OP_Null, 0, regOld+i);      }    }    if( chngRowid==0 ){      sqlite3VdbeAddOp2(v, OP_Copy, regOldRowid, regNewRowid);    }  }  newmask = sqlite3TriggerColmask(      pParse, pTrigger, pChanges, 1, TRIGGER_BEFORE, pTab, onError  );  for(i=0; i<pTab->nCol; i++){    if( i==pTab->iPKey ){
开发者ID:qtekfun,项目名称:htcDesire820Kernel,代码行数:67,


示例29: codeAttach

/*** This procedure generates VDBE code for a single invocation of either the** sqlite_detach() or sqlite_attach() SQL user functions.*/static void codeAttach(  Parse *pParse,       /* The parser context */  int type,            /* Either SQLITE_ATTACH or SQLITE_DETACH */  const char *zFunc,   /* Either "sqlite_attach" or "sqlite_detach */  int nFunc,           /* Number of args to pass to zFunc */  Expr *pAuthArg,      /* Expression to pass to authorization callback */  Expr *pFilename,     /* Name of database file */  Expr *pDbname,       /* Name of the database to use internally */  Expr *pKey           /* Database key for encryption extension */){  int rc;  NameContext sName;  Vdbe *v;  FuncDef *pFunc;  sqlite3* db = pParse->db;  int regArgs;#ifndef SQLITE_OMIT_AUTHORIZATION  assert( db->mallocFailed || pAuthArg );  if( pAuthArg ){    char *zAuthArg = sqlite3NameFromToken(db, &pAuthArg->span);    if( !zAuthArg ){      goto attach_end;    }    rc = sqlite3AuthCheck(pParse, type, zAuthArg, 0, 0);    sqlite3_free(zAuthArg);    if(rc!=SQLITE_OK ){      goto attach_end;    }  }#endif /* SQLITE_OMIT_AUTHORIZATION */  memset(&sName, 0, sizeof(NameContext));  sName.pParse = pParse;  if(       SQLITE_OK!=(rc = resolveAttachExpr(&sName, pFilename)) ||      SQLITE_OK!=(rc = resolveAttachExpr(&sName, pDbname)) ||      SQLITE_OK!=(rc = resolveAttachExpr(&sName, pKey))  ){    pParse->nErr++;    goto attach_end;  }  v = sqlite3GetVdbe(pParse);  regArgs = sqlite3GetTempRange(pParse, 3);  sqlite3ExprCode(pParse, pFilename, regArgs);  sqlite3ExprCode(pParse, pDbname, regArgs+1);  sqlite3ExprCode(pParse, pKey, regArgs+2);  assert( v || db->mallocFailed );  if( v ){    sqlite3VdbeAddOp3(v, OP_Function, 0, regArgs+3-nFunc, regArgs);    sqlite3VdbeChangeP5(v, nFunc);    pFunc = sqlite3FindFunction(db, zFunc, strlen(zFunc), nFunc, SQLITE_UTF8,0);    sqlite3VdbeChangeP4(v, -1, (char *)pFunc, P4_FUNCDEF);    /* Code an OP_Expire. For an ATTACH statement, set P1 to true (expire this    ** statement only). For DETACH, set it to false (expire all existing    ** statements).    */    sqlite3VdbeAddOp1(v, OP_Expire, (type==SQLITE_ATTACH));  }  attach_end:  sqlite3ExprDelete(pFilename);  sqlite3ExprDelete(pDbname);  sqlite3ExprDelete(pKey);}
开发者ID:riseven,项目名称:ri7engine,代码行数:73,


示例30: updateVirtualTable

/*** Generate code for an UPDATE of a virtual table.**** There are two possible strategies - the default and the special ** "onepass" strategy. Onepass is only used if the virtual table ** implementation indicates that pWhere may match at most one row.**** The default strategy is to create an ephemeral table that contains** for each row to be changed:****   (A)  The original rowid of that row.**   (B)  The revised rowid for the row.**   (C)  The content of every column in the row.**** Then loop through the contents of this ephemeral table executing a** VUpdate for each row. When finished, drop the ephemeral table.**** The "onepass" strategy does not use an ephemeral table. Instead, it** stores the same values (A, B and C above) in a register array and** makes a single invocation of VUpdate.*/static void updateVirtualTable(  Parse *pParse,       /* The parsing context */  SrcList *pSrc,       /* The virtual table to be modified */  Table *pTab,         /* The virtual table */  ExprList *pChanges,  /* The columns to change in the UPDATE statement */  Expr *pRowid,        /* Expression used to recompute the rowid */  int *aXRef,          /* Mapping from columns of pTab to entries in pChanges */  Expr *pWhere,        /* WHERE clause of the UPDATE statement */  int onError          /* ON CONFLICT strategy */){  Vdbe *v = pParse->pVdbe;  /* Virtual machine under construction */  int ephemTab;             /* Table holding the result of the SELECT */  int i;                    /* Loop counter */  sqlite3 *db = pParse->db; /* Database connection */  const char *pVTab = (const char*)sqlite3GetVTable(db, pTab);  WhereInfo *pWInfo;  int nArg = 2 + pTab->nCol;      /* Number of arguments to VUpdate */  int regArg;                     /* First register in VUpdate arg array */  int regRec;                     /* Register in which to assemble record */  int regRowid;                   /* Register for ephem table rowid */  int iCsr = pSrc->a[0].iCursor;  /* Cursor used for virtual table scan */  int aDummy[2];                  /* Unused arg for sqlite3WhereOkOnePass() */  int eOnePass;                   /* True to use onepass strategy */  int addr;                       /* Address of OP_OpenEphemeral */  /* Allocate nArg registers in which to gather the arguments for VUpdate. Then  ** create and open the ephemeral table in which the records created from  ** these arguments will be temporarily stored. */  assert( v );  ephemTab = pParse->nTab++;  addr= sqlite3VdbeAddOp2(v, OP_OpenEphemeral, ephemTab, nArg);  regArg = pParse->nMem + 1;  pParse->nMem += nArg;  regRec = ++pParse->nMem;  regRowid = ++pParse->nMem;  /* Start scanning the virtual table */  pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0,0,WHERE_ONEPASS_DESIRED,0);  if( pWInfo==0 ) return;  /* Populate the argument registers. */  for(i=0; i<pTab->nCol; i++){    if( aXRef[i]>=0 ){      sqlite3ExprCode(pParse, pChanges->a[aXRef[i]].pExpr, regArg+2+i);    }else{      sqlite3VdbeAddOp3(v, OP_VColumn, iCsr, i, regArg+2+i);      sqlite3VdbeChangeP5(v, OPFLAG_NOCHNG);/* Enable sqlite3_vtab_nochange() */    }  }  if( HasRowid(pTab) ){    sqlite3VdbeAddOp2(v, OP_Rowid, iCsr, regArg);    if( pRowid ){      sqlite3ExprCode(pParse, pRowid, regArg+1);    }else{      sqlite3VdbeAddOp2(v, OP_Rowid, iCsr, regArg+1);    }  }else{    Index *pPk;   /* PRIMARY KEY index */    i16 iPk;      /* PRIMARY KEY column */    pPk = sqlite3PrimaryKeyIndex(pTab);    assert( pPk!=0 );    assert( pPk->nKeyCol==1 );    iPk = pPk->aiColumn[0];    sqlite3VdbeAddOp3(v, OP_VColumn, iCsr, iPk, regArg);    sqlite3VdbeAddOp2(v, OP_SCopy, regArg+2+iPk, regArg+1);  }  eOnePass = sqlite3WhereOkOnePass(pWInfo, aDummy);  /* There is no ONEPASS_MULTI on virtual tables */  assert( eOnePass==ONEPASS_OFF || eOnePass==ONEPASS_SINGLE );  if( eOnePass ){    /* If using the onepass strategy, no-op out the OP_OpenEphemeral coded    ** above. */    sqlite3VdbeChangeToNoop(v, addr);    sqlite3VdbeAddOp1(v, OP_Close, iCsr);  }else{    /* Create a record from the argument register contents and insert it into//.........这里部分代码省略.........
开发者ID:SCALE-GmbH,项目名称:sqlcipher,代码行数:101,



注:本文中的sqlite3VdbeAddOp3函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ sqlite3VdbeChangeP4函数代码示例
C++ sqlite3VdbeAddOp2函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。