System.Data.SQLite
Check-in [40cdd9c8a0]
Not logged in

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 | SQL archive
Timelines: family | ancestors | descendants | both | tkt-e30b820248
Files: files | file ages | folders
SHA1: 40cdd9c8a03565f532d912f0fe4d96ca76c5a29e
User & Date: mistachkin 2011-11-14 05:12:07
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
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to System.Data.SQLite/SQLite3.cs.

     4      4    * 
     5      5    * Released to the public domain, use at your own risk!
     6      6    ********************************************************/
     7      7   
     8      8   namespace System.Data.SQLite
     9      9   {
    10     10     using System;
           11  +#if DEBUG
           12  +  using System.Diagnostics;
           13  +#endif
    11     14     using System.Runtime.InteropServices;
    12     15   
    13     16   #if !PLATFORM_COMPACTFRAMEWORK
    14     17     [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
    15     18   #endif
    16     19     internal delegate void SQLiteLogCallback(IntPtr puser, int err_code, IntPtr message);
    17     20   
................................................................................
   164    167           IntPtr db;
   165    168   
   166    169   #if !SQLITE_STANDARD
   167    170           int n = UnsafeNativeMethods.sqlite3_open_interop(ToUTF8(strFilename), (int)flags, out db);
   168    171   #else
   169    172           int n = UnsafeNativeMethods.sqlite3_open_v2(ToUTF8(strFilename), out db, (int)flags, IntPtr.Zero);
   170    173   #endif
          174  +
          175  +#if DEBUG
          176  +        Trace.WriteLine(String.Format("Open: {0}", db));
          177  +#endif
          178  +
   171    179           if (n > 0) throw new SQLiteException(n, null);
   172    180   
   173    181           _sql = db;
   174    182         }
   175    183         // Bind functions to this connection.  If any previous functions of the same name
   176    184         // were already bound, then the new bindings replace the old.
   177    185         _functionsArray = SQLiteFunction.BindFunctions(this);
................................................................................
   319    327           {
   320    328   #if !SQLITE_STANDARD
   321    329             n = UnsafeNativeMethods.sqlite3_prepare_interop(_sql, psql, b.Length - 1, out stmt, out ptr, out len);
   322    330   #else
   323    331             n = UnsafeNativeMethods.sqlite3_prepare(_sql, psql, b.Length - 1, out stmt, out ptr);
   324    332             len = -1;
   325    333   #endif
          334  +
          335  +#if DEBUG
          336  +          Trace.WriteLine(String.Format("Prepare: {0}", stmt));
          337  +#endif
   326    338   
   327    339             if (n == 17)
   328    340               retries++;
   329    341             else if (n == 1)
   330    342             {
   331    343               if (String.Compare(SQLiteLastError(), "near \"TYPES\": syntax error", StringComparison.OrdinalIgnoreCase) == 0)
   332    344               {

Changes to System.Data.SQLite/SQLite3_UTF16.cs.

     4      4    * 
     5      5    * Released to the public domain, use at your own risk!
     6      6    ********************************************************/
     7      7   
     8      8   namespace System.Data.SQLite
     9      9   {
    10     10     using System;
           11  +#if DEBUG
           12  +  using System.Diagnostics;
           13  +#endif
    11     14     using System.Runtime.InteropServices;
    12     15   
    13     16     /// <summary>
    14     17     /// Alternate SQLite3 object, overriding many text behaviors to support UTF-16 (Unicode)
    15     18     /// </summary>
    16     19     internal class SQLite3_UTF16 : SQLite3
    17     20     {
................................................................................
    60     63           int n = UnsafeNativeMethods.sqlite3_open16_interop(ToUTF8(strFilename), (int)flags, out db);
    61     64   #else
    62     65           if ((flags & SQLiteOpenFlagsEnum.Create) == 0 && System.IO.File.Exists(strFilename) == false)
    63     66             throw new SQLiteException((int)SQLiteErrorCode.CantOpen, strFilename);
    64     67   
    65     68           int n = UnsafeNativeMethods.sqlite3_open16(strFilename, out db);
    66     69   #endif
           70  +
           71  +#if DEBUG
           72  +        Trace.WriteLine(String.Format("Open: {0}", db));
           73  +#endif
           74  +
    67     75           if (n > 0) throw new SQLiteException(n, null);
    68     76   
    69     77           _sql = db;
    70     78         }
    71     79         _functionsArray = SQLiteFunction.BindFunctions(this);
    72     80       }
    73     81   

Changes to System.Data.SQLite/SQLiteLog.cs.

   353    353           {
   354    354               if (e == null)
   355    355                   return;
   356    356   
   357    357               string message = e.Message;
   358    358   
   359    359               if (message == null)
          360  +            {
   360    361                   message = "<null>";
   361         -            else if (message.Length == 0)
          362  +            }
          363  +            else
          364  +            {
          365  +                message = message.Trim();
          366  +
          367  +                if (message.Length == 0)
   362    368                   message = "<empty>";
          369  +            }
   363    370   
   364    371               Trace.WriteLine(String.Format("SQLite error ({0}): {1}",
   365    372                   e.ErrorCode, message));
   366    373           }
   367    374       }
   368    375   #endif
   369    376   }

Changes to System.Data.SQLite/UnsafeNativeMethods.cs.

     4      4    * 
     5      5    * Released to the public domain, use at your own risk!
     6      6    ********************************************************/
     7      7   
     8      8   namespace System.Data.SQLite
     9      9   {
    10     10     using System;
           11  +#if DEBUG
           12  +  using System.Diagnostics;
           13  +#endif
    11     14   
    12     15   #if !PLATFORM_COMPACTFRAMEWORK && !DEBUG
    13     16     using System.Security;
    14     17   #endif
    15     18   
    16     19     using System.Runtime.InteropServices;
    17     20   
................................................................................
   869    872       {
   870    873       }
   871    874   
   872    875       protected override bool ReleaseHandle()
   873    876       {
   874    877         try
   875    878         {
          879  +#if DEBUG
          880  +        Trace.WriteLine(String.Format("CloseConnection: {0}", handle));
          881  +#endif
          882  +
   876    883           SQLiteBase.CloseConnection(this);
   877    884   #if DEBUG
   878    885           return true;
   879    886   #endif
   880    887         }
   881    888         catch (SQLiteException)
   882    889         {
................................................................................
   918    925       {
   919    926       }
   920    927   
   921    928       protected override bool ReleaseHandle()
   922    929       {
   923    930         try
   924    931         {
          932  +#if DEBUG
          933  +        Trace.WriteLine(String.Format("FinalizeStatement: {0}", handle));
          934  +#endif
          935  +
   925    936           SQLiteBase.FinalizeStatement(this);
   926    937   #if DEBUG
   927    938           return true;
   928    939   #endif
   929    940         }
   930    941         catch (SQLiteException)
   931    942         {