System.Data.SQLite
Check-in [654d96246c]
Not logged in

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

Overview
Comment:Add support for the '%PreLoadSQLite_TargetFramework%' configuration setting replacement token. Pursuant to [d4728aecb7].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 654d96246cb75a52bdb53889ee7b43ef6e1476ee
User & Date: mistachkin 2016-10-29 06:58:54
Context
2016-10-29
21:48
Update version history docs. check-in: 9a84e18abe user: mistachkin tags: trunk
06:58
Add support for the '%PreLoadSQLite_TargetFramework%' configuration setting replacement token. Pursuant to [d4728aecb7]. check-in: 654d96246c user: mistachkin tags: trunk
03:58
Rename the new configuration setting replacement tokens to include a 'PreLoad' prefix and add them to the documentation. check-in: 6a9bb02b77 user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to Doc/Extra/Provider/environment.html.

    55     55             <th>Name</th>
    56     56             <th>Description</th>
    57     57           </tr>
    58     58           <tr valign="top">
    59     59             <td>%PreLoadSQLite_AssemblyDirectory%</td>
    60     60             <td>If this token (which is <b>case-sensitive</b> and <b>must include
    61     61             the percent characters</b>) is present within a setting value being
    62         -          returned, it will be replaced with the qualified name of the directory
    63         -          containing the System.Data.SQLite assembly.  If the name of the
    64         -          directory is not available, the token will not be replaced.</td>
           62  +          returned, it will be replaced with the qualified name of the
           63  +          directory containing the System.Data.SQLite assembly.  If the name of
           64  +          the directory is not available, the token will not be replaced.</td>
           65  +        </tr>
           66  +        <tr valign="top">
           67  +          <td>%PreLoadSQLite_TargetFramework%</td>
           68  +          <td>If this token (which is <b>case-sensitive</b> and <b>must include
           69  +          the percent characters</b>) is present within a setting value being
           70  +          returned, it will be replaced with an abbreviation of the target
           71  +          framework attribute value for the System.Data.SQLite assembly.  If
           72  +          the target framework attribute value is not available, the token will
           73  +          not be replaced.</td>
    65     74           </tr>
    66     75           <tr valign="top">
    67     76             <td>%PreLoadSQLite_XmlConfigDirectory%</td>
    68     77             <td>If this token (which is <b>case-sensitive</b> and <b>must include
    69     78             the percent characters</b>) is present within a setting value
    70     79             being returned, it will be replaced with the qualified name of the
    71     80             directory containing the XML configuration file.  If the name of the

Changes to System.Data.SQLite/Configurations/System.Data.SQLite.dll.config.

    18     18       <!--
    19     19           NOTE: %PreLoadSQLite_AssemblyDirectory% - If this token (which is
    20     20                 case-sensitive and must include the percent characters) is
    21     21                 present within a setting value being returned, it will be
    22     22                 replaced with the qualified name of the directory containing the
    23     23                 System.Data.SQLite assembly.  If the name of the directory is not
    24     24                 available, the token will not be replaced.
           25  +
           26  +        NOTE: %PreLoadSQLite_TargetFramework% - If this token (which is
           27  +              case-sensitive and must include the percent characters) is
           28  +              present within a setting value being returned, it will be
           29  +              replaced with an abbreviation of the target framework attribute
           30  +              value for the System.Data.SQLite assembly.  If the target
           31  +              framework attribute value is not available, the token will not be
           32  +              replaced.
    25     33   
    26     34           NOTE: %PreLoadSQLite_XmlConfigDirectory% - If this token (which is
    27     35                 case-sensitive and must include the percent characters) is
    28     36                 present within a setting value being returned, it will be
    29     37                 replaced with the qualified name of the directory containing the
    30     38                 XML configuration file.  If the name of the directory is not
    31     39                 available, the token will not be replaced.  Generally, this token

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

    19     19     using System.Reflection;
    20     20   
    21     21   #if !PLATFORM_COMPACTFRAMEWORK
    22     22     using System.Security;
    23     23   #endif
    24     24   
    25     25     using System.Runtime.InteropServices;
           26  +
           27  +#if (NET_40 || NET_45 || NET_451 || NET_452 || NET_46 || NET_461 || NET_462) && !PLATFORM_COMPACTFRAMEWORK
           28  +  using System.Runtime.Versioning;
           29  +#endif
    26     30   
    27     31   #if !PLATFORM_COMPACTFRAMEWORK
    28         -  using System.Text;
           32  +    using System.Text;
    29     33   #endif
    30     34   
    31     35   #if !PLATFORM_COMPACTFRAMEWORK || COUNT_HANDLE
    32     36     using System.Threading;
    33     37   #endif
    34     38   
    35     39     using System.Xml;
................................................................................
   598    602   #if !PLATFORM_COMPACTFRAMEWORK
   599    603         /// <summary>
   600    604         /// This is the environment variable token that will be replaced with
   601    605         /// the qualified path to the directory containing this assembly.
   602    606         /// </summary>
   603    607         private static readonly string AssemblyDirectoryToken =
   604    608             "%PreLoadSQLite_AssemblyDirectory%";
          609  +
          610  +      /////////////////////////////////////////////////////////////////////////
          611  +      /// <summary>
          612  +      /// This is the environment variable token that will be replaced with an
          613  +      /// abbreviation of the target framework attribute value associated with
          614  +      /// this assembly.
          615  +      /// </summary>
          616  +      private static readonly string TargetFrameworkToken =
          617  +          "%PreLoadSQLite_TargetFramework%";
   605    618   #endif
   606    619         #endregion
   607    620   
   608    621         /////////////////////////////////////////////////////////////////////////
   609    622   
   610    623         #region Private Data
   611    624         /// <summary>
................................................................................
   945    958   
   946    959             return @default;
   947    960         }
   948    961   
   949    962         /////////////////////////////////////////////////////////////////////////
   950    963   
   951    964   #if !PLATFORM_COMPACTFRAMEWORK
          965  +      /// <summary>
          966  +      /// Attempts to determine the target framework attribute value that is
          967  +      /// associated with the specified managed assembly, if applicable.
          968  +      /// </summary>
          969  +      /// <param name="assembly">
          970  +      /// The managed assembly to read the target framework attribute value
          971  +      /// from.
          972  +      /// </param>
          973  +      /// <returns>
          974  +      /// The value of the target framework attribute value for the specified
          975  +      /// managed assembly -OR- null if it cannot be determined.  If this
          976  +      /// assembly was compiled with a version of the .NET Framework prior to
          977  +      /// version 4.0, the value returned MAY reflect that version of the .NET
          978  +      /// Framework instead of the one associated with the specified managed
          979  +      /// assembly.
          980  +      /// </returns>
          981  +      private static string GetAssemblyTargetFramework(
          982  +          Assembly assembly
          983  +          )
          984  +      {
          985  +          if (assembly != null)
          986  +          {
          987  +#if (NET_40 || NET_45 || NET_451 || NET_452 || NET_46 || NET_461 || NET_462) && !PLATFORM_COMPACTFRAMEWORK
          988  +              try
          989  +              {
          990  +                  if (assembly.IsDefined(
          991  +                          typeof(TargetFrameworkAttribute), false))
          992  +                  {
          993  +                      TargetFrameworkAttribute targetFramework =
          994  +                          (TargetFrameworkAttribute)
          995  +                          assembly.GetCustomAttributes(
          996  +                              typeof(TargetFrameworkAttribute), false)[0];
          997  +
          998  +                      return targetFramework.FrameworkName;
          999  +                  }
         1000  +              }
         1001  +              catch
         1002  +              {
         1003  +                  // do nothing.
         1004  +              }
         1005  +#elif NET_35
         1006  +              return ".NETFramework,Version=v3.5";
         1007  +#elif NET_20
         1008  +              return ".NETFramework,Version=v2.0";
         1009  +#endif
         1010  +          }
         1011  +
         1012  +          return null;
         1013  +      }
         1014  +
         1015  +      /////////////////////////////////////////////////////////////////////////
         1016  +
         1017  +      /// <summary>
         1018  +      /// Accepts a long target framework attribute value and makes it into a
         1019  +      /// much shorter version, suitable for use with NuGet packages.
         1020  +      /// </summary>
         1021  +      /// <param name="value">
         1022  +      /// The long target framework attribute value to convert.
         1023  +      /// </param>
         1024  +      /// <returns>
         1025  +      /// The short target framework attribute value -OR- null if it cannot
         1026  +      /// be determined or converted.
         1027  +      /// </returns>
         1028  +      private static string AbbreviateTargetFramework(
         1029  +          string value
         1030  +          )
         1031  +      {
         1032  +          if (String.IsNullOrEmpty(value))
         1033  +              return value;
         1034  +
         1035  +          value = value.Replace(".NETFramework,Version=v", "net");
         1036  +          value = value.Replace(".", String.Empty);
         1037  +
         1038  +          return value;
         1039  +      }
         1040  +
         1041  +      /////////////////////////////////////////////////////////////////////////
         1042  +
   952   1043         /// <summary>
   953   1044         /// If necessary, replaces all supported environment variable tokens
   954   1045         /// with their associated values.
   955   1046         /// </summary>
   956   1047         /// <param name="value">
   957   1048         /// A setting value read from an environment variable.
   958   1049         /// </param>
................................................................................
   983   1074   #endif
   984   1075                     {
   985   1076   #if !NET_COMPACT_20 && TRACE_SHARED
   986   1077                         try
   987   1078                         {
   988   1079                             Trace.WriteLine(HelperMethods.StringFormat(
   989   1080                                 CultureInfo.CurrentCulture, "Native library " +
   990         -                              "pre-loader failed to replace environment " +
   991         -                              "variable tokens: {0}", e)); /* throw */
         1081  +                              "pre-loader failed to replace assembly " +
         1082  +                              "directory token: {0}", e)); /* throw */
         1083  +                      }
         1084  +                      catch
         1085  +                      {
         1086  +                          // do nothing.
         1087  +                      }
         1088  +#endif
         1089  +                  }
         1090  +              }
         1091  +
         1092  +              Assembly assembly = null;
         1093  +
         1094  +              try
         1095  +              {
         1096  +                  assembly = Assembly.GetExecutingAssembly();
         1097  +              }
         1098  +#if !NET_COMPACT_20 && TRACE_SHARED
         1099  +              catch (Exception e)
         1100  +#else
         1101  +              catch (Exception)
         1102  +#endif
         1103  +              {
         1104  +#if !NET_COMPACT_20 && TRACE_SHARED
         1105  +                  try
         1106  +                  {
         1107  +                      Trace.WriteLine(HelperMethods.StringFormat(
         1108  +                          CultureInfo.CurrentCulture, "Native library " +
         1109  +                          "pre-loader failed to obtain executing " +
         1110  +                          "assembly: {0}", e)); /* throw */
         1111  +                  }
         1112  +                  catch
         1113  +                  {
         1114  +                      // do nothing.
         1115  +                  }
         1116  +#endif
         1117  +              }
         1118  +
         1119  +              string targetFramework = AbbreviateTargetFramework(
         1120  +                  GetAssemblyTargetFramework(assembly));
         1121  +
         1122  +              if (!String.IsNullOrEmpty(targetFramework))
         1123  +              {
         1124  +                  try
         1125  +                  {
         1126  +                      value = value.Replace(
         1127  +                          TargetFrameworkToken, targetFramework);
         1128  +                  }
         1129  +#if !NET_COMPACT_20 && TRACE_SHARED
         1130  +                  catch (Exception e)
         1131  +#else
         1132  +                  catch (Exception)
         1133  +#endif
         1134  +                  {
         1135  +#if !NET_COMPACT_20 && TRACE_SHARED
         1136  +                      try
         1137  +                      {
         1138  +                          Trace.WriteLine(HelperMethods.StringFormat(
         1139  +                              CultureInfo.CurrentCulture, "Native library " +
         1140  +                              "pre-loader failed to replace target " +
         1141  +                              "framework token: {0}", e)); /* throw */
   992   1142                         }
   993   1143                         catch
   994   1144                         {
   995   1145                             // do nothing.
   996   1146                         }
   997   1147   #endif
   998   1148                     }

Changes to Tests/tkt-d4728aecb7.eagle.

    21     21   ###############################################################################
    22     22   
    23     23   moveSystemDataSQLiteDllConfig false
    24     24   
    25     25   ###############################################################################
    26     26   
    27     27   set d472_binary_directory [string map [list \\ /] [getBinaryDirectory]]
           28  +set d472_target_framework [string map [list Fx ""] [getBuildNetFx]]
    28     29   
    29     30   ###############################################################################
    30     31   
    31     32   runTest {test tkt-d4728aecb7-1.1 {tokens in environment variable} -setup \
    32     33       [getAppDomainPreamble] -body {
    33     34     package require Eagle.Library
    34     35     package require Eagle.Test
    35     36     package require System.Data.SQLite.Test
    36     37   
    37         -  saveEnvironmentVariables [list d472_1 d472_2] savedEnv
           38  +  saveEnvironmentVariables [list d472_1 d472_2 d472_3] savedEnv
    38     39   
    39     40     set env(d472_1) {prfx1/%PreLoadSQLite_AssemblyDirectory%/sufx1}
    40         -  set env(d472_2) {prfx2/%PreLoadSQLite_XmlConfigDirectory%/sufx2}
           41  +  set env(d472_2) {prfx2/%PreLoadSQLite_TargetFramework%/sufx2}
           42  +  set env(d472_3) {prfx3/%PreLoadSQLite_XmlConfigDirectory%/sufx3}
    41     43   
    42     44     object load -loadtype File [file join \
    43     45         [getBinaryDirectory] System.Data.SQLite.dll]
    44     46   
    45     47     set result [list]
    46     48   
    47     49     lappend result [string map [list \\ /] [object invoke -flags +NonPublic \
    48     50         System.Data.SQLite.UnsafeNativeMethods GetSettingValue d472_1 null]]
    49     51   
    50     52     lappend result [string map [list \\ /] [object invoke -flags +NonPublic \
    51     53         System.Data.SQLite.UnsafeNativeMethods GetSettingValue d472_2 null]]
    52     54   
           55  +  lappend result [string map [list \\ /] [object invoke -flags +NonPublic \
           56  +      System.Data.SQLite.UnsafeNativeMethods GetSettingValue d472_3 null]]
           57  +
    53     58     set result
    54     59   } -cleanup {
    55         -  restoreEnvironmentVariables [list d472_1 d472_2] savedEnv
           60  +  restoreEnvironmentVariables [list d472_1 d472_2 d472_3] savedEnv
    56     61   
    57     62     unset -nocomplain result
    58     63   } -isolationLevel AppDomain -constraints {eagle command.object\
    59     64   compile.ISOLATED_INTERPRETERS System.Data.SQLite} -result [list [appendArgs \
    60         -prfx1/ $d472_binary_directory /sufx1] \
    61         -prfx2/%PreLoadSQLite_XmlConfigDirectory%/sufx2]}
           65  +prfx1/ $d472_binary_directory /sufx1] [appendArgs prfx2/ \
           66  +$d472_target_framework /sufx2] prfx3/%PreLoadSQLite_XmlConfigDirectory%/sufx3]}
    62     67   
    63     68   ###############################################################################
    64     69   
    65     70   runTest {test tkt-d4728aecb7-1.2 {tokens in XML configuration file} -setup \
    66     71       [getAppDomainPreamble] -body {
    67     72     package require Eagle.Library
    68     73     package require Eagle.Test
................................................................................
    76     81     writeFile $fileName [string trim {
    77     82       <?xml version="1.0"?>
    78     83       <configuration>
    79     84         <appSettings>
    80     85           <add key="d472_1"
    81     86                value="prfx1/%PreLoadSQLite_AssemblyDirectory%/sufx1" />
    82     87           <add key="d472_2"
    83         -             value="prfx2/%PreLoadSQLite_XmlConfigDirectory%/sufx2" />
           88  +             value="prfx2/%PreLoadSQLite_TargetFramework%/sufx2" />
           89  +        <add key="d472_3"
           90  +             value="prfx3/%PreLoadSQLite_XmlConfigDirectory%/sufx3" />
    84     91         </appSettings>
    85     92       </configuration>
    86     93     }]
    87     94   
    88     95     object load -loadtype Bytes [base64 encode [readFile [file join \
    89     96         [getBinaryDirectory] System.Data.SQLite.dll]]]
    90     97   
................................................................................
    92     99   
    93    100     lappend result [string map [list \\ /] [object invoke -flags +NonPublic \
    94    101         System.Data.SQLite.UnsafeNativeMethods GetSettingValue d472_1 null]]
    95    102   
    96    103     lappend result [string map [list \\ /] [object invoke -flags +NonPublic \
    97    104         System.Data.SQLite.UnsafeNativeMethods GetSettingValue d472_2 null]]
    98    105   
          106  +  lappend result [string map [list \\ /] [object invoke -flags +NonPublic \
          107  +      System.Data.SQLite.UnsafeNativeMethods GetSettingValue d472_3 null]]
          108  +
    99    109     set result
   100    110   } -cleanup {
   101    111     catch {file delete $fileName}
   102    112   
   103    113     unset -nocomplain result fileName
   104    114   
   105    115     moveSystemDataSQLiteDllConfig true
   106    116   } -isolationLevel AppDomain -constraints {eagle command.object\
   107    117   compile.ISOLATED_INTERPRETERS System.Data.SQLite} -result [list [appendArgs \
   108    118   prfx1/ $d472_binary_directory /sufx1] [appendArgs prfx2/ \
   109         -$d472_binary_directory /sufx2]]}
          119  +$d472_target_framework /sufx2] [appendArgs prfx3/ $d472_binary_directory \
          120  +/sufx3]]}
   110    121   
   111    122   ###############################################################################
   112    123   
   113         -unset -nocomplain d472_binary_directory
          124  +unset -nocomplain d472_target_framework d472_binary_directory
   114    125   
   115    126   ###############################################################################
   116    127   
   117    128   moveSystemDataSQLiteDllConfig true
   118    129   
   119    130   ###############################################################################
   120    131   
   121    132   runSQLiteTestEpilogue
   122    133   runTestEpilogue