System.Data.SQLite

Login
This project makes use of Eagle, provided by Mistachkin Systems.
Eagle: Secure Software Automation

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

Changes In Branch sqliteLog Excluding Merge-Ins

This is equivalent to a diff from 232364a514 to 5cd4a102a9

2019-05-15
01:49
Bump version number. Update version history docs. check-in: 95e0135ad1 user: mistachkin tags: trunk
01:28
Experimental changes to the SQLiteLog class to enable forced use of the managed logging callback. Leaf check-in: 5cd4a102a9 user: mistachkin tags: sqliteLog
01:08
Add additional tests for the SQLiteLog.Initialize method. Add 'No_SQLiteLog' environment variable to disable the SQLiteLog subsystem initialization. check-in: 232364a514 user: mistachkin tags: trunk
2019-05-14
20:22
Slightly improve error handling in the SQLiteLog.Initialize method. check-in: 0f34d6ea03 user: mistachkin tags: trunk

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

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

    static SQLiteFactory()
    {
#if (SQLITE_STANDARD || USE_INTEROP_DLL || PLATFORM_COMPACTFRAMEWORK) && PRELOAD_NATIVE_LIBRARY
        UnsafeNativeMethods.Initialize();
#endif

        SQLiteLog.Initialize(typeof(SQLiteFactory).Name);

        string version =
#if NET_40 || NET_45 || NET_451 || NET_452 || NET_46 || NET_461 || NET_462 || NET_47 || NET_471 || NET_472
            "4.0.0.0";
#else
            "3.5.0.0";
#endif







|







39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

    static SQLiteFactory()
    {
#if (SQLITE_STANDARD || USE_INTEROP_DLL || PLATFORM_COMPACTFRAMEWORK) && PRELOAD_NATIVE_LIBRARY
        UnsafeNativeMethods.Initialize();
#endif

        SQLiteLog.Initialize(typeof(SQLiteFactory).Name, false);

        string version =
#if NET_40 || NET_45 || NET_451 || NET_452 || NET_46 || NET_461 || NET_462 || NET_47 || NET_471 || NET_472
            "4.0.0.0";
#else
            "3.5.0.0";
#endif

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

1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
    {
      _noDispose = false;

#if (SQLITE_STANDARD || USE_INTEROP_DLL || PLATFORM_COMPACTFRAMEWORK) && PRELOAD_NATIVE_LIBRARY
      UnsafeNativeMethods.Initialize();
#endif

      SQLiteLog.Initialize(typeof(SQLiteConnection).Name);

#if !PLATFORM_COMPACTFRAMEWORK && !INTEROP_LEGACY_CLOSE && SQLITE_STANDARD
      //
      // NOTE: Check if the sqlite3_close_v2() native API should be available
      //       to use.  This must be done dynamically because the delegate set
      //       here is used by the SQLiteConnectionHandle class, which is a
      //       CriticalHandle derived class (i.e. protected by a constrained







|







1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
    {
      _noDispose = false;

#if (SQLITE_STANDARD || USE_INTEROP_DLL || PLATFORM_COMPACTFRAMEWORK) && PRELOAD_NATIVE_LIBRARY
      UnsafeNativeMethods.Initialize();
#endif

      SQLiteLog.Initialize(typeof(SQLiteConnection).Name, false);

#if !PLATFORM_COMPACTFRAMEWORK && !INTEROP_LEGACY_CLOSE && SQLITE_STANDARD
      //
      // NOTE: Check if the sqlite3_close_v2() native API should be available
      //       to use.  This must be done dynamically because the delegate set
      //       here is used by the SQLiteConnectionHandle class, which is a
      //       CriticalHandle derived class (i.e. protected by a constrained

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

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
        /// <summary>
        /// The default log event handler.
        /// </summary>
        private static SQLiteLogEventHandler _defaultHandler;

        ///////////////////////////////////////////////////////////////////////

#if !USE_INTEROP_DLL || !INTEROP_LOG
        /// <summary>
        /// The log callback passed to native SQLite engine.  This must live
        /// as long as the SQLite library has a pointer to it.
        /// </summary>
        private static SQLiteLogCallback _callback;

        ///////////////////////////////////////////////////////////////////////

        /// <summary>
        /// The base SQLite object to interop with.
        /// </summary>
        private static SQLiteBase _sql;
#endif

        ///////////////////////////////////////////////////////////////////////

        /// <summary>
        /// The number of times that the <see cref="Initialize(string)" />
        /// has been called when the logging subystem was actually eligible
        /// to be initialized (i.e. without the "No_SQLiteLog" environment
        /// variable being set).
        /// </summary>
        private static int _initializeCallCount;

        ///////////////////////////////////////////////////////////////////////







<












<




|







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
        /// <summary>
        /// The default log event handler.
        /// </summary>
        private static SQLiteLogEventHandler _defaultHandler;

        ///////////////////////////////////////////////////////////////////////


        /// <summary>
        /// The log callback passed to native SQLite engine.  This must live
        /// as long as the SQLite library has a pointer to it.
        /// </summary>
        private static SQLiteLogCallback _callback;

        ///////////////////////////////////////////////////////////////////////

        /// <summary>
        /// The base SQLite object to interop with.
        /// </summary>
        private static SQLiteBase _sql;


        ///////////////////////////////////////////////////////////////////////

        /// <summary>
        /// The number of times that the <see cref="Initialize(string,bool)" />
        /// has been called when the logging subystem was actually eligible
        /// to be initialized (i.e. without the "No_SQLiteLog" environment
        /// variable being set).
        /// </summary>
        private static int _initializeCallCount;

        ///////////////////////////////////////////////////////////////////////
148
149
150
151
152
153
154



















155
156
157
158
159
160
161
162
163
164
165
166







167
168

169
170
171
172
173
174
175
        ///////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Initializes the SQLite logging facilities.
        /// </summary>
        public static void Initialize()
        {



















            Initialize(null);
        }

        ///////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Initializes the SQLite logging facilities.
        /// </summary>
        /// <param name="className">
        /// The name of the managed class that called this method.  This
        /// parameter may be null.
        /// </param>







        internal static void Initialize(
            string className

            )
        {
            //
            // NOTE: See if the logging subsystem has been totally disabled.
            //       If so, do nothing.
            //
            if (UnsafeNativeMethods.GetSettingValue(







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|











>
>
>
>
>
>
>

|
>







146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
        ///////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Initializes the SQLite logging facilities.
        /// </summary>
        public static void Initialize()
        {
            Initialize(false);
        }

        ///////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Initializes the SQLite logging facilities.
        /// </summary>
        /// <param name="managedOnly">
        /// When this parameter is non-zero, the native logging callback
        /// provided by the SQLite interop assembly will not be used, even
        /// if it is available.  When the native logging callback provided
        /// by the SQLite interop assembly is not available, the value of
        /// this parameter is ignored.
        /// </param>
        public static void Initialize(
            bool managedOnly
            )
        {
            Initialize(null, managedOnly);
        }

        ///////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Initializes the SQLite logging facilities.
        /// </summary>
        /// <param name="className">
        /// The name of the managed class that called this method.  This
        /// parameter may be null.
        /// </param>
        /// <param name="managedOnly">
        /// When this parameter is non-zero, the native logging callback
        /// provided by the SQLite interop assembly will not be used, even
        /// if it is available.  When the native logging callback provided
        /// by the SQLite interop assembly is not available, the value of
        /// this parameter is ignored.
        /// </param>
        internal static void Initialize(
            string className,
            bool managedOnly
            )
        {
            //
            // NOTE: See if the logging subsystem has been totally disabled.
            //       If so, do nothing.
            //
            if (UnsafeNativeMethods.GetSettingValue(
256
257
258
259
260
261
262


263
264
265
266
267
268
269
270
271
272
273
274
275
276

277


278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308

309
310
311
312
313
314
315
                    AppDomain.CurrentDomain.DomainUnload += _domainUnload;
                }
#endif

                ///////////////////////////////////////////////////////////////

#if USE_INTEROP_DLL && INTEROP_LOG


                //
                // NOTE: Attempt to setup interop assembly log callback.
                //       This may fail, e.g. if the SQLite core library
                //       has somehow been initialized.  An exception will
                //       be raised in that case.
                //
                SQLiteErrorCode rc = SQLite3.ConfigureLogForInterop(
                    className);

                if (rc != SQLiteErrorCode.Ok)
                {
                    throw new SQLiteException(rc,
                        "Failed to configure interop assembly logging.");
                }

#else


                //
                // NOTE: Create an instance of the SQLite wrapper class.
                //
                if (_sql == null)
                {
                    _sql = new SQLite3(
                        SQLiteDateFormats.Default, DateTimeKind.Unspecified,
                        null, IntPtr.Zero, null, false);
                }

                //
                // NOTE: Create a single "global" (i.e. per-process) callback
                //       to register with SQLite.  This callback will pass the
                //       event on to any registered handler.  We only want to
                //       do this once.
                //
                if (_callback == null)
                {
                    _callback = new SQLiteLogCallback(LogCallback);

                    SQLiteErrorCode rc = _sql.SetLogCallback(_callback);

                    if (rc != SQLiteErrorCode.Ok)
                    {
                        _callback = null; /* UNDO */

                        throw new SQLiteException(rc,
                            "Failed to configure managed assembly logging.");
                    }
                }
#endif


                ///////////////////////////////////////////////////////////////

                //
                // NOTE: Logging is enabled by default unless the configuration
                //       setting "Disable_SQLiteLog" is present.
                //







>
>
|
|
|
|
|
|
|
|

|
|
|
|
|
>
|
>
>
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|

|

|
|
|

|
|
|
|
<
>







281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337

338
339
340
341
342
343
344
345
                    AppDomain.CurrentDomain.DomainUnload += _domainUnload;
                }
#endif

                ///////////////////////////////////////////////////////////////

#if USE_INTEROP_DLL && INTEROP_LOG
                if (!managedOnly)
                {
                    //
                    // NOTE: Attempt to setup interop assembly log callback.
                    //       This may fail, e.g. if the SQLite core library
                    //       has somehow been initialized.  An exception will
                    //       be raised in that case.
                    //
                    SQLiteErrorCode rc = SQLite3.ConfigureLogForInterop(
                        className);

                    if (rc != SQLiteErrorCode.Ok)
                    {
                        throw new SQLiteException(rc,
                            "Failed to configure interop assembly logging.");
                    }
                }
                else
#endif
                {
                    //
                    // NOTE: Create an instance of the SQLite wrapper class.
                    //
                    if (_sql == null)
                    {
                        _sql = new SQLite3(SQLiteDateFormats.Default,
                            DateTimeKind.Unspecified, null, IntPtr.Zero,
                            null, false);
                    }

                    //
                    // NOTE: Create single global (i.e. per-process) callback
                    //       to register with SQLite.  The callback will pass
                    //       the event on to any registered handler.  We only
                    //       want to do this once.
                    //
                    if (_callback == null)
                    {
                        _callback = new SQLiteLogCallback(LogCallback);

                        SQLiteErrorCode rc = _sql.SetLogCallback(_callback);

                        if (rc != SQLiteErrorCode.Ok)
                        {
                            _callback = null; /* UNDO */

                            throw new SQLiteException(rc,
                                "Failed to configure managed assembly logging.");
                        }
                    }

                }

                ///////////////////////////////////////////////////////////////

                //
                // NOTE: Logging is enabled by default unless the configuration
                //       setting "Disable_SQLiteLog" is present.
                //