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

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

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

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

在下文中一共展示了sqlite3VdbeAddOp2函数的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: returnSingleInt

/*** Generate code to return a single integer value.*/static void returnSingleInt(Parse *pParse, const char *zLabel, int value){  Vdbe *v = sqlite3GetVdbe(pParse);  int mem = ++pParse->nMem;  sqlite3VdbeAddOp2(v, OP_Integer, value, mem);  if( pParse->explain==0 ){    sqlite3VdbeSetNumCols(v, 1);    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, P4_STATIC);  }  sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1);}
开发者ID:cdaffara,项目名称:symbiandump-os2,代码行数:13,


示例3: 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,


示例4: sqlite3Vacuum

/*** The non-standard VACUUM command is used to clean up the database,** collapse free space, etc.  It is modelled after the VACUUM command** in PostgreSQL.**** In version 1.0.x of SQLite, the VACUUM command would call** gdbm_reorganize() on all the database tables.  But beginning** with 2.0.0, SQLite no longer uses GDBM so this command has** become a no-op.*/void sqlite3Vacuum(Parse *pParse){  Vdbe *v = sqlite3GetVdbe(pParse);  if( v ){    sqlite3VdbeAddOp2(v, OP_Vacuum, 0, 0);  }  return;}
开发者ID:kfengbest,项目名称:GenericDB,代码行数:17,


示例5: codec_vdbe_return_static_string

/* Generate code to return a string value */static void codec_vdbe_return_static_string(Parse *pParse, const char *zLabel, const char *value){  Vdbe *v = sqlite3GetVdbe(pParse);  sqlite3VdbeSetNumCols(v, 1);  sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, SQLITE_STATIC);  sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, value, 0);  sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);}
开发者ID:CoderXL,项目名称:sqlcipher,代码行数:8,


示例6: sqlite3Vacuum

