System.Data.SQLite

Check-in [654d96246c]
Login

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
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 654d96246cb75a52bdb53889ee7b43ef6e1476ee
User & Date: mistachkin 2016-10-29 06:58:54.024
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
Side-by-Side Diff Ignore Whitespace Patch
Changes to Doc/Extra/Provider/environment.html.
55
56
57
58
59
60
61
62
63
64












65
66
67
68
69
70
71
55
56
57
58
59
60
61



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80







-
-
-
+
+
+
+
+
+
+
+
+
+
+
+







          <th>Name</th>
          <th>Description</th>
        </tr>
        <tr valign="top">
          <td>%PreLoadSQLite_AssemblyDirectory%</td>
          <td>If this token (which is <b>case-sensitive</b> and <b>must include
          the percent characters</b>) is present within a setting value being
          returned, it will be replaced with the qualified name of the directory
          containing the System.Data.SQLite assembly.  If the name of the
          directory is not available, the token will not be replaced.</td>
          returned, it will be replaced with the qualified name of the
          directory containing the System.Data.SQLite assembly.  If the name of
          the directory is not available, the token will not be replaced.</td>
        </tr>
        <tr valign="top">
          <td>%PreLoadSQLite_TargetFramework%</td>
          <td>If this token (which is <b>case-sensitive</b> and <b>must include
          the percent characters</b>) is present within a setting value being
          returned, it will be replaced with an abbreviation of the target
          framework attribute value for the System.Data.SQLite assembly.  If
          the target framework attribute value is not available, the token will
          not be replaced.</td>
        </tr>
        <tr valign="top">
          <td>%PreLoadSQLite_XmlConfigDirectory%</td>
          <td>If this token (which is <b>case-sensitive</b> and <b>must include
          the percent characters</b>) is present within a setting value
          being returned, it will be replaced with the qualified name of the
          directory containing the XML configuration file.  If the name of the
Changes to System.Data.SQLite/Configurations/System.Data.SQLite.dll.config.
18
19
20
21
22
23
24








25
26
27
28
29
30
31
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39







+
+
+
+
+
+
+
+







    <!--
        NOTE: %PreLoadSQLite_AssemblyDirectory% - If this token (which is
              case-sensitive and must include the percent characters) is
              present within a setting value being returned, it will be
              replaced with the qualified name of the directory containing the
              System.Data.SQLite assembly.  If the name of the directory is not
              available, the token will not be replaced.

        NOTE: %PreLoadSQLite_TargetFramework% - If this token (which is
              case-sensitive and must include the percent characters) is
              present within a setting value being returned, it will be
              replaced with an abbreviation of the target framework attribute
              value for the System.Data.SQLite assembly.  If the target
              framework attribute value is not available, the token will not be
              replaced.

        NOTE: %PreLoadSQLite_XmlConfigDirectory% - If this token (which is
              case-sensitive and must include the percent characters) is
              present within a setting value being returned, it will be
              replaced with the qualified name of the directory containing the
              XML configuration file.  If the name of the directory is not
              available, the token will not be replaced.  Generally, this token
Changes to System.Data.SQLite/UnsafeNativeMethods.cs.
19
20
21
22
23
24
25
26




27
28

29
30
31
32
33
34
35
19
20
21
22
23
24
25
26
27
28
29
30
31

32
33
34
35
36
37
38
39








+
+
+
+

-
+







  using System.Reflection;

#if !PLATFORM_COMPACTFRAMEWORK
  using System.Security;
#endif

  using System.Runtime.InteropServices;

#if (NET_40 || NET_45 || NET_451 || NET_452 || NET_46 || NET_461 || NET_462) && !PLATFORM_COMPACTFRAMEWORK
  using System.Runtime.Versioning;
#endif

#if !PLATFORM_COMPACTFRAMEWORK
  using System.Text;
    using System.Text;
#endif

#if !PLATFORM_COMPACTFRAMEWORK || COUNT_HANDLE
  using System.Threading;
#endif

  using System.Xml;
598
599
600
601
602
603
604









605
606
607
608
609
610
611
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624







+
+
+
+
+
+
+
+
+







#if !PLATFORM_COMPACTFRAMEWORK
      /// <summary>
      /// This is the environment variable token that will be replaced with
      /// the qualified path to the directory containing this assembly.
      /// </summary>
      private static readonly string AssemblyDirectoryToken =
          "%PreLoadSQLite_AssemblyDirectory%";

      /////////////////////////////////////////////////////////////////////////
      /// <summary>
      /// This is the environment variable token that will be replaced with an
      /// abbreviation of the target framework attribute value associated with
      /// this assembly.
      /// </summary>
      private static readonly string TargetFrameworkToken =
          "%PreLoadSQLite_TargetFramework%";
#endif
      #endregion

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

      #region Private Data
      /// <summary>
945
946
947
948
949
950
951














































































952
953
954
955
956
957
958
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








          return @default;
      }

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

#if !PLATFORM_COMPACTFRAMEWORK
      /// <summary>
      /// Attempts to determine the target framework attribute value that is
      /// associated with the specified managed assembly, if applicable.
      /// </summary>
      /// <param name="assembly">
      /// The managed assembly to read the target framework attribute value
      /// from.
      /// </param>
      /// <returns>
      /// The value of the target framework attribute value for the specified
      /// managed assembly -OR- null if it cannot be determined.  If this
      /// assembly was compiled with a version of the .NET Framework prior to
      /// version 4.0, the value returned MAY reflect that version of the .NET
      /// Framework instead of the one associated with the specified managed
      /// assembly.
      /// </returns>
      private static string GetAssemblyTargetFramework(
          Assembly assembly
          )
      {
          if (assembly != null)
          {
#if (NET_40 || NET_45 || NET_451 || NET_452 || NET_46 || NET_461 || NET_462) && !PLATFORM_COMPACTFRAMEWORK
              try
              {
                  if (assembly.IsDefined(
                          typeof(TargetFrameworkAttribute), false))
                  {
                      TargetFrameworkAttribute targetFramework =
                          (TargetFrameworkAttribute)
                          assembly.GetCustomAttributes(
                              typeof(TargetFrameworkAttribute), false)[0];

                      return targetFramework.FrameworkName;
                  }
              }
              catch
              {
                  // do nothing.
              }
#elif NET_35
              return ".NETFramework,Version=v3.5";
#elif NET_20
              return ".NETFramework,Version=v2.0";
#endif
          }

          return null;
      }

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

      /// <summary>
      /// Accepts a long target framework attribute value and makes it into a
      /// much shorter version, suitable for use with NuGet packages.
      /// </summary>
      /// <param name="value">
      /// The long target framework attribute value to convert.
      /// </param>
      /// <returns>
      /// The short target framework attribute value -OR- null if it cannot
      /// be determined or converted.
      /// </returns>
      private static string AbbreviateTargetFramework(
          string value
          )
      {
          if (String.IsNullOrEmpty(value))
              return value;

          value = value.Replace(".NETFramework,Version=v", "net");
          value = value.Replace(".", String.Empty);

          return value;
      }

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

      /// <summary>
      /// If necessary, replaces all supported environment variable tokens
      /// with their associated values.
      /// </summary>
      /// <param name="value">
      /// A setting value read from an environment variable.
      /// </param>
983
984
985
986
987
988
989
990
991





























































992
993
994
995
996
997
998
1074
1075
1076
1077
1078
1079
1080


1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148







-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







#endif
                  {
#if !NET_COMPACT_20 && TRACE_SHARED
                      try
                      {
                          Trace.WriteLine(HelperMethods.StringFormat(
                              CultureInfo.CurrentCulture, "Native library " +
                              "pre-loader failed to replace environment " +
                              "variable tokens: {0}", e)); /* throw */
                              "pre-loader failed to replace assembly " +
                              "directory token: {0}", e)); /* throw */
                      }
                      catch
                      {
                          // do nothing.
                      }
#endif
                  }
              }

              Assembly assembly = null;

              try
              {
                  assembly = Assembly.GetExecutingAssembly();
              }
#if !NET_COMPACT_20 && TRACE_SHARED
              catch (Exception e)
#else
              catch (Exception)
#endif
              {
#if !NET_COMPACT_20 && TRACE_SHARED
                  try
                  {
                      Trace.WriteLine(HelperMethods.StringFormat(
                          CultureInfo.CurrentCulture, "Native library " +
                          "pre-loader failed to obtain executing " +
                          "assembly: {0}", e)); /* throw */
                  }
                  catch
                  {
                      // do nothing.
                  }
#endif
              }

              string targetFramework = AbbreviateTargetFramework(
                  GetAssemblyTargetFramework(assembly));

              if (!String.IsNullOrEmpty(targetFramework))
              {
                  try
                  {
                      value = value.Replace(
                          TargetFrameworkToken, targetFramework);
                  }
#if !NET_COMPACT_20 && TRACE_SHARED
                  catch (Exception e)
#else
                  catch (Exception)
#endif
                  {
#if !NET_COMPACT_20 && TRACE_SHARED
                      try
                      {
                          Trace.WriteLine(HelperMethods.StringFormat(
                              CultureInfo.CurrentCulture, "Native library " +
                              "pre-loader failed to replace target " +
                              "framework token: {0}", e)); /* throw */
                      }
                      catch
                      {
                          // do nothing.
                      }
#endif
                  }
Changes to Tests/tkt-d4728aecb7.eagle.
21
22
23
24
25
26
27

28
29
30
31
32
33
34
35
36
37

38
39
40


41
42
43
44
45
46
47
48
49
50
51
52



53
54
55

56
57
58
59
60
61


62
63
64
65
66
67
68
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

38
39
40

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

60
61
62
63
64


65
66
67
68
69
70
71
72
73







+









-
+


-
+
+












+
+
+


-
+




-
-
+
+







###############################################################################

moveSystemDataSQLiteDllConfig false

###############################################################################

set d472_binary_directory [string map [list \\ /] [getBinaryDirectory]]
set d472_target_framework [string map [list Fx ""] [getBuildNetFx]]

###############################################################################

runTest {test tkt-d4728aecb7-1.1 {tokens in environment variable} -setup \
    [getAppDomainPreamble] -body {
  package require Eagle.Library
  package require Eagle.Test
  package require System.Data.SQLite.Test

  saveEnvironmentVariables [list d472_1 d472_2] savedEnv
  saveEnvironmentVariables [list d472_1 d472_2 d472_3] savedEnv

  set env(d472_1) {prfx1/%PreLoadSQLite_AssemblyDirectory%/sufx1}
  set env(d472_2) {prfx2/%PreLoadSQLite_XmlConfigDirectory%/sufx2}
  set env(d472_2) {prfx2/%PreLoadSQLite_TargetFramework%/sufx2}
  set env(d472_3) {prfx3/%PreLoadSQLite_XmlConfigDirectory%/sufx3}

  object load -loadtype File [file join \
      [getBinaryDirectory] System.Data.SQLite.dll]

  set result [list]

  lappend result [string map [list \\ /] [object invoke -flags +NonPublic \
      System.Data.SQLite.UnsafeNativeMethods GetSettingValue d472_1 null]]

  lappend result [string map [list \\ /] [object invoke -flags +NonPublic \
      System.Data.SQLite.UnsafeNativeMethods GetSettingValue d472_2 null]]

  lappend result [string map [list \\ /] [object invoke -flags +NonPublic \
      System.Data.SQLite.UnsafeNativeMethods GetSettingValue d472_3 null]]

  set result
} -cleanup {
  restoreEnvironmentVariables [list d472_1 d472_2] savedEnv
  restoreEnvironmentVariables [list d472_1 d472_2 d472_3] savedEnv

  unset -nocomplain result
} -isolationLevel AppDomain -constraints {eagle command.object\
compile.ISOLATED_INTERPRETERS System.Data.SQLite} -result [list [appendArgs \
prfx1/ $d472_binary_directory /sufx1] \
prfx2/%PreLoadSQLite_XmlConfigDirectory%/sufx2]}
prfx1/ $d472_binary_directory /sufx1] [appendArgs prfx2/ \
$d472_target_framework /sufx2] prfx3/%PreLoadSQLite_XmlConfigDirectory%/sufx3]}

###############################################################################

runTest {test tkt-d4728aecb7-1.2 {tokens in XML configuration file} -setup \
    [getAppDomainPreamble] -body {
  package require Eagle.Library
  package require Eagle.Test
76
77
78
79
80
81
82
83



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98



99
100
101
102
103
104
105
106
107
108
109


110
111
112
113

114
115
116
117
118
119
120
121
122
81
82
83
84
85
86
87

88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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







-
+
+
+















+
+
+










-
+
+



-
+









  writeFile $fileName [string trim {
    <?xml version="1.0"?>
    <configuration>
      <appSettings>
        <add key="d472_1"
             value="prfx1/%PreLoadSQLite_AssemblyDirectory%/sufx1" />
        <add key="d472_2"
             value="prfx2/%PreLoadSQLite_XmlConfigDirectory%/sufx2" />
             value="prfx2/%PreLoadSQLite_TargetFramework%/sufx2" />
        <add key="d472_3"
             value="prfx3/%PreLoadSQLite_XmlConfigDirectory%/sufx3" />
      </appSettings>
    </configuration>
  }]

  object load -loadtype Bytes [base64 encode [readFile [file join \
      [getBinaryDirectory] System.Data.SQLite.dll]]]

  set result [list]

  lappend result [string map [list \\ /] [object invoke -flags +NonPublic \
      System.Data.SQLite.UnsafeNativeMethods GetSettingValue d472_1 null]]

  lappend result [string map [list \\ /] [object invoke -flags +NonPublic \
      System.Data.SQLite.UnsafeNativeMethods GetSettingValue d472_2 null]]

  lappend result [string map [list \\ /] [object invoke -flags +NonPublic \
      System.Data.SQLite.UnsafeNativeMethods GetSettingValue d472_3 null]]

  set result
} -cleanup {
  catch {file delete $fileName}

  unset -nocomplain result fileName

  moveSystemDataSQLiteDllConfig true
} -isolationLevel AppDomain -constraints {eagle command.object\
compile.ISOLATED_INTERPRETERS System.Data.SQLite} -result [list [appendArgs \
prfx1/ $d472_binary_directory /sufx1] [appendArgs prfx2/ \
$d472_binary_directory /sufx2]]}
$d472_target_framework /sufx2] [appendArgs prfx3/ $d472_binary_directory \
/sufx3]]}

###############################################################################

unset -nocomplain d472_binary_directory
unset -nocomplain d472_target_framework d472_binary_directory

###############################################################################

moveSystemDataSQLiteDllConfig true

###############################################################################

runSQLiteTestEpilogue
runTestEpilogue