/ Check-in [85e6a474]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Make sure the VACUUM statement locks down the page_size and auto_vacuum modes after it runs. Otherwise, pragmas might change these settings on a populated database, resulting in problems. (CVS 6442)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:85e6a4740d6db731c8c35a331031c346e9189c27
User & Date: drh 2009-04-02 20:16:59
Context
2009-04-02
20:27
Make sure count(*) works on the sqlite_master table of an empty database. Ticket #3774. (CVS 6443) check-in: e0c1a780 user: drh tags: trunk
20:16
Make sure the VACUUM statement locks down the page_size and auto_vacuum modes after it runs. Otherwise, pragmas might change these settings on a populated database, resulting in problems. (CVS 6442) check-in: 85e6a474 user: drh tags: trunk
18:32
Fix the sqlite3_prepare() family of interfaces so that they zero the *ppStmt value even on an SQLITE_MISUSE return. Make it clear in the documentation that the ppStmt parameter cannot be zero. (CVS 6441) check-in: 23bf9f26 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

     5      5   ** a legal notice, here is a blessing:
     6      6   **
     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12         -** $Id: btree.c,v 1.588 2009/04/02 18:28:08 danielk1977 Exp $
           12  +** $Id: btree.c,v 1.589 2009/04/02 20:16:59 drh Exp $
    13     13   **
    14     14   ** This file implements a external (disk-based) database using BTrees.
    15     15   ** See the header comment on "btreeInt.h" for additional information.
    16     16   ** Including a description of file format and an overview of operation.
    17     17   */
    18     18   #include "btreeInt.h"
    19     19   
................................................................................
  1753   1753     sqlite3BtreeLeave(p);
  1754   1754     return rc;
  1755   1755   }
  1756   1756   
  1757   1757   #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) || !defined(SQLITE_OMIT_VACUUM)
  1758   1758   /*
  1759   1759   ** Change the default pages size and the number of reserved bytes per page.
         1760  +** Or, if the page size has already been fixed, return SQLITE_READONLY 
         1761  +** without changing anything.
  1760   1762   **
  1761   1763   ** The page size must be a power of 2 between 512 and 65536.  If the page
  1762   1764   ** size supplied does not meet this constraint then the page size is not
  1763   1765   ** changed.
  1764   1766   **
  1765   1767   ** Page sizes are constrained to be a power of two so that the region
  1766   1768   ** of the database file used for locking (beginning at PENDING_BYTE,
  1767   1769   ** the first byte past the 1GB boundary, 0x40000000) needs to occur
  1768   1770   ** at the beginning of a page.
  1769   1771   **
  1770   1772   ** If parameter nReserve is less than zero, then the number of reserved
  1771   1773   ** bytes per page is left unchanged.
         1774  +**
         1775  +** If the iFix!=0 then the pageSizeFixed flag is set so that the page size
         1776  +** and autovacuum mode can no longer be changed.
  1772   1777   */
  1773         -int sqlite3BtreeSetPageSize(Btree *p, int pageSize, int nReserve){
         1778  +int sqlite3BtreeSetPageSize(Btree *p, int pageSize, int nReserve, int iFix){
  1774   1779     int rc = SQLITE_OK;
  1775   1780     BtShared *pBt = p->pBt;
  1776   1781     assert( nReserve>=-1 && nReserve<=255 );
  1777   1782     sqlite3BtreeEnter(p);
  1778   1783     if( pBt->pageSizeFixed ){
  1779   1784       sqlite3BtreeLeave(p);
  1780   1785       return SQLITE_READONLY;
................................................................................
  1788   1793       assert( (pageSize & 7)==0 );
  1789   1794       assert( !pBt->pPage1 && !pBt->pCursor );
  1790   1795       pBt->pageSize = (u16)pageSize;
  1791   1796       freeTempSpace(pBt);
  1792   1797       rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize);
  1793   1798     }
  1794   1799     pBt->usableSize = pBt->pageSize - (u16)nReserve;
         1800  +  if( iFix ) pBt->pageSizeFixed = 1;
  1795   1801     sqlite3BtreeLeave(p);
  1796   1802     return rc;
  1797   1803   }
  1798   1804   
  1799   1805   /*
  1800   1806   ** Return the currently defined page size
  1801   1807   */

Changes to src/btree.h.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This header file defines the interface that the sqlite B-Tree file
    13     13   ** subsystem.  See comments in the source code for a detailed description
    14     14   ** of what each interface routine does.
    15     15   **
    16         -** @(#) $Id: btree.h,v 1.111 2009/03/18 10:33:01 danielk1977 Exp $
           16  +** @(#) $Id: btree.h,v 1.112 2009/04/02 20:16:59 drh Exp $
    17     17   */
    18     18   #ifndef _BTREE_H_
    19     19   #define _BTREE_H_
    20     20   
    21     21   /* TODO: This definition is just included so other modules compile. It
    22     22   ** needs to be revisited.
    23     23   */
................................................................................
    76     76   #define BTREE_READWRITE    16  /* Open for both reading and writing */
    77     77   #define BTREE_CREATE       32  /* Create the database if it does not exist */
    78     78   
    79     79   int sqlite3BtreeClose(Btree*);
    80     80   int sqlite3BtreeSetCacheSize(Btree*,int);
    81     81   int sqlite3BtreeSetSafetyLevel(Btree*,int,int);
    82     82   int sqlite3BtreeSyncDisabled(Btree*);
    83         -int sqlite3BtreeSetPageSize(Btree*,int,int);
           83  +int sqlite3BtreeSetPageSize(Btree*,int,int,int);
    84     84   int sqlite3BtreeGetPageSize(Btree*);
    85     85   int sqlite3BtreeMaxPageCount(Btree*,int);
    86     86   int sqlite3BtreeGetReserve(Btree*);
    87     87   int sqlite3BtreeSetAutoVacuum(Btree *, int);
    88     88   int sqlite3BtreeGetAutoVacuum(Btree *);
    89     89   int sqlite3BtreeBeginTrans(Btree*,int);
    90     90   int sqlite3BtreeCommitPhaseOne(Btree*, const char *zMaster);

Changes to src/pragma.c.

     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code used to implement the PRAGMA command.
    13     13   **
    14         -** $Id: pragma.c,v 1.204 2009/02/23 16:52:08 drh Exp $
           14  +** $Id: pragma.c,v 1.205 2009/04/02 20:16:59 drh Exp $
    15     15   */
    16     16   #include "sqliteInt.h"
    17     17   
    18     18   /* Ignore this whole file if pragmas are disabled
    19     19   */
    20     20   #if !defined(SQLITE_OMIT_PRAGMA) && !defined(SQLITE_OMIT_PARSER)
    21     21   
................................................................................
   365    365         int size = ALWAYS(pBt) ? sqlite3BtreeGetPageSize(pBt) : 0;
   366    366         returnSingleInt(pParse, "page_size", size);
   367    367       }else{
   368    368         /* Malloc may fail when setting the page-size, as there is an internal
   369    369         ** buffer that the pager module resizes using sqlite3_realloc().
   370    370         */
   371    371         db->nextPagesize = atoi(zRight);
   372         -      if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, -1) ){
          372  +      if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, -1, 0) ){
   373    373           db->mallocFailed = 1;
   374    374         }
   375    375       }
   376    376     }else
   377    377   
   378    378     /*
   379    379     **  PRAGMA [database.]max_page_count

Changes to src/vacuum.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code used to implement the VACUUM command.
    13     13   **
    14     14   ** Most of the code in this file may be omitted by defining the
    15     15   ** SQLITE_OMIT_VACUUM macro.
    16     16   **
    17         -** $Id: vacuum.c,v 1.86 2009/02/03 16:51:25 danielk1977 Exp $
           17  +** $Id: vacuum.c,v 1.87 2009/04/02 20:16:59 drh Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include "vdbeInt.h"
    21     21   
    22     22   #if !defined(SQLITE_OMIT_VACUUM) && !defined(SQLITE_OMIT_ATTACH)
    23     23   /*
    24     24   ** Execute zSql on database db. Return an error code.
................................................................................
   136    136       int nKey;
   137    137       char *zKey;
   138    138       sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
   139    139       if( nKey ) db->nextPagesize = 0;
   140    140     }
   141    141   #endif
   142    142   
   143         -  if( sqlite3BtreeSetPageSize(pTemp, sqlite3BtreeGetPageSize(pMain), nRes)
   144         -   || (!isMemDb && sqlite3BtreeSetPageSize(pTemp, db->nextPagesize, nRes))
          143  +  if( sqlite3BtreeSetPageSize(pTemp, sqlite3BtreeGetPageSize(pMain), nRes, 0)
          144  +   || (!isMemDb && sqlite3BtreeSetPageSize(pTemp, db->nextPagesize, nRes, 0))
   145    145      || db->mallocFailed 
   146    146     ){
   147    147       rc = SQLITE_NOMEM;
   148    148       goto end_of_vacuum;
   149    149     }
   150    150     rc = execSql(db, "PRAGMA vacuum_db.synchronous=OFF");
   151    151     if( rc!=SQLITE_OK ){
................................................................................
   264    264       if( rc!=SQLITE_OK ) goto end_of_vacuum;
   265    265   #ifndef SQLITE_OMIT_AUTOVACUUM
   266    266       sqlite3BtreeSetAutoVacuum(pMain, sqlite3BtreeGetAutoVacuum(pTemp));
   267    267   #endif
   268    268     }
   269    269   
   270    270     if( rc==SQLITE_OK ){
   271         -    rc = sqlite3BtreeSetPageSize(pMain, sqlite3BtreeGetPageSize(pTemp), nRes);
          271  +    rc = sqlite3BtreeSetPageSize(pMain, sqlite3BtreeGetPageSize(pTemp), nRes,1);
   272    272     }
   273    273   
   274    274   end_of_vacuum:
   275    275     /* Restore the original value of db->flags */
   276    276     db->flags = saved_flags;
   277    277     db->nChange = saved_nChange;
   278    278     db->nTotalChange = saved_nTotalChange;