Esempio n. 1
0
        // was:sqlite3BtreeClose
        public static RC Close(ref Btree p)
        {
            // Close all cursors opened via this handle.
            Debug.Assert(MutexEx.Held(p.DB.Mutex));
            p.sqlite3BtreeEnter();
            var shared = p.Shared;
            var cursor = shared.Cursors;
            while (cursor != null)
            {
                var lastCursor = cursor;
                cursor = cursor.Next;
                if (lastCursor.Tree == p)
                    lastCursor.Close();
            }
            // Rollback any active transaction and free the handle structure. The call to sqlite3BtreeRollback() drops any table-locks held by this handle.
            p.Rollback();
            p.sqlite3BtreeLeave();
            // If there are still other outstanding references to the shared-btree structure, return now. The remainder of this procedure cleans up the shared-btree.
            Debug.Assert(p.WantToLock == 0 && !p.Locked);
            if (!p.Sharable || shared.removeFromSharingList())
            {
                // The pBt is no longer on the sharing list, so we can access it without having to hold the mutex.
                // Clean out and delete the BtShared object.
                Debug.Assert(shared.Cursors == null);
                shared.Pager.Close();
                if (shared.xFreeSchema != null && shared.Schema != null)
                    shared.xFreeSchema(shared.Schema);
                shared.Schema = null;// sqlite3DbFree(0, pBt->pSchema);
                //freeTempSpace(pBt);
                shared = null; //sqlite3_free(ref pBt);
            }
#if !SQLITE_OMIT_SHARED_CACHE
            Debug.Assert(p.WantToLock == 0);
            Debug.Assert(p.Locked == false);
            if (p.Prev != null) p.Prev.Next = p.Next;
            if (p.Next != null) p.Next.Prev = p.Prev;
#endif
            return RC.OK;
        }
Esempio n. 2
0
        // was:sqlite3BtreeClose
        public static RC Close(ref Btree p)
        {
            // Close all cursors opened via this handle.
            Debug.Assert(MutexEx.Held(p.DB.Mutex));
            p.sqlite3BtreeEnter();
            var shared = p.Shared;
            var cursor = shared.Cursors;
            while (cursor != null)
            {
                var lastCursor = cursor;
                cursor = cursor.Next;
                if (lastCursor.Tree == p)
                    lastCursor.Close();
            }
            // Rollback any active transaction and free the handle structure. The call to sqlite3BtreeRollback() drops any table-locks held by this handle.
            p.Rollback();
            p.sqlite3BtreeLeave();
            // If there are still other outstanding references to the shared-btree structure, return now. The remainder of this procedure cleans up the shared-btree.
            Debug.Assert(p.WantToLock == 0 && !p.Locked);
            if (!p.Sharable || shared.removeFromSharingList())
            {
                // The pBt is no longer on the sharing list, so we can access it without having to hold the mutex.
                // Clean out and delete the BtShared object.
                Debug.Assert(shared.Cursors == null);
                shared.Pager.Close();
                if (shared.xFreeSchema != null && shared.Schema != null)
                    shared.xFreeSchema(shared.Schema);
                shared.Schema = null;// sqlite3DbFree(0, pBt->pSchema);
                //freeTempSpace(pBt);
                shared = null; //sqlite3_free(ref pBt);
            }
#if !SQLITE_OMIT_SHARED_CACHE
            Debug.Assert(p.WantToLock == 0);
            Debug.Assert(p.Locked == false);
            if (p.Prev != null) p.Prev.Next = p.Next;
            if (p.Next != null) p.Next.Prev = p.Prev;
#endif
            return RC.OK;
        }