System.Data.SQLite

Check-in [40cdd9c8a0]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Revise and improve diagnostics for opening/closing connections and preparing/finalizing statements.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | tkt-e30b820248
Files: files | file ages | folders
SHA1: 40cdd9c8a03565f532d912f0fe4d96ca76c5a29e
User & Date: mistachkin 2011-11-14 05:12:07.343
Context
2011-11-14
05:20
Stop simply characterizing all log messages as errors. From now on, if the errorCode is zero, the message will not be considered an error. check-in: e6e51e382e user: mistachkin tags: tkt-e30b820248
05:12
Revise and improve diagnostics for opening/closing connections and preparing/finalizing statements. check-in: 40cdd9c8a0 user: mistachkin tags: tkt-e30b820248
2011-11-13
23:47
When compiling with DEBUG defined, complain about failures to release CriticalHandle objects. Also, add more diagnostics to test case for ticket [e30b820248]. check-in: 5578f853af user: mistachkin tags: tkt-e30b820248
Changes
Side-by-Side Diff Ignore Whitespace Patch
Changes to System.Data.SQLite/SQLite3.cs.
1
2
3
4
5
6
7
8
9
10



11
12
13
14
15
16
17
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20










+
+
+







/********************************************************
 * ADO.NET 2.0 Data Provider for SQLite Version 3.X
 * Written by Robert Simpson (robert@blackcastlesoft.com)
 * 
 * Released to the public domain, use at your own risk!
 ********************************************************/

namespace System.Data.SQLite
{
  using System;
#if DEBUG
  using System.Diagnostics;
#endif
  using System.Runtime.InteropServices;

#if !PLATFORM_COMPACTFRAMEWORK
  [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
#endif
  internal delegate void SQLiteLogCallback(IntPtr puser, int err_code, IntPtr message);

164
165
166
167
168
169
170





171
172
173
174
175
176
177
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185







+
+
+
+
+







        IntPtr db;

#if !SQLITE_STANDARD
        int n = UnsafeNativeMethods.sqlite3_open_interop(ToUTF8(strFilename), (int)flags, out db);
#else
        int n = UnsafeNativeMethods.sqlite3_open_v2(ToUTF8(strFilename), out db, (int)flags, IntPtr.Zero);
#endif

#if DEBUG
        Trace.WriteLine(String.Format("Open: {0}", db));
#endif

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

        _sql = db;
      }
      // Bind functions to this connection.  If any previous functions of the same name
      // were already bound, then the new bindings replace the old.
      _functionsArray = SQLiteFunction.BindFunctions(this);
319
320
321
322
323
324
325




326
327
328
329
330
331
332
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344







+
+
+
+







        {
#if !SQLITE_STANDARD
          n = UnsafeNativeMethods.sqlite3_prepare_interop(_sql, psql, b.Length - 1, out stmt, out ptr, out len);
#else
          n = UnsafeNativeMethods.sqlite3_prepare(_sql, psql, b.Length - 1, out stmt, out ptr);
          len = -1;
#endif

#if DEBUG
          Trace.WriteLine(String.Format("Prepare: {0}", stmt));
#endif

          if (n == 17)
            retries++;
          else if (n == 1)
          {
            if (String.Compare(SQLiteLastError(), "near \"TYPES\": syntax error", StringComparison.OrdinalIgnoreCase) == 0)
            {
Changes to System.Data.SQLite/SQLite3_UTF16.cs.
1
2
3
4
5
6
7
8
9
10



11
12
13
14
15
16
17
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20










+
+
+







/********************************************************
 * ADO.NET 2.0 Data Provider for SQLite Version 3.X
 * Written by Robert Simpson (robert@blackcastlesoft.com)
 * 
 * Released to the public domain, use at your own risk!
 ********************************************************/

namespace System.Data.SQLite
{
  using System;
#if DEBUG
  using System.Diagnostics;
#endif
  using System.Runtime.InteropServices;

  /// <summary>
  /// Alternate SQLite3 object, overriding many text behaviors to support UTF-16 (Unicode)
  /// </summary>
  internal class SQLite3_UTF16 : SQLite3
  {
60
61
62
63
64
65
66





67
68
69
70
71
72
73
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81







+
+
+
+
+







        int n = UnsafeNativeMethods.sqlite3_open16_interop(ToUTF8(strFilename), (int)flags, out db);
#else
        if ((flags & SQLiteOpenFlagsEnum.Create) == 0 && System.IO.File.Exists(strFilename) == false)
          throw new SQLiteException((int)SQLiteErrorCode.CantOpen, strFilename);

        int n = UnsafeNativeMethods.sqlite3_open16(strFilename, out db);
#endif

#if DEBUG
        Trace.WriteLine(String.Format("Open: {0}", db));
#endif

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

        _sql = db;
      }
      _functionsArray = SQLiteFunction.BindFunctions(this);
    }

Changes to System.Data.SQLite/SQLiteLog.cs.
353
354
355
356
357
358
359

360





361
362



363
364
365
366
367
368
369
353
354
355
356
357
358
359
360
361
362
363
364
365
366


367
368
369
370
371
372
373
374
375
376







+

+
+
+
+
+
-
-
+
+
+







        {
            if (e == null)
                return;

            string message = e.Message;

            if (message == null)
            {
                message = "<null>";
            }
            else
            {
                message = message.Trim();

            else if (message.Length == 0)
                message = "<empty>";
                if (message.Length == 0)
                    message = "<empty>";
            }

            Trace.WriteLine(String.Format("SQLite error ({0}): {1}",
                e.ErrorCode, message));
        }
    }
#endif
}
Changes to System.Data.SQLite/UnsafeNativeMethods.cs.
1
2
3
4
5
6
7
8
9
10



11
12
13
14
15
16
17
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20










+
+
+







/********************************************************
 * ADO.NET 2.0 Data Provider for SQLite Version 3.X
 * Written by Robert Simpson (robert@blackcastlesoft.com)
 * 
 * Released to the public domain, use at your own risk!
 ********************************************************/

namespace System.Data.SQLite
{
  using System;
#if DEBUG
  using System.Diagnostics;
#endif

#if !PLATFORM_COMPACTFRAMEWORK && !DEBUG
  using System.Security;
#endif

  using System.Runtime.InteropServices;

869
870
871
872
873
874
875




876
877
878
879
880
881
882
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889







+
+
+
+







    {
    }

    protected override bool ReleaseHandle()
    {
      try
      {
#if DEBUG
        Trace.WriteLine(String.Format("CloseConnection: {0}", handle));
#endif

        SQLiteBase.CloseConnection(this);
#if DEBUG
        return true;
#endif
      }
      catch (SQLiteException)
      {
918
919
920
921
922
923
924




925
926
927
928
929
930
931
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942







+
+
+
+







    {
    }

    protected override bool ReleaseHandle()
    {
      try
      {
#if DEBUG
        Trace.WriteLine(String.Format("FinalizeStatement: {0}", handle));
#endif

        SQLiteBase.FinalizeStatement(this);
#if DEBUG
        return true;
#endif
      }
      catch (SQLiteException)
      {