/ Check-in [7b488362]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Clarify error handling in pager code. No functional changes. (CVS 2956)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 7b48836214ea3152f46e2dffb097ae7ea14901f4
User & Date: danielk1977 2006-01-16 11:29:19
Context
2006-01-16
12:46
Run the tests in shared.test a second time using an autovacuum database. (CVS 2957) check-in: 99275229 user: danielk1977 tags: trunk
11:29
Clarify error handling in pager code. No functional changes. (CVS 2956) check-in: 7b488362 user: danielk1977 tags: trunk
02:39
Version 3.3.1 (alpha) (CVS 2953) check-in: bd7c5699 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/pager.c.

    14     14   ** The pager is used to access a database disk file.  It implements
    15     15   ** atomic commit and rollback through the use of a journal file that
    16     16   ** is separate from the database file.  The pager also implements file
    17     17   ** locking to prevent two processes from writing the same database
    18     18   ** file simultaneously, or one process from reading the database while
    19     19   ** another is writing.
    20     20   **
    21         -** @(#) $Id: pager.c,v 1.237 2006/01/15 20:28:28 drh Exp $
           21  +** @(#) $Id: pager.c,v 1.238 2006/01/16 11:29:19 danielk1977 Exp $
    22     22   */
    23     23   #ifndef SQLITE_OMIT_DISKIO
    24     24   #include "sqliteInt.h"
    25     25   #include "os.h"
    26     26   #include "pager.h"
    27     27   #include <assert.h>
    28     28   #include <string.h>
................................................................................
   221    221   /*
   222    222   ** Hash a page number
   223    223   */
   224    224   #define pager_hash(PN)  ((PN)&(N_PG_HASH-1))
   225    225   
   226    226   /*
   227    227   ** A open page cache is an instance of the following structure.
          228  +**
          229  +** Pager.errCode may be set to SQLITE_IOERR, SQLITE_CORRUPT, SQLITE_PROTOCOL
          230  +** or SQLITE_FULL. Once one of the first three errors occurs, it persists
          231  +** and is returned as the result of every major pager API call.  The
          232  +** SQLITE_FULL return code is slightly different. It persists only until the
          233  +** next successful rollback is performed on the pager cache. Also,
          234  +** SQLITE_FULL does not affect the sqlite3pager_get() and sqlite3pager_lookup()
          235  +** APIs, they may still be used successfully.
   228    236   */
   229    237   struct Pager {
   230    238     u8 journalOpen;             /* True if journal file descriptors is valid */
   231    239     u8 journalStarted;          /* True if header of journal is synced */
   232    240     u8 useJournal;              /* Use a rollback journal on this file */
   233    241     u8 noReadlock;              /* Do not bother to obtain readlocks */
   234    242     u8 stmtOpen;                /* True if the statement subjournal is open */
   235    243     u8 stmtInUse;               /* True we are in a statement subtransaction */
   236    244     u8 stmtAutoopen;            /* Open stmt journal when main journal is opened*/
   237    245     u8 noSync;                  /* Do not sync the journal if true */
   238    246     u8 fullSync;                /* Do extra syncs of the journal for robustness */
   239    247     u8 state;                   /* PAGER_UNLOCK, _SHARED, _RESERVED, etc. */
   240         -  u8 errMask;                 /* One of several kinds of errors */
          248  +  u8 errCode;                 /* One of several kinds of errors */
   241    249     u8 tempFile;                /* zFilename is a temporary file */
   242    250     u8 readOnly;                /* True for a read-only database */
   243    251     u8 needSync;                /* True if an fsync() is needed on the journal */
   244    252     u8 dirtyCache;              /* True if cached pages have changed */
   245    253     u8 alwaysRollback;          /* Disable dont_rollback() for all pages */
   246    254     u8 memDb;                   /* True to inhibit all file I/O */
   247    255     u8 setMaster;               /* True if a m-j name has been written to jrnl */
................................................................................
   295    303   */
   296    304   #ifdef SQLITE_TEST
   297    305   # define TEST_INCR(x)  x++
   298    306   #else
   299    307   # define TEST_INCR(x)
   300    308   #endif
   301    309   
   302         -/*
   303         -** These are bits that can be set in Pager.errMask.
   304         -**
   305         -** TODO: Maybe we just want a variable - Pager.errCode. Can we really 
   306         -**       have two simultaneous error conditions?
   307         -**
   308         -** Recovering from an SQLITE_FULL, SQLITE_LOCK, SQLITE_CORRUPT or 
   309         -** SQLITE_IOERR error is not a simple matter, particularly if the pager 
   310         -** cache is shared between multiple connections.
   311         -**
   312         -** SQLITE_FULL (PAGER_ERR_FULL):
   313         -**     Cleared when the transaction is rolled back.
   314         -**
   315         -** SQLITE_CORRUPT (PAGER_ERR_CORRUPT):
   316         -**     Cannot be cleared. The upper layer must close the current pager 
   317         -**     and open a new one on the same file to continue.
   318         -**
   319         -** SQLITE_PROTOCOL (PAGER_ERR_LOCK):
   320         -**     This error only occurs if an internal error occurs or another process 
   321         -**     is not following the sqlite locking protocol (i.e. someone is 
   322         -**     manipulating the database file using something other than sqlite).
   323         -**     This is handled in the same way as database corruption - the error 
   324         -**     cannot be cleared except by closing the current pager and opening 
   325         -**     a brand new one on the same file.
   326         -**
   327         -** SQLITE_IOERR (PAGER_ERR_DISK):
   328         -**     Cleared when the transaction is rolled back.
   329         -*/
   330         -#define PAGER_ERR_FULL     0x01  /* a write() failed */
   331         -#define PAGER_ERR_LOCK     0x02  /* error in the locking protocol */
   332         -#define PAGER_ERR_CORRUPT  0x04  /* database or journal corruption */
   333         -#define PAGER_ERR_DISK     0x08  /* general disk I/O error - bad hard drive? */
   334         -
   335    310   /*
   336    311   ** Journal files begin with the following magic string.  The data
   337    312   ** was obtained from /dev/random.  It is used only as a sanity check.
   338    313   **
   339    314   ** Since version 2.8.0, the journal format contains additional sanity
   340    315   ** checking information.  If the power fails while the journal is begin
   341    316   ** written, semi-random garbage data might appear in the journal
................................................................................
   476    451   static u32 retrieve32bits(PgHdr *p, int offset){
   477    452     unsigned char *ac;
   478    453     ac = &((unsigned char*)PGHDR_TO_DATA(p))[offset];
   479    454     return (ac[0]<<24) | (ac[1]<<16) | (ac[2]<<8) | ac[3];
   480    455   }
   481    456   
   482    457   
   483         -/*
   484         -** Convert the bits in the pPager->errMask into an approprate
   485         -** return code.
   486         -*/
   487         -static int pager_errcode(Pager *pPager){
   488         -  int rc = SQLITE_OK;
   489         -  if( pPager->errMask & PAGER_ERR_LOCK )    rc = SQLITE_PROTOCOL;
   490         -  if( pPager->errMask & PAGER_ERR_DISK )    rc = SQLITE_IOERR;
   491         -  if( pPager->errMask & PAGER_ERR_FULL )    rc = SQLITE_FULL;
   492         -  if( pPager->errMask & PAGER_ERR_CORRUPT ) rc = SQLITE_CORRUPT;
   493         -  return rc;
   494         -}
   495         -
   496    458   /*
   497    459   ** This function should be called when an error occurs within the pager
   498         -** code to set the appropriate bits in Pager.errMask.
          460  +** code to set Pager.errCode.
   499    461   */
   500    462   static int pager_error(Pager *pPager, int rc){
   501         -  switch( rc ){
   502         -    case SQLITE_PROTOCOL:
   503         -      pPager->errMask |= PAGER_ERR_LOCK;
   504         -      break;
   505         -    case SQLITE_IOERR:
   506         -      pPager->errMask |= PAGER_ERR_DISK;
   507         -      break;
   508         -    case SQLITE_FULL:
   509         -      pPager->errMask |= PAGER_ERR_FULL;
   510         -      break;
   511         -    case SQLITE_CORRUPT:
   512         -      pPager->errMask |= PAGER_ERR_CORRUPT;
   513         -      break;
          463  +  assert( pPager->errCode==SQLITE_FULL || pPager->errCode==SQLITE_OK );
          464  +  if( 
          465  +    rc==SQLITE_FULL || 
          466  +    rc==SQLITE_IOERR || 
          467  +    rc==SQLITE_CORRUPT ||
          468  +    rc==SQLITE_PROTOCOL
          469  +  ){
          470  +    pPager->errCode = rc;
   514    471     }
   515    472     return rc;
   516    473   }
   517    474   
   518    475   #ifdef SQLITE_CHECK_PAGES
   519    476   /*
   520    477   ** Return a 32-bit hash of the page data for pPage.
................................................................................
   533    490   ** The CHECK_PAGE macro takes a PgHdr* as an argument. If SQLITE_CHECK_PAGES
   534    491   ** is defined, and NDEBUG is not defined, an assert() statement checks
   535    492   ** that the page is either dirty or still matches the calculated page-hash.
   536    493   */
   537    494   #define CHECK_PAGE(x) checkPage(x)
   538    495   static void checkPage(PgHdr *pPg){
   539    496     Pager *pPager = pPg->pPager;
   540         -  assert( !pPg->pageHash || pPager->errMask || MEMDB || pPg->dirty || 
          497  +  assert( !pPg->pageHash || pPager->errCode || MEMDB || pPg->dirty || 
   541    498         pPg->pageHash==pager_pagehash(pPg) );
   542    499   }
   543    500   
   544    501   #else
   545    502   #define CHECK_PAGE(x)
   546    503   #endif
   547    504   
................................................................................
   875    832   ** Unlock the database and clear the in-memory cache.  This routine
   876    833   ** sets the state of the pager back to what it was when it was first
   877    834   ** opened.  Any outstanding pages are invalidated and subsequent attempts
   878    835   ** to access those pages will likely result in a coredump.
   879    836   */
   880    837   static void pager_reset(Pager *pPager){
   881    838     PgHdr *pPg, *pNext;
   882         -  if( pPager->errMask ) return;
          839  +  if( pPager->errCode ) return;
   883    840     for(pPg=pPager->pAll; pPg; pPg=pNext){
   884    841       pNext = pPg->pNextAll;
   885    842       sqliteFree(pPg);
   886    843     }
   887    844     pPager->pFirst = 0;
   888    845     pPager->pFirstSynced = 0;
   889    846     pPager->pLast = 0;
................................................................................
  1496   1453       }
  1497   1454     }
  1498   1455   
  1499   1456     pPager->journalOff = szJ;
  1500   1457     
  1501   1458   end_stmt_playback:
  1502   1459     if( rc!=SQLITE_OK ){
  1503         -    pPager->errMask |= PAGER_ERR_CORRUPT;
  1504         -    rc = SQLITE_CORRUPT;
         1460  +    rc = pager_error(pPager, SQLITE_CORRUPT);
  1505   1461     }else{
  1506   1462       pPager->journalOff = szJ;
  1507   1463       /* pager_reload_cache(pPager); */
  1508   1464     }
  1509   1465     return rc;
  1510   1466   }
  1511   1467   
................................................................................
  1829   1785   int sqlite3pager_pagecount(Pager *pPager){
  1830   1786     i64 n;
  1831   1787     assert( pPager!=0 );
  1832   1788     if( pPager->dbSize>=0 ){
  1833   1789       n = pPager->dbSize;
  1834   1790     } else {
  1835   1791       if( sqlite3OsFileSize(pPager->fd, &n)!=SQLITE_OK ){
  1836         -      pPager->errMask |= PAGER_ERR_DISK;
         1792  +      pager_error(pPager, SQLITE_IOERR);
  1837   1793         return 0;
  1838   1794       }
  1839   1795       if( n>0 && n<pPager->pageSize ){
  1840   1796         n = 1;
  1841   1797       }else{
  1842   1798         n /= pPager->pageSize;
  1843   1799       }
................................................................................
  1975   1931   
  1976   1932   /*
  1977   1933   ** Truncate the file to the number of pages specified.
  1978   1934   */
  1979   1935   int sqlite3pager_truncate(Pager *pPager, Pgno nPage){
  1980   1936     int rc;
  1981   1937     sqlite3pager_pagecount(pPager);
  1982         -  if( pPager->errMask!=0 ){
  1983         -    rc = pager_errcode(pPager);
         1938  +  if( pPager->errCode ){
         1939  +    rc = pPager->errCode;
  1984   1940       return rc;
  1985   1941     }
  1986   1942     if( nPage>=(unsigned)pPager->dbSize ){
  1987   1943       return SQLITE_OK;
  1988   1944     }
  1989   1945     if( MEMDB ){
  1990   1946       pPager->dbSize = nPage;
................................................................................
  2039   1995         */
  2040   1996         disable_simulated_io_errors();
  2041   1997         sqlite3pager_rollback(pPager);
  2042   1998         enable_simulated_io_errors();
  2043   1999         if( !MEMDB ){
  2044   2000           sqlite3OsUnlock(pPager->fd, NO_LOCK);
  2045   2001         }
  2046         -      assert( pPager->errMask || pPager->journalOpen==0 );
         2002  +      assert( pPager->errCode || pPager->journalOpen==0 );
  2047   2003         break;
  2048   2004       }
  2049   2005       case PAGER_SHARED: {
  2050   2006         if( !MEMDB ){
  2051   2007           sqlite3OsUnlock(pPager->fd, NO_LOCK);
  2052   2008         }
  2053   2009         break;
................................................................................
  2066   2022         assert( !pHist->pStmt );
  2067   2023       }
  2068   2024   #endif
  2069   2025       pNext = pPg->pNextAll;
  2070   2026       sqliteFree(pPg);
  2071   2027     }
  2072   2028     TRACE2("CLOSE %d\n", PAGERID(pPager));
  2073         -  assert( pPager->errMask || (pPager->journalOpen==0 && pPager->stmtOpen==0) );
         2029  +  assert( pPager->errCode || (pPager->journalOpen==0 && pPager->stmtOpen==0) );
  2074   2030     if( pPager->journalOpen ){
  2075   2031       sqlite3OsClose(&pPager->jfd);
  2076   2032     }
  2077   2033     sqliteFree(pPager->aInJournal);
  2078   2034     if( pPager->stmtOpen ){
  2079   2035       sqlite3OsClose(&pPager->stfd);
  2080   2036     }
................................................................................
  2363   2319     }
  2364   2320   }
  2365   2321   
  2366   2322   /*
  2367   2323   ** Try to find a page in the cache that can be recycled. 
  2368   2324   **
  2369   2325   ** This routine may return SQLITE_IOERR, SQLITE_FULL or SQLITE_OK. It 
  2370         -** does not set the pPager->errMask variable.
         2326  +** does not set the pPager->errCode variable.
  2371   2327   */
  2372   2328   static int pager_recycle(Pager *pPager, int syncOk, PgHdr **ppPg){
  2373   2329     PgHdr *pPg;
  2374   2330     *ppPg = 0;
  2375   2331   
  2376   2332     /* Find a page to recycle.  Try to locate a page that does not
  2377   2333     ** require us to do an fsync() on the journal.
................................................................................
  2508   2464           nReleased += sqliteAllocSize(pPg);
  2509   2465           sqliteFree(pPg);
  2510   2466         }
  2511   2467   
  2512   2468         if( rc!=SQLITE_OK ){
  2513   2469           /* An error occured whilst writing to the database file or 
  2514   2470           ** journal in pager_recycle(). The error is not returned to the 
  2515         -        ** caller of this function. Instead, set the Pager.errMask variable.
         2471  +        ** caller of this function. Instead, set the Pager.errCode variable.
  2516   2472           ** The error will be returned to the user (or users, in the case 
  2517   2473           ** of a shared pager cache) of the pager for which the error occured.
  2518   2474           */
  2519   2475           assert( rc==SQLITE_IOERR || rc==SQLITE_FULL );
  2520   2476           assert( p->state>=PAGER_RESERVED );
  2521   2477           pager_error(p, rc);
  2522   2478         }
................................................................................
  2561   2517       return SQLITE_CORRUPT_BKPT;
  2562   2518     }
  2563   2519   
  2564   2520     /* Make sure we have not hit any critical errors.
  2565   2521     */ 
  2566   2522     assert( pPager!=0 );
  2567   2523     *ppPage = 0;
  2568         -  if( pPager->errMask & ~(PAGER_ERR_FULL) ){
  2569         -    return pager_errcode(pPager);
         2524  +  if( pPager->errCode && pPager->errCode!=SQLITE_FULL ){
         2525  +    return pPager->errCode;
  2570   2526     }
  2571   2527   
  2572   2528     /* If this is the first page accessed, then get a SHARED lock
  2573   2529     ** on the database file.
  2574   2530     */
  2575   2531     if( pPager->nRef==0 && !MEMDB ){
  2576   2532       if( !pPager->noReadlock ){
................................................................................
  2698   2654       if( pPg->pNextHash ){
  2699   2655         assert( pPg->pNextHash->pPrevHash==0 );
  2700   2656         pPg->pNextHash->pPrevHash = pPg;
  2701   2657       }
  2702   2658       if( pPager->nExtra>0 ){
  2703   2659         memset(PGHDR_TO_EXTRA(pPg, pPager), 0, pPager->nExtra);
  2704   2660       }
  2705         -    if( pPager->errMask!=0 ){
         2661  +    if( pPager->errCode ){
  2706   2662         sqlite3pager_unref(PGHDR_TO_DATA(pPg));
  2707         -      rc = pager_errcode(pPager);
         2663  +      rc = pPager->errCode;
  2708   2664         return rc;
  2709   2665       }
  2710   2666       if( sqlite3pager_pagecount(pPager)<(int)pgno ){
  2711   2667         memset(PGHDR_TO_DATA(pPg), 0, pPager->pageSize);
  2712   2668       }else{
  2713   2669         int rc;
  2714   2670         assert( MEMDB==0 );
................................................................................
  2757   2713   ** has ever happened.
  2758   2714   */
  2759   2715   void *sqlite3pager_lookup(Pager *pPager, Pgno pgno){
  2760   2716     PgHdr *pPg;
  2761   2717   
  2762   2718     assert( pPager!=0 );
  2763   2719     assert( pgno!=0 );
  2764         -  if( pPager->errMask & ~(PAGER_ERR_FULL) ){
         2720  +  if( pPager->errCode && pPager->errCode!=SQLITE_FULL ){
  2765   2721       return 0;
  2766   2722     }
  2767   2723     pPg = pager_lookup(pPager, pgno);
  2768   2724     if( pPg==0 ) return 0;
  2769   2725     page_ref(pPg);
  2770   2726     return PGHDR_TO_DATA(pPg);
  2771   2727   }
................................................................................
  2855   2811     sqlite3OsSetFullSync(pPager->fd, pPager->fullSync);
  2856   2812     sqlite3OsOpenDirectory(pPager->jfd, pPager->zDirectory);
  2857   2813     pPager->journalOpen = 1;
  2858   2814     pPager->journalStarted = 0;
  2859   2815     pPager->needSync = 0;
  2860   2816     pPager->alwaysRollback = 0;
  2861   2817     pPager->nRec = 0;
  2862         -  if( pPager->errMask!=0 ){
  2863         -    rc = pager_errcode(pPager);
         2818  +  if( pPager->errCode ){
         2819  +    rc = pPager->errCode;
  2864   2820       goto failed_to_open_journal;
  2865   2821     }
  2866   2822     pPager->origDbSize = pPager->dbSize;
  2867   2823   
  2868   2824     rc = writeJournalHdr(pPager);
  2869   2825   
  2870   2826     if( pPager->stmtAutoopen && rc==SQLITE_OK ){
................................................................................
  2974   2930   int sqlite3pager_write(void *pData){
  2975   2931     PgHdr *pPg = DATA_TO_PGHDR(pData);
  2976   2932     Pager *pPager = pPg->pPager;
  2977   2933     int rc = SQLITE_OK;
  2978   2934   
  2979   2935     /* Check for errors
  2980   2936     */
  2981         -  if( pPager->errMask ){ 
  2982         -    return pager_errcode(pPager);
         2937  +  if( pPager->errCode ){ 
         2938  +    return pPager->errCode;
  2983   2939     }
  2984   2940     if( pPager->readOnly ){
  2985   2941       return SQLITE_PERM;
  2986   2942     }
  2987   2943   
  2988   2944     assert( !pPager->setMaster );
  2989   2945   
................................................................................
  3049   3005             pPager->journalOff += szPg;
  3050   3006             TRACE4("JOURNAL %d page %d needSync=%d\n",
  3051   3007                     PAGERID(pPager), pPg->pgno, pPg->needSync);
  3052   3008             CODEC(pPager, pData, pPg->pgno, 0);
  3053   3009             *(u32*)PGHDR_TO_EXTRA(pPg, pPager) = saved;
  3054   3010             if( rc!=SQLITE_OK ){
  3055   3011               sqlite3pager_rollback(pPager);
  3056         -            pPager->errMask |= PAGER_ERR_FULL;
         3012  +            if( !pPager->errCode ){
         3013  +              pager_error(pPager, SQLITE_FULL);
         3014  +            }
  3057   3015               return rc;
  3058   3016             }
  3059   3017             pPager->nRec++;
  3060   3018             assert( pPager->aInJournal!=0 );
  3061   3019             pPager->aInJournal[pPg->pgno/8] |= 1<<(pPg->pgno&7);
  3062   3020             pPg->needSync = !pPager->noSync;
  3063   3021             if( pPager->stmtInUse ){
................................................................................
  3096   3054           CODEC(pPager, pData, pPg->pgno, 7);
  3097   3055           rc = sqlite3OsWrite(pPager->stfd,((char*)pData)-4,
  3098   3056                                  pPager->pageSize+4);
  3099   3057           TRACE3("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno);
  3100   3058           CODEC(pPager, pData, pPg->pgno, 0);
  3101   3059           if( rc!=SQLITE_OK ){
  3102   3060             sqlite3pager_rollback(pPager);
  3103         -          pPager->errMask |= PAGER_ERR_FULL;
         3061  +          if( !pPager->errCode ){
         3062  +            pager_error(pPager, SQLITE_FULL);
         3063  +          }
  3104   3064             return rc;
  3105   3065           }
  3106   3066           pPager->stmtNRec++;
  3107   3067           assert( pPager->aInStmt!=0 );
  3108   3068           pPager->aInStmt[pPg->pgno/8] |= 1<<(pPg->pgno&7);
  3109   3069         }
  3110   3070         page_add_to_stmt_list(pPg);
................................................................................
  3256   3216   ** and an error code is returned.  If the commit worked, SQLITE_OK
  3257   3217   ** is returned.
  3258   3218   */
  3259   3219   int sqlite3pager_commit(Pager *pPager){
  3260   3220     int rc;
  3261   3221     PgHdr *pPg;
  3262   3222   
  3263         -  if( pPager->errMask==PAGER_ERR_FULL ){
         3223  +  if( pPager->errCode==SQLITE_FULL ){
  3264   3224       rc = sqlite3pager_rollback(pPager);
  3265   3225       if( rc==SQLITE_OK ){
  3266   3226         rc = SQLITE_FULL;
  3267   3227       }
  3268   3228       return rc;
  3269   3229     }
  3270         -  if( pPager->errMask!=0 ){
  3271         -    rc = pager_errcode(pPager);
         3230  +  if( pPager->errCode ){
         3231  +    rc = pPager->errCode;
  3272   3232       return rc;
  3273   3233     }
  3274   3234     if( pPager->state<PAGER_RESERVED ){
  3275   3235       return SQLITE_ERROR;
  3276   3236     }
  3277   3237     TRACE2("COMMIT %d\n", PAGERID(pPager));
  3278   3238     if( MEMDB ){
................................................................................
  3375   3335   
  3376   3336     if( !pPager->dirtyCache || !pPager->journalOpen ){
  3377   3337       rc = pager_unwritelock(pPager);
  3378   3338       pPager->dbSize = -1;
  3379   3339       return rc;
  3380   3340     }
  3381   3341   
  3382         -  if( pPager->errMask!=0 && pPager->errMask!=PAGER_ERR_FULL ){
         3342  +  if( pPager->errCode && pPager->errCode!=SQLITE_FULL ){
  3383   3343       if( pPager->state>=PAGER_EXCLUSIVE ){
  3384   3344         pager_playback(pPager);
  3385   3345       }
  3386         -    return pager_errcode(pPager);
         3346  +    return pPager->errCode;
  3387   3347     }
  3388   3348     if( pPager->state==PAGER_RESERVED ){
  3389   3349       int rc2;
  3390   3350       rc = pager_reload_cache(pPager);
  3391   3351       rc2 = pager_unwritelock(pPager);
  3392   3352       if( rc==SQLITE_OK ){
  3393   3353         rc = rc2;
  3394   3354       }
  3395   3355     }else{
  3396   3356       rc = pager_playback(pPager);
  3397   3357     }
  3398   3358     if( rc!=SQLITE_OK ){
  3399   3359       rc = SQLITE_CORRUPT_BKPT;
  3400         -    pPager->errMask |= PAGER_ERR_CORRUPT;
         3360  +    pager_error(pPager, SQLITE_CORRUPT);
  3401   3361     }
  3402   3362     pPager->dbSize = -1;
  3403   3363     return rc;
  3404   3364   }
  3405   3365   
  3406   3366   /*
  3407   3367   ** Return TRUE if the database file is opened read-only.  Return FALSE
................................................................................
  3417   3377   int *sqlite3pager_stats(Pager *pPager){
  3418   3378     static int a[11];
  3419   3379     a[0] = pPager->nRef;
  3420   3380     a[1] = pPager->nPage;
  3421   3381     a[2] = pPager->mxPage;
  3422   3382     a[3] = pPager->dbSize;
  3423   3383     a[4] = pPager->state;
  3424         -  a[5] = pPager->errMask;
         3384  +  a[5] = pPager->errCode;
  3425   3385   #ifdef SQLITE_TEST
  3426   3386     a[6] = pPager->nHit;
  3427   3387     a[7] = pPager->nMiss;
  3428   3388     a[8] = pPager->nOvfl;
  3429   3389     a[9] = pPager->nRead;
  3430   3390     a[10] = pPager->nWrite;
  3431   3391   #endif

Changes to src/prepare.c.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains the implementation of the sqlite3_prepare()
    13     13   ** interface, and routines that contribute to loading the database schema
    14     14   ** from disk.
    15     15   **
    16         -** $Id: prepare.c,v 1.22 2006/01/13 06:33:24 danielk1977 Exp $
           16  +** $Id: prepare.c,v 1.23 2006/01/16 11:29:20 danielk1977 Exp $
    17     17   */
    18     18   #include "sqliteInt.h"
    19     19   #include "os.h"
    20     20   #include <ctype.h>
    21     21   
    22     22   /*
    23     23   ** Fill the InitData structure with an error message that indicates
................................................................................
   491    491     const char** pzTail       /* OUT: End of parsed string */
   492    492   ){
   493    493     Parse sParse;
   494    494     char *zErrMsg = 0;
   495    495     int rc = SQLITE_OK;
   496    496     int i;
   497    497   
          498  +  /* Assert that malloc() has not failed */
   498    499     assert( !sqlite3ThreadDataReadOnly()->mallocFailed );
   499    500   
   500    501     assert( ppStmt );
   501    502     *ppStmt = 0;
   502    503     if( sqlite3SafetyOn(db) ){
   503    504       return SQLITE_MISUSE;
   504    505     }

Changes to src/sqliteInt.h.

     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   ** Internal interface definitions for SQLite.
    13     13   **
    14         -** @(#) $Id: sqliteInt.h,v 1.467 2006/01/13 06:33:24 danielk1977 Exp $
           14  +** @(#) $Id: sqliteInt.h,v 1.468 2006/01/16 11:29:20 danielk1977 Exp $
    15     15   */
    16     16   #ifndef _SQLITEINT_H_
    17     17   #define _SQLITEINT_H_
    18     18   
    19     19   /*
    20     20   ** Extra interface definitions for those who need them
    21     21   */
................................................................................
  1750   1750   #ifndef SQLITE_OMIT_SHARED_CACHE
  1751   1751     void sqlite3TableLock(Parse *, int, int, u8, const char *);
  1752   1752   #else
  1753   1753     #define sqlite3TableLock(v,w,x,y,z)
  1754   1754   #endif
  1755   1755   
  1756   1756   void sqlite3MallocClearFailed();
  1757         -#ifdef NDEBUG
         1757  +#ifndef SQLITE_MEMDEBUG
  1758   1758     #define sqlite3MallocDisallow()
  1759   1759     #define sqlite3MallocAllow()
  1760   1760   #else
  1761   1761     void sqlite3MallocDisallow();
  1762   1762     void sqlite3MallocAllow();
  1763   1763   #endif
  1764   1764   
  1765   1765   #ifdef SQLITE_SSE
  1766   1766   #include "sseInt.h"
  1767   1767   #endif
  1768   1768   
  1769   1769   #endif

Changes to src/vdbeapi.c.

   152    152   ** statement is completely executed or an error occurs.
   153    153   */
   154    154   int sqlite3_step(sqlite3_stmt *pStmt){
   155    155     Vdbe *p = (Vdbe*)pStmt;
   156    156     sqlite3 *db;
   157    157     int rc;
   158    158   
   159         -  assert(!sqlite3ThreadDataReadOnly()->mallocFailed);
          159  +  /* Assert that malloc() has not failed */
          160  +  assert( !sqlite3ThreadDataReadOnly()->mallocFailed );
   160    161   
   161    162     if( p==0 || p->magic!=VDBE_MAGIC_RUN ){
   162    163       return SQLITE_MISUSE;
   163    164     }
   164    165     if( p->aborted ){
   165    166       return SQLITE_ABORT;
   166    167     }