-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSQLiteBackup.cs
executable file
·149 lines (128 loc) · 4.63 KB
/
SQLiteBackup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/********************************************************
* ADO.NET 2.0 Data Provider for SQLite Version 3.X
* Written by Joe Mistachkin ([email protected])
*
* Released to the public domain, use at your own risk!
********************************************************/
namespace System.Data.SQLite
{
using System;
/// <summary>
/// Represents a single SQL backup in SQLite.
/// </summary>
internal sealed class SQLiteBackup : IDisposable
{
/// <summary>
/// The underlying SQLite object this backup is bound to.
/// </summary>
internal SQLiteBase _sql;
/// <summary>
/// The actual backup handle.
/// </summary>
internal SQLiteBackupHandle _sqlite_backup;
/// <summary>
/// The destination database for the backup.
/// </summary>
internal IntPtr _destDb;
/// <summary>
/// The destination database name for the backup.
/// </summary>
internal byte[] _zDestName;
/// <summary>
/// The source database for the backup.
/// </summary>
internal IntPtr _sourceDb;
/// <summary>
/// The source database name for the backup.
/// </summary>
internal byte[] _zSourceName;
/// <summary>
/// The last result from the StepBackup method of the SQLite3 class.
/// This is used to determine if the call to the FinishBackup method of
/// the SQLite3 class should throw an exception when it receives a non-Ok
/// return code from the core SQLite library.
/// </summary>
internal SQLiteErrorCode _stepResult;
/// <summary>
/// Initializes the backup.
/// </summary>
/// <param name="sqlbase">The base SQLite object.</param>
/// <param name="backup">The backup handle.</param>
/// <param name="destDb">The destination database for the backup.</param>
/// <param name="zDestName">The destination database name for the backup.</param>
/// <param name="sourceDb">The source database for the backup.</param>
/// <param name="zSourceName">The source database name for the backup.</param>
internal SQLiteBackup(
SQLiteBase sqlbase,
SQLiteBackupHandle backup,
IntPtr destDb,
byte[] zDestName,
IntPtr sourceDb,
byte[] zSourceName
)
{
_sql = sqlbase;
_sqlite_backup = backup;
_destDb = destDb;
_zDestName = zDestName;
_sourceDb = sourceDb;
_zSourceName = zSourceName;
}
///////////////////////////////////////////////////////////////////////////////////////////////
#region IDisposable Members
/// <summary>
/// Disposes and finalizes the backup.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
///////////////////////////////////////////////////////////////////////////////////////////////
#region IDisposable "Pattern" Members
private bool disposed;
private void CheckDisposed() /* throw */
{
#if THROW_ON_DISPOSED
if (disposed)
throw new ObjectDisposedException(typeof(SQLiteBackup).Name);
#endif
}
///////////////////////////////////////////////////////////////////////////////////////////////
private void Dispose(bool disposing)
{
if (!disposed)
{
if (disposing)
{
////////////////////////////////////
// dispose managed resources here...
////////////////////////////////////
if (_sqlite_backup != null)
{
_sqlite_backup.Dispose();
_sqlite_backup = null;
}
_zSourceName = null;
_sourceDb = IntPtr.Zero;
_zDestName = null;
_destDb = IntPtr.Zero;
_sql = null;
}
//////////////////////////////////////
// release unmanaged resources here...
//////////////////////////////////////
disposed = true;
}
}
#endregion
///////////////////////////////////////////////////////////////////////////////////////////////
#region Destructor
~SQLiteBackup()
{
Dispose(false);
}
#endregion
}
}