Index: System.Data.SQLite/LINQ/SQLiteFactory_Linq.cs
==================================================================
--- System.Data.SQLite/LINQ/SQLiteFactory_Linq.cs
+++ System.Data.SQLite/LINQ/SQLiteFactory_Linq.cs
@@ -19,10 +19,14 @@
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 =
Index: System.Data.SQLite/SQLiteConnection.cs
==================================================================
--- System.Data.SQLite/SQLiteConnection.cs
+++ System.Data.SQLite/SQLiteConnection.cs
@@ -276,10 +276,14 @@
/// Initializes the connection with the specified connection string
///
/// The connection string to use on the connection
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;
Index: System.Data.SQLite/UnsafeNativeMethods.cs
==================================================================
--- System.Data.SQLite/UnsafeNativeMethods.cs
+++ System.Data.SQLite/UnsafeNativeMethods.cs
@@ -51,10 +51,14 @@
/// architecture of the current process.
///
private static readonly string PROCESSOR_ARCHITECTURE =
"PROCESSOR_ARCHITECTURE";
#endif
+
+ /////////////////////////////////////////////////////////////////////////
+
+ private static readonly string DllFileExtension = ".dll";
/////////////////////////////////////////////////////////////////////////
///
/// Stores the mappings between processor architecture names and platform
/// names.
@@ -88,15 +92,33 @@
///
private static IntPtr _SQLiteModule = IntPtr.Zero;
/////////////////////////////////////////////////////////////////////////
///
- /// Attempts to initialize this class by pre-loading the native SQLite
- /// library for the processor architecture of the current process.
+ /// For now, this method simply calls the Initialize method.
///
static UnsafeNativeMethods()
{
+ Initialize();
+ }
+
+ /////////////////////////////////////////////////////////////////////////
+ ///
+ /// Attempts to initialize this class by pre-loading the native SQLite
+ /// library for the processor architecture of the current process.
+ ///
+ 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)
@@ -150,10 +172,46 @@
}
return null;
#endif
}
+
+ /////////////////////////////////////////////////////////////////////////
+ ///
+ /// Determines if the dynamic link library file name requires a suffix
+ /// and adds it if necessary.
+ ///
+ ///
+ /// The original dynamic link library file name to inspect.
+ ///
+ ///
+ /// The dynamic link library file name, possibly modified to include an
+ /// extension.
+ ///
+ 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;
+ }
/////////////////////////////////////////////////////////////////////////
///
/// Queries and returns the processor architecture of the current
/// process.
@@ -260,11 +318,12 @@
//
// NOTE: If the native SQLite library exists in the base directory
// itself, stop now.
//
- string fileName = Path.Combine(directory, SQLITE_DLL);
+ string fileName = FixUpDllFileName(Path.Combine(directory,
+ SQLITE_DLL));
if (File.Exists(fileName))
return IntPtr.Zero;
//
@@ -282,12 +341,12 @@
//
// 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);
+ 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.
//
@@ -307,12 +366,12 @@
//
// 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);
+ 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))