System.Data.SQLite
Check-in [2b37dc7c86]
Not logged in

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

Overview
Comment:Fix reading setting values from the XML configuration file and allow for a default value to be specified.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | refactorNativeLibraryPreLoader
Files: files | file ages | folders
SHA1: 2b37dc7c8632fbb5c3ffbf1d458c56d0d4ea38a3
User & Date: mistachkin 2013-12-27 04:55:42
Context
2013-12-27
04:57
Merge updates from trunk. check-in: f2075b5036 user: mistachkin tags: refactorNativeLibraryPreLoader
04:55
Fix reading setting values from the XML configuration file and allow for a default value to be specified. check-in: 2b37dc7c86 user: mistachkin tags: refactorNativeLibraryPreLoader
04:03
Merge testing changes. Rename the XML configuration file to 'System.Data.SQLite.dll.config'. Break out shared native library pre-loading code to fix compilation issues. check-in: c43afb58ea user: mistachkin tags: refactorNativeLibraryPreLoader
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

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

  1619   1619         int n;
  1620   1620         SortedList<string, string> ls = new SortedList<string, string>(StringComparer.OrdinalIgnoreCase);
  1621   1621   
  1622   1622         // First split into semi-colon delimited values.
  1623   1623         string error = null;
  1624   1624         string[] arParts;
  1625   1625   
  1626         -      if (UnsafeNativeMethods.GetSettingValue("No_SQLiteConnectionNewParser") != null)
         1626  +      if (UnsafeNativeMethods.GetSettingValue("No_SQLiteConnectionNewParser", null) != null)
  1627   1627             arParts = SQLiteConvert.Split(s, ';');
  1628   1628         else
  1629   1629             arParts = SQLiteConvert.NewSplit(s, ';', true, ref error);
  1630   1630   
  1631   1631         if (arParts == null)
  1632   1632         {
  1633   1633             throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,

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

   653    653         try
   654    654         {
   655    655   #if !PLATFORM_COMPACTFRAMEWORK
   656    656           //
   657    657           // NOTE: If the "No_SQLiteFunctions" environment variable is set,
   658    658           //       skip all our special code and simply return.
   659    659           //
   660         -        if (UnsafeNativeMethods.GetSettingValue("No_SQLiteFunctions") != null)
          660  +        if (UnsafeNativeMethods.GetSettingValue("No_SQLiteFunctions", null) != null)
   661    661             return;
   662    662   
   663    663           SQLiteFunctionAttribute at;
   664    664           System.Reflection.Assembly[] arAssemblies = System.AppDomain.CurrentDomain.GetAssemblies();
   665    665           int w = arAssemblies.Length;
   666    666           System.Reflection.AssemblyName sqlite = System.Reflection.Assembly.GetExecutingAssembly().GetName();
   667    667   

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

   148    148               //         is loaded per-process and has only one logging callback,
   149    149               //         not one per-AppDomain, which it knows nothing about),
   150    150               //         prevent all non-default AppDomains from registering a
   151    151               //         log handler unless the "Force_SQLiteLog" environment
   152    152               //         variable is used to manually override this safety check.
   153    153               //
   154    154               if (!AppDomain.CurrentDomain.IsDefaultAppDomain() &&
   155         -                UnsafeNativeMethods.GetSettingValue("Force_SQLiteLog") == null)
          155  +                UnsafeNativeMethods.GetSettingValue("Force_SQLiteLog", null) == null)
   156    156               {
   157    157                   return;
   158    158               }
   159    159   #endif
   160    160   
   161    161               lock (syncRoot)
   162    162               {

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

   107    107         /// variable, using the XML configuration file and/or the environment
   108    108         /// variables for the current process and/or the current system, when
   109    109         /// available.
   110    110         /// </summary>
   111    111         /// <param name="name">
   112    112         /// The name of the configuration variable.
   113    113         /// </param>
          114  +      /// <param name="default">
          115  +      /// The value to be returned if the configuration variable has not been
          116  +      /// set explicitly or cannot be determined.
          117  +      /// </param>
   114    118         /// <returns>
   115         -      /// The value of the configuration variable -OR- null if it cannot be
   116         -      /// determined.  By default, references to existing environment will
   117         -      /// be expanded within the returned value unless either the "No_Expand"
   118         -      /// or "No_Expand_<paramref name="name" />" environment variables are
   119         -      /// set.
          119  +      /// The value of the configuration variable -OR- the default value
          120  +      /// specified by <paramref name="default" /> if it has not been set
          121  +      /// explicitly or cannot be determined.  By default, all references to
          122  +      /// existing environment will be expanded within the value to be returned
          123  +      /// unless either the "No_Expand" or "No_Expand_<paramref name="name" />"
          124  +      /// environment variables are set [to anything].
   120    125         /// </returns>
   121    126         internal static string GetSettingValue(
   122         -          string name
          127  +          string name,
          128  +          string @default
   123    129             )
   124    130         {
   125         -          string value = null;
   126         -
   127    131             if (name == null)
   128         -              return value;
          132  +              return @default;
          133  +
          134  +          string value = null;
   129    135   
   130    136   #if !PLATFORM_COMPACTFRAMEWORK
   131    137             bool expand = true;
   132    138   
   133    139             if (Environment.GetEnvironmentVariable("No_Expand") != null)
   134    140             {
   135    141                 expand = false;
................................................................................
   150    156   #endif
   151    157   
   152    158             try
   153    159             {
   154    160                 string fileName = GetXmlConfigFileName();
   155    161   
   156    162                 if (fileName == null)
   157         -                  return value;
          163  +                  return @default;
   158    164   
   159    165                 XmlDocument document = new XmlDocument();
   160    166   
   161    167                 document.Load(fileName);
   162    168   
   163    169                 XmlElement element = document.SelectSingleNode(String.Format(
   164         -                  "/configuration/appSettings/add[@key='{0}']")) as XmlElement;
          170  +                  "/configuration/appSettings/add[@key='{0}']", name)) as
          171  +                  XmlElement;
   165    172   
   166    173                 if (element != null)
   167    174                 {
   168    175                     if (element.HasAttribute("value"))
   169    176                         value = element.GetAttribute("value");
   170    177   
   171    178   #if !PLATFORM_COMPACTFRAMEWORK
   172    179                     if (expand && !String.IsNullOrEmpty(value))
   173    180                         value = Environment.ExpandEnvironmentVariables(value);
   174    181   #endif
          182  +
          183  +                  if (value != null)
          184  +                      return value;
   175    185                 }
   176    186             }
   177    187   #if !NET_COMPACT_20 && TRACE_SHARED
   178    188             catch (Exception e)
   179    189   #else
   180    190             catch (Exception)
   181    191   #endif
................................................................................
   191    201                 catch
   192    202                 {
   193    203                     // do nothing.
   194    204                 }
   195    205   #endif
   196    206             }
   197    207   
   198         -          return value;
          208  +          return @default;
   199    209         }
   200    210   
   201    211         /////////////////////////////////////////////////////////////////////////
   202    212         /// <summary>
   203    213         /// Queries and returns the directory for the assembly currently being
   204    214         /// executed.
   205    215         /// </summary>
................................................................................
   407    417         /// </summary>
   408    418         internal static void Initialize()
   409    419         {
   410    420             //
   411    421             // NOTE: If the "No_PreLoadSQLite" environment variable is set (to
   412    422             //       anything), skip all our special code and simply return.
   413    423             //
   414         -          if (GetSettingValue("No_PreLoadSQLite") != null)
          424  +          if (GetSettingValue("No_PreLoadSQLite", null) != null)
   415    425                 return;
   416    426   
   417    427             lock (staticSyncRoot)
   418    428             {
   419    429                 //
   420    430                 // TODO: Make sure this list is updated if the supported
   421    431                 //       processor architecture names and/or platform names
................................................................................
   461    471         /// </returns>
   462    472         private static string GetBaseDirectory()
   463    473         {
   464    474             //
   465    475             // NOTE: If the "PreLoadSQLite_BaseDirectory" environment variable
   466    476             //       is set, use it verbatim for the base directory.
   467    477             //
   468         -          string directory = GetSettingValue("PreLoadSQLite_BaseDirectory");
          478  +          string directory = GetSettingValue("PreLoadSQLite_BaseDirectory", null);
   469    479   
   470    480             if (directory != null)
   471    481                 return directory;
   472    482   
   473    483   #if !PLATFORM_COMPACTFRAMEWORK
   474    484             //
   475    485             // NOTE: If the "PreLoadSQLite_UseAssemblyDirectory" environment
   476    486             //       variable is set (to anything), attempt to use the directory
   477    487             //       containing the currently executing assembly (i.e.
   478    488             //       System.Data.SQLite) intsead of the application domain base
   479    489             //       directory.
   480    490             //
   481         -          if (GetSettingValue("PreLoadSQLite_UseAssemblyDirectory") != null)
          491  +          if (GetSettingValue("PreLoadSQLite_UseAssemblyDirectory", null) != null)
   482    492             {
   483    493                 directory = GetAssemblyDirectory();
   484    494   
   485    495                 if (directory != null)
   486    496                     return directory;
   487    497             }
   488    498   
................................................................................
   549    559         {
   550    560             //
   551    561             // NOTE: If the "PreLoadSQLite_ProcessorArchitecture" environment
   552    562             //       variable is set, use it verbatim for the current processor
   553    563             //       architecture.
   554    564             //
   555    565             string processorArchitecture = GetSettingValue(
   556         -              "PreLoadSQLite_ProcessorArchitecture");
          566  +              "PreLoadSQLite_ProcessorArchitecture", null);
   557    567   
   558    568             if (processorArchitecture != null)
   559    569                 return processorArchitecture;
   560    570   
   561    571             //
   562    572             // BUGBUG: Will this always be reliable?
   563    573             //
   564         -          processorArchitecture = GetSettingValue(PROCESSOR_ARCHITECTURE);
          574  +          processorArchitecture = GetSettingValue(PROCESSOR_ARCHITECTURE, null);
   565    575   
   566    576             /////////////////////////////////////////////////////////////////////
   567    577   
   568    578   #if !PLATFORM_COMPACTFRAMEWORK
   569    579             //
   570    580             // HACK: Check for an "impossible" situation.  If the pointer size
   571    581             //       is 32-bits, the processor architecture cannot be "AMD64".