コード例 #1
0
 public void Close()
 {
     if (_open && Handle != NullHandle)
     {
         try
         {
             if (_mappings != null)
             {
                 foreach (TableMapping value in _mappings.Values)
                 {
                     value.Dispose();
                 }
             }
             SQLite3.Result result = SQLite3.Close(Handle);
             if (result != 0)
             {
                 string errmsg = SQLite3.GetErrmsg(Handle);
                 throw SQLiteException.New(result, errmsg);
             }
         }
         finally
         {
             Handle = NullHandle;
             _open  = false;
         }
     }
 }
コード例 #2
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);
        }
コード例 #3
0
ファイル: SQLite.cs プロジェクト: azcoov/Monospace09
 public void Dispose()
 {
     if (_open)
     {
         SQLite3.Close(_db);
         _db   = IntPtr.Zero;
         _open = false;
     }
 }
コード例 #4
0
ファイル: SqLite.cs プロジェクト: nicwise/onthetelly
 public void Dispose()
 {
     if (_open)
     {
         SQLite3.Close(Handle);
         Handle = IntPtr.Zero;
         _open  = false;
     }
 }