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

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

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

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

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

示例1: sqlite3Analyze

/*** Generate code for the ANALYZE command.  The parser calls this routine** when it recognizes an ANALYZE command.****        ANALYZE                            -- 1**        ANALYZE  <database>                -- 2**        ANALYZE  ?<database>.?<tablename>  -- 3**** Form 1 causes all indices in all attached databases to be analyzed.** Form 2 analyzes all indices the single database named.** Form 3 analyzes all indices associated with the named table.*/void sqlite3Analyze(Parse *pParse, Token *pName1, Token *pName2){  sqlite3 *db = pParse->db;  int iDb;  int i;  char *z, *zDb;  Table *pTab;  Index *pIdx;  Token *pTableName;  /* Read the database schema. If an error occurs, leave an error message  ** and code in pParse and return NULL. */  assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );  if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){    return;  }  assert( pName2!=0 || pName1==0 );  if( pName1==0 ){    /* Form 1:  Analyze everything */    for(i=0; i<db->nDb; i++){      if( i==1 ) continue;  /* Do not analyze the TEMP database */      analyzeDatabase(pParse, i);    }  }else if( pName2->n==0 ){    /* Form 2:  Analyze the database or table named */    iDb = sqlite3FindDb(db, pName1);    if( iDb>=0 ){      analyzeDatabase(pParse, iDb);    }else{      z = sqlite3NameFromToken(db, pName1);      if( z ){        if( (pIdx = sqlite3FindIndex(db, z, 0))!=0 ){          analyzeTable(pParse, pIdx->pTable, pIdx);        }else if( (pTab = sqlite3LocateTable(pParse, 0, z, 0))!=0 ){          analyzeTable(pParse, pTab, 0);        }        sqlite3DbFree(db, z);      }    }  }else{    /* Form 3: Analyze the fully qualified table name */    iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pTableName);    if( iDb>=0 ){      zDb = db->aDb[iDb].zName;      z = sqlite3NameFromToken(db, pTableName);      if( z ){        if( (pIdx = sqlite3FindIndex(db, z, zDb))!=0 ){          analyzeTable(pParse, pIdx->pTable, pIdx);        }else if( (pTab = sqlite3LocateTable(pParse, 0, z, zDb))!=0 ){          analyzeTable(pParse, pTab, 0);        }        sqlite3DbFree(db, z);      }    }     }}
开发者ID:sunyangkobe,项目名称:db_research,代码行数:68,


示例2: openStatTable

/*** This routine generates code that opens the sqlite_stat1 table on cursor** iStatCur.**** If the sqlite_stat1 tables does not previously exist, it is created.** If it does previously exist, all entires associated with table zWhere** are removed.  If zWhere==0 then all entries are removed.*/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 associated with this table */){  sqlite3 *db = pParse->db;  Db *pDb;  int iRootPage;  Table *pStat;  Vdbe *v = sqlite3GetVdbe(pParse);  if( v==0 ) return;  assert( sqlite3BtreeHoldsAllMutexes(db) );  assert( sqlite3VdbeDb(v)==db );  pDb = &db->aDb[iDb];  if( (pStat = sqlite3FindTable(db, "sqlite_stat1", pDb->zName))==0 ){    /* The sqlite_stat1 tables does not exist.  Create it.      ** Note that a side-effect of the CREATE TABLE statement is to leave    ** the rootpage of the new table on the top of the stack.  This is    ** important because the OpenWrite opcode below will be needing it. */    sqlite3NestedParse(pParse,      "CREATE TABLE %Q.sqlite_stat1(tbl,idx,stat)",      pDb->zName    );    iRootPage = 0;  /* Cause rootpage to be taken from top of stack */  }else if( zWhere ){    /* The sqlite_stat1 table exists.  Delete all entries associated with    ** the table zWhere. */    sqlite3NestedParse(pParse,       "DELETE FROM %Q.sqlite_stat1 WHERE tbl=%Q",       pDb->zName, zWhere    );    iRootPage = pStat->tnum;  }else{    /* The sqlite_stat1 table already exists.  Delete all rows. */    iRootPage = pStat->tnum;    sqlite3VdbeAddOp(v, OP_Clear, pStat->tnum, iDb);  }  /* Open the sqlite_stat1 table for writing. Unless it was created  ** by this vdbe program, lock it for writing at the shared-cache level.   ** If this vdbe did create the sqlite_stat1 table, then it must have   ** already obtained a schema-lock, making the write-lock redundant.  */  if( iRootPage>0 ){    sqlite3TableLock(pParse, iDb, iRootPage, 1, "sqlite_stat1");  }  sqlite3VdbeAddOp(v, OP_Integer, iDb, 0);  sqlite3VdbeAddOp(v, OP_OpenWrite, iStatCur, iRootPage);  sqlite3VdbeAddOp(v, OP_SetNumColumns, iStatCur, 3);}
开发者ID:ChunHungLiu,项目名称:Reclass-2015,代码行数:60,


示例3: analyzeTable

/*** Generate code that will do an analysis of a single table in** a database.*/static void analyzeTable(Parse *pParse, Table *pTab){  int iDb;  int iStatCur;  assert( pTab!=0 );  assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );  iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);  sqlite3BeginWriteOperation(pParse, 0, iDb);  iStatCur = pParse->nTab++;  openStatTable(pParse, iDb, iStatCur, pTab->zName);  analyzeOneTable(pParse, pTab, iStatCur, pParse->nMem);  loadAnalysis(pParse, iDb);}
开发者ID:ChunHungLiu,项目名称:Reclass-2015,代码行数:17,


示例4: sqlite3VtabUnlockList

/*** Disconnect all the virtual table objects in the sqlite3.pDisconnect list.**** This function may only be called when the mutexes associated with all** shared b-tree databases opened using connection db are held by the ** caller. This is done to protect the sqlite3.pDisconnect list. The** sqlite3.pDisconnect list is accessed only as follows:****   1) By this function. In this case, all BtShared mutexes and the mutex**      associated with the database handle itself must be held.****   2) By function vtabDisconnectAll(), when it adds a VTable entry to**      the sqlite3.pDisconnect list. In this case either the BtShared mutex**      associated with the database the virtual table is stored in is held**      or, if the virtual table is stored in a non-sharable database, then**      the database handle mutex is held.**** As a result, a sqlite3.pDisconnect cannot be accessed simultaneously ** by multiple threads. It is thread-safe.*/void sqlite3VtabUnlockList(sqlite3 *db){  VTable *p = db->pDisconnect;  db->pDisconnect = 0;  assert( sqlite3BtreeHoldsAllMutexes(db) );  assert( sqlite3_mutex_held(db->mutex) );  if( p ){    sqlite3ExpirePreparedStatements(db);    do {      VTable *pNext = p->pNext;      sqlite3VtabUnlock(p);      p = pNext;    }while( p );  }}
开发者ID:wangyiran126,项目名称:sqlite,代码行数:36,


示例5: sqlite3VtabDisconnect

/*** Table *p is a virtual table. This function removes the VTable object** for table *p associated with database connection db from the linked** list in p->pVTab. It also decrements the VTable ref count. This is** used when closing database connection db to free all of its VTable** objects without disturbing the rest of the Schema object (which may** be being used by other shared-cache connections).*/void sqlite3VtabDisconnect(sqlite3 *db, Table *p){  VTable **ppVTab;  assert( IsVirtual(p) );  assert( sqlite3BtreeHoldsAllMutexes(db) );  assert( sqlite3_mutex_held(db->mutex) );  for(ppVTab=&p->pVTable; *ppVTab; ppVTab=&(*ppVTab)->pNext){    if( (*ppVTab)->db==db  ){      VTable *pVTab = *ppVTab;      *ppVTab = pVTab->pNext;      sqlite3VtabUnlock(pVTab);      break;    }  }}
开发者ID:wangyiran126,项目名称:sqlite,代码行数:24,


示例6: analyzeTable

/*** Generate code that will do an analysis of a single table in** a database.  If pOnlyIdx is not NULL then it is a single index** in pTab that should be analyzed.*/static void analyzeTable(Parse *pParse, Table *pTab, Index *pOnlyIdx){  int iDb;  int iStatCur;  assert( pTab!=0 );  assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );  iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);  sqlite3BeginWriteOperation(pParse, 0, iDb);  iStatCur = pParse->nTab;  pParse->nTab += 2;  if( pOnlyIdx ){    openStatTable(pParse, iDb, iStatCur, pOnlyIdx->zName, "idx");  }else{    openStatTable(pParse, iDb, iStatCur, pTab->zName, "tbl");  }  analyzeOneTable(pParse, pTab, pOnlyIdx, iStatCur, pParse->nMem+1);  loadAnalysis(pParse, iDb);}
开发者ID:sunyangkobe,项目名称:db_research,代码行数:23,


示例7: reloadTableSchema

/*** Generate code to drop and reload the internal representation of table** pTab from the database, including triggers and temporary triggers.** Argument zName is the name of the table in the database schema at** the time the generated code is executed. This can be different from** pTab->zName if this function is being called to code part of an ** "ALTER TABLE RENAME TO" statement.生成代码删除和重新加载从数据库表pTab的内部表达示,包括触发器和临时触发器。参数zName在数据库模式中的表的名称生成的代码执行。这可以不同于pTab - > zName如果这个函数被调用的代码的一部分“ALTER TABLE RENAME TO”声明。*/static void reloadTableSchema(Parse *pParse, Table *pTab, const char *zName){  Vdbe *v;  char *zWhere;  int iDb;                   /* Index of database containing pTab 包含pTab数据库索引*/#ifndef SQLITE_OMIT_TRIGGER  Trigger *pTrig;#endif  v = sqlite3GetVdbe(pParse);  if( NEVER(v==0) ) return;  assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );  iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);  assert( iDb>=0 );#ifndef SQLITE_OMIT_TRIGGER  /* Drop any table triggers from the internal schema. 降低任何表触发器内部模式。*/  for(pTrig=sqlite3TriggerList(pParse, pTab); pTrig; pTrig=pTrig->pNext){    int iTrigDb = sqlite3SchemaToIndex(pParse->db, pTrig->pSchema);    assert( iTrigDb==iDb || iTrigDb==1 );    sqlite3VdbeAddOp4(v, OP_DropTrigger, iTrigDb, 0, 0, pTrig->zName, 0);  }#endif  /* Drop the table and index from the internal schema.  从内部模式中降低表和索引*/  sqlite3VdbeAddOp4(v, OP_DropTable, iDb, 0, 0, pTab->zName, 0);  /* Reload the table, index and permanent trigger schemas. 重载表、索引和不变的触发器模式*/  zWhere = sqlite3MPrintf(pParse->db, "tbl_name=%Q", zName);  if( !zWhere ) return;  sqlite3VdbeAddParseSchemaOp(v, iDb, zWhere);#ifndef SQLITE_OMIT_TRIGGER  /* Now, if the table is not stored in the temp database, reload any temp   ** triggers. Don't use IN(...) in case SQLITE_OMIT_SUBQUERY is defined.   现在,如果表没有在临时数据库中存储,那么重载任何临时触发器。  不要用IN(...)在 SQLITE_OMIT_SUBQUERY被默认的情况下。  */  if( (zWhere=whereTempTriggers(pParse, pTab))!=0 ){    sqlite3VdbeAddParseSchemaOp(v, 1, zWhere);  }#endif}
开发者ID:Guidachengong,项目名称:Sqlite3.07.14,代码行数:54,


示例8: sqlite3DropTrigger

/*** This function is called to drop a trigger from the database schema.**** This may be called directly from the parser and therefore identifies** the trigger by name.  The sqlite3DropTriggerPtr() routine does the** same job as this routine except it takes a pointer to the trigger** instead of the trigger name.**/void sqlite3DropTrigger(Parse *pParse, SrcList *pName, int noErr){    Trigger *pTrigger = 0;    int i;    const char *zDb;    const char *zName;    int nName;    sqlite3 *db = pParse->db;    if (db->mallocFailed) goto drop_trigger_cleanup;    if (SQLITE_OK != sqlite3ReadSchema(pParse)){        goto drop_trigger_cleanup;    }    assert(pName->nSrc == 1);    zDb = pName->a[0].zDatabase;    zName = pName->a[0].zName;    nName = sqlite3Strlen30(zName);    assert(zDb != 0 || sqlite3BtreeHoldsAllMutexes(db));    for (i = OMIT_TEMPDB; i < db->nDb; i++){        int j = (i < 2) ? i ^ 1 : i;  /* Search TEMP before MAIN */        if (zDb && sqlite3StrICmp(db->aDb[j].zName, zDb)) continue;        assert(sqlite3SchemaMutexHeld(db, j, 0));        pTrigger = sqlite3HashFind(&(db->aDb[j].pSchema->trigHash), zName, nName);        if (pTrigger) break;    }    if (!pTrigger){        if (!noErr){            sqlite3ErrorMsg(pParse, "no such trigger: %S", pName, 0);        }        else{            sqlite3CodeVerifyNamedSchema(pParse, zDb);        }        pParse->checkSchema = 1;        goto drop_trigger_cleanup;    }    sqlite3DropTriggerPtr(pParse, pTrigger);drop_trigger_cleanup:    sqlite3SrcListDelete(db, pName);}
开发者ID:scott-zgeng,项目名称:thor,代码行数:48,


示例9: reloadTableSchema

/*** Generate code to drop and reload the internal representation of table** pTab from the database, including triggers and temporary triggers.** Argument zName is the name of the table in the database schema at** the time the generated code is executed. This can be different from** pTab->zName if this function is being called to code part of an ** "ALTER TABLE RENAME TO" statement.*/static void reloadTableSchema(Parse *pParse, Table *pTab, const char *zName){  Vdbe *v;  char *zWhere;  int iDb;                   /* Index of database containing pTab */#ifndef SQLITE_OMIT_TRIGGER  Trigger *pTrig;#endif  v = sqlite3GetVdbe(pParse);  if( !v ) return;  assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );  iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);  assert( iDb>=0 );#ifndef SQLITE_OMIT_TRIGGER  /* Drop any table triggers from the internal schema. */  for(pTrig=pTab->pTrigger; pTrig; pTrig=pTrig->pNext){    int iTrigDb = sqlite3SchemaToIndex(pParse->db, pTrig->pSchema);    assert( iTrigDb==iDb || iTrigDb==1 );    sqlite3VdbeAddOp4(v, OP_DropTrigger, iTrigDb, 0, 0, pTrig->name, 0);  }#endif  /* Drop the table and index from the internal schema */  sqlite3VdbeAddOp4(v, OP_DropTable, iDb, 0, 0, pTab->zName, 0);  /* Reload the table, index and permanent trigger schemas. */  zWhere = sqlite3MPrintf(pParse->db, "tbl_name=%Q", zName);  if( !zWhere ) return;  sqlite3VdbeAddOp4(v, OP_ParseSchema, iDb, 0, 0, zWhere, P4_DYNAMIC);#ifndef SQLITE_OMIT_TRIGGER  /* Now, if the table is not stored in the temp database, reload any temp   ** triggers. Don't use IN(...) in case SQLITE_OMIT_SUBQUERY is defined.   */  if( (zWhere=whereTempTriggers(pParse, pTab))!=0 ){    sqlite3VdbeAddOp4(v, OP_ParseSchema, 1, 0, 0, zWhere, P4_DYNAMIC);  }#endif}
开发者ID:qiuping,项目名称:sqlcipher,代码行数:48,


示例10: sqlite3AlterBeginAddColumn

/*** This function is called by the parser after the table-name in** an "ALTER TABLE <table-name> ADD" statement is parsed. Argument ** pSrc is the full-name of the table being altered.**** This routine makes a (partial) copy of the Table structure** for the table being altered and sets Parse.pNewTable to point** to it. Routines called by the parser as the column definition** is parsed (i.e. sqlite3AddColumn()) add the new Column data to ** the copy. The copy of the Table structure is deleted by tokenize.c ** after parsing is finished.**** Routine sqlite3AlterFinishAddColumn() will be called to complete** coding the "ALTER TABLE ... ADD" statement.*/void sqlite3AlterBeginAddColumn(Parse *pParse, SrcList *pSrc){  Table *pNew;  Table *pTab;  Vdbe *v;  int iDb;  int i;  int nAlloc;  sqlite3 *db = pParse->db;  /* Look up the table being altered. */  assert( pParse->pNewTable==0 );  assert( sqlite3BtreeHoldsAllMutexes(db) );  if( db->mallocFailed ) goto exit_begin_add_column;  pTab = sqlite3LocateTable(pParse, 0, pSrc->a[0].zName, pSrc->a[0].zDatabase);  if( !pTab ) goto exit_begin_add_column;#ifndef SQLITE_OMIT_VIRTUALTABLE  if( IsVirtual(pTab) ){    sqlite3ErrorMsg(pParse, "virtual tables may not be altered");    goto exit_begin_add_column;  }#endif  /* Make sure this is not an attempt to ALTER a view. */  if( pTab->pSelect ){    sqlite3ErrorMsg(pParse, "Cannot add a column to a view");    goto exit_begin_add_column;  }  assert( pTab->addColOffset>0 );  iDb = sqlite3SchemaToIndex(db, pTab->pSchema);  /* Put a copy of the Table struct in Parse.pNewTable for the  ** sqlite3AddColumn() function and friends to modify.  But modify  ** the name by adding an "sqlite_altertab_" prefix.  By adding this  ** prefix, we insure that the name will not collide with an existing  ** table because user table are not allowed to have the "sqlite_"  ** prefix on their name.  */  pNew = (Table*)sqlite3DbMallocZero(db, sizeof(Table));  if( !pNew ) goto exit_begin_add_column;  pParse->pNewTable = pNew;  pNew->nRef = 1;  pNew->db = db;  pNew->nCol = pTab->nCol;  assert( pNew->nCol>0 );  nAlloc = (((pNew->nCol-1)/8)*8)+8;  assert( nAlloc>=pNew->nCol && nAlloc%8==0 && nAlloc-pNew->nCol<8 );  pNew->aCol = (Column*)sqlite3DbMallocZero(db, sizeof(Column)*nAlloc);  pNew->zName = sqlite3MPrintf(db, "sqlite_altertab_%s", pTab->zName);  if( !pNew->aCol || !pNew->zName ){    db->mallocFailed = 1;    goto exit_begin_add_column;  }  memcpy(pNew->aCol, pTab->aCol, sizeof(Column)*pNew->nCol);  for(i=0; i<pNew->nCol; i++){    Column *pCol = &pNew->aCol[i];    pCol->zName = sqlite3DbStrDup(db, pCol->zName);    pCol->zColl = 0;    pCol->zType = 0;    pCol->pDflt = 0;  }  pNew->pSchema = db->aDb[iDb].pSchema;  pNew->addColOffset = pTab->addColOffset;  pNew->nRef = 1;  /* Begin a transaction and increment the schema cookie.  */  sqlite3BeginWriteOperation(pParse, 0, iDb);  v = sqlite3GetVdbe(pParse);  if( !v ) goto exit_begin_add_column;  sqlite3ChangeCookie(pParse, iDb);exit_begin_add_column:  sqlite3SrcListDelete(db, pSrc);  return;}
开发者ID:qiuping,项目名称:sqlcipher,代码行数:91,


示例11: sqlite3AlterFinishAddColumn

/*** This function is called after an "ALTER TABLE ... ADD" statement** has been parsed. Argument pColDef contains the text of the new** column definition.**** The Table structure pParse->pNewTable was extended to include** the new column during parsing.*/void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){  Table *pNew;              /* Copy of pParse->pNewTable */  Table *pTab;              /* Table being altered */  int iDb;                  /* Database number */  const char *zDb;          /* Database name */  const char *zTab;         /* Table name */  char *zCol;               /* Null-terminated column definition */  Column *pCol;             /* The new column */  Expr *pDflt;              /* Default value for the new column */  sqlite3 *db;              /* The database connection; */  db = pParse->db;  if( pParse->nErr || db->mallocFailed ) return;  pNew = pParse->pNewTable;  assert( pNew );  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->isPrimKey ){    sqlite3ErrorMsg(pParse, "Cannot add a PRIMARY KEY column");    return;  }  if( pNew->pIndex ){    sqlite3ErrorMsg(pParse, "Cannot add a UNIQUE column");    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;    if( sqlite3ValueFromExpr(db, pDflt, SQLITE_UTF8, SQLITE_AFF_NONE, &pVal) ){      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];    while( (zEnd>zCol && *zEnd==';') || sqlite3Isspace(*zEnd) ){      *zEnd-- = '/0';    }    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);  }  /* If the default value of the new column is NULL, then set the file//.........这里部分代码省略.........
开发者ID:qiuping,项目名称:sqlcipher,代码行数:101,


示例12: sqlite3AlterRenameTable

/*** Generate code to implement the "ALTER TABLE xxx RENAME TO yyy" ** command. */void sqlite3AlterRenameTable(  Parse *pParse,            /* Parser context. */  SrcList *pSrc,            /* The table to rename. */  Token *pName              /* The new table name. */){  int iDb;                  /* Database that contains the table */  char *zDb;                /* Name of database iDb */  Table *pTab;              /* Table being renamed */  char *zName = 0;          /* NULL-terminated version of pName */   sqlite3 *db = pParse->db; /* Database connection */  int nTabName;             /* Number of UTF-8 characters in zTabName */  const char *zTabName;     /* Original name of the table */  Vdbe *v;#ifndef SQLITE_OMIT_TRIGGER  char *zWhere = 0;         /* Where clause to locate temp triggers */#endif  int isVirtualRename = 0;  /* True if this is a v-table with an xRename() */    if( db->mallocFailed ) goto exit_rename_table;  assert( pSrc->nSrc==1 );  assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );  pTab = sqlite3LocateTable(pParse, 0, pSrc->a[0].zName, pSrc->a[0].zDatabase);  if( !pTab ) goto exit_rename_table;  iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);  zDb = db->aDb[iDb].zName;  /* Get a NULL terminated version of the new table name. */  zName = sqlite3NameFromToken(db, pName);  if( !zName ) goto exit_rename_table;  /* Check that a table or index named 'zName' does not already exist  ** in database iDb. If so, this is an error.  */  if( sqlite3FindTable(db, zName, zDb) || sqlite3FindIndex(db, zName, zDb) ){    sqlite3ErrorMsg(pParse,         "there is already another table or index with this name: %s", zName);    goto exit_rename_table;  }  /* Make sure it is not a system table being altered, or a reserved name  ** that the table is being renamed to.  */  if( sqlite3Strlen30(pTab->zName)>6    && 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7)  ){    sqlite3ErrorMsg(pParse, "table %s may not be altered", pTab->zName);    goto exit_rename_table;  }  if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){    goto exit_rename_table;  }#ifndef SQLITE_OMIT_VIEW  if( pTab->pSelect ){    sqlite3ErrorMsg(pParse, "view %s may not be altered", pTab->zName);    goto exit_rename_table;  }#endif#ifndef SQLITE_OMIT_AUTHORIZATION  /* Invoke the authorization callback. */  if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, 0) ){    goto exit_rename_table;  }#endif#ifndef SQLITE_OMIT_VIRTUALTABLE  if( sqlite3ViewGetColumnNames(pParse, pTab) ){    goto exit_rename_table;  }  if( IsVirtual(pTab) && pTab->pMod->pModule->xRename ){    isVirtualRename = 1;  }#endif  /* Begin a transaction and code the VerifyCookie for database iDb.   ** Then modify the schema cookie (since the ALTER TABLE modifies the  ** schema). Open a statement transaction if the table is a virtual  ** table.  */  v = sqlite3GetVdbe(pParse);  if( v==0 ){    goto exit_rename_table;  }  sqlite3BeginWriteOperation(pParse, isVirtualRename, iDb);  sqlite3ChangeCookie(pParse, iDb);  /* If this is a virtual table, invoke the xRename() function if  ** one is defined. The xRename() callback will modify the names  ** of any resources used by the v-table implementation (including other  ** SQLite tables) that are identified by the name of the virtual table.  */#ifndef SQLITE_OMIT_VIRTUALTABLE  if( isVirtualRename ){    int i = ++pParse->nMem;//.........这里部分代码省略.........
开发者ID:qiuping,项目名称:sqlcipher,代码行数:101,


示例13: sqlite3AlterFinishAddColumn

/*** This function is called after an "ALTER TABLE ... ADD" statement** has been parsed. Argument pColDef contains the text of the new** column definition.**** The Table structure pParse->pNewTable was extended to include** the new column during parsing.*/void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){  Table *pNew;              /* Copy of pParse->pNewTable */  Table *pTab;              /* Table being altered */  int iDb;                  /* Database number */  const char *zDb;          /* Database name */  const char *zTab;         /* Table name */  char *zCol;               /* Null-terminated column definition */  Column *pCol;             /* The new column */  Expr *pDflt;              /* Default value for the new column */  sqlite3 *db;              /* The database connection; */  Vdbe *v = pParse->pVdbe;  /* The prepared statement under construction */  db = pParse->db;  if( pParse->nErr || db->mallocFailed ) return;  assert( v!=0 );  pNew = pParse->pNewTable;  assert( pNew );  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';    }//.........这里部分代码省略.........
开发者ID:arizwanp,项目名称:intel_sgx,代码行数:101,


示例14: sqlite3AlterRenameTable

/*** Generate code to implement the "ALTER TABLE xxx RENAME TO yyy"** command.*/void sqlite3AlterRenameTable(  Parse *pParse,            /* Parser context. */  SrcList *pSrc,            /* The table to rename. */  Token *pName              /* The new table name. */){  int iDb;                  /* Database that contains the table */  char *zDb;                /* Name of database iDb */  Table *pTab;              /* Table being renamed */  char *zName = 0;          /* NULL-terminated version of pName */  sqlite3 *db = pParse->db; /* Database connection */  int nTabName;             /* Number of UTF-8 characters in zTabName */  const char *zTabName;     /* Original name of the table */  Vdbe *v;#ifndef SQLITE_OMIT_TRIGGER  char *zWhere = 0;         /* Where clause to locate temp triggers */#endif  VTable *pVTab = 0;        /* Non-zero if this is a v-tab with an xRename() */  int savedDbFlags;         /* Saved value of db->flags */  savedDbFlags = db->flags;  if( NEVER(db->mallocFailed) ) goto exit_rename_table;  assert( pSrc->nSrc==1 );  assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );  pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]);  if( !pTab ) goto exit_rename_table;  iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);  zDb = db->aDb[iDb].zName;  db->flags |= SQLITE_PreferBuiltin;  /* Get a NULL terminated version of the new table name. */  zName = sqlite3NameFromToken(db, pName);  if( !zName ) goto exit_rename_table;  /* Check that a table or index named 'zName' does not already exist  ** in database iDb. If so, this is an error.  */  if( sqlite3FindTable(db, zName, zDb) || sqlite3FindIndex(db, zName, zDb) ){    sqlite3ErrorMsg(pParse,        "there is already another table or index with this name: %s", zName);    goto exit_rename_table;  }  /* Make sure it is not a system table being altered, or a reserved name  ** that the table is being renamed to.  */  if( SQLITE_OK!=isSystemTable(pParse, pTab->zName) ){    goto exit_rename_table;  }  if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){ goto    exit_rename_table;  }#ifndef SQLITE_OMIT_VIEW  if( pTab->pSelect ){    sqlite3ErrorMsg(pParse, "view %s may not be altered", pTab->zName);    goto exit_rename_table;  }#endif#ifndef SQLITE_OMIT_AUTHORIZATION  /* Invoke the authorization callback. */  if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, 0) ){    goto exit_rename_table;  }#endif#ifndef SQLITE_OMIT_VIRTUALTABLE  if( sqlite3ViewGetColumnNames(pParse, pTab) ){    goto exit_rename_table;  }  if( IsVirtual(pTab) ){    pVTab = sqlite3GetVTable(db, pTab);    if( pVTab->pVtab->pModule->xRename==0 ){      pVTab = 0;    }  }#endif  /* Begin a transaction for database iDb.  ** Then modify the schema cookie (since the ALTER TABLE modifies the  ** schema). Open a statement transaction if the table is a virtual  ** table.  */  v = sqlite3GetVdbe(pParse);  if( v==0 ){    goto exit_rename_table;  }  sqlite3BeginWriteOperation(pParse, pVTab!=0, iDb);  sqlite3ChangeCookie(pParse, iDb);  /* If this is a virtual table, invoke the xRename() function if  ** one is defined. The xRename() callback will modify the names  ** of any resources used by the v-table implementation (including other  ** SQLite tables) that are identified by the name of the virtual table.  *///.........这里部分代码省略.........
开发者ID:arizwanp,项目名称:intel_sgx,代码行数: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 */  int iStatCur,    /* Cursor that writes to the sqlite_stat1 table */  int iMem         /* Available memory locations begin here */){  Index *pIdx;     /* An index to being analyzed */  int iIdxCur;     /* Cursor number for index being analyzed */  int nCol;        /* Number of columns in the index */  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 addr;        /* The address of an instruction */  int iDb;         /* Index of database containing pTab */  v = sqlite3GetVdbe(pParse);  if( v==0 || pTab==0 || pTab->pIndex==0 ){    /* Do no analysis for tables that have no indices */    return;  }  assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );  iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);  assert( iDb>=0 );#ifndef SQLITE_OMIT_AUTHORIZATION  if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0,      pParse->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;  for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){    KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx);    /* Open a cursor to the index to be analyzed    */    assert( iDb==sqlite3SchemaToIndex(pParse->db, pIdx->pSchema) );    sqlite3VdbeAddOp(v, OP_Integer, iDb, 0);    VdbeComment((v, "# %s", pIdx->zName));    sqlite3VdbeOp3(v, OP_OpenRead, iIdxCur, pIdx->tnum,        (char *)pKey, P3_KEYINFO_HANDOFF);    nCol = pIdx->nColumn;    if( iMem+nCol*2>=pParse->nMem ){      pParse->nMem = iMem+nCol*2+1;    }    sqlite3VdbeAddOp(v, OP_SetNumColumns, iIdxCur, nCol+1);    /* Memory cells are used as follows:    **    **    mem[iMem]:             The total number of rows in the table.    **    mem[iMem+1]:           Number of distinct values in column 1    **    ...    **    mem[iMem+nCol]:        Number of distinct values in column N    **    mem[iMem+nCol+1]       Last observed value of column 1    **    ...    **    mem[iMem+nCol+nCol]:   Last observed value of column N    **    ** Cells iMem through iMem+nCol are initialized to 0.  The others    ** are initialized to NULL.    */    for(i=0; i<=nCol; i++){      sqlite3VdbeAddOp(v, OP_MemInt, 0, iMem+i);    }    for(i=0; i<nCol; i++){      sqlite3VdbeAddOp(v, OP_MemNull, iMem+nCol+i+1, 0);    }    /* Do the analysis.    */    endOfLoop = sqlite3VdbeMakeLabel(v);    sqlite3VdbeAddOp(v, OP_Rewind, iIdxCur, endOfLoop);    topOfLoop = sqlite3VdbeCurrentAddr(v);    sqlite3VdbeAddOp(v, OP_MemIncr, 1, iMem);    for(i=0; i<nCol; i++){      sqlite3VdbeAddOp(v, OP_Column, iIdxCur, i);      sqlite3VdbeAddOp(v, OP_MemLoad, iMem+nCol+i+1, 0);      sqlite3VdbeAddOp(v, OP_Ne, 0x100, 0);    }    sqlite3VdbeAddOp(v, OP_Goto, 0, endOfLoop);    for(i=0; i<nCol; i++){      addr = sqlite3VdbeAddOp(v, OP_MemIncr, 1, iMem+i+1);      sqlite3VdbeChangeP2(v, topOfLoop + 3*i + 3, addr);      sqlite3VdbeAddOp(v, OP_Column, iIdxCur, i);      sqlite3VdbeAddOp(v, OP_MemStore, iMem+nCol+i+1, 1);    }    sqlite3VdbeResolveLabel(v, endOfLoop);    sqlite3VdbeAddOp(v, OP_Next, iIdxCur, topOfLoop);    sqlite3VdbeAddOp(v, OP_Close, iIdxCur, 0);    /* Store the results.      **    ** The result is a single row of the sqlite_stat1 table.  The first//.........这里部分代码省略.........
开发者ID:ChunHungLiu,项目名称:Reclass-2015,代码行数:101,


示例16: sqlite3AlterRenameTable

/*** Generate code to implement the "ALTER TABLE xxx RENAME TO yyy" ** command. 生成代码来实现“ALTER TABLE xxx重命名yyy”命令。*/void sqlite3AlterRenameTable(  Parse *pParse,            /* Parser context. 语法分析器上下文*/  SrcList *pSrc,            /* The table to rename. 重命名的表*/  Token *pName              /* The new table name. 新表名*/){  int iDb;                  /* Database that contains the table 包含表的数据库*/  char *zDb;                /* Name of database iDb 数据库iDb 的名称*/  Table *pTab;              /* Table being renamed 正在重命名的表*/  char *zName = 0;          /* NULL-terminated version of pName  pName的空值终止版本*/   sqlite3 *db = pParse->db; /* Database connection 数据库的连接*/  int nTabName;             /* Number of UTF-8 characters in zTabName 在 zTabName里的UTF-8类型的数目*/  const char *zTabName;     /* Original name of the table 最初的数据库名称*/  Vdbe *v;#ifndef SQLITE_OMIT_TRIGGER  char *zWhere = 0;         /* Where clause to locate temp triggers Where 子句位于temp触发器*/#endif  VTable *pVTab = 0;        /* Non-zero if this is a v-tab with an xRename() 如果是 一个v-tab 和一个xRename() ,则为零*/  int savedDbFlags;         /* Saved value of db->flags db->flags的保留值*/  savedDbFlags = db->flags;    if( NEVER(db->mallocFailed) ) goto exit_rename_table;  assert( pSrc->nSrc==1 );  assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );  pTab = sqlite3LocateTable(pParse, 0, pSrc->a[0].zName, pSrc->a[0].zDatabase);  if( !pTab ) goto exit_rename_table;  iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);  zDb = db->aDb[iDb].zName;  db->flags |= SQLITE_PreferBuiltin;  /* Get a NULL terminated version of the new table name. 得到一个空终止版本的新表的名称。*/  zName = sqlite3NameFromToken(db, pName);  if( !zName ) goto exit_rename_table;  /* Check that a table or index named 'zName' does not already exist  ** in database iDb. If so, this is an error.检查一个表或索引名叫“zName”不存在数据库iDb。  如果是这样,这是一个错误。  */  if( sqlite3FindTable(db, zName, zDb) || sqlite3FindIndex(db, zName, zDb) ){    sqlite3ErrorMsg(pParse,         "there is already another table or index with this name: %s", zName);    goto exit_rename_table;  }  /* Make sure it is not a system table being altered, or a reserved name  ** that the table is being renamed to.  确保它不是一个正在被修改的系统表或者一个正在被重命名的保留的名称表  */  if( SQLITE_OK!=isSystemTable(pParse, pTab->zName) ){    goto exit_rename_table;  }  if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){ goto    exit_rename_table;  }#ifndef SQLITE_OMIT_VIEW  if( pTab->pSelect ){    sqlite3ErrorMsg(pParse, "view %s may not be altered", pTab->zName);    goto exit_rename_table;  }#endif#ifndef SQLITE_OMIT_AUTHORIZATION  /* Invoke the authorization callback. 调用授权回调。*/  if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, 0) ){    goto exit_rename_table;  }#endif#ifndef SQLITE_OMIT_VIRTUALTABLE  if( sqlite3ViewGetColumnNames(pParse, pTab) ){    goto exit_rename_table;  }  if( IsVirtual(pTab) ){    pVTab = sqlite3GetVTable(db, pTab);    if( pVTab->pVtab->pModule->xRename==0 ){      pVTab = 0;    }  }#endif  /* Begin a transaction and code the VerifyCookie for database iDb.   ** Then modify the schema cookie (since the ALTER TABLE modifies the  ** schema). Open a statement transaction if the table is a virtual  ** table.  对于iDb数据库开始一个事务和代码的VerifyCookie。然后修改模式cookie(因为ALTER TABLE修改模式)。如果表是一个虚拟表打开一个声明事务。  */  v = sqlite3GetVdbe(pParse);  if( v==0 ){    goto exit_rename_table;  }  sqlite3BeginWriteOperation(pParse, pVTab!=0, iDb);  sqlite3ChangeCookie(pParse, iDb);//.........这里部分代码省略.........
开发者ID:Guidachengong,项目名称:Sqlite3.07.14,代码行数:101,


示例17: sqlite3AlterFinishAddColumn

/*** This function is called after an "ALTER TABLE ... ADD" statement** has been parsed. Argument pColDef contains the text of the new** column definition.**** The Table structure pParse->pNewTable was extended to include** the new column during parsing.在“ALTER TABLE…添加“声明解析后这个函数被调用。参数pColDef包含新列定义的文本。表结构pParse - > pNewTable扩大到包括在解析新列。*/void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){  Table *pNew;              /* Copy of pParse->pNewTable pParse->pNew表的副本*/  Table *pTab;              /* Table being altered 被修改的表*/  int iDb;                  /* Database number 数据库数*/  const char *zDb;          /* Database name 数据库名*/  const char *zTab;         /* Table name 表名*/  char *zCol;               /* Null-terminated column definition 空值终止列定义*/  Column *pCol;             /* The new column 新列*/  Expr *pDflt;              /* Default value for the new column 为新列默认数值*/  sqlite3 *db;              /* The database connection; 数据库的连接*/  db = pParse->db;  if( pParse->nErr || db->mallocFailed ) return;  pNew = pParse->pNewTable;  assert( pNew );  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 跳过“sqlite_altertab_”前缀的名称*/  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.  如果新列的默认值是用文字指定NULL,那么pDflt设置为0。  这简化了检查SQL空下面的默认。  */  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->isPrimKey ){    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.)  确保默认表达式是sqlite3ValueFromExpr()可以处理的事(即不是当前时间等。)  */  if( pDflt ){    sqlite3_value *pVal;    if( sqlite3ValueFromExpr(db, pDflt, SQLITE_UTF8, SQLITE_AFF_NONE, &pVal) ){      db->mallocFailed = 1;      return;    }    if( !pVal ){      sqlite3ErrorMsg(pParse, "Cannot add a column with non-constant default");      return;    }    sqlite3ValueFree(pVal);  }  /* Modify the CREATE TABLE statement. 修改CREATE TABLE语句。*/  zCol = sqlite3DbStrNDup(db, (char*)pColDef->z, pColDef->n);  if( zCol ){    char *zEnd = &zCol[pColDef->n-1];    int savedDbFlags = db->flags;//.........这里部分代码省略.........
开发者ID:Guidachengong,项目名称:Sqlite3.07.14,代码行数:101,


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


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



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


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