Beispiel #1
0
 public static RC xInit(object NotUsed)
 {
     SysEx.UNUSED_PARAMETER(NotUsed);
     Debug.Assert(pcache1 == null);
     pcache1 = new PCacheGlobal();
     if (sqlite3GlobalConfig_bCoreMutex)
     {
         pcache1.grp.mutex = MutexEx.sqlite3_mutex_alloc(MutexEx.MUTEX.STATIC_LRU);
         pcache1.mutex     = MutexEx.sqlite3_mutex_alloc(MutexEx.MUTEX.STATIC_PMEM);
     }
     pcache1.grp.mxPinned = 10;
     return(RC.OK);
 }
Beispiel #2
0
        public override RC Truncate(long size)
        {
            SysEx.UNUSED_PARAMETER(size);
            Debug.Assert(size == 0);
            var pChunk = pFirst;

            while (pChunk != null)
            {
                var pTmp = pChunk;
                pChunk = pChunk.pNext;
            }
            // clear
            pFirst    = null;
            endpoint  = new FilePoint();
            readpoint = new FilePoint();
            return(RC.OK);
        }
Beispiel #3
0
        public override RC Write(byte[] zBuf, int iAmt, long iOfst)
        {
            SysEx.UNUSED_PARAMETER(iOfst);
            // An in-memory journal file should only ever be appended to. Random access writes are not required by sqlite.
            Debug.Assert(iOfst == endpoint.iOffset);
            var izWrite = 0;

            while (iAmt > 0)
            {
                var pChunk       = endpoint.pChunk;
                var iChunkOffset = (int)(endpoint.iOffset % JOURNAL_CHUNKSIZE);
                var iSpace       = Math.Min(iAmt, JOURNAL_CHUNKSIZE - iChunkOffset);
                if (iChunkOffset == 0)
                {
                    // New chunk is required to extend the file.
                    var pNew = new FileChunk();
                    if (pNew == null)
                    {
                        return(RC.IOERR_NOMEM);
                    }
                    pNew.pNext = null;
                    if (pChunk != null)
                    {
                        Debug.Assert(pFirst != null); pChunk.pNext = pNew;
                    }
                    else
                    {
                        Debug.Assert(pFirst == null); pFirst = pNew;
                    }
                    endpoint.pChunk = pNew;
                }
                Buffer.BlockCopy(zBuf, izWrite, endpoint.pChunk.zChunk, iChunkOffset, iSpace);
                izWrite          += iSpace;
                iAmt             -= iSpace;
                endpoint.iOffset += iSpace;
            }
            return(RC.OK);
        }
Beispiel #4
0
        private RC pager_incr_changecounter(bool isDirectMode)
        {
            var rc = RC.OK;

            Debug.Assert(this.eState == PAGER.WRITER_CACHEMOD || this.eState == PAGER.WRITER_DBMOD);
            Debug.Assert(assert_pager_state());
            // Declare and initialize constant integer 'isDirect'. If the atomic-write optimization is enabled in this build, then isDirect
            // is initialized to the value passed as the isDirectMode parameter to this function. Otherwise, it is always set to zero.
            // The idea is that if the atomic-write optimization is not enabled at compile time, the compiler can omit the tests of
            // 'isDirect' below, as well as the block enclosed in the "if( isDirect )" condition.
#if !SQLITE_ENABLE_ATOMIC_WRITE
            var DIRECT_MODE = false;
            Debug.Assert(!isDirectMode);
            SysEx.UNUSED_PARAMETER(isDirectMode);
#else
            var DIRECT_MODE = isDirectMode;
#endif
            if (!this.changeCountDone && this.dbSize > 0)
            {
                PgHdr pPgHdr = null; // Reference to page 1
                Debug.Assert(!this.tempFile && this.fd.IsOpen);
                // Open page 1 of the file for writing.
                rc = Get(1, ref pPgHdr);
                Debug.Assert(pPgHdr == null || rc == RC.OK);
                // If page one was fetched successfully, and this function is not operating in direct-mode, make page 1 writable.  When not in
                // direct mode, page 1 is always held in cache and hence the PagerGet() above is always successful - hence the ALWAYS on rc==SQLITE.OK.
                if (!DIRECT_MODE && Check.ALWAYS(rc == RC.OK))
                {
                    rc = Write(pPgHdr);
                }
                if (rc == RC.OK)
                {
                    // Actually do the update of the change counter
                    pager_write_changecounter(pPgHdr);
                    // If running in direct mode, write the contents of page 1 to the file.
                    if (DIRECT_MODE)
                    {
                        byte[] zBuf = null;
                        Debug.Assert(this.dbFileSize > 0);
                        if (CODEC2(this, pPgHdr.Data, 1, codec_ctx.ENCRYPT_WRITE_CTX, ref zBuf))
                        {
                            return(rc = RC.NOMEM);
                        }
                        if (rc == RC.OK)
                        {
                            rc = this.fd.Write(zBuf, this.pageSize, 0);
                        }
                        if (rc == RC.OK)
                        {
                            this.changeCountDone = true;
                        }
                    }
                    else
                    {
                        this.changeCountDone = true;
                    }
                }
                // Release the page reference.
                Unref(pPgHdr);
            }
            return(rc);
        }
Beispiel #5
0
 public override RC Sync(SYNC NotUsed2)
 {
     SysEx.UNUSED_PARAMETER(NotUsed2); return(RC.OK);
 }
Beispiel #6
0
 public static void xShutdown(object NotUsed)
 {
     SysEx.UNUSED_PARAMETER(NotUsed);
     Debug.Assert(pcache1 != null);
     pcache1 = null;
 }