Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Diff of /System.Data.SQLite/SQLiteBase.cs [51a8cf] .. [d2857c] Maximize Restore

  Switch to unified view

a/System.Data.SQLite/SQLiteBase.cs b/System.Data.SQLite/SQLiteBase.cs
1
/********************************************************
1
/********************************************************
2
 * ADO.NET 2.0 Data Provider for SQLite Version 3.X
2
 * ADO.NET 2.0 Data Provider for SQLite Version 3.X
3
 * Written by Robert Simpson (robert@blackcastlesoft.com)
3
 * Written by Robert Simpson (robert@blackcastlesoft.com)
4
 * 
4
 * 
5
 * Released to the public domain, use at your own risk!
5
 * Released to the public domain, use at your own risk!
6
 ********************************************************/
6
 ********************************************************/

7
7
8
namespace System.Data.SQLite
8
namespace System.Data.SQLite

9
{
9
{

10
  using System;
11
  using System.Data;
12
  using System.Runtime.InteropServices;
13
  using System.Collections.Generic;
14
15
  /// <summary>
10
    /// <summary>

16
  /// This internal class provides the foundation of SQLite support.  It defines all the abstract members needed to implement
11
    /// This internal class provides the foundation of SQLite support.  It defines all the abstract members needed to implement

17
  /// a SQLite data provider, and inherits from SQLiteConvert which allows for simple translations of string to and from SQLite.
12
    /// a SQLite data provider, and inherits from SQLiteConvert which allows for simple translations of string to and from SQLite.

18
  /// </summary>
13
    /// </summary>

19
  internal abstract class SQLiteBase : SQLiteConvert, IDisposable
14
    internal abstract class SQLiteBase : SQLiteConvert, IDisposable

20
  {
15
    {
16
        internal static object _lock = new object();
17
21
    internal SQLiteBase(SQLiteDateFormats fmt)
18
        internal SQLiteBase(SQLiteDateFormats fmt)

22
      : base(fmt) { }
19
            : base(fmt)

23
20
        {
24
    static internal object _lock = new object();
21
        }
25
22
26
    /// <summary>
23
        /// <summary>

27
    /// Returns a string representing the active version of SQLite
24
        /// Returns a string representing the active version of SQLite

28
    /// </summary>
25
        /// </summary>

29
    internal abstract string Version { get; }
26
        internal abstract string Version { get; }

27
30
    /// <summary>
28
        /// <summary>

31
    /// Returns the number of changes the last executing insert/update caused.
29
        /// Returns the number of changes the last executing insert/update caused.

32
    /// </summary>
30
        /// </summary>

33
    internal abstract int Changes { get; }
31
        internal abstract int Changes { get; }

32
33
        internal abstract bool AutoCommit { get; }
34
35
        #region IDisposable Members
36
37
        public void Dispose()
38
        {
39
            Dispose(true);
40
            GC.SuppressFinalize(this);
41
        }
42
43
        #endregion
44
34
    /// <summary>
45
        /// <summary>

35
    /// Opens a database.
46
        /// Opens a database.

36
    /// </summary>
47
        /// </summary>

37
    /// <remarks>
48
        /// <remarks>

38
    /// Implementers should call SQLiteFunction.BindFunctions() and save the array after opening a connection
49
        /// Implementers should call SQLiteFunction.BindFunctions() and save the array after opening a connection

39
    /// to bind all attributed user-defined functions and collating sequences to the new connection.
50
        /// to bind all attributed user-defined functions and collating sequences to the new connection.

40
    /// </remarks>
51
        /// </remarks>

41
    /// <param name="strFilename">The filename of the database to open.  SQLite automatically creates it if it doesn't exist.</param>
52
        /// <param name="strFilename">The filename of the database to open.  SQLite automatically creates it if it doesn't exist.</param>

42
    /// <param name="flags">The open flags to use when creating the connection</param>
53
        /// <param name="flags">The open flags to use when creating the connection</param>

43
    /// <param name="maxPoolSize">The maximum size of the pool for the given filename</param>
54
        /// <param name="maxPoolSize">The maximum size of the pool for the given filename</param>

44
    /// <param name="usePool">If true, the connection can be pulled from the connection pool</param>
55
        /// <param name="usePool">If true, the connection can be pulled from the connection pool</param>

45
    internal abstract void Open(string strFilename, SQLiteOpenFlagsEnum flags, int maxPoolSize, bool usePool);
56
        internal abstract void Open(string strFilename, SQLiteOpenFlagsEnum flags, int maxPoolSize, bool usePool);

57
46
    /// <summary>
58
        /// <summary>

47
    /// Closes the currently-open database.
59
        /// Closes the currently-open database.

48
    /// </summary>
60
        /// </summary>

49
    /// <remarks>
61
        /// <remarks>

50
    /// After the database has been closed implemeters should call SQLiteFunction.UnbindFunctions() to deallocate all interop allocated
62
        /// After the database has been closed implemeters should call SQLiteFunction.UnbindFunctions() to deallocate all interop allocated

51
    /// memory associated with the user-defined functions and collating sequences tied to the closed connection.
63
        /// memory associated with the user-defined functions and collating sequences tied to the closed connection.

52
    /// </remarks>
64
        /// </remarks>

53
    internal abstract void Close();
65
        internal abstract void Close();

66
54
    /// <summary>
67
        /// <summary>

55
    /// Sets the busy timeout on the connection.  SQLiteCommand will call this before executing any command.
68
        /// Sets the busy timeout on the connection.  SQLiteCommand will call this before executing any command.

56
    /// </summary>
69
        /// </summary>

57
    /// <param name="nTimeoutMS">The number of milliseconds to wait before returning SQLITE_BUSY</param>
70
        /// <param name="nTimeoutMS">The number of milliseconds to wait before returning SQLITE_BUSY</param>

58
    internal abstract void SetTimeout(int nTimeoutMS);
71
        internal abstract void SetTimeout(int nTimeoutMS);

72
59
    /// <summary>
73
        /// <summary>

60
    /// Returns the text of the last error issued by SQLite
74
        /// Returns the text of the last error issued by SQLite

61
    /// </summary>
75
        /// </summary>

62
    /// <returns></returns>
76
        /// <returns></returns>

63
    internal abstract string SQLiteLastError();
77
        internal abstract string SQLiteLastError();

64
78
65
    /// <summary>
79
        /// <summary>

66
    /// When pooling is enabled, force this connection to be disposed rather than returned to the pool
80
        /// When pooling is enabled, force this connection to be disposed rather than returned to the pool

67
    /// </summary>
81
        /// </summary>

68
    internal abstract void ClearPool();
82
        internal abstract void ClearPool();

69
83
70
    /// <summary>
84
        /// <summary>

71
    /// Prepares a SQL statement for execution.
85
        /// Prepares a SQL statement for execution.

72
    /// </summary>
86
        /// </summary>

73
    /// <param name="cnn">The source connection preparing the command.  Can be null for any caller except LINQ</param>
87
        /// <param name="cnn">The source connection preparing the command.  Can be null for any caller except LINQ</param>

74
    /// <param name="strSql">The SQL command text to prepare</param>
88
        /// <param name="strSql">The SQL command text to prepare</param>

75
    /// <param name="previous">The previous statement in a multi-statement command, or null if no previous statement exists</param>
89
        /// <param name="previous">The previous statement in a multi-statement command, or null if no previous statement exists</param>

76
    /// <param name="timeoutMS">The timeout to wait before aborting the prepare</param>
90
        /// <param name="timeoutMS">The timeout to wait before aborting the prepare</param>

77
    /// <param name="strRemain">The remainder of the statement that was not processed.  Each call to prepare parses the
91
        /// <param name="strRemain">The remainder of the statement that was not processed.  Each call to prepare parses the

78
    /// SQL up to to either the end of the text or to the first semi-colon delimiter.  The remaining text is returned
92
        /// SQL up to to either the end of the text or to the first semi-colon delimiter.  The remaining text is returned

79
    /// here for a subsequent call to Prepare() until all the text has been processed.</param>
93
        /// here for a subsequent call to Prepare() until all the text has been processed.</param>

80
    /// <returns>Returns an initialized SQLiteStatement.</returns>
94
        /// <returns>Returns an initialized SQLiteStatement.</returns>

81
    internal abstract SQLiteStatement Prepare(SQLiteConnection cnn, string strSql, SQLiteStatement previous, uint timeoutMS, out string strRemain);
95
        internal abstract SQLiteStatement Prepare(SQLiteConnection cnn, string strSql, SQLiteStatement previous,

96
                                                  uint timeoutMS, out string strRemain);
97
82
    /// <summary>
98
        /// <summary>

83
    /// Steps through a prepared statement.
99
        /// Steps through a prepared statement.

84
    /// </summary>
100
        /// </summary>

85
    /// <param name="stmt">The SQLiteStatement to step through</param>
101
        /// <param name="stmt">The SQLiteStatement to step through</param>

86
    /// <returns>True if a row was returned, False if not.</returns>
102
        /// <returns>True if a row was returned, False if not.</returns>

87
    internal abstract bool Step(SQLiteStatement stmt);
103
        internal abstract bool Step(SQLiteStatement stmt);

104
88
    /// <summary>
105
        /// <summary>

89
    /// Resets a prepared statement so it can be executed again.  If the error returned is SQLITE_SCHEMA, 
106
        /// Resets a prepared statement so it can be executed again.  If the error returned is SQLITE_SCHEMA, 

90
    /// transparently attempt to rebuild the SQL statement and throw an error if that was not possible.
107
        /// transparently attempt to rebuild the SQL statement and throw an error if that was not possible.

91
    /// </summary>
108
        /// </summary>

92
    /// <param name="stmt">The statement to reset</param>
109
        /// <param name="stmt">The statement to reset</param>

93
    /// <returns>Returns -1 if the schema changed while resetting, 0 if the reset was sucessful or 6 (SQLITE_LOCKED) if the reset failed due to a lock</returns>
110
        /// <returns>Returns -1 if the schema changed while resetting, 0 if the reset was sucessful or 6 (SQLITE_LOCKED) if the reset failed due to a lock</returns>

94
    internal abstract int Reset(SQLiteStatement stmt);
111
        internal abstract int Reset(SQLiteStatement stmt);

112
95
    internal abstract void Cancel();
113
        internal abstract void Cancel();

96
114
97
    internal abstract void Bind_Double(SQLiteStatement stmt, int index, double value);
115
        internal abstract void Bind_Double(SQLiteStatement stmt, int index, double value);

98
    internal abstract void Bind_Int32(SQLiteStatement stmt, int index, Int32 value);
116
        internal abstract void Bind_Int32(SQLiteStatement stmt, int index, Int32 value);

99
    internal abstract void Bind_Int64(SQLiteStatement stmt, int index, Int64 value);
117
        internal abstract void Bind_Int64(SQLiteStatement stmt, int index, Int64 value);

100
    internal abstract void Bind_Text(SQLiteStatement stmt, int index, string value);
118
        internal abstract void Bind_Text(SQLiteStatement stmt, int index, string value);

101
    internal abstract void Bind_Blob(SQLiteStatement stmt, int index, byte[] blobData);
119
        internal abstract void Bind_Blob(SQLiteStatement stmt, int index, byte[] blobData);

102
    internal abstract void Bind_DateTime(SQLiteStatement stmt, int index, DateTime dt);
120
        internal abstract void Bind_DateTime(SQLiteStatement stmt, int index, DateTime dt);

103
    internal abstract void Bind_Null(SQLiteStatement stmt, int index);
121
        internal abstract void Bind_Null(SQLiteStatement stmt, int index);

104
122
105
    internal abstract int Bind_ParamCount(SQLiteStatement stmt);
123
        internal abstract int Bind_ParamCount(SQLiteStatement stmt);

106
    internal abstract string Bind_ParamName(SQLiteStatement stmt, int index);
124
        internal abstract string Bind_ParamName(SQLiteStatement stmt, int index);

107
    internal abstract int Bind_ParamIndex(SQLiteStatement stmt, string paramName);
125
        internal abstract int Bind_ParamIndex(SQLiteStatement stmt, string paramName);

108
126
109
    internal abstract int ColumnCount(SQLiteStatement stmt);
127
        internal abstract int ColumnCount(SQLiteStatement stmt);

110
    internal abstract string ColumnName(SQLiteStatement stmt, int index);
128
        internal abstract string ColumnName(SQLiteStatement stmt, int index);

111
    internal abstract TypeAffinity ColumnAffinity(SQLiteStatement stmt, int index);
129
        internal abstract TypeAffinity ColumnAffinity(SQLiteStatement stmt, int index);

112
    internal abstract string ColumnType(SQLiteStatement stmt, int index, out TypeAffinity nAffinity);
130
        internal abstract string ColumnType(SQLiteStatement stmt, int index, out TypeAffinity nAffinity);

113
    internal abstract int ColumnIndex(SQLiteStatement stmt, string columnName);
131
        internal abstract int ColumnIndex(SQLiteStatement stmt, string columnName);

114
    internal abstract string ColumnOriginalName(SQLiteStatement stmt, int index);
132
        internal abstract string ColumnOriginalName(SQLiteStatement stmt, int index);

115
    internal abstract string ColumnDatabaseName(SQLiteStatement stmt, int index);
133
        internal abstract string ColumnDatabaseName(SQLiteStatement stmt, int index);

116
    internal abstract string ColumnTableName(SQLiteStatement stmt, int index);
134
        internal abstract string ColumnTableName(SQLiteStatement stmt, int index);

117
    internal abstract void ColumnMetaData(string dataBase, string table, string column, out string dataType, out string collateSequence, out bool notNull, out bool primaryKey, out bool autoIncrement);
135
136
        internal abstract void ColumnMetaData(string dataBase, string table, string column, out string dataType,
137
                                              out string collateSequence, out bool notNull, out bool primaryKey,
138
                                              out bool autoIncrement);
139
118
    internal abstract void GetIndexColumnExtendedInfo(string database, string index, string column, out int sortMode, out int onError, out string collationSequence);
140
        internal abstract void GetIndexColumnExtendedInfo(string database, string index, string column, out int sortMode,

119
141
                                                          out int onError, out string collationSequence);
142
120
    internal abstract double GetDouble(SQLiteStatement stmt, int index);
143
        internal abstract double GetDouble(SQLiteStatement stmt, int index);

121
    internal abstract Int32 GetInt32(SQLiteStatement stmt, int index);
144
        internal abstract Int32 GetInt32(SQLiteStatement stmt, int index);

122
    internal abstract Int64 GetInt64(SQLiteStatement stmt, int index);
145
        internal abstract Int64 GetInt64(SQLiteStatement stmt, int index);

123
    internal abstract string GetText(SQLiteStatement stmt, int index);
146
        internal abstract string GetText(SQLiteStatement stmt, int index);

147
124
    internal abstract long GetBytes(SQLiteStatement stmt, int index, int nDataoffset, byte[] bDest, int nStart, int nLength);
148
        internal abstract long GetBytes(SQLiteStatement stmt, int index, int nDataoffset, byte[] bDest, int nStart,

149
                                        int nLength);
150
125
    internal abstract long GetChars(SQLiteStatement stmt, int index, int nDataoffset, char[] bDest, int nStart, int nLength);
151
        internal abstract long GetChars(SQLiteStatement stmt, int index, int nDataoffset, char[] bDest, int nStart,

152
                                        int nLength);
153
126
    internal abstract DateTime GetDateTime(SQLiteStatement stmt, int index);
154
        internal abstract DateTime GetDateTime(SQLiteStatement stmt, int index);

127
    internal abstract bool IsNull(SQLiteStatement stmt, int index);
155
        internal abstract bool IsNull(SQLiteStatement stmt, int index);

128
156
129
    internal abstract void CreateCollation(string strCollation, SQLiteCollation func, SQLiteCollation func16);
157
        internal abstract void CreateCollation(string strCollation, SQLiteCollation func, SQLiteCollation func16);

158
130
    internal abstract void CreateFunction(string strFunction, int nArgs, bool needCollSeq, SQLiteCallback func, SQLiteCallback funcstep, SQLiteFinalCallback funcfinal);
159
        internal abstract void CreateFunction(string strFunction, int nArgs, bool needCollSeq, SQLiteCallback func,

160
                                              SQLiteCallback funcstep, SQLiteFinalCallback funcfinal);
161
131
    internal abstract CollationSequence GetCollationSequence(SQLiteFunction func, IntPtr context);
162
        internal abstract CollationSequence GetCollationSequence(SQLiteFunction func, IntPtr context);

132
    internal abstract int ContextCollateCompare(CollationEncodingEnum enc, IntPtr context, string s1, string s2);
163
        internal abstract int ContextCollateCompare(CollationEncodingEnum enc, IntPtr context, string s1, string s2);

133
    internal abstract int ContextCollateCompare(CollationEncodingEnum enc, IntPtr context, char[] c1, char[] c2);
164
        internal abstract int ContextCollateCompare(CollationEncodingEnum enc, IntPtr context, char[] c1, char[] c2);

134
165
135
    internal abstract int AggregateCount(IntPtr context);
166
        internal abstract int AggregateCount(IntPtr context);

136
    internal abstract IntPtr AggregateContext(IntPtr context);
167
        internal abstract IntPtr AggregateContext(IntPtr context);

137
168
138
    internal abstract long GetParamValueBytes(IntPtr ptr, int nDataOffset, byte[] bDest, int nStart, int nLength);
169
        internal abstract long GetParamValueBytes(IntPtr ptr, int nDataOffset, byte[] bDest, int nStart, int nLength);

139
    internal abstract double GetParamValueDouble(IntPtr ptr);
170
        internal abstract double GetParamValueDouble(IntPtr ptr);

140
    internal abstract int GetParamValueInt32(IntPtr ptr);
171
        internal abstract int GetParamValueInt32(IntPtr ptr);

141
    internal abstract Int64 GetParamValueInt64(IntPtr ptr);
172
        internal abstract Int64 GetParamValueInt64(IntPtr ptr);

142
    internal abstract string GetParamValueText(IntPtr ptr);
173
        internal abstract string GetParamValueText(IntPtr ptr);

143
    internal abstract TypeAffinity GetParamValueType(IntPtr ptr);
174
        internal abstract TypeAffinity GetParamValueType(IntPtr ptr);

144
175
145
    internal abstract void ReturnBlob(IntPtr context, byte[] value);
176
        internal abstract void ReturnBlob(IntPtr context, byte[] value);

146
    internal abstract void ReturnDouble(IntPtr context, double value);
177
        internal abstract void ReturnDouble(IntPtr context, double value);

147
    internal abstract void ReturnError(IntPtr context, string value);
178
        internal abstract void ReturnError(IntPtr context, string value);

148
    internal abstract void ReturnInt32(IntPtr context, Int32 value);
179
        internal abstract void ReturnInt32(IntPtr context, Int32 value);

149
    internal abstract void ReturnInt64(IntPtr context, Int64 value);
180
        internal abstract void ReturnInt64(IntPtr context, Int64 value);

150
    internal abstract void ReturnNull(IntPtr context);
181
        internal abstract void ReturnNull(IntPtr context);

151
    internal abstract void ReturnText(IntPtr context, string value);
182
        internal abstract void ReturnText(IntPtr context, string value);

152
183
153
    internal abstract void SetPassword(byte[] passwordBytes);
184
        internal abstract void SetPassword(byte[] passwordBytes);

154
    internal abstract void ChangePassword(byte[] newPasswordBytes);
185
        internal abstract void ChangePassword(byte[] newPasswordBytes);

155
186
156
    internal abstract void SetUpdateHook(SQLiteUpdateCallback func);
187
        internal abstract void SetUpdateHook(SQLiteUpdateCallback func);

157
    internal abstract void SetCommitHook(SQLiteCommitCallback func);
188
        internal abstract void SetCommitHook(SQLiteCommitCallback func);

158
    internal abstract void SetRollbackHook(SQLiteRollbackCallback func);
189
        internal abstract void SetRollbackHook(SQLiteRollbackCallback func);

159
190
160
    internal abstract int GetCursorForTable(SQLiteStatement stmt, int database, int rootPage);
191
        internal abstract int GetCursorForTable(SQLiteStatement stmt, int database, int rootPage);

161
    internal abstract long GetRowIdForCursor(SQLiteStatement stmt, int cursor);
192
        internal abstract long GetRowIdForCursor(SQLiteStatement stmt, int cursor);

162
193
163
    internal abstract object GetValue(SQLiteStatement stmt, int index, SQLiteType typ);
194
        internal abstract object GetValue(SQLiteStatement stmt, int index, SQLiteType typ);

164
195
165
    internal abstract bool AutoCommit
166
    {
167
      get;
168
    }
169
170
    protected virtual void Dispose(bool bDisposing)
196
        protected virtual void Dispose(bool bDisposing)

171
    {
197
        {
172
    }
198
        }
173
199
174
    public void Dispose()
175
    {
176
      Dispose(true);
177
      GC.SuppressFinalize(this);
178
    }
179
180
    // These statics are here for lack of a better place to put them.
200
        // These statics are here for lack of a better place to put them.

181
    // They exist here because they are called during the finalization of
201
        // They exist here because they are called during the finalization of

182
    // a SQLiteStatementHandle, SQLiteConnectionHandle, and SQLiteFunctionCookieHandle.
202
        // a SQLiteStatementHandle, SQLiteConnectionHandle, and SQLiteFunctionCookieHandle.

183
    // Therefore these functions have to be static, and have to be low-level.
203
        // Therefore these functions have to be static, and have to be low-level.

184
204
185
    internal static string SQLiteLastError(SQLiteConnectionHandle db)
205
        internal static string SQLiteLastError(SQLiteConnectionHandle db)

186
    {
206
        {
187
#if !SQLITE_STANDARD
207
#if !SQLITE_STANDARD

188
      int len;
208
            int len;

189
      return UTF8ToString(UnsafeNativeMethods.sqlite3_errmsg_interop(db, out len), len);
209
            return UTF8ToString(UnsafeNativeMethods.sqlite3_errmsg_interop(db, out len), len);

190
#else
210
#else
191
      return UTF8ToString(UnsafeNativeMethods.sqlite3_errmsg(db), -1);
211
      return UTF8ToString(UnsafeNativeMethods.sqlite3_errmsg(db), -1);

192
#endif
212
#endif

193
    }
213
        }
194
214
195
    internal static void FinalizeStatement(SQLiteStatementHandle stmt)
215
        internal static void FinalizeStatement(SQLiteStatementHandle stmt)

196
    {
216
        {
197
      lock (_lock)
217
            lock (_lock)

198
      {
218
            {
199
#if !SQLITE_STANDARD
219
#if !SQLITE_STANDARD

200
        int n = UnsafeNativeMethods.sqlite3_finalize_interop(stmt);
220
                int n = UnsafeNativeMethods.sqlite3_finalize_interop(stmt);

201
#else
221
#else
202
      int n = UnsafeNativeMethods.sqlite3_finalize(stmt);
222
      int n = UnsafeNativeMethods.sqlite3_finalize(stmt);

203
#endif
223
#endif

204
        if (n > 0) throw new SQLiteException(n, null);
224
                if (n > 0) throw new SQLiteException(n, null);

225
            }
205
      }
226
        }

206
    }
227
207
208
    internal static void CloseConnection(SQLiteConnectionHandle db)
228
        internal static void CloseConnection(SQLiteConnectionHandle db)

209
    {
229
        {
210
      lock (_lock)
230
            lock (_lock)

211
      {
231
            {
212
#if !SQLITE_STANDARD
232
#if !SQLITE_STANDARD

213
        int n = UnsafeNativeMethods.sqlite3_close_interop(db);
233
                int n = UnsafeNativeMethods.sqlite3_close_interop(db);

214
#else
234
#else
215
      ResetConnection(db);
235
      ResetConnection(db);
216
      int n = UnsafeNativeMethods.sqlite3_close(db);
236
      int n = UnsafeNativeMethods.sqlite3_close(db);

217
#endif
237
#endif

218
        if (n > 0) throw new SQLiteException(n, SQLiteLastError(db));
238
                if (n > 0) throw new SQLiteException(n, SQLiteLastError(db));

239
            }
219
      }
240
        }

220
    }
241
221
222
    internal static void ResetConnection(SQLiteConnectionHandle db)
242
        internal static void ResetConnection(SQLiteConnectionHandle db)

223
    {
224
      lock (_lock)
225
      {
226
        IntPtr stmt = IntPtr.Zero;
227
        int n;
228
        do
229
        {
243
        {

244
            lock (_lock)
245
            {
246
                IntPtr stmt = IntPtr.Zero;
247
                int n;
248
                do
249
                {
230
          stmt = UnsafeNativeMethods.sqlite3_next_stmt(db, stmt);
250
                    stmt = UnsafeNativeMethods.sqlite3_next_stmt(db, stmt);

231
          if (stmt != IntPtr.Zero)
251
                    if (stmt != IntPtr.Zero)

232
          {
252
                    {
233
#if !SQLITE_STANDARD
253
#if !SQLITE_STANDARD

234
            n = UnsafeNativeMethods.sqlite3_reset_interop(stmt);
254
                        n = UnsafeNativeMethods.sqlite3_reset_interop(stmt);

235
#else
255
#else
236
            n = UnsafeNativeMethods.sqlite3_reset(stmt);
256
            n = UnsafeNativeMethods.sqlite3_reset(stmt);

237
#endif
257
#endif

238
          }
258
                    }
239
        } while (stmt != IntPtr.Zero);
259
                } while (stmt != IntPtr.Zero);

240
260
241
        if (IsAutocommit(db) == false) // a transaction is pending on the connection
261
                if (IsAutocommit(db) == false) // a transaction is pending on the connection

242
        {
262
                {
243
          n = UnsafeNativeMethods.sqlite3_exec(db, ToUTF8("ROLLBACK"), IntPtr.Zero, IntPtr.Zero, out stmt);
263
                    n = UnsafeNativeMethods.sqlite3_exec(db, ToUTF8("ROLLBACK"), IntPtr.Zero, IntPtr.Zero, out stmt);

244
          if (n > 0) throw new SQLiteException(n, SQLiteLastError(db));
264
                    if (n > 0) throw new SQLiteException(n, SQLiteLastError(db));

265
                }
266
            }
245
        }
267
        }

246
      }
268
247
    }
248
249
    internal static bool IsAutocommit(SQLiteConnectionHandle hdl)
269
        internal static bool IsAutocommit(SQLiteConnectionHandle hdl)

250
    {
270
        {
251
      return (UnsafeNativeMethods.sqlite3_get_autocommit(hdl) == 1);
271
            return (UnsafeNativeMethods.sqlite3_get_autocommit(hdl) == 1);

272
        }
252
    }
273
    }

253
  }
274
254
255
  internal interface ISQLiteSchemaExtensions
275
    internal interface ISQLiteSchemaExtensions

256
  {
276
    {
257
    void BuildTempSchema(SQLiteConnection cnn);
277
        void BuildTempSchema(SQLiteConnection cnn);

258
  }
278
    }
259
279
260
  [Flags]
280
    [Flags]

261
  internal enum SQLiteOpenFlagsEnum
281
    internal enum SQLiteOpenFlagsEnum

262
  {
282
    {
263
    None = 0,
283
        None = 0,

264
    ReadOnly = 0x01,
284
        ReadOnly = 0x01,

265
    ReadWrite = 0x02,
285
        ReadWrite = 0x02,

266
    Create = 0x04,
286
        Create = 0x04,

267
    SharedCache = 0x01000000,
287
        SharedCache = 0x01000000,

268
    Default = 0x06,
288
        Default = 0x06,

269
  }
289
    }
270
}
290
}