/*** The VACUUM command is used to clean up the database,** collapse free space, etc.  It is modelled after the VACUUM command** in PostgreSQL.  The VACUUM command works as follows:****   (1)  Create a new transient database file**   (2)  Copy all content from the database being vacuumed into**        the new transient database file**   (3)  Copy content from the transient database back into the**        original database.**** The transient database requires temporary disk space approximately** equal to the size of the original database.  The copy operation of** step (3) requires additional temporary disk space approximately equal** to the size of the original database for the rollback journal.** Hence, temporary disk space that is approximately 2x the size of the** original database is required.  Every page of the database is written** approximately 3 times:  Once for step (2) and twice for step (3).** Two writes per page are required in step (3) because the original** database content must be written into the rollback journal prior to** overwriting the database with the vacuumed content.**** Only 1x temporary space and only 1x writes would be required if** the copy of step (3) were replaced by deleting the original database** and renaming the transient database as the original.  But that will** not work if other processes are attached to the original database.** And a power loss in between deleting the original and renaming the** transient would cause the database file to appear to be deleted** following reboot.*/void sqlite3Vacuum(Parse *pParse, Token *pNm, Expr *pInto){  Vdbe *v = sqlite3GetVdbe(pParse);  int iDb = 0;  if( v==0 ) goto build_vacuum_end;  if( pNm ){#ifndef SQLITE_BUG_COMPATIBLE_20160819    /* Default behavior:  Report an error if the argument to VACUUM is    ** not recognized */    iDb = sqlite3TwoPartName(pParse, pNm, pNm, &pNm);    if( iDb<0 ) goto build_vacuum_end;#else    /* When SQLITE_BUG_COMPATIBLE_20160819 is defined, unrecognized arguments    ** to VACUUM are silently ignored.  This is a back-out of a bug fix that    ** occurred on 2016-08-19 (https://www.sqlite.org/src/info/083f9e6270).    ** The buggy behavior is required for binary compatibility with some    ** legacy applications. */    iDb = sqlite3FindDb(pParse->db, pNm);    if( iDb<0 ) iDb = 0;#endif  }  if( iDb!=1 ){    int iIntoReg = 0;    if( pInto && sqlite3ResolveSelfReference(pParse,0,0,pInto,0)==0 ){      iIntoReg = ++pParse->nMem;      sqlite3ExprCode(pParse, pInto, iIntoReg);    }    sqlite3VdbeAddOp2(v, OP_Vacuum, iDb, iIntoReg);    sqlite3VdbeUsesBtree(v, iDb);  }build_vacuum_end:  sqlite3ExprDelete(pParse->db, pInto);  return;}
开发者ID:SCALE-GmbH,项目名称:sqlcipher,代码行数:63,


示例7: flagPragma

/*** Check to see if zRight and zLeft refer to a pragma that queries** or changes one of the flags in db->flags.  Return 1 if so and 0 if not.** Also, implement the pragma.*/static int flagPragma(Parse *pParse, const char *zLeft, const char *zRight){  static const struct sPragmaType {    const char *zName;  /* Name of the pragma */    int mask;           /* Mask for the db->flags value */  } aPragma[] = {    { "full_column_names",        SQLITE_FullColNames  },    { "short_column_names",       SQLITE_ShortColNames },    { "count_changes",            SQLITE_CountRows     },    { "empty_result_callbacks",   SQLITE_NullCallback  },    { "legacy_file_format",       SQLITE_LegacyFileFmt },    { "fullfsync",                SQLITE_FullFSync     },#ifdef SQLITE_DEBUG    { "sql_trace",                SQLITE_SqlTrace      },    { "vdbe_listing",             SQLITE_VdbeListing   },    { "vdbe_trace",               SQLITE_VdbeTrace     },#endif#ifndef SQLITE_OMIT_CHECK    { "ignore_check_constraints", SQLITE_IgnoreChecks  },#endif    /* The following is VERY experimental */    { "writable_schema",          SQLITE_WriteSchema|SQLITE_RecoveryMode },    { "omit_readlock",            SQLITE_NoReadlock    },    /* TODO: Maybe it shouldn't be possible to change the ReadUncommitted    ** flag if there are any active statements. */    { "read_uncommitted",         SQLITE_ReadUncommitted },  };  int i;  const struct sPragmaType *p;  for(i=0, p=aPragma; i<sizeof(aPragma)/sizeof(aPragma[0]); i++, p++){    if( sqlite3StrICmp(zLeft, p->zName)==0 ){      sqlite3 *db = pParse->db;      Vdbe *v;      v = sqlite3GetVdbe(pParse);      if( v ){        if( zRight==0 ){          returnSingleInt(pParse, p->zName, (db->flags & p->mask)!=0 );        }else{          if( getBoolean(zRight) ){            db->flags |= p->mask;          }else{            db->flags &= ~p->mask;          }          /* Many of the flag-pragmas modify the code generated by the SQL           ** compiler (eg. count_changes). So add an opcode to expire all          ** compiled SQL statements after modifying a pragma value.          */          sqlite3VdbeAddOp2(v, OP_Expire, 0, 0);        }      }      return 1;    }  }  return 0;}
开发者ID:cdaffara,项目名称:symbiandump-os2,代码行数:62,


示例8: sqlite3DropTriggerPtr

/*** Drop a trigger given a pointer to that trigger. */void sqlite3DropTriggerPtr(Parse *pParse, Trigger *pTrigger){  Table   *pTable;  Vdbe *v;  sqlite3 *db = pParse->db;  int iDb;  iDb = sqlite3SchemaToIndex(pParse->db, pTrigger->pSchema);  assert( iDb>=0 && iDb<db->nDb );  pTable = tableOfTrigger(pTrigger);  assert( pTable );  assert( pTable->pSchema==pTrigger->pSchema || iDb==1 );#ifndef SQLITE_OMIT_AUTHORIZATION  {    int code = SQLITE_DROP_TRIGGER;    const char *zDb = db->aDb[iDb].zName;    const char *zTab = SCHEMA_TABLE(iDb);    if( iDb==1 ) code = SQLITE_DROP_TEMP_TRIGGER;    if( sqlite3AuthCheck(pParse, code, pTrigger->zName, pTable->zName, zDb) ||      sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){      return;    }  }#endif  /* Generate code to destroy the database record of the trigger.  */  assert( pTable!=0 );  if( (v = sqlite3GetVdbe(pParse))!=0 ){    int base;    static const int iLn = VDBE_OFFSET_LINENO(2);    static const VdbeOpList dropTrigger[] = {      { OP_Rewind,     0, ADDR(9),  0},      { OP_String8,    0, 1,        0}, /* 1 */      { OP_Column,     0, 1,        2},      { OP_Ne,         2, ADDR(8),  1},      { OP_String8,    0, 1,        0}, /* 4: "trigger" */      { OP_Column,     0, 0,        2},      { OP_Ne,         2, ADDR(8),  1},      { OP_Delete,     0, 0,        0},      { OP_Next,       0, ADDR(1),  0}, /* 8 */    };    sqlite3BeginWriteOperation(pParse, 0, iDb);    sqlite3OpenMasterTable(pParse, iDb);    base = sqlite3VdbeAddOpList(v,  ArraySize(dropTrigger), dropTrigger, iLn);    sqlite3VdbeChangeP4(v, base+1, pTrigger->zName, P4_TRANSIENT);    sqlite3VdbeChangeP4(v, base+4, "trigger", P4_STATIC);    sqlite3ChangeCookie(pParse, iDb);    sqlite3VdbeAddOp2(v, OP_Close, 0, 0);    sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0);    if( pParse->nMem<3 ){      pParse->nMem = 3;    }  }}
开发者ID:AchironOS,项目名称:chromium-2,代码行数:58,


示例9: 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,


示例10: 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,


示例11: sqlite3FkDropTable

/*** This function is called to generate code that runs when table pTab is** being dropped from the database. The SrcList passed as the second argument** to this function contains a single entry guaranteed to resolve to** table pTab.**** Normally, no code is required. However, if either****   (a) The table is the parent table of a FK constraint, or**   (b) The table is the child table of a deferred FK constraint and it is**       determined at runtime that there are outstanding deferred FK **       constraint violations in the database,**** then the equivalent of "DELETE FROM <tbl>" is executed before dropping** the table from the database. Triggers are disabled while running this** DELETE, but foreign key actions are not.*/void sqlite3FkDropTable(Parse *pParse, SrcList *pName, Table *pTab){  sqlite3 *db = pParse->db;  if( (db->flags&SQLITE_ForeignKeys) && !IsVirtual(pTab) && !pTab->pSelect ){    int iSkip = 0;    Vdbe *v = sqlite3GetVdbe(pParse);    assert( v );                  /* VDBE has already been allocated */    if( sqlite3FkReferences(pTab)==0 ){      /* Search for a deferred foreign key constraint for which this table      ** is the child table. If one cannot be found, return without       ** generating any VDBE code. If one can be found, then jump over      ** the entire DELETE if there are no outstanding deferred constraints      ** when this statement is run.  */      FKey *p;      for(p=pTab->pFKey; p; p=p->pNextFrom){        if( p->isDeferred ) break;      }      if( !p ) return;      iSkip = sqlite3VdbeMakeLabel(v);      sqlite3VdbeAddOp2(v, OP_FkIfZero, 1, iSkip);    }    pParse->disableTriggers = 1;    sqlite3DeleteFrom(pParse, sqlite3SrcListDup(db, pName, 0), 0);    pParse->disableTriggers = 0;    /* If the DELETE has generated immediate foreign key constraint     ** violations, halt the VDBE and return an error at this point, before    ** any modifications to the schema are made. This is because statement    ** transactions are not able to rollback schema changes.  */    sqlite3VdbeAddOp2(v, OP_FkIfZero, 0, sqlite3VdbeCurrentAddr(v)+2);    sqlite3HaltConstraint(        pParse, OE_Abort, "foreign key constraint failed", P4_STATIC    );    if( iSkip ){      sqlite3VdbeResolveLabel(v, iSkip);    }  }}
开发者ID:77songsong,项目名称:sqlite3,代码行数:57,


示例12: 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,


示例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 "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,


示例14: 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,


示例15: sqlite3VtabFinishParse

/*** The parser calls this routine after the CREATE VIRTUAL TABLE statement** has been completely parsed.*/void sqlite3VtabFinishParse(Parse *pParse, Token *pEnd){  Table *pTab = pParse->pNewTable;  /* The table being constructed */  sqlite3 *db = pParse->db;         /* The database connection */  if( pTab==0 ) return;  addArgumentToVtab(pParse);  pParse->sArg.z = 0;  if( pTab->nModuleArg<1 ) return;    /* If the CREATE VIRTUAL TABLE statement is being entered for the  ** first time (in other words if the virtual table is actually being  ** created now instead of just being read out of sqlite_master) then  ** do additional initialization work and store the statement text  ** in the sqlite_master table.  */  if( !db->init.busy ){    char *zStmt;    char *zWhere;    int iDb;    int iReg;    Vdbe *v;    /* Compute the complete text of the CREATE VIRTUAL TABLE statement */    if( pEnd ){      pParse->sNameToken.n = (int)(pEnd->z - pParse->sNameToken.z) + pEnd->n;    }    zStmt = sqlite3MPrintf(db, "CREATE VIRTUAL TABLE %T", &pParse->sNameToken);    /* A slot for the record has already been allocated in the     ** SQLITE_MASTER table.  We just need to update that slot with all    ** the information we've collected.      **    ** The VM register number pParse->regRowid holds the rowid of an    ** entry in the sqlite_master table tht was created for this vtab    ** by sqlite3StartTable().    */    iDb = sqlite3SchemaToIndex(db, pTab->pSchema);    sqlite3NestedParse(pParse,      "UPDATE %Q.%s "         "SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q "       "WHERE rowid=#%d",      db->aDb[iDb].zDbSName, MASTER_NAME,      pTab->zName,      pTab->zName,      zStmt,      pParse->regRowid    );    sqlite3DbFree(db, zStmt);    v = sqlite3GetVdbe(pParse);    sqlite3ChangeCookie(pParse, iDb);    sqlite3VdbeAddOp0(v, OP_Expire);    zWhere = sqlite3MPrintf(db, "name='%q' AND type='table'", pTab->zName);    sqlite3VdbeAddParseSchemaOp(v, iDb, zWhere);    iReg = ++pParse->nMem;    sqlite3VdbeLoadString(v, iReg, pTab->zName);    sqlite3VdbeAddOp2(v, OP_VCreate, iDb, iReg);  }  /* If we are rereading the sqlite_master table create the in-memory  ** record of the table. The xConnect() method is not called until  ** the first time the virtual table is used in an SQL statement. This  ** allows a schema that contains virtual tables to be loaded before  ** the required virtual table implementations are registered.  */  else {    Table *pOld;    Schema *pSchema = pTab->pSchema;    const char *zName = pTab->zName;    assert( sqlite3SchemaMutexHeld(db, 0, pSchema) );    pOld = sqlite3HashInsert(&pSchema->tblHash, zName, pTab);    if( pOld ){      sqlite3OomFault(db);      assert( pTab==pOld );  /* Malloc must have failed inside HashInsert() */      return;    }    pParse->pNewTable = 0;  }}
开发者ID:wangyiran126,项目名称:sqlite,代码行数:83,


示例16: fkScanChildren

/*** This function is called to generate code executed when a row is deleted** from the parent table of foreign key constraint pFKey and, if pFKey is ** deferred, when a row is inserted into the same table. When generating** code for an SQL UPDATE operation, this function may be called twice -** once to "delete" the old row and once to "insert" the new row.**** The code generated by this function scans through the rows in the child** table that correspond to the parent table row being deleted or inserted.** For each child row found, one of the following actions is taken:****   Operation | FK type   | Action taken**   --------------------------------------------------------------------------**   DELETE      immediate   Increment the "immediate constraint counter".**                           Or, if the ON (UPDATE|DELETE) action is RESTRICT,**                           throw a "foreign key constraint failed" exception.****   INSERT      immediate   Decrement the "immediate constraint counter".****   DELETE      deferred    Increment the "deferred constraint counter".**                           Or, if the ON (UPDATE|DELETE) action is RESTRICT,**                           throw a "foreign key constraint failed" exception.****   INSERT      deferred    Decrement the "deferred constraint counter".**** These operations are identified in the comment at the top of this file ** (fkey.c) as "I.2" and "D.2".*/static void fkScanChildren(  Parse *pParse,                  /* Parse context */  SrcList *pSrc,                  /* SrcList containing the table to scan */  Table *pTab,  Index *pIdx,                    /* Foreign key index */  FKey *pFKey,                    /* Foreign key relationship */  int *aiCol,                     /* Map from pIdx cols to child table cols */  int regData,                    /* Referenced table data starts here */  int nIncr                       /* Amount to increment deferred counter by */){  sqlite3 *db = pParse->db;       /* Database handle */  int i;                          /* Iterator variable */  Expr *pWhere = 0;               /* WHERE clause to scan with */  NameContext sNameContext;       /* Context used to resolve WHERE clause */  WhereInfo *pWInfo;              /* Context used by sqlite3WhereXXX() */  int iFkIfZero = 0;              /* Address of OP_FkIfZero */  Vdbe *v = sqlite3GetVdbe(pParse);  assert( !pIdx || pIdx->pTable==pTab );  if( nIncr<0 ){    iFkIfZero = sqlite3VdbeAddOp2(v, OP_FkIfZero, pFKey->isDeferred, 0);  }  /* Create an Expr object representing an SQL expression like:  **  **   <parent-key1> = <child-key1> AND <parent-key2> = <child-key2> ...  **  ** The collation sequence used for the comparison should be that of  ** the parent key columns. The affinity of the parent key column should  ** be applied to each child key value before the comparison takes place.  */  for(i=0; i<pFKey->nCol; i++){    Expr *pLeft;                  /* Value from parent table row */    Expr *pRight;                 /* Column ref to child table */    Expr *pEq;                    /* Expression (pLeft = pRight) */    int iCol;                     /* Index of column in child table */     const char *zCol;             /* Name of column in child table */    pLeft = sqlite3Expr(db, TK_REGISTER, 0);    if( pLeft ){      /* Set the collation sequence and affinity of the LHS of each TK_EQ      ** expression to the parent key column defaults.  */      if( pIdx ){        Column *pCol;        iCol = pIdx->aiColumn[i];        pCol = &pTab->aCol[iCol];        if( pTab->iPKey==iCol ) iCol = -1;        pLeft->iTable = regData+iCol+1;        pLeft->affinity = pCol->affinity;        pLeft->pColl = sqlite3LocateCollSeq(pParse, pCol->zColl);      }else{        pLeft->iTable = regData;        pLeft->affinity = SQLITE_AFF_INTEGER;      }    }    iCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom;    assert( iCol>=0 );    zCol = pFKey->pFrom->aCol[iCol].zName;    pRight = sqlite3Expr(db, TK_ID, zCol);    pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight, 0);    pWhere = sqlite3ExprAnd(db, pWhere, pEq);  }  /* If the child table is the same as the parent table, and this scan  ** is taking place as part of a DELETE operation (operation D.2), omit the  ** row being deleted from the scan by adding ($rowid != rowid) to the WHERE   ** clause, where $rowid is the rowid of the row being deleted.  */  if( pTab==pFKey->pFrom && nIncr>0 ){    Expr *pEq;                    /* Expression (pLeft = pRight) */    Expr *pLeft;                  /* Value from parent table row */    Expr *pRight;                 /* Column ref to child table *///.........这里部分代码省略.........
开发者ID:77songsong,项目名称:sqlite3,代码行数:101,


示例17: sqlite3FkCheck

/*** This function is called when inserting, deleting or updating a row of** table pTab to generate VDBE code to perform foreign key constraint ** processing for the operation.**** For a DELETE operation, parameter regOld is passed the index of the** first register in an array of (pTab->nCol+1) registers containing the** rowid of the row being deleted, followed by each of the column values** of the row being deleted, from left to right. Parameter regNew is passed** zero in this case.**** For an INSERT operation, regOld is passed zero and regNew is passed the** first register of an array of (pTab->nCol+1) registers containing the new** row data.**** For an UPDATE operation, this function is called twice. Once before** the original record is deleted from the table using the calling convention** described for DELETE. Then again after the original record is deleted** but before the new record is inserted using the INSERT convention. */void sqlite3FkCheck(  Parse *pParse,                  /* Parse context */  Table *pTab,                    /* Row is being deleted from this table */   int regOld,                     /* Previous row data is stored here */  int regNew                      /* New row data is stored here */){  sqlite3 *db = pParse->db;       /* Database handle */  FKey *pFKey;                    /* Used to iterate through FKs */  int iDb;                        /* Index of database containing pTab */  const char *zDb;                /* Name of database containing pTab */  int isIgnoreErrors = pParse->disableTriggers;  /* Exactly one of regOld and regNew should be non-zero. */  assert( (regOld==0)!=(regNew==0) );  /* If foreign-keys are disabled, this function is a no-op. */  if( (db->flags&SQLITE_ForeignKeys)==0 ) return;  iDb = sqlite3SchemaToIndex(db, pTab->pSchema);  zDb = db->aDb[iDb].zName;  /* Loop through all the foreign key constraints for which pTab is the  ** child table (the table that the foreign key definition is part of).  */  for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){    Table *pTo;                   /* Parent table of foreign key pFKey */    Index *pIdx = 0;              /* Index on key columns in pTo */    int *aiFree = 0;    int *aiCol;    int iCol;    int i;    int isIgnore = 0;    /* Find the parent table of this foreign key. Also find a unique index     ** on the parent key columns in the parent table. If either of these     ** schema items cannot be located, set an error in pParse and return     ** early.  */    if( pParse->disableTriggers ){      pTo = sqlite3FindTable(db, pFKey->zTo, zDb);    }else{      pTo = sqlite3LocateTable(pParse, 0, pFKey->zTo, zDb);    }    if( !pTo || locateFkeyIndex(pParse, pTo, pFKey, &pIdx, &aiFree) ){      assert( isIgnoreErrors==0 || (regOld!=0 && regNew==0) );      if( !isIgnoreErrors || db->mallocFailed ) return;      if( pTo==0 ){        /* If isIgnoreErrors is true, then a table is being dropped. In this        ** case SQLite runs a "DELETE FROM xxx" on the table being dropped        ** before actually dropping it in order to check FK constraints.        ** If the parent table of an FK constraint on the current table is        ** missing, behave as if it is empty. i.e. decrement the relevant        ** FK counter for each row of the current table with non-NULL keys.        */        Vdbe *v = sqlite3GetVdbe(pParse);        int iJump = sqlite3VdbeCurrentAddr(v) + pFKey->nCol + 1;        for(i=0; i<pFKey->nCol; i++){          int iReg = pFKey->aCol[i].iFrom + regOld + 1;          sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iJump);        }        sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, -1);      }      continue;    }    assert( pFKey->nCol==1 || (aiFree && pIdx) );    if( aiFree ){      aiCol = aiFree;    }else{      iCol = pFKey->aCol[0].iFrom;      aiCol = &iCol;    }    for(i=0; i<pFKey->nCol; i++){      if( aiCol[i]==pTab->iPKey ){        aiCol[i] = -1;      }#ifndef SQLITE_OMIT_AUTHORIZATION      /* Request permission to read the parent key columns. If the       ** authorization callback returns SQLITE_IGNORE, behave as if any      ** values read from the parent table are NULL. */      if( db->xAuth ){        int rcauth;//.........这里部分代码省略.........
开发者ID:77songsong,项目名称:sqlite3,代码行数:101,


示例18: sqlite3Update

//.........这里部分代码省略.........  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);    if( pWInfo==0 ) goto update_cleanup;    okOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);    for(i=0; i<nPk; i++){      assert( pPk->aiColumn[i]>=0 );      sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, pPk->aiColumn[i],                                      iPk+i);    }    if( okOnePass ){      sqlite3VdbeChangeToNoop(v, addrOpen);
开发者ID:hoangdoanh,项目名称:sqlite,代码行数:67,


示例19: 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,


示例20: sqlite3DeleteFrom

//.........这里部分代码省略.........    iEndBeforeTrigger = sqlite3VdbeAddOp0(v, OP_Goto);    iBeginAfterTrigger = sqlite3VdbeCurrentAddr(v);    (void)sqlite3CodeRowTrigger(pParse, TK_DELETE, 0, TRIGGER_AFTER, pTab, -1,        oldIdx, orconf, addr, &old_col_mask, 0);    iEndAfterTrigger = sqlite3VdbeAddOp0(v, OP_Goto);    sqlite3VdbeJumpHere(v, iGoto);  }  /* 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.
开发者ID:kfengbest,项目名称:GenericDB,代码行数:67,


示例21: sqlite3DeleteFrom

//.........这里部分代码省略.........  /* Begin generating code.  */  v = sqlite3GetVdbe(pParse);  if( v==0 ){    goto delete_from_cleanup;  }  if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);  sqlite3BeginWriteOperation(pParse, 1, iDb);  /* 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. Prior to version 3.6.5,  ** this optimization caused the row change count (the value returned by   ** API function sqlite3_count_changes) to be set incorrectly.  */  if( rcauth==SQLITE_OK && pWhere==0 && !pTrigger && !IsVirtual(pTab)    && 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
开发者ID:Mars-Wu,项目名称:djyos,代码行数:67,


示例22: sqlite3Update

//.........这里部分代码省略.........   /* Begin generating code.  */  v = sqlite3GetVdbe(pParse);  if( v==0 ) goto update_cleanup;  if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);  sqlite3BeginWriteOperation(pParse, 1, iDb);#ifndef SQLITE_OMIT_VIRTUALTABLE  /* Virtual tables must be handled separately */  if( IsVirtual(pTab) ){    updateVirtualTable(pParse, pTabList, pTab, pChanges, pRowidExpr, aXRef,                       pWhere);    pWhere = 0;    pTabList = 0;    goto update_cleanup;  }#endif  /* Start the view context  */  if( isView ){    sqlite3AuthContextPush(pParse, &sContext, pTab->zName);  }  /* Generate the code for triggers.  */  if( triggers_exist ){    int iGoto;    /* Create pseudo-tables for NEW and OLD    */    sqlite3VdbeAddOp2(v, OP_SetNumColumns, 0, pTab->nCol);    sqlite3VdbeAddOp2(v, OP_OpenPseudo, oldIdx, 0);    sqlite3VdbeAddOp2(v, OP_SetNumColumns, 0, pTab->nCol);    sqlite3VdbeAddOp2(v, OP_OpenPseudo, newIdx, 0);    iGoto = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0);    addr = sqlite3VdbeMakeLabel(v);    iBeginBeforeTrigger = sqlite3VdbeCurrentAddr(v);    if( sqlite3CodeRowTrigger(pParse, TK_UPDATE, pChanges, TRIGGER_BEFORE, pTab,          newIdx, oldIdx, onError, addr, &old_col_mask, &new_col_mask) ){      goto update_cleanup;    }    iEndBeforeTrigger = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0);    iBeginAfterTrigger = sqlite3VdbeCurrentAddr(v);    if( sqlite3CodeRowTrigger(pParse, TK_UPDATE, pChanges, TRIGGER_AFTER, pTab,           newIdx, oldIdx, onError, addr, &old_col_mask, &new_col_mask) ){      goto update_cleanup;    }    iEndAfterTrigger = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0);    sqlite3VdbeJumpHere(v, iGoto);  }  /* If we are trying to update 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 all the expressions in the  ** WHERE clause.
开发者ID:DoganA,项目名称:nightingale-deps,代码行数:67,


示例23: sqlite3AlterFinishAddColumn

//.........这里部分代码省略.........  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.  */  assert( pDflt==0 || pDflt->op==TK_SPAN );  if( pDflt && pDflt->pLeft->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;  }  /* Make sure the schema version is at least 3.  But do not upgrade  ** from less than 3 to 4, as that will corrupt any preexisting DESC  ** index.  */  r1 = sqlite3GetTempReg(pParse);  sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, r1, BTREE_FILE_FORMAT);  sqlite3VdbeUsesBtree(v, iDb);  sqlite3VdbeAddOp2(v, OP_AddImm, r1, -2);  sqlite3VdbeAddOp2(v, OP_IfPos, r1, sqlite3VdbeCurrentAddr(v)+2);  VdbeCoverage(v);  sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, 3);  sqlite3ReleaseTempReg(pParse, r1);  /* Reload the schema of the modified table. */  reloadTableSchema(pParse, pTab, pTab->zName);}
开发者ID:chinesemanbobo,项目名称:PPDemo,代码行数:101,


示例24: sqlite3Update

//.........这里部分代码省略.........    pWhere = 0;    pTabList = 0;    goto update_cleanup;  }#endif    regOldRowid = regNewRowid = ++pParse->nMem;  if( pTrigger || hasFK ){    regOld = pParse->nMem + 1;    pParse->nMem += pTab->nCol;  }  if( chngRowid || pTrigger || hasFK ){    regNewRowid = ++pParse->nMem;  }  regNew = pParse->nMem + 1;  pParse->nMem += pTab->nCol;    if( isView ){    sqlite3AuthContextPush(pParse, &sContext, pTab->zName);  }#if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)  if( isView ){    sqlite3MaterializeView(pParse, pTab, pWhere, iCur);  }#endif  if( sqlite3ResolveExprNames(&sNC, pWhere) ){    goto update_cleanup;  }  sqlite3VdbeAddOp2(v, OP_Null, 0, regOldRowid);  pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere,0, WHERE_ONEPASS_DESIRED);  if( pWInfo==0 ) goto update_cleanup;  okOnePass = pWInfo->okOnePass;  sqlite3VdbeAddOp2(v, OP_Rowid, iCur, regOldRowid);  if( !okOnePass ){    regRowSet = ++pParse->nMem;    sqlite3VdbeAddOp2(v, OP_RowSetAdd, regRowSet, regOldRowid);  }  sqlite3WhereEnd(pWInfo);  if( (db->flags & SQLITE_CountRows) && !pParse->pTriggerTab ){    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 ){
开发者ID:qtekfun,项目名称:htcDesire820Kernel,代码行数:67,


示例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: sqlite3DeleteFrom

//.........这里部分代码省略.........  /* Begin generating code.  */  v = sqlite3GetVdbe(pParse);  if( v==0 ){    goto delete_from_cleanup;  }  if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);  sqlite3BeginWriteOperation(pParse, 1, iDb);  /* If we are trying to delete from a view, realize that view into  ** an ephemeral table.  */#if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)  if( isView ){    sqlite3MaterializeView(pParse, pTab, pWhere, iTabCur);    iDataCur = iIdxCur = iTabCur;  }#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. Prior to version 3.6.5,  ** this optimization caused the row change count (the value returned by   ** API function sqlite3_count_changes) to be set incorrectly.  */  if( rcauth==SQLITE_OK   && pWhere==0   && !bComplex   && !IsVirtual(pTab)#ifdef SQLITE_ENABLE_PREUPDATE_HOOK   && db->xPreUpdateCallback==0#endif  ){    assert( !isView );    sqlite3TableLock(pParse, iDb, pTab->tnum, 1, pTab->zName);    if( HasRowid(pTab) ){      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 */  {    u16 wcf = WHERE_ONEPASS_DESIRED|WHERE_DUPLICATES_OK|WHERE_SEEK_TABLE;    if( sNC.ncFlags & NC_VarSelect ) bComplex = 1;    wcf |= (bComplex ? 0 : WHERE_ONEPASS_MULTIROW);    if( HasRowid(pTab) ){
开发者ID:chinesemanbobo,项目名称:PPDemo,代码行数:67,


示例28: 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,


示例29: sqlite3GenerateRowDelete

/*** This routine generates VDBE code that causes a single row of a** single table to be deleted.  Both the original table entry and** all indices are removed.**** Preconditions:****   1.  iDataCur is an open cursor on the btree that is the canonical data**       store for the table.  (This will be either the table itself,**       in the case of a rowid table, or the PRIMARY KEY index in the case**       of a WITHOUT ROWID table.)****   2.  Read/write cursors for all indices of pTab must be open as**       cursor number iIdxCur+i for the i-th index.****   3.  The primary key for the row to be deleted must be stored in a**       sequence of nPk memory cells starting at iPk.  If nPk==0 that means**       that a search record formed from OP_MakeRecord is contained in the**       single memory location iPk.**** eMode:**   Parameter eMode may be passed either ONEPASS_OFF (0), ONEPASS_SINGLE, or**   ONEPASS_MULTI.  If eMode is not ONEPASS_OFF, then the cursor**   iDataCur already points to the row to delete. If eMode is ONEPASS_OFF**   then this function must seek iDataCur to the entry identified by iPk**   and nPk before reading from it.****   If eMode is ONEPASS_MULTI, then this call is being made as part**   of a ONEPASS delete that affects multiple rows. In this case, if **   iIdxNoSeek is a valid cursor number (>=0), then its position should**   be preserved following the delete operation. Or, if iIdxNoSeek is not**   a valid cursor number, the position of iDataCur should be preserved**   instead.**** iIdxNoSeek:**   If iIdxNoSeek is a valid cursor number (>=0), then it identifies an**   index cursor (from within array of cursors starting at iIdxCur) that**   already points to the index entry to be deleted.*/void sqlite3GenerateRowDelete(  Parse *pParse,     /* Parsing context */  Table *pTab,       /* Table containing the row to be deleted */  Trigger *pTrigger, /* List of triggers to (potentially) fire */  int iDataCur,      /* Cursor from which column data is extracted */  int iIdxCur,       /* First index cursor */  int iPk,           /* First memory cell containing the PRIMARY KEY */  i16 nPk,           /* Number of PRIMARY KEY memory cells */  u8 count,          /* If non-zero, increment the row change counter */  u8 onconf,         /* Default ON CONFLICT policy for triggers */  u8 eMode,          /* ONEPASS_OFF, _SINGLE, or _MULTI.  See above */  int iIdxNoSeek     /* Cursor number of cursor that does not need seeking */){  Vdbe *v = pParse->pVdbe;        /* Vdbe */  int iOld = 0;                   /* First register in OLD.* array */  int iLabel;                     /* Label resolved to end of generated code */  u8 opSeek;                      /* Seek opcode */  /* Vdbe is guaranteed to have been allocated by this stage. */  assert( v );  VdbeModuleComment((v, "BEGIN: GenRowDel(%d,%d,%d,%d)",                         iDataCur, iIdxCur, iPk, (int)nPk));  /* 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);  opSeek = HasRowid(pTab) ? OP_NotExists : OP_NotFound;  if( eMode==ONEPASS_OFF ){    sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);    VdbeCoverageIf(v, opSeek==OP_NotExists);    VdbeCoverageIf(v, opSeek==OP_NotFound);  }   /* 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.* */    int addrStart;                /* Start of BEFORE trigger programs */    /* 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, iPk, iOld);    for(iCol=0; iCol<pTab->nCol; iCol++){      testcase( mask!=0xffffffff && iCol==31 );      testcase( mask!=0xffffffff && iCol==32 );      if( mask==0xffffffff || (iCol<=31 && (mask & MASKBIT32(iCol))!=0) ){        sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, iCol, iOld+iCol+1);      }    }//.........这里部分代码省略.........
开发者ID:chinesemanbobo,项目名称:PPDemo,代码行数:101,


示例30: sqlite3Update

//.........这里部分代码省略.........    regOld = pParse->nMem + 1;    pParse->nMem += pTab->nCol;  }  if( chngRowid || pTrigger || hasFK ){    regNewRowid = ++pParse->nMem;  }  regNew = pParse->nMem + 1;  pParse->nMem += pTab->nCol;  regRec = ++pParse->nMem;  /* Start the view context. */  if( isView ){    sqlite3AuthContextPush(pParse, &sContext, pTab->zName);  }  /* If we are trying to update 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 all the expressions in the  ** WHERE clause.  */  if( sqlite3ResolveExprNames(&sNC, pWhere) ){    goto update_cleanup;  }  /* Begin the database scan  */  sqlite3VdbeAddOp2(v, OP_Null, 0, regOldRowid);  pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere,0, WHERE_ONEPASS_DESIRED);  if( pWInfo==0 ) goto update_cleanup;  okOnePass = pWInfo->okOnePass;  /* Remember the rowid of every item to be updated.  */  sqlite3VdbeAddOp2(v, OP_Rowid, iCur, regOldRowid);  if( !okOnePass ){    regRowSet = ++pParse->nMem;    sqlite3VdbeAddOp2(v, OP_RowSetAdd, regRowSet, regOldRowid);  }  /* End the database scan loop.  */  sqlite3WhereEnd(pWInfo);  /* Initialize the count of updated rows  */  if( (db->flags & SQLITE_CountRows) && !pParse->pTriggerTab ){    regRowCount = ++pParse->nMem;    sqlite3VdbeAddOp2(v, OP_Integer, 0, regRowCount);  }  if( !isView ){    /*     ** 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 ){
开发者ID:Sheridan,项目名称:sqlite,代码行数:67,



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


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