System.Data.SQLite

Check-in [2b37dc7c86]
Login

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
Timelines: family | ancestors | descendants | both | refactorNativeLibraryPreLoader
Files: files | file ages | folders
SHA1: 2b37dc7c8632fbb5c3ffbf1d458c56d0d4ea38a3
User & Date: mistachkin 2013-12-27 04:55:42.792
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
Side-by-Side Diff Ignore Whitespace Patch
Changes to System.Data.SQLite/SQLiteConnection.cs.
1619
1620
1621
1622
1623
1624
1625
1626

1627
1628
1629
1630
1631
1632
1633
1619
1620
1621
1622
1623
1624
1625

1626
1627
1628
1629
1630
1631
1632
1633







-
+







      int n;
      SortedList<string, string> ls = new SortedList<string, string>(StringComparer.OrdinalIgnoreCase);

      // First split into semi-colon delimited values.
      string error = null;
      string[] arParts;

      if (UnsafeNativeMethods.GetSettingValue("No_SQLiteConnectionNewParser") != null)
      if (UnsafeNativeMethods.GetSettingValue("No_SQLiteConnectionNewParser", null) != null)
          arParts = SQLiteConvert.Split(s, ';');
      else
          arParts = SQLiteConvert.NewSplit(s, ';', true, ref error);

      if (arParts == null)
      {
          throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,
Changes to System.Data.SQLite/SQLiteFunction.cs.
653
654
655
656
657
658
659
660

661
662
663
664
665
666
667
653
654
655
656
657
658
659

660
661
662
663
664
665
666
667







-
+







      try
      {
#if !PLATFORM_COMPACTFRAMEWORK
        //
        // NOTE: If the "No_SQLiteFunctions" environment variable is set,
        //       skip all our special code and simply return.
        //
        if (UnsafeNativeMethods.GetSettingValue("No_SQLiteFunctions") != null)
        if (UnsafeNativeMethods.GetSettingValue("No_SQLiteFunctions", null) != null)
          return;

        SQLiteFunctionAttribute at;
        System.Reflection.Assembly[] arAssemblies = System.AppDomain.CurrentDomain.GetAssemblies();
        int w = arAssemblies.Length;
        System.Reflection.AssemblyName sqlite = System.Reflection.Assembly.GetExecutingAssembly().GetName();

Changes to System.Data.SQLite/SQLiteLog.cs.
148
149
150
151
152
153
154
155

156
157
158
159
160
161
162
148
149
150
151
152
153
154

155
156
157
158
159
160
161
162







-
+







            //         is loaded per-process and has only one logging callback,
            //         not one per-AppDomain, which it knows nothing about),
            //         prevent all non-default AppDomains from registering a
            //         log handler unless the "Force_SQLiteLog" environment
            //         variable is used to manually override this safety check.
            //
            if (!AppDomain.CurrentDomain.IsDefaultAppDomain() &&
                UnsafeNativeMethods.GetSettingValue("Force_SQLiteLog") == null)
                UnsafeNativeMethods.GetSettingValue("Force_SQLiteLog", null) == null)
            {
                return;
            }
#endif

            lock (syncRoot)
            {
Changes to System.Data.SQLite/UnsafeNativeMethods.cs.
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
134
135
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
134
135
136
137
138
139
140
141







+
+
+
+

-
-
-
-
+
+
+
+
+
+
-


-
+
+


-
-

-
+
+
+







      /// variable, using the XML configuration file and/or the environment
      /// variables for the current process and/or the current system, when
      /// available.
      /// </summary>
      /// <param name="name">
      /// The name of the configuration variable.
      /// </param>
      /// <param name="default">
      /// The value to be returned if the configuration variable has not been
      /// set explicitly or cannot be determined.
      /// </param>
      /// <returns>
      /// The value of the configuration variable -OR- null if it cannot be
      /// determined.  By default, references to existing environment will
      /// be expanded within the returned value unless either the "No_Expand"
      /// or "No_Expand_<paramref name="name" />" environment variables are
      /// The value of the configuration variable -OR- the default value
      /// specified by <paramref name="default" /> if it has not been set
      /// explicitly or cannot be determined.  By default, all references to
      /// existing environment will be expanded within the value to be returned
      /// unless either the "No_Expand" or "No_Expand_<paramref name="name" />"
      /// environment variables are set [to anything].
      /// set.
      /// </returns>
      internal static string GetSettingValue(
          string name
          string name,
          string @default
          )
      {
          string value = null;

          if (name == null)
              return value;
              return @default;

          string value = null;

#if !PLATFORM_COMPACTFRAMEWORK
          bool expand = true;

          if (Environment.GetEnvironmentVariable("No_Expand") != null)
          {
              expand = false;
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
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







-
+






-
+
+










+
+
+







#endif

          try
          {
              string fileName = GetXmlConfigFileName();

              if (fileName == null)
                  return value;
                  return @default;

              XmlDocument document = new XmlDocument();

              document.Load(fileName);

              XmlElement element = document.SelectSingleNode(String.Format(
                  "/configuration/appSettings/add[@key='{0}']")) as XmlElement;
                  "/configuration/appSettings/add[@key='{0}']", name)) as
                  XmlElement;

              if (element != null)
              {
                  if (element.HasAttribute("value"))
                      value = element.GetAttribute("value");

#if !PLATFORM_COMPACTFRAMEWORK
                  if (expand && !String.IsNullOrEmpty(value))
                      value = Environment.ExpandEnvironmentVariables(value);
#endif

                  if (value != null)
                      return value;
              }
          }
#if !NET_COMPACT_20 && TRACE_SHARED
          catch (Exception e)
#else
          catch (Exception)
#endif
191
192
193
194
195
196
197
198

199
200
201
202
203
204
205
201
202
203
204
205
206
207

208
209
210
211
212
213
214
215







-
+







              catch
              {
                  // do nothing.
              }
#endif
          }

          return value;
          return @default;
      }

      /////////////////////////////////////////////////////////////////////////
      /// <summary>
      /// Queries and returns the directory for the assembly currently being
      /// executed.
      /// </summary>
