コード例 #1
0
        public int BackupDataBase(string backupPath)
        {
            Sqlite3DatabaseHandle backupHandle;

            if (string.IsNullOrEmpty(backupPath))
            {
                throw new ArgumentException("Must be specified", "databasePath");
            }
            var backupPathAsBytes = GetNullTerminatedUtf8(backupPath);
            //A
            var r = SQLite3.Open(backupPathAsBytes, out backupHandle,
                                 (int)(SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create), IntPtr.Zero);

            if (r != SQLite3.Result.OK)
            {
                throw SQLiteException.New(r, String.Format("Could not open database file: {0} ({1})", backupPath, r));
            }

            //Открыли БД, пора приступить к бэкапу

            Sqlite3Backup pBackup;

            //1
            pBackup = BackupInit(backupHandle, "main", Handle, "main");

            if (pBackup != IntPtr.Zero)
            {
                while (true)
                {
                    //2
                    r = BackupStep(pBackup, 25);

                    if (BackupProgress != null)
                    {
                        BackupProgress(BackupRemaining(pBackup), BackupPagecount(pBackup));
                    }

                    if (r == SQLite3.Result.OK || r == SQLite3.Result.Busy || r == SQLite3.Result.Locked)
                    {
                        Thread.Sleep(100);
                    }
                    else
                    {
                        break;
                    }
                }

                //3
                BackupFinish(pBackup);
            }
            //B
            r = SQLite3.Close(backupHandle);
            if (r != SQLite3.Result.OK)
            {
                string msg = SQLite3.GetErrmsg(backupHandle);
                throw SQLiteException.New(r, msg);
            }

            return((int)r);
        }
コード例 #2
0
ファイル: SQLite.cs プロジェクト: azcoov/Monospace09
        public SQLiteConnection(string database)
        {
            Database = database;
            var r = SQLite3.Open(Database, out _db);

            if (r != SQLite3.Result.OK)
            {
                throw SQLiteException.New(r, "Could not open database file: " + Database);
            }
            _open = true;
        }
コード例 #3
0
ファイル: SqLite.cs プロジェクト: nicwise/onthetelly
        /// <summary>
        /// Constructs a new SQLiteConnection and opens a SQLite database specified by databasePath.
        /// </summary>
        /// <param name="databasePath">
        /// Specifies the path to the database file.
        /// </param>
        public SQLiteConnection(string databasePath)
        {
            MaxExecuteAttempts = 10;
            DatabasePath       = databasePath;
            IntPtr handle;
            var    r = SQLite3.Open(DatabasePath, out handle);

            Handle = handle;
            if (r != SQLite3.Result.OK)
            {
                throw SQLiteException.New(r, "Could not open database file: " + DatabasePath);
            }
            _open = true;
        }
コード例 #4
0
        public SQLiteConnection(string databasePath, SQLiteOpenFlags openFlags, bool storeDateTimeAsTicks = false)
        {
            if (string.IsNullOrEmpty(databasePath))
            {
                throw new ArgumentException("Must be specified", "databasePath");
            }
            DatabasePath = databasePath;
            mayCreateSyncObject(databasePath);
            byte[] nullTerminatedUtf = GetNullTerminatedUtf8(DatabasePath);
            IntPtr db;

            SQLite3.Result result = SQLite3.Open(nullTerminatedUtf, out db, (int)openFlags, IntPtr.Zero);
            Handle = db;
            if (result != 0)
            {
                throw SQLiteException.New(result, $"Could not open database file: {DatabasePath} ({result})");
            }
            _open = true;
            StoreDateTimeAsTicks = storeDateTimeAsTicks;
            BusyTimeout          = TimeSpan.FromSeconds(0.1);
        }