Пример #1
0
    /*
    ** Shutdown the page cache.  Free all memory and close all files.
    **
    ** If a transaction was in progress when this routine is called, that
    ** transaction is rolled back.  All outstanding pages are invalidated
    ** and their memory is freed.  Any attempt to use a page associated
    ** with this page cache after this function returns will likely
    ** result in a coredump.
    **
    ** This function always succeeds. If a transaction is active an attempt
    ** is made to roll it back. If an error occurs during the rollback
    ** a hot journal may be left in the filesystem but no error is returned
    ** to the caller.
    */
    static int sqlite3PagerClose( Pager pPager )
    {
#if SQLITE_TEST
      disable_simulated_io_errors();
#endif
      sqlite3BeginBenignMalloc();
      pPager.errCode = 0;
      pPager.exclusiveMode = false;
      pager_reset( pPager );
      if (
#if SQLITE_OMIT_MEMORYDB
1==MEMDB
#else
 1 == pPager.memDb
#endif
 )
      {
        pager_unlock( pPager );
      }
      else
      {
        /* Set Pager.journalHdr to -1 for the benefit of the pager_playback()
        ** call which may be made from within pagerUnlockAndRollback(). If it
        ** is not -1, then the unsynced portion of an open journal file may
        ** be played back into the database. If a power failure occurs while
        ** this is happening, the database may become corrupt.
        */
        pPager.journalHdr = -1;
        pagerUnlockAndRollback( pPager );
      }
      sqlite3EndBenignMalloc();
#if SQLITE_TEST
      enable_simulated_io_errors();
#endif

      PAGERTRACE( "CLOSE %d\n", PAGERID( pPager ) );
      IOTRACE( "CLOSE %p\n", pPager );
      sqlite3OsClose( pPager.fd );
      //sqlite3_free( ref  pPager.pTmpSpace );
      sqlite3PcacheClose( pPager.pPCache );

#if SQLITE_HAS_CODEC
      if ( pPager.xCodecFree != null ) pPager.xCodecFree(ref pPager.pCodec );
#endif
      Debug.Assert( null == pPager.aSavepoint && !pPager.pInJournal );
      Debug.Assert( !isOpen( pPager.jfd ) && !isOpen( pPager.sjfd ) );

      //sqlite3_free( ref  pPager );
      return SQLITE_OK;
    }
Пример #2
0
/*
** Set or retrieve the codec for this pager
*/
    static void sqlite3PagerSetCodec(
    Pager pPager,
    dxCodec xCodec,                 //void *(*xCodec)(void*,void*,Pgno,int),
    dxCodecSizeChng xCodecSizeChng, //void (*xCodecSizeChng)(void*,int,int),
    dxCodecFree xCodecFree,         //void (*xCodecFree)(void*),
    codec_ctx pCodec
    )
    {
      if ( pPager.xCodecFree != null ) pPager.xCodecFree( ref pPager.pCodec );
      pPager.xCodec = (pPager.memDb!=0) ? null : xCodec;
      pPager.xCodecSizeChng = xCodecSizeChng;
      pPager.xCodecFree = xCodecFree;
      pPager.pCodec = pCodec;
      pagerReportSize( pPager );
    }
Пример #3
0
        /*
        ** Shutdown the page cache.  Free all memory and close all files.
        **
        ** If a transaction was in progress when this routine is called, that
        ** transaction is rolled back.  All outstanding pages are invalidated
        ** and their memory is freed.  Any attempt to use a page associated
        ** with this page cache after this function returns will likely
        ** result in a coredump.
        **
        ** This function always succeeds. If a transaction is active an attempt
        ** is made to roll it back. If an error occurs during the rollback
        ** a hot journal may be left in the filesystem but no error is returned
        ** to the caller.
        */
        static int sqlite3PagerClose( Pager pPager )
        {
            u8[] pTmp = pPager.pTmpSpace;
            #if SQLITE_TEST
              disable_simulated_io_errors();
            #endif
              sqlite3BeginBenignMalloc();
              /* pPager->errCode = 0; */
              pPager.exclusiveMode = false;
            #if !SQLITE_OMIT_WAL
            sqlite3WalClose(pPager->pWal, pPager->ckptSyncFlags, pPager->pageSize, pTmp);
            pPager.pWal = 0;
            #endif
              pager_reset( pPager );
              if (
            #if SQLITE_OMIT_MEMORYDB
            1==MEMDB
            #else
             1 == pPager.memDb
            #endif
             )
              {
            pager_unlock( pPager );
              }
              else
              {
            /* If it is open, sync the journal file before calling UnlockAndRollback.
            ** If this is not done, then an unsynced portion of the open journal
            ** file may be played back into the database. If a power failure occurs
            ** while this is happening, the database could become corrupt.
            **
            ** If an error occurs while trying to sync the journal, shift the pager
            ** into the ERROR state. This causes UnlockAndRollback to unlock the
            ** database and close the journal file without attempting to roll it
            ** back or finalize it. The next database user will have to do hot-journal
            ** rollback before accessing the database file.
            */
            if ( isOpen( pPager.jfd ) )
            {
              pager_error( pPager, pagerSyncHotJournal( pPager ) );
            }
            pagerUnlockAndRollback( pPager );
              }
              sqlite3EndBenignMalloc();
            #if SQLITE_TEST
              enable_simulated_io_errors();
            #endif

              PAGERTRACE( "CLOSE %d\n", PAGERID( pPager ) );
              IOTRACE( "CLOSE %p\n", pPager );
              sqlite3OsClose( pPager.jfd );
              sqlite3OsClose( pPager.fd );
              //sqlite3_free( ref  pTmp );
              sqlite3PcacheClose( pPager.pPCache );

            #if SQLITE_HAS_CODEC
              if ( pPager.xCodecFree != null )
            pPager.xCodecFree( ref pPager.pCodec );
            #endif
              Debug.Assert( null == pPager.aSavepoint && !pPager.pInJournal );
              Debug.Assert( !isOpen( pPager.jfd ) && !isOpen( pPager.sjfd ) );

              //sqlite3_free( ref  pPager );
              return SQLITE_OK;
        }