Пример #1
0
        // This function is invoked once for each page that has already been written into the log file when a WAL transaction is rolled back.
        // Parameter iPg is the page number of said page. The pCtx argument is actually a pointer to the Pager structure.
        //
        // If page iPg is present in the cache, and has no outstanding references, it is discarded. Otherwise, if there are one or more outstanding
        // references, the page content is reloaded from the database. If the attempt to reload content from the database is required and fails,
        // return an SQLite error code. Otherwise, SQLITE.OK.
        static int pagerUndoCallback(Pager pCtx, Pgno iPg)
        {
            var   rc     = SQLITE.OK;
            Pager pPager = (Pager)pCtx;
            PgHdr pPg;

            pPg = sqlite3PagerLookup(pPager, iPg);
            if (pPg)
            {
                if (sqlite3PcachePageRefcount(pPg) == 1)
                {
                    sqlite3PcacheDrop(pPg);
                }
                else
                {
                    rc = readDbPage(pPg);
                    if (rc == SQLITE.OK)
                    {
                        pPager.xReiniter(pPg);
                    }
                    sqlite3PagerUnref(pPg);
                }
            }
            // Normally, if a transaction is rolled back, any backup processes are updated as data is copied out of the rollback journal and into the
            // database. This is not generally possible with a WAL database, as rollback involves simply truncating the log file. Therefore, if one
            // or more frames have already been written to the log (and therefore also copied into the backup databases) as part of this transaction,
            // the backups must be restarted.
            sqlite3BackupRestart(pPager.pBackup);
            return(rc);
        }