System.Data.SQLite

Check-in [91849ccd75]
Login

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

Overview
Comment:Support enabling the PreLoadNativeLibrary and UseSqliteStandard build properties together. Add SQLite native library pre-load support to several more managed entry points. Add 'No_PreLoadSQLite' environment variable to disable SQLite native library pre-load support at runtime.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 91849ccd75040913888d86a1c466a4df54360a17
User & Date: mistachkin 2012-02-22 07:51:24.473
Context
2012-02-22
11:23
Document the recent changes in the version history. check-in: fbef21c4bb user: mistachkin tags: trunk
07:51
Support enabling the PreLoadNativeLibrary and UseSqliteStandard build properties together. Add SQLite native library pre-load support to several more managed entry points. Add 'No_PreLoadSQLite' environment variable to disable SQLite native library pre-load support at runtime. check-in: 91849ccd75 user: mistachkin tags: trunk
05:39
Fix typo in reference to the openFlags parameter of the SQLite3_UTF16.Open method. check-in: b3d26cefe0 user: mistachkin tags: trunk
Changes
Unified Diff Show Whitespace Changes Patch
Changes to System.Data.SQLite/LINQ/SQLiteFactory_Linq.cs.
17
18
19
20
21
22
23




24
25
26
27
28
29
30
  public sealed partial class SQLiteFactory : IServiceProvider
  {
    private static Type _dbProviderServicesType;
    private static object _sqliteServices;

    static SQLiteFactory()
    {




#if !PLATFORM_COMPACTFRAMEWORK
        SQLiteLog.Initialize();
#endif

        string version =
#if NET_20
            "3.5.0.0";







>
>
>
>







17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
  public sealed partial class SQLiteFactory : IServiceProvider
  {
    private static Type _dbProviderServicesType;
    private static object _sqliteServices;

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

#if !PLATFORM_COMPACTFRAMEWORK
        SQLiteLog.Initialize();
#endif

        string version =
#if NET_20
            "3.5.0.0";
Changes to System.Data.SQLite/SQLiteConnection.cs.
274
275
276
277
278
279
280




281
282
283
284
285
286
287

    /// <summary>
    /// Initializes the connection with the specified connection string
    /// </summary>
    /// <param name="connectionString">The connection string to use on the connection</param>
    public SQLiteConnection(string connectionString)
    {




#if !PLATFORM_COMPACTFRAMEWORK
      SQLiteLog.Initialize();
#endif

      _flags = SQLiteConnectionFlags.Default;
      _connectionState = ConnectionState.Closed;
      _connectionString = "";







>
>
>
>







274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291

    /// <summary>
    /// Initializes the connection with the specified connection string
    /// </summary>
    /// <param name="connectionString">The connection string to use on the connection</param>
    public SQLiteConnection(string connectionString)
    {
#if (SQLITE_STANDARD || USE_INTEROP_DLL || PLATFORM_COMPACTFRAMEWORK) && PRELOAD_NATIVE_LIBRARY
      UnsafeNativeMethods.Initialize();
#endif

#if !PLATFORM_COMPACTFRAMEWORK
      SQLiteLog.Initialize();
#endif

      _flags = SQLiteConnectionFlags.Default;
      _connectionState = ConnectionState.Closed;
      _connectionString = "";
Changes to System.Data.SQLite/UnsafeNativeMethods.cs.
49
50
51
52
53
54
55




56
57
58
59
60
61
62
      /// <summary>
      /// The name of the environment variable containing the processor
      /// architecture of the current process.
      /// </summary>
      private static readonly string PROCESSOR_ARCHITECTURE =
          "PROCESSOR_ARCHITECTURE";
#endif





      /////////////////////////////////////////////////////////////////////////
      /// <summary>
      /// Stores the mappings between processor architecture names and platform
      /// names.
      /// </summary>
      private static Dictionary<string, string> processorArchitecturePlatforms;







>
>
>
>







49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
      /// <summary>
      /// The name of the environment variable containing the processor
      /// architecture of the current process.
      /// </summary>
      private static readonly string PROCESSOR_ARCHITECTURE =
          "PROCESSOR_ARCHITECTURE";
#endif

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

      private static readonly string DllFileExtension = ".dll";

      /////////////////////////////////////////////////////////////////////////
      /// <summary>
      /// Stores the mappings between processor architecture names and platform
      /// names.
      /// </summary>
      private static Dictionary<string, string> processorArchitecturePlatforms;
86
87
88
89
90
91
92
93
94
95
96
97



















98
99
100
101
102
103
104
      /// The native module handle for the native SQLite library or the value
      /// IntPtr.Zero.
      /// </summary>
      private static IntPtr _SQLiteModule = IntPtr.Zero;

      /////////////////////////////////////////////////////////////////////////
      /// <summary>
      /// Attempts to initialize this class by pre-loading the native SQLite
      /// library for the processor architecture of the current process.
      /// </summary>
      static UnsafeNativeMethods()
      {



















          //
          // TODO: Make sure this list is updated if the supported processor
          //       architecture names and/or platform names changes.
          //
          if (processorArchitecturePlatforms == null)
          {
              processorArchitecturePlatforms =







|
<



>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







90
91
92
93
94
95
96
97

98
99
100
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
      /// The native module handle for the native SQLite library or the value
      /// IntPtr.Zero.
      /// </summary>
      private static IntPtr _SQLiteModule = IntPtr.Zero;

      /////////////////////////////////////////////////////////////////////////
      /// <summary>
      /// For now, this method simply calls the Initialize method.

      /// </summary>
      static UnsafeNativeMethods()
      {
          Initialize();
      }

      /////////////////////////////////////////////////////////////////////////
      /// <summary>
      /// Attempts to initialize this class by pre-loading the native SQLite
      /// library for the processor architecture of the current process.
      /// </summary>
      internal static void Initialize()
      {
#if !PLATFORM_COMPACTFRAMEWORK
          //
          // NOTE: If the "NoPreLoadSQLite" environment variable is set, skip
          //       all our special code and simply return.
          //
          if (Environment.GetEnvironmentVariable("No_PreLoadSQLite") != null)
              return;
#endif

          //
          // TODO: Make sure this list is updated if the supported processor
          //       architecture names and/or platform names changes.
          //
          if (processorArchitecturePlatforms == null)
          {
              processorArchitecturePlatforms =
148
149
150
151
152
153
154




































155
156
157
158
159
160
161
          {
              // do nothing.
          }

          return null;
#endif
      }





































      /////////////////////////////////////////////////////////////////////////
      /// <summary>
      /// Queries and returns the processor architecture of the current
      /// process.
      /// </summary>
      /// <returns>







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
          {
              // do nothing.
          }

          return null;
#endif
      }

      /////////////////////////////////////////////////////////////////////////
      /// <summary>
      /// Determines if the dynamic link library file name requires a suffix
      /// and adds it if necessary.
      /// </summary>
      /// <param name="fileName">
      /// The original dynamic link library file name to inspect.
      /// </param>
      /// <returns>
      /// The dynamic link library file name, possibly modified to include an
      /// extension.
      /// </returns>
      private static string FixUpDllFileName(
          string fileName
          )
      {
          if (!String.IsNullOrEmpty(fileName))
          {
              PlatformID platformId = Environment.OSVersion.Platform;

              if ((platformId == PlatformID.Win32S) ||
                  (platformId == PlatformID.Win32Windows) ||
                  (platformId == PlatformID.Win32NT) ||
                  (platformId == PlatformID.WinCE))
              {
                  if (!fileName.EndsWith(DllFileExtension,
                        StringComparison.InvariantCultureIgnoreCase))
                  {
                      return fileName + DllFileExtension;
                  }
              }
          }

          return fileName;
      }

      /////////////////////////////////////////////////////////////////////////
      /// <summary>
      /// Queries and returns the processor architecture of the current
      /// process.
      /// </summary>
      /// <returns>
258
259
260
261
262
263
264
265

266
267
268
269
270
271
272
          if (directory == null)
              return IntPtr.Zero;

          //
          // NOTE: If the native SQLite library exists in the base directory
          //       itself, stop now.
          //
          string fileName = Path.Combine(directory, SQLITE_DLL);


          if (File.Exists(fileName))
              return IntPtr.Zero;

          //
          // NOTE: If the specified processor architecture is null, use the
          //       default.







|
>







316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
          if (directory == null)
              return IntPtr.Zero;

          //
          // NOTE: If the native SQLite library exists in the base directory
          //       itself, stop now.
          //
          string fileName = FixUpDllFileName(Path.Combine(directory,
              SQLITE_DLL));

          if (File.Exists(fileName))
              return IntPtr.Zero;

          //
          // NOTE: If the specified processor architecture is null, use the
          //       default.
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
          if (processorArchitecture == null)
              return IntPtr.Zero;

          //
          // NOTE: Build the full path and file name for the native SQLite
          //       library using the processor architecture name.
          //
          fileName = Path.Combine(Path.Combine(directory,
              processorArchitecture), SQLITE_DLL);

          //
          // NOTE: If the file name based on the processor architecture name
          // is not found, try using the associated platform name.
          //
          if (!File.Exists(fileName))
          {







|
|







339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
          if (processorArchitecture == null)
              return IntPtr.Zero;

          //
          // NOTE: Build the full path and file name for the native SQLite
          //       library using the processor architecture name.
          //
          fileName = FixUpDllFileName(Path.Combine(Path.Combine(directory,
              processorArchitecture), SQLITE_DLL));

          //
          // NOTE: If the file name based on the processor architecture name
          // is not found, try using the associated platform name.
          //
          if (!File.Exists(fileName))
          {
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
              if (platformName == null)
                  return IntPtr.Zero;

              //
              // NOTE: Build the full path and file name for the native SQLite
              //       library using the platform name.
              //
              fileName = Path.Combine(Path.Combine(directory, platformName),
                  SQLITE_DLL);

              //
              // NOTE: If the file does not exist, skip trying to load it.
              //
              if (!File.Exists(fileName))
                  return IntPtr.Zero;
          }







|
|







364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
              if (platformName == null)
                  return IntPtr.Zero;

              //
              // NOTE: Build the full path and file name for the native SQLite
              //       library using the platform name.
              //
              fileName = FixUpDllFileName(Path.Combine(Path.Combine(directory,
                  platformName), SQLITE_DLL));

              //
              // NOTE: If the file does not exist, skip trying to load it.
              //
              if (!File.Exists(fileName))
                  return IntPtr.Zero;
          }