Exemplo n.º 1
0
        private static void TestVFS()
        {
            var vfs = FileEx.sqlite3_vfs_find(null);

            VirtualFileSystem.OPEN flagOut = 0;
            VirtualFile            file    = new VirtualFile();
            var rc = FileEx.sqlite3OsOpen(vfs, @"Test", file, VirtualFileSystem.OPEN.CREATE, ref flagOut);
        }
Exemplo n.º 2
0
        private static Pager Open(VirtualFileSystem vfs)
        {
            var   zDbHeader = new byte[100]; // Database header content
            Pager pager;

            Pager.PAGEROPEN        flags    = 0;
            VirtualFileSystem.OPEN vfsFlags = VirtualFileSystem.OPEN.CREATE | VirtualFileSystem.OPEN.READWRITE | VirtualFileSystem.OPEN.MAIN_DB;
            //
            var rc = Pager.Open(vfs, out pager, @"Test", 0, flags, vfsFlags, x => { }, null);

            if (rc == RC.OK)
            {
                rc = pager.ReadFileHeader(zDbHeader.Length, zDbHeader);
            }
            pager.SetBusyHandler(BusyHandler, null);
            var readOnly = pager.IsReadonly;
            //
            int nReserve;
            var pageSize = (uint)((zDbHeader[16] << 8) | (zDbHeader[17] << 16));

            if (pageSize < 512 || pageSize > Pager.SQLITE_MAX_PAGE_SIZE || ((pageSize - 1) & pageSize) != 0)
            {
                pageSize = 0;
                nReserve = 0;
            }
            else
            {
                nReserve = zDbHeader[20];
            }
            rc = pager.SetPageSize(ref pageSize, nReserve);
            if (rc != RC.OK)
            {
                goto _out;
            }
_out:
            if (rc != RC.OK)
            {
                if (pager != null)
                {
                    pager.Close();
                }
                pager = null;
            }
            pager.SetCacheSize(2000);
            return(pager);
        }
Exemplo n.º 3
0
        //internal static SQLITE sqlite3OsDelete(VirtualFileSystem pVfs, string zPath, int dirSync) { return pVfs.xDelete(zPath, dirSync); }
        //internal static SQLITE sqlite3OsAccess(VirtualFileSystem pVfs, string zPath, VirtualFileSystem.ACCESS flags, ref int pResOut) { return pVfs.xAccess(zPath, flags, out pResOut); }
        //internal static SQLITE sqlite3OsFullPathname(VirtualFileSystem pVfs, string zPath, int nPathOut, StringBuilder zPathOut) { zPathOut.Length = 0; return pVfs.xFullPathname(zPath, nPathOut, zPathOut); }
#if !SQLITE_OMIT_LOAD_EXTENSION
        //internal static IntPtr sqlite3OsDlOpen(VirtualFileSystem pVfs, string zPath) { return pVfs.xDlOpen(zPath); }
        //internal static void sqlite3OsDlError(VirtualFileSystem pVfs, int nByte, string zBufOut) { pVfs.xDlError(nByte, zBufOut); }
        //internal static object sqlite3OsDlSym(VirtualFileSystem pVfs, IntPtr pHdle, ref string zSym) { return pVfs.xDlSym(pHdle, zSym); }
        //internal static void sqlite3OsDlClose(VirtualFileSystem pVfs, IntPtr pHandle) { pVfs.xDlClose(pHandle); }
#endif
        //internal static int sqlite3OsRandomness(VirtualFileSystem pVfs, int nByte, byte[] zBufOut) { return pVfs.xRandomness(nByte, zBufOut); }
        //internal static int sqlite3OsSleep(VirtualFileSystem pVfs, int nMicro) { return pVfs.xSleep(nMicro); }

        //internal static SQLITE sqlite3OsCurrentTimeInt64(VirtualFileSystem pVfs, ref long pTimeOut)
        //{
        //    // IMPLEMENTATION-OF: R-49045-42493 SQLite will use the xCurrentTimeInt64() method to get the current date and time if that method is available
        //    // (if iVersion is 2 or greater and the function pointer is not NULL) and will fall back to xCurrentTime() if xCurrentTimeInt64() is unavailable.
        //    SQLITE rc;
        //    if (pVfs.iVersion >= 2)
        //        rc = pVfs.xCurrentTimeInt64(ref pTimeOut);
        //    else
        //    {
        //        double r = 0;
        //        rc = pVfs.xCurrentTime(ref r);
        //        pTimeOut = (long)(r * 86400000.0);
        //    }
        //    return rc;
        //}

        internal static RC OsOpenWithAlloc(ref VirtualFileSystem pVfs, string zFile, ref VirtualFile ppFile, VirtualFileSystem.OPEN flags, ref VirtualFileSystem.OPEN pOutFlags)
        {
            var rc    = RC.NOMEM;
            var pFile = new VirtualFile();

            if (pFile != null)
            {
                rc = OsOpen(pVfs, zFile, pFile, flags, ref pOutFlags);
                if (rc != RC.OK)
                {
                    pFile = null;
                }
                else
                {
                    ppFile = pFile;
                }
            }
            return(rc);
        }
Exemplo n.º 4
0
 public static RC OsOpen(VirtualFileSystem pVfs, string zPath, VirtualFile pFile, VirtualFileSystem.OPEN flags, ref VirtualFileSystem.OPEN pFlagsOut)
 {
     // 0x87f3f is a mask of SQLITE_OPEN_ flags that are valid to be passed down into the VFS layer.  Some SQLITE_OPEN_ flags (for example,
     // SQLITE_OPEN_FULLMUTEX or SQLITE_OPEN_SHAREDCACHE) are blocked before reaching the VFS.
     var rc = pVfs.xOpen(zPath, pFile, (VirtualFileSystem.OPEN)((int)flags & 0x87f3f), out pFlagsOut); Debug.Assert(rc == RC.OK || !pFile.IsOpen); return(rc);
 }