407
408
409
410
411
412
413
414

415
416
417
418
419
420
421
417
418
419
420
421
422
423

424
425
426
427
428
429
430
431







-
+







      /// </summary>
      internal static void Initialize()
      {
          //
          // NOTE: If the "No_PreLoadSQLite" environment variable is set (to
          //       anything), skip all our special code and simply return.
          //
          if (GetSettingValue("No_PreLoadSQLite") != null)
          if (GetSettingValue("No_PreLoadSQLite", null) != null)
              return;

          lock (staticSyncRoot)
          {
              //
              // TODO: Make sure this list is updated if the supported
              //       processor architecture names and/or platform names
461
462
463
464
465
466
467
468

469
470
471
472
473
474
475
476
477
478
479
480
481

482
483
484
485
486
487
488
471
472
473
474
475
476
477

478
479
480
481
482
483
484
485
486
487
488
489
490

491
492
493
494
495
496
497
498







-
+












-
+







      /// </returns>
      private static string GetBaseDirectory()
      {
          //
          // NOTE: If the "PreLoadSQLite_BaseDirectory" environment variable
          //       is set, use it verbatim for the base directory.
          //
          string directory = GetSettingValue("PreLoadSQLite_BaseDirectory");
          string directory = GetSettingValue("PreLoadSQLite_BaseDirectory", null);

          if (directory != null)
              return directory;

#if !PLATFORM_COMPACTFRAMEWORK
          //
          // NOTE: If the "PreLoadSQLite_UseAssemblyDirectory" environment
          //       variable is set (to anything), attempt to use the directory
          //       containing the currently executing assembly (i.e.
          //       System.Data.SQLite) intsead of the application domain base
          //       directory.
          //
          if (GetSettingValue("PreLoadSQLite_UseAssemblyDirectory") != null)
          if (GetSettingValue("PreLoadSQLite_UseAssemblyDirectory", null) != null)
          {
              directory = GetAssemblyDirectory();

              if (directory != null)
                  return directory;
          }

549
550
551
552
553
554
555
556

557
558
559
560
561
562
563
564

565
566
567
568
569
570
571
559
560
561
562
563
564
565

566
567
568
569
570
571
572
573

574
575
576
577
578
579
580
581







-
+







-
+







      {
          //
          // NOTE: If the "PreLoadSQLite_ProcessorArchitecture" environment
          //       variable is set, use it verbatim for the current processor
          //       architecture.
          //
          string processorArchitecture = GetSettingValue(
              "PreLoadSQLite_ProcessorArchitecture");
              "PreLoadSQLite_ProcessorArchitecture", null);

          if (processorArchitecture != null)
              return processorArchitecture;

          //
          // BUGBUG: Will this always be reliable?
          //
          processorArchitecture = GetSettingValue(PROCESSOR_ARCHITECTURE);
          processorArchitecture = GetSettingValue(PROCESSOR_ARCHITECTURE, null);

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

#if !PLATFORM_COMPACTFRAMEWORK
          //
          // HACK: Check for an "impossible" situation.  If the pointer size
          //       is 32-bits, the processor architecture cannot be "AMD64".