System.Data.SQLite
Check-in [91849ccd75]
Not logged in

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 | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 91849ccd75040913888d86a1c466a4df54360a17
User & Date: mistachkin 2012-02-22 07:51:24
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
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

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

    17     17     public sealed partial class SQLiteFactory : IServiceProvider
    18     18     {
    19     19       private static Type _dbProviderServicesType;
    20     20       private static object _sqliteServices;
    21     21   
    22     22       static SQLiteFactory()
    23     23       {
           24  +#if (SQLITE_STANDARD || USE_INTEROP_DLL || PLATFORM_COMPACTFRAMEWORK) && PRELOAD_NATIVE_LIBRARY
           25  +        UnsafeNativeMethods.Initialize();
           26  +#endif
           27  +
    24     28   #if !PLATFORM_COMPACTFRAMEWORK
    25     29           SQLiteLog.Initialize();
    26     30   #endif
    27     31   
    28     32           string version =
    29     33   #if NET_20
    30     34               "3.5.0.0";

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

   274    274   
   275    275       /// <summary>
   276    276       /// Initializes the connection with the specified connection string
   277    277       /// </summary>
   278    278       /// <param name="connectionString">The connection string to use on the connection</param>
   279    279       public SQLiteConnection(string connectionString)
   280    280       {
          281  +#if (SQLITE_STANDARD || USE_INTEROP_DLL || PLATFORM_COMPACTFRAMEWORK) && PRELOAD_NATIVE_LIBRARY
          282  +      UnsafeNativeMethods.Initialize();
          283  +#endif
          284  +
   281    285   #if !PLATFORM_COMPACTFRAMEWORK
   282    286         SQLiteLog.Initialize();
   283    287   #endif
   284    288   
   285    289         _flags = SQLiteConnectionFlags.Default;
   286    290         _connectionState = ConnectionState.Closed;
   287    291         _connectionString = "";

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

    49     49         /// <summary>
    50     50         /// The name of the environment variable containing the processor
    51     51         /// architecture of the current process.
    52     52         /// </summary>
    53     53         private static readonly string PROCESSOR_ARCHITECTURE =
    54     54             "PROCESSOR_ARCHITECTURE";
    55     55   #endif
           56  +
           57  +      /////////////////////////////////////////////////////////////////////////
           58  +
           59  +      private static readonly string DllFileExtension = ".dll";
    56     60   
    57     61         /////////////////////////////////////////////////////////////////////////
    58     62         /// <summary>
    59     63         /// Stores the mappings between processor architecture names and platform
    60     64         /// names.
    61     65         /// </summary>
    62     66         private static Dictionary<string, string> processorArchitecturePlatforms;
................................................................................
    86     90         /// The native module handle for the native SQLite library or the value
    87     91         /// IntPtr.Zero.
    88     92         /// </summary>
    89     93         private static IntPtr _SQLiteModule = IntPtr.Zero;
    90     94   
    91     95         /////////////////////////////////////////////////////////////////////////
    92     96         /// <summary>
    93         -      /// Attempts to initialize this class by pre-loading the native SQLite
    94         -      /// library for the processor architecture of the current process.
           97  +      /// For now, this method simply calls the Initialize method.
    95     98         /// </summary>
    96     99         static UnsafeNativeMethods()
    97    100         {
          101  +          Initialize();
          102  +      }
          103  +
          104  +      /////////////////////////////////////////////////////////////////////////
          105  +      /// <summary>
          106  +      /// Attempts to initialize this class by pre-loading the native SQLite
          107  +      /// library for the processor architecture of the current process.
          108  +      /// </summary>
          109  +      internal static void Initialize()
          110  +      {
          111  +#if !PLATFORM_COMPACTFRAMEWORK
          112  +          //
          113  +          // NOTE: If the "NoPreLoadSQLite" environment variable is set, skip
          114  +          //       all our special code and simply return.
          115  +          //
          116  +          if (Environment.GetEnvironmentVariable("No_PreLoadSQLite") != null)
          117  +              return;
          118  +#endif
          119  +
    98    120             //
    99    121             // TODO: Make sure this list is updated if the supported processor
   100    122             //       architecture names and/or platform names changes.
   101    123             //
   102    124             if (processorArchitecturePlatforms == null)
   103    125             {
   104    126                 processorArchitecturePlatforms =
................................................................................
   148    170             {
   149    171                 // do nothing.
   150    172             }
   151    173   
   152    174             return null;
   153    175   #endif
   154    176         }
          177  +
          178  +      /////////////////////////////////////////////////////////////////////////
          179  +      /// <summary>
          180  +      /// Determines if the dynamic link library file name requires a suffix
          181  +      /// and adds it if necessary.
          182  +      /// </summary>
          183  +      /// <param name="fileName">
          184  +      /// The original dynamic link library file name to inspect.
          185  +      /// </param>
          186  +      /// <returns>
          187  +      /// The dynamic link library file name, possibly modified to include an
          188  +      /// extension.
          189  +      /// </returns>
          190  +      private static string FixUpDllFileName(
          191  +          string fileName
          192  +          )
          193  +      {
          194  +          if (!String.IsNullOrEmpty(fileName))
          195  +          {
          196  +              PlatformID platformId = Environment.OSVersion.Platform;
          197  +
          198  +              if ((platformId == PlatformID.Win32S) ||
          199  +                  (platformId == PlatformID.Win32Windows) ||
          200  +                  (platformId == PlatformID.Win32NT) ||
          201  +                  (platformId == PlatformID.WinCE))
          202  +              {
          203  +                  if (!fileName.EndsWith(DllFileExtension,
          204  +                        StringComparison.InvariantCultureIgnoreCase))
          205  +                  {
          206  +                      return fileName + DllFileExtension;
          207  +                  }
          208  +              }
          209  +          }
          210  +
          211  +          return fileName;
          212  +      }
   155    213   
   156    214         /////////////////////////////////////////////////////////////////////////
   157    215         /// <summary>
   158    216         /// Queries and returns the processor architecture of the current
   159    217         /// process.
   160    218         /// </summary>
   161    219         /// <returns>
................................................................................
   258    316             if (directory == null)
   259    317                 return IntPtr.Zero;
   260    318   
   261    319             //
   262    320             // NOTE: If the native SQLite library exists in the base directory
   263    321             //       itself, stop now.
   264    322             //
   265         -          string fileName = Path.Combine(directory, SQLITE_DLL);
          323  +          string fileName = FixUpDllFileName(Path.Combine(directory,
          324  +              SQLITE_DLL));
   266    325   
   267    326             if (File.Exists(fileName))
   268    327                 return IntPtr.Zero;
   269    328   
   270    329             //
   271    330             // NOTE: If the specified processor architecture is null, use the
   272    331             //       default.
................................................................................
   280    339             if (processorArchitecture == null)
   281    340                 return IntPtr.Zero;
   282    341   
   283    342             //
   284    343             // NOTE: Build the full path and file name for the native SQLite
   285    344             //       library using the processor architecture name.
   286    345             //
   287         -          fileName = Path.Combine(Path.Combine(directory,
   288         -              processorArchitecture), SQLITE_DLL);
          346  +          fileName = FixUpDllFileName(Path.Combine(Path.Combine(directory,
          347  +              processorArchitecture), SQLITE_DLL));
   289    348   
   290    349             //
   291    350             // NOTE: If the file name based on the processor architecture name
   292    351             // is not found, try using the associated platform name.
   293    352             //
   294    353             if (!File.Exists(fileName))
   295    354             {
................................................................................
   305    364                 if (platformName == null)
   306    365                     return IntPtr.Zero;
   307    366   
   308    367                 //
   309    368                 // NOTE: Build the full path and file name for the native SQLite
   310    369                 //       library using the platform name.
   311    370                 //
   312         -              fileName = Path.Combine(Path.Combine(directory, platformName),
   313         -                  SQLITE_DLL);
          371  +              fileName = FixUpDllFileName(Path.Combine(Path.Combine(directory,
          372  +                  platformName), SQLITE_DLL));
   314    373   
   315    374                 //
   316    375                 // NOTE: If the file does not exist, skip trying to load it.
   317    376                 //
   318    377                 if (!File.Exists(fileName))
   319    378                     return IntPtr.Zero;
   320    379             }