System.Data.SQLite
Check-in [4a9980ac1d]
Not logged in

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

Overview
Comment:More reform to the logging subsystem. Move interop log callback into the SQLiteLog class.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 4a9980ac1dd1910d0d792bc8c10bedf788e967ea
User & Date: mistachkin 2018-07-26 07:56:30
Context
2018-07-26
08:18
Update 'vendor.eagle' to account for changes missing from check-in [7ffb245069b22e2e]. check-in: de528e1be1 user: mistachkin tags: trunk
07:56
More reform to the logging subsystem. Move interop log callback into the SQLiteLog class. check-in: 4a9980ac1d user: mistachkin tags: trunk
07:24
Fixes to the new SQLiteLog initialization handling and associated test suite infrastructure updates. check-in: 04d60edbdf user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to System.Data.SQLite/LINQ/SQLiteFactory_Linq.cs.

    39     39   
    40     40       static SQLiteFactory()
    41     41       {
    42     42   #if (SQLITE_STANDARD || USE_INTEROP_DLL || PLATFORM_COMPACTFRAMEWORK) && PRELOAD_NATIVE_LIBRARY
    43     43           UnsafeNativeMethods.Initialize();
    44     44   #endif
    45     45   
    46         -#if USE_INTEROP_DLL && INTEROP_LOG
    47         -        SQLiteErrorCode rc = UnsafeNativeMethods.sqlite3_config_log_interop();
    48         -
    49         -        if (rc == SQLiteErrorCode.Ok)
    50         -        {
    51         -            UnsafeNativeMethods.sqlite3_log(
    52         -                rc, SQLiteConvert.ToUTF8("logging initialized via SQLiteFactory."));
    53         -        }
    54         -#endif
    55         -
    56         -        SQLiteLog.Initialize();
           46  +        SQLiteLog.Initialize(typeof(SQLiteFactory).Name);
    57     47   
    58     48           string version =
    59     49   #if NET_40 || NET_45 || NET_451 || NET_452 || NET_46 || NET_461 || NET_462 || NET_47 || NET_471 || NET_472
    60     50               "4.0.0.0";
    61     51   #else
    62     52               "3.5.0.0";
    63     53   #endif

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

  3942   3942       /// initialized for the current process.
  3943   3943       /// </returns>
  3944   3944       internal override bool IsInitialized()
  3945   3945       {
  3946   3946           return StaticIsInitialized();
  3947   3947       }
  3948   3948   
         3949  +    ///////////////////////////////////////////////////////////////////////////////////////////////
         3950  +
  3949   3951       /// <summary>
  3950   3952       /// Determines if the SQLite core library has been initialized for the
  3951   3953       /// current process.
  3952   3954       /// </summary>
  3953   3955       /// <returns>
  3954   3956       /// A boolean indicating whether or not the SQLite core library has been
  3955   3957       /// initialized for the current process.
................................................................................
  3984   3986               }
  3985   3987               finally
  3986   3988               {
  3987   3989                   SQLiteLog.Enabled = savedEnabled;
  3988   3990               }
  3989   3991           }
  3990   3992       }
         3993  +
         3994  +    ///////////////////////////////////////////////////////////////////////////////////////////////
         3995  +
         3996  +#if USE_INTEROP_DLL && INTEROP_LOG
         3997  +    internal static SQLiteErrorCode TryConfigureLogForInterop(
         3998  +        string className
         3999  +        )
         4000  +    {
         4001  +        SQLiteErrorCode rc = UnsafeNativeMethods.sqlite3_config_log_interop();
         4002  +
         4003  +        if (rc == SQLiteErrorCode.Ok)
         4004  +        {
         4005  +            UnsafeNativeMethods.sqlite3_log(rc, SQLiteConvert.ToUTF8(
         4006  +                HelperMethods.StringFormat(CultureInfo.InvariantCulture,
         4007  +                    "logging initialized via \"{0}\".", className)));
         4008  +        }
         4009  +
         4010  +        return rc;
         4011  +    }
         4012  +#endif
         4013  +
         4014  +    ///////////////////////////////////////////////////////////////////////////////////////////////
  3991   4015   
  3992   4016       /// <summary>
  3993   4017       /// Helper function to retrieve a column of data from an active statement.
  3994   4018       /// </summary>
  3995   4019       /// <param name="stmt">The statement being step()'d through</param>
  3996   4020       /// <param name="flags">The flags associated with the connection.</param>
  3997   4021       /// <param name="index">The column index to retrieve</param>

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

  1762   1762       {
  1763   1763         _noDispose = false;
  1764   1764   
  1765   1765   #if (SQLITE_STANDARD || USE_INTEROP_DLL || PLATFORM_COMPACTFRAMEWORK) && PRELOAD_NATIVE_LIBRARY
  1766   1766         UnsafeNativeMethods.Initialize();
  1767   1767   #endif
  1768   1768   
  1769         -      SQLiteLog.Initialize();
         1769  +      SQLiteLog.Initialize(typeof(SQLiteConnection).Name);
  1770   1770   
  1771   1771   #if !PLATFORM_COMPACTFRAMEWORK && !INTEROP_LEGACY_CLOSE && SQLITE_STANDARD
  1772   1772         //
  1773   1773         // NOTE: Check if the sqlite3_close_v2() native API should be available
  1774   1774         //       to use.  This must be done dynamically because the delegate set
  1775   1775         //       here is used by the SQLiteConnectionHandle class, which is a
  1776   1776         //       CriticalHandle derived class (i.e. protected by a constrained
................................................................................
  1788   1788   
  1789   1789                 if (_versionNumber >= 3007014)
  1790   1790                     SQLiteConnectionHandle.closeConnection = SQLiteBase.CloseConnectionV2;
  1791   1791             }
  1792   1792         }
  1793   1793   #endif
  1794   1794   
  1795         -#if USE_INTEROP_DLL && INTEROP_LOG
  1796         -      SQLiteErrorCode rc = UnsafeNativeMethods.sqlite3_config_log_interop();
  1797         -
  1798         -      if (rc == SQLiteErrorCode.Ok)
  1799         -      {
  1800         -          UnsafeNativeMethods.sqlite3_log(
  1801         -              rc, SQLiteConvert.ToUTF8("logging initialized via SQLiteConnection."));
  1802         -      }
  1803         -#endif
  1804         -
  1805   1795         _cachedSettings = new Dictionary<string, object>(
  1806   1796             new TypeNameStringComparer());
  1807   1797   
  1808   1798         _typeNames = new SQLiteDbTypeMap();
  1809   1799         _typeCallbacks = new SQLiteTypeCallbacksMap();
  1810   1800         _parseViaFramework = parseViaFramework;
  1811   1801         _flags = SQLiteConnectionFlags.None;

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

   137    137   
   138    138           ///////////////////////////////////////////////////////////////////////
   139    139   
   140    140           /// <summary>
   141    141           /// Initializes the SQLite logging facilities.
   142    142           /// </summary>
   143    143           public static void Initialize()
          144  +        {
          145  +            Initialize(null);
          146  +        }
          147  +
          148  +        ///////////////////////////////////////////////////////////////////////
          149  +
          150  +        /// <summary>
          151  +        /// Initializes the SQLite logging facilities.
          152  +        /// </summary>
          153  +        /// <param name="className">
          154  +        /// The name of the managed class that called this method.  This
          155  +        /// parameter may be null.
          156  +        /// </param>
          157  +        internal static void Initialize(
          158  +            string className
          159  +            )
   144    160           {
   145    161               //
   146    162               // NOTE: First, check if the managed logging subsystem is always
   147    163               //       supposed to at least attempt to initialize itself.  In
   148    164               //       order to do this, several fairly complex steps must be
   149    165               //       taken, including calling a P/Invoke (interop) method;
   150    166               //       therefore, by default, attempt to perform these steps
................................................................................
   156    172                   if (Interlocked.Increment(ref _attemptedInitialize) > 1)
   157    173                   {
   158    174                       Interlocked.Decrement(ref _attemptedInitialize);
   159    175                       return;
   160    176                   }
   161    177               }
   162    178   
          179  +            ///////////////////////////////////////////////////////////////////
          180  +
   163    181               //
   164    182               // BUFXIX: We cannot initialize the logging interface if the SQLite
   165    183               //         core library has already been initialized anywhere in
   166    184               //         the process (see ticket [2ce0870fad]).
   167    185               //
   168    186               if (SQLite3.StaticIsInitialized())
   169    187                   return;
          188  +
          189  +            ///////////////////////////////////////////////////////////////////
   170    190   
   171    191   #if !PLATFORM_COMPACTFRAMEWORK
   172    192               //
   173    193               // BUGFIX: To avoid nasty situations where multiple AppDomains are
   174    194               //         attempting to initialize and/or shutdown what is really
   175    195               //         a shared native resource (i.e. the SQLite core library
   176    196               //         is loaded per-process and has only one logging callback,
................................................................................
   181    201               //
   182    202               if (!AppDomain.CurrentDomain.IsDefaultAppDomain() &&
   183    203                   UnsafeNativeMethods.GetSettingValue("Force_SQLiteLog", null) == null)
   184    204               {
   185    205                   return;
   186    206               }
   187    207   #endif
          208  +
          209  +            ///////////////////////////////////////////////////////////////////
   188    210   
   189    211               lock (syncRoot)
   190    212               {
   191    213   #if !PLATFORM_COMPACTFRAMEWORK
   192    214                   //
   193    215                   // NOTE: Add an event handler for the DomainUnload event so
   194    216                   //       that we can unhook our logging managed function
................................................................................
   201    223                   if (_domainUnload == null)
   202    224                   {
   203    225                       _domainUnload = new EventHandler(DomainUnload);
   204    226                       AppDomain.CurrentDomain.DomainUnload += _domainUnload;
   205    227                   }
   206    228   #endif
   207    229   
   208         -#if !USE_INTEROP_DLL || !INTEROP_LOG
          230  +                ///////////////////////////////////////////////////////////////
          231  +
          232  +#if USE_INTEROP_DLL && INTEROP_LOG
          233  +                //
          234  +                // NOTE: Attempt to setup interop assembly log callback.
          235  +                //       This may fail, e.g. if the SQLite core library
          236  +                //       has somehow been initialized.  An exception will
          237  +                //       be raised in that case.
          238  +                //
          239  +                SQLiteErrorCode rc = SQLite3.TryConfigureLogForInterop(
          240  +                    className);
          241  +
          242  +                if (rc != SQLiteErrorCode.Ok)
          243  +                {
          244  +                    throw new SQLiteException(rc,
          245  +                        "Failed to configure interop assembly logging.");
          246  +                }
          247  +#else
   209    248                   //
   210    249                   // NOTE: Create an instance of the SQLite wrapper class.
   211    250                   //
   212    251                   if (_sql == null)
   213    252                   {
   214    253                       _sql = new SQLite3(
   215    254                           SQLiteDateFormats.Default, DateTimeKind.Unspecified,
................................................................................
   225    264                   if (_callback == null)
   226    265                   {
   227    266                       _callback = new SQLiteLogCallback(LogCallback);
   228    267   
   229    268                       SQLiteErrorCode rc = _sql.SetLogCallback(_callback);
   230    269   
   231    270                       if (rc != SQLiteErrorCode.Ok)
          271  +                    {
   232    272                           throw new SQLiteException(rc,
   233         -                            "Failed to initialize logging.");
          273  +                            "Failed to configure managed assembly logging.");
          274  +                    }
   234    275                   }
   235    276   #endif
          277  +
          278  +                ///////////////////////////////////////////////////////////////
   236    279   
   237    280                   //
   238    281                   // NOTE: Logging is enabled by default unless the configuration
   239    282                   //       setting "Disable_SQLiteLog" is present.
   240    283                   //
   241    284                   if (UnsafeNativeMethods.GetSettingValue(
   242    285                           "Disable_SQLiteLog", null) == null)
   243    286                   {
   244    287                       _enabled = true;
   245    288                   }
          289  +
          290  +                ///////////////////////////////////////////////////////////////
   246    291   
   247    292                   //
   248    293                   // NOTE: For now, always setup the default log event handler.
   249    294                   //
   250    295                   AddDefaultHandler();
   251    296               }
   252    297           }