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

📄 pragma.c

📁 最新的sqlite3.6.2源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
  /*  **  PRAGMA [database.]page_size  **  PRAGMA [database.]page_size=N  **  ** The first form reports the current setting for the  ** database page size in bytes.  The second form sets the  ** database page size value.  The value can only be set if  ** the database has not yet been created.  */  if( sqlite3StrICmp(zLeft,"page_size")==0 ){    Btree *pBt = pDb->pBt;    if( !zRight ){      int size = pBt ? sqlite3BtreeGetPageSize(pBt) : 0;      returnSingleInt(pParse, "page_size", size);    }else{      /* Malloc may fail when setting the page-size, as there is an internal      ** buffer that the pager module resizes using sqlite3_realloc().      */      db->nextPagesize = atoi(zRight);      if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, -1) ){        db->mallocFailed = 1;      }    }  }else  /*  **  PRAGMA [database.]max_page_count  **  PRAGMA [database.]max_page_count=N  **  ** The first form reports the current setting for the  ** maximum number of pages in the database file.  The   ** second form attempts to change this setting.  Both  ** forms return the current setting.  */  if( sqlite3StrICmp(zLeft,"max_page_count")==0 ){    Btree *pBt = pDb->pBt;    int newMax = 0;    if( zRight ){      newMax = atoi(zRight);    }    if( pBt ){      newMax = sqlite3BtreeMaxPageCount(pBt, newMax);    }    returnSingleInt(pParse, "max_page_count", newMax);  }else  /*  **  PRAGMA [database.]page_count  **  ** Return the number of pages in the specified database.  */  if( sqlite3StrICmp(zLeft,"page_count")==0 ){    Vdbe *v;    int iReg;    v = sqlite3GetVdbe(pParse);    if( !v || sqlite3ReadSchema(pParse) ) goto pragma_out;    sqlite3CodeVerifySchema(pParse, iDb);    iReg = ++pParse->nMem;    sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg);    sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1);    sqlite3VdbeSetNumCols(v, 1);    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "page_count", P4_STATIC);  }else  /*  **  PRAGMA [database.]locking_mode  **  PRAGMA [database.]locking_mode = (normal|exclusive)  */  if( sqlite3StrICmp(zLeft,"locking_mode")==0 ){    const char *zRet = "normal";    int eMode = getLockingMode(zRight);    if( pId2->n==0 && eMode==PAGER_LOCKINGMODE_QUERY ){      /* Simple "PRAGMA locking_mode;" statement. This is a query for      ** the current default locking mode (which may be different to      ** the locking-mode of the main database).      */      eMode = db->dfltLockMode;    }else{      Pager *pPager;      if( pId2->n==0 ){        /* This indicates that no database name was specified as part        ** of the PRAGMA command. In this case the locking-mode must be        ** set on all attached databases, as well as the main db file.        **        ** Also, the sqlite3.dfltLockMode variable is set so that        ** any subsequently attached databases also use the specified        ** locking mode.        */        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", P4_STATIC);    sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, zRet, 0);    sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);  }else  /*  **  PRAGMA [database.]journal_mode  **  PRAGMA [database.]journal_mode = (delete|persist|off)  */  if( sqlite3StrICmp(zLeft,"journal_mode")==0 ){    int eMode;    static const char *azModeName[] = {"delete", "persist", "off"};    if( zRight==0 ){      eMode = PAGER_JOURNALMODE_QUERY;    }else{      int n = strlen(zRight);      eMode = 2;      while( eMode>=0 && sqlite3StrNICmp(zRight, azModeName[eMode], n)!=0 ){        eMode--;      }    }    if( pId2->n==0 && eMode==PAGER_JOURNALMODE_QUERY ){      /* Simple "PRAGMA journal_mode;" statement. This is a query for      ** the current default journal mode (which may be different to      ** the journal-mode of the main database).      */      eMode = db->dfltJournalMode;    }else{      Pager *pPager;      if( pId2->n==0 ){        /* This indicates that no database name was specified as part        ** of the PRAGMA command. In this case the journal-mode must be        ** set on all attached databases, as well as the main db file.        **        ** Also, the sqlite3.dfltJournalMode variable is set so that        ** any subsequently attached databases also use the specified        ** journal mode.        */        int ii;        assert(pDb==&db->aDb[0]);        for(ii=1; ii<db->nDb; ii++){          if( db->aDb[ii].pBt ){            pPager = sqlite3BtreePager(db->aDb[ii].pBt);            sqlite3PagerJournalMode(pPager, eMode);          }        }        db->dfltJournalMode = eMode;      }      pPager = sqlite3BtreePager(pDb->pBt);      eMode = sqlite3PagerJournalMode(pPager, eMode);    }    assert( eMode==PAGER_JOURNALMODE_DELETE              || eMode==PAGER_JOURNALMODE_PERSIST              || eMode==PAGER_JOURNALMODE_OFF );    sqlite3VdbeSetNumCols(v, 1);    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "journal_mode", P4_STATIC);    sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0,            azModeName[eMode], P4_STATIC);    sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);  }else  /*  **  PRAGMA [database.]journal_size_limit  **  PRAGMA [database.]journal_size_limit=N  **  ** Get or set the (boolean) value of the database 'auto-vacuum' parameter.  */  if( sqlite3StrICmp(zLeft,"journal_size_limit")==0 ){    Pager *pPager = sqlite3BtreePager(pDb->pBt);    i64 iLimit = -2;    if( zRight ){      int iLimit32 = atoi(zRight);      if( iLimit32<-1 ){        iLimit32 = -1;      }      iLimit = iLimit32;    }    iLimit = sqlite3PagerJournalSizeLimit(pPager, iLimit);    returnSingleInt(pParse, "journal_size_limit", (int)iLimit);  }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);      db->nextAutovac = eAuto;      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,               1,        3},    /* 1 */            { OP_If,             1,               0,        0},    /* 2 */            { OP_Halt,           SQLITE_OK,       OE_Abort, 0},    /* 3 */            { OP_Integer,        0,               1,        0},    /* 4 */            { OP_SetCookie,      0,               6,        1},    /* 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);          sqlite3VdbeUsesBtree(v, 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);    sqlite3VdbeAddOp2(v, OP_Integer, iLimit, 1);    addr = sqlite3VdbeAddOp1(v, OP_IncrVacuum, iDb);    sqlite3VdbeAddOp1(v, OP_ResultRow, 1);    sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);    sqlite3VdbeAddOp2(v, OP_IfPos, 1, 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", P4_STATIC);        sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, sqlite3_temp_directory, 0);        sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);

⌨️ 快捷键说明

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