⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pragma.c

📁 sqlite-3.4.1,嵌入式数据库.是一个功能强大的开源数据库,给学习和研发以及小型公司的发展带来了全所未有的好处.
💻 C
📖 第 1 页 / 共 3 页
字号:
        int ii;        assert(pDb==&db->aDb[0]);        for(ii=2; ii<db->nDb; ii++){          pPager = sqlite3BtreePager(db->aDb[ii].pBt);          sqlite3PagerLockingMode(pPager, eMode);        }        db->dfltLockMode = eMode;      }      pPager = sqlite3BtreePager(pDb->pBt);      eMode = sqlite3PagerLockingMode(pPager, eMode);    }    assert(eMode==PAGER_LOCKINGMODE_NORMAL||eMode==PAGER_LOCKINGMODE_EXCLUSIVE);    if( eMode==PAGER_LOCKINGMODE_EXCLUSIVE ){      zRet = "exclusive";    }    sqlite3VdbeSetNumCols(v, 1);    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "locking_mode", P3_STATIC);    sqlite3VdbeOp3(v, OP_String8, 0, 0, zRet, 0);    sqlite3VdbeAddOp(v, OP_Callback, 1, 0);  }else#endif /* SQLITE_OMIT_PAGER_PRAGMAS */  /*  **  PRAGMA [database.]auto_vacuum  **  PRAGMA [database.]auto_vacuum=N  **  ** Get or set the (boolean) value of the database 'auto-vacuum' parameter.  */#ifndef SQLITE_OMIT_AUTOVACUUM  if( sqlite3StrICmp(zLeft,"auto_vacuum")==0 ){    Btree *pBt = pDb->pBt;    if( sqlite3ReadSchema(pParse) ){      goto pragma_out;    }    if( !zRight ){      int auto_vacuum =           pBt ? sqlite3BtreeGetAutoVacuum(pBt) : SQLITE_DEFAULT_AUTOVACUUM;      returnSingleInt(pParse, "auto_vacuum", auto_vacuum);    }else{      int eAuto = getAutoVacuum(zRight);      if( eAuto>=0 ){        /* Call SetAutoVacuum() to set initialize the internal auto and        ** incr-vacuum flags. This is required in case this connection        ** creates the database file. It is important that it is created        ** as an auto-vacuum capable db.        */        int rc = sqlite3BtreeSetAutoVacuum(pBt, eAuto);        if( rc==SQLITE_OK && (eAuto==1 || eAuto==2) ){          /* When setting the auto_vacuum mode to either "full" or           ** "incremental", write the value of meta[6] in the database          ** file. Before writing to meta[6], check that meta[3] indicates          ** that this really is an auto-vacuum capable database.          */          static const VdbeOpList setMeta6[] = {            { OP_Transaction,    0,               1,        0},    /* 0 */            { OP_ReadCookie,     0,               3,        0},    /* 1 */            { OP_If,             0,               0,        0},    /* 2 */            { OP_Halt,           SQLITE_OK,       OE_Abort, 0},    /* 3 */            { OP_Integer,        0,               0,        0},    /* 4 */            { OP_SetCookie,      0,               6,        0},    /* 5 */          };          int iAddr;          iAddr = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6);          sqlite3VdbeChangeP1(v, iAddr, iDb);          sqlite3VdbeChangeP1(v, iAddr+1, iDb);          sqlite3VdbeChangeP2(v, iAddr+2, iAddr+4);          sqlite3VdbeChangeP1(v, iAddr+4, eAuto-1);          sqlite3VdbeChangeP1(v, iAddr+5, iDb);        }      }    }  }else#endif  /*  **  PRAGMA [database.]incremental_vacuum(N)  **  ** Do N steps of incremental vacuuming on a database.  */#ifndef SQLITE_OMIT_AUTOVACUUM  if( sqlite3StrICmp(zLeft,"incremental_vacuum")==0 ){    int iLimit, addr;    if( sqlite3ReadSchema(pParse) ){      goto pragma_out;    }    if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){      iLimit = 0x7fffffff;    }    sqlite3BeginWriteOperation(pParse, 0, iDb);    sqlite3VdbeAddOp(v, OP_MemInt, iLimit, 0);    addr = sqlite3VdbeAddOp(v, OP_IncrVacuum, iDb, 0);    sqlite3VdbeAddOp(v, OP_Callback, 0, 0);    sqlite3VdbeAddOp(v, OP_MemIncr, -1, 0);    sqlite3VdbeAddOp(v, OP_IfMemPos, 0, addr);    sqlite3VdbeJumpHere(v, addr);  }else#endif#ifndef SQLITE_OMIT_PAGER_PRAGMAS  /*  **  PRAGMA [database.]cache_size  **  PRAGMA [database.]cache_size=N  **  ** The first form reports the current local setting for the  ** page cache size.  The local setting can be different from  ** the persistent cache size value that is stored in the database  ** file itself.  The value returned is the maximum number of  ** pages in the page cache.  The second form sets the local  ** page cache size value.  It does not change the persistent  ** cache size stored on the disk so the cache size will revert  ** to its default value when the database is closed and reopened.  ** N should be a positive integer.  */  if( sqlite3StrICmp(zLeft,"cache_size")==0 ){    if( sqlite3ReadSchema(pParse) ) goto pragma_out;    if( !zRight ){      returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size);    }else{      int size = atoi(zRight);      if( size<0 ) size = -size;      pDb->pSchema->cache_size = size;      sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);    }  }else  /*  **   PRAGMA temp_store  **   PRAGMA temp_store = "default"|"memory"|"file"  **  ** Return or set the local value of the temp_store flag.  Changing  ** the local value does not make changes to the disk file and the default  ** value will be restored the next time the database is opened.  **  ** Note that it is possible for the library compile-time options to  ** override this setting  */  if( sqlite3StrICmp(zLeft, "temp_store")==0 ){    if( !zRight ){      returnSingleInt(pParse, "temp_store", db->temp_store);    }else{      changeTempStorage(pParse, zRight);    }  }else  /*  **   PRAGMA temp_store_directory  **   PRAGMA temp_store_directory = ""|"directory_name"  **  ** Return or set the local value of the temp_store_directory flag.  Changing  ** the value sets a specific directory to be used for temporary files.  ** Setting to a null string reverts to the default temporary directory search.  ** If temporary directory is changed, then invalidateTempStorage.  **  */  if( sqlite3StrICmp(zLeft, "temp_store_directory")==0 ){    if( !zRight ){      if( sqlite3_temp_directory ){        sqlite3VdbeSetNumCols(v, 1);        sqlite3VdbeSetColName(v, 0, COLNAME_NAME,             "temp_store_directory", P3_STATIC);        sqlite3VdbeOp3(v, OP_String8, 0, 0, sqlite3_temp_directory, 0);        sqlite3VdbeAddOp(v, OP_Callback, 1, 0);      }    }else{      if( zRight[0] && !sqlite3OsIsDirWritable(zRight) ){        sqlite3ErrorMsg(pParse, "not a writable directory");        goto pragma_out;      }      if( TEMP_STORE==0       || (TEMP_STORE==1 && db->temp_store<=1)       || (TEMP_STORE==2 && db->temp_store==1)      ){        invalidateTempStorage(pParse);      }      sqliteFree(sqlite3_temp_directory);      if( zRight[0] ){        sqlite3_temp_directory = zRight;        zRight = 0;      }else{        sqlite3_temp_directory = 0;      }    }  }else  /*  **   PRAGMA [database.]synchronous  **   PRAGMA [database.]synchronous=OFF|ON|NORMAL|FULL  **  ** Return or set the local value of the synchronous flag.  Changing  ** the local value does not make changes to the disk file and the  ** default value will be restored the next time the database is  ** opened.  */  if( sqlite3StrICmp(zLeft,"synchronous")==0 ){    if( sqlite3ReadSchema(pParse) ) goto pragma_out;    if( !zRight ){      returnSingleInt(pParse, "synchronous", pDb->safety_level-1);    }else{      if( !db->autoCommit ){        sqlite3ErrorMsg(pParse,             "Safety level may not be changed inside a transaction");      }else{        pDb->safety_level = getSafetyLevel(zRight)+1;      }    }  }else#endif /* SQLITE_OMIT_PAGER_PRAGMAS */#ifndef SQLITE_OMIT_FLAG_PRAGMAS  if( flagPragma(pParse, zLeft, zRight) ){    /* The flagPragma() subroutine also generates any necessary code    ** there is nothing more to do here */  }else#endif /* SQLITE_OMIT_FLAG_PRAGMAS */#ifndef SQLITE_OMIT_SCHEMA_PRAGMAS  /*  **   PRAGMA table_info(<table>)  **  ** Return a single row for each column of the named table. The columns of  ** the returned data set are:  **  ** cid:        Column id (numbered from left to right, starting at 0)  ** name:       Column name  ** type:       Column declaration type.  ** notnull:    True if 'NOT NULL' is part of column declaration  ** dflt_value: The default value for the column, if any.  */  if( sqlite3StrICmp(zLeft, "table_info")==0 && zRight ){    Table *pTab;    if( sqlite3ReadSchema(pParse) ) goto pragma_out;    pTab = sqlite3FindTable(db, zRight, zDb);    if( pTab ){      int i;      int nHidden = 0;      Column *pCol;      sqlite3VdbeSetNumCols(v, 6);      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cid", P3_STATIC);      sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P3_STATIC);      sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "type", P3_STATIC);      sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "notnull", P3_STATIC);      sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "dflt_value", P3_STATIC);      sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "pk", P3_STATIC);      sqlite3ViewGetColumnNames(pParse, pTab);      for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){        const Token *pDflt;        if( IsHiddenColumn(pCol) ){          nHidden++;          continue;        }        sqlite3VdbeAddOp(v, OP_Integer, i-nHidden, 0);        sqlite3VdbeOp3(v, OP_String8, 0, 0, pCol->zName, 0);        sqlite3VdbeOp3(v, OP_String8, 0, 0,           pCol->zType ? pCol->zType : "", 0);        sqlite3VdbeAddOp(v, OP_Integer, pCol->notNull, 0);        if( pCol->pDflt && (pDflt = &pCol->pDflt->span)->z ){          sqlite3VdbeOp3(v, OP_String8, 0, 0, (char*)pDflt->z, pDflt->n);        }else{          sqlite3VdbeAddOp(v, OP_Null, 0, 0);        }        sqlite3VdbeAddOp(v, OP_Integer, pCol->isPrimKey, 0);        sqlite3VdbeAddOp(v, OP_Callback, 6, 0);      }    }  }else  if( sqlite3StrICmp(zLeft, "index_info")==0 && zRight ){    Index *pIdx;    Table *pTab;    if( sqlite3ReadSchema(pParse) ) goto pragma_out;    pIdx = sqlite3FindIndex(db, zRight, zDb);    if( pIdx ){      int i;      pTab = pIdx->pTable;      sqlite3VdbeSetNumCols(v, 3);      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seqno", P3_STATIC);      sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "cid", P3_STATIC);      sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "name", P3_STATIC);      for(i=0; i<pIdx->nColumn; i++){        int cnum = pIdx->aiColumn[i];        sqlite3VdbeAddOp(v, OP_Integer, i, 0);        sqlite3VdbeAddOp(v, OP_Integer, cnum, 0);        assert( pTab->nCol>cnum );        sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->aCol[cnum].zName, 0);        sqlite3VdbeAddOp(v, OP_Callback, 3, 0);      }    }  }else  if( sqlite3StrICmp(zLeft, "index_list")==0 && zRight ){    Index *pIdx;    Table *pTab;    if( sqlite3ReadSchema(pParse) ) goto pragma_out;    pTab = sqlite3FindTable(db, zRight, zDb);    if( pTab ){      v = sqlite3GetVdbe(pParse);      pIdx = pTab->pIndex;      if( pIdx ){        int i = 0;         sqlite3VdbeSetNumCols(v, 3);        sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", P3_STATIC);        sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P3_STATIC);        sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "unique", P3_STATIC);        while(pIdx){          sqlite3VdbeAddOp(v, OP_Integer, i, 0);          sqlite3VdbeOp3(v, OP_String8, 0, 0, pIdx->zName, 0);          sqlite3VdbeAddOp(v, OP_Integer, pIdx->onError!=OE_None, 0);          sqlite3VdbeAddOp(v, OP_Callback, 3, 0);          ++i;          pIdx = pIdx->pNext;        }      }    }  }else  if( sqlite3StrICmp(zLeft, "database_list")==0 ){    int i;    if( sqlite3ReadSchema(pParse) ) goto pragma_out;    sqlite3VdbeSetNumCols(v, 3);    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", P3_STATIC);    sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P3_STATIC);    sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "file", P3_STATIC);    for(i=0; i<db->nDb; i++){      if( db->aDb[i].pBt==0 ) continue;      assert( db->aDb[i].zName!=0 );      sqlite3VdbeAddOp(v, OP_Integer, i, 0);      sqlite3VdbeOp3(v, OP_String8, 0, 0, db->aDb[i].zName, 0);      sqlite3VdbeOp3(v, OP_String8, 0, 0,           sqlite3BtreeGetFilename(db->aDb[i].pBt), 0);      sqlite3VdbeAddOp(v, OP_Callback, 3, 0);    }  }else  if( sqlite3StrICmp(zLeft, "collation_list")==0 ){    int i = 0;    HashElem *p;    sqlite3VdbeSetNumCols(v, 2);    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", P3_STATIC);    sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P3_STATIC);    for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){      CollSeq *pColl = (CollSeq *)sqliteHashData(p);      sqlite3VdbeAddOp(v, OP_Integer, i++, 0);      sqlite3VdbeOp3(v, OP_String8, 0, 0, pColl->zName, 0);      sqlite3VdbeAddOp(v, OP_Callback, 2, 0);    }  }else#endif /* SQLITE_OMIT_SCHEMA_PRAGMAS */#ifndef SQLITE_OMIT_FOREIGN_KEY  if( sqlite3StrICmp(zLeft, "foreign_key_list")==0 && zRight ){    FKey *pFK;    Table *pTab;    if( sqlite3ReadSchema(pParse) ) goto pragma_out;    pTab = sqlite3FindTable(db, zRight, zDb);    if( pTab ){      v = sqlite3GetVdbe(pParse);      pFK = pTab->pFKey;      if( pFK ){        int i = 0;         sqlite3VdbeSetNumCols(v, 5);        sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "id", P3_STATIC);        sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "seq", P3_STATIC);        sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "table", P3_STATIC);        sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "from", P3_STATIC);        sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "to", P3_STATIC);        while(pFK){          int j;          for(j=0; j<pFK->nCol; j++){            char *zCol = pFK->aCol[j].zCol;            sqlite3VdbeAddOp(v, OP_Integer, i, 0);            sqlite3VdbeAddOp(v, OP_Integer, j, 0);            sqlite3VdbeOp3(v, OP_String8, 0, 0, pFK->zTo, 0);            sqlite3VdbeOp3(v, OP_String8, 0, 0,                             pTab->aCol[pFK->aCol[j].iFrom].zName, 0);            sqlite3VdbeOp3(v, zCol ? OP_String8 : OP_Null, 0, 0, zCol, 0);            sqlite3VdbeAddOp(v, OP_Callback, 5, 0);          }          ++i;          pFK = pFK->pNextFrom;        }      }    }  }else#endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */#ifndef NDEBUG  if( sqlite3StrICmp(zLeft, "parser_trace")==0 ){    if( zRight ){      if( getBoolean(zRight) ){        sqlite3ParserTrace(stderr, "parser: ");      }else{        sqlite3ParserTrace(0, 0);      }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -