System.Data.SQLite
Check-in [59d43c48bb]
Not logged in

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

Overview
Comment:Add NoConvertSettings connection flag to disable querying of runtime configuration settings from within the SQLiteConvert class. Pursuant to [58ed318f2f].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 59d43c48bb884614afcf17279b30f3f934f668dd
User & Date: mistachkin 2014-08-12 19:19:39
References
2014-08-12
19:20 Ticket [58ed318f2f] GetValue hits the xml config file every time status still Closed with 3 other changes artifact: 0d0e610d0b user: mistachkin
Context
2014-08-12
19:40
Revise and enhance tests for [58ed318f2f]. check-in: 984343ce67 user: mistachkin tags: trunk
19:19
Add NoConvertSettings connection flag to disable querying of runtime configuration settings from within the SQLiteConvert class. Pursuant to [58ed318f2f]. check-in: 59d43c48bb user: mistachkin tags: trunk
2014-08-11
23:59
Improve clarity of using statements in the UnsafeNativeMethods class. Also, obtain the static lock prior to touching settingReadCounts (only applies to Debug builds). check-in: 8b0d28f75a user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

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

    45     45       <h1 class="heading">Version History</h1>
    46     46       <p><b>1.0.94.0 - August XX, 2014 <font color="red">(release scheduled)</font></b></p>
    47     47       <ul>
    48     48         <li>Updated to <a href="http://www.nuget.org/packages/EntityFramework/6.1.1">Entity Framework 6.1.1</a>.</li>
    49     49         <li>Add RefreshFlags method to the SQLiteDataReader class to forcibly refresh its connection flags.</li>
    50     50         <li>Improve automatic detection and handling of the Entity Framework 6 assembly by the design-time components installer. Pursuant to <a href="http://system.data.sqlite.org/index.html/info/e634e330a6">[e634e330a6]</a>.&nbsp;<b>** Potentially Incompatible Change **</b></li>
    51     51         <li>Improve SQLiteDataReader performance slightly by caching the connection flags.&nbsp;<b>** Potentially Incompatible Change **</b></li>
           52  +      <li>Add NoConvertSettings connection flag to disable querying of runtime configuration settings from within the SQLiteConvert class. Pursuant to <a href="http://system.data.sqlite.org/index.html/info/58ed318f2f">[58ed318f2f]</a>.</li>
    52     53         <li>Minimize usage of the &quot;Use_SQLiteConvert_DefaultDbType&quot; and &quot;Use_SQLiteConvert_DefaultTypeName&quot; settings. Fix for <a href="http://system.data.sqlite.org/index.html/info/58ed318f2f">[58ed318f2f]</a>.&nbsp;<b>** Potentially Incompatible Change **</b></li>
    53     54       </ul>
    54     55       <p><b>1.0.93.0 - June 23, 2014</b></p>
    55     56       <ul>
    56     57         <li>Updated to <a href="http://www.sqlite.org/releaselog/3_8_5.html">SQLite 3.8.5</a>.</li>
    57     58         <li>Updated to <a href="http://www.nuget.org/packages/EntityFramework/6.1">Entity Framework 6.1</a>.</li>
    58     59         <li>Add support for mapping transaction isolation levels to their legacy default values. Pursuant to <a href="http://system.data.sqlite.org/index.html/info/56b42d99c1">[56b42d99c1]</a>.</li>

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

  1081   1081         /// the <see cref="TypeAffinity.Null" />,
  1082   1082         /// <see cref="TypeAffinity.Int64" />,
  1083   1083         /// <see cref="TypeAffinity.Double" />,
  1084   1084         /// or <see cref="TypeAffinity.DateTime" /> types.
  1085   1085         /// </summary>
  1086   1086         DetectStringType = 0x4000000,
  1087   1087   
         1088  +      /// <summary>
         1089  +      /// Skip querying runtime configuration settings for use by the
         1090  +      /// <see cref="SQLiteConvert" /> class, including the default
         1091  +      /// <see cref="DbType" /> value and default database type name.
         1092  +      /// <b>NOTE: If the <see cref="SQLiteConnection.DefaultDbType" />
         1093  +      /// and/or <see cref="SQLiteConnection.DefaultTypeName" />
         1094  +      /// properties are not set explicitly nor set via their connection
         1095  +      /// string properties and repeated calls to determine these runtime
         1096  +      /// configuration settings are seen to be a problem, this flag
         1097  +      /// should be set.</b>
         1098  +      /// </summary>
         1099  +      NoConvertSettings = 0x8000000,
         1100  +
  1088   1101         /// <summary>
  1089   1102         /// When binding parameter values or returning column values, always
  1090   1103         /// treat them as though they were plain text (i.e. no numeric,
  1091   1104         /// date/time, or other conversions should be attempted).
  1092   1105         /// </summary>
  1093   1106         BindAndGetAllAsText = BindAllAsText | GetAllAsText,
  1094   1107   

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

  1091   1091         DBNull.Value  // Xml (25)
  1092   1092       };
  1093   1093   
  1094   1094       /// <summary>
  1095   1095       /// Determines the default database type name to be used when a
  1096   1096       /// per-connection value is not available.
  1097   1097       /// </summary>
         1098  +    /// <param name="connection">
         1099  +    /// The connection context for type mappings, if any.
         1100  +    /// </param>
  1098   1101       /// <returns>
  1099   1102       /// The default database type name to use.
  1100   1103       /// </returns>
  1101         -    private static string GetDefaultTypeName()
         1104  +    private static string GetDefaultTypeName(
         1105  +        SQLiteConnection connection
         1106  +        )
  1102   1107       {
         1108  +        SQLiteConnectionFlags flags = (connection != null) ?
         1109  +            connection.Flags : SQLiteConnectionFlags.None;
         1110  +
         1111  +        if ((flags & SQLiteConnectionFlags.NoConvertSettings)
         1112  +                == SQLiteConnectionFlags.NoConvertSettings)
         1113  +        {
         1114  +            return FallbackDefaultTypeName;
         1115  +        }
         1116  +
  1103   1117           string value = UnsafeNativeMethods.GetSettingValue(
  1104   1118               "Use_SQLiteConvert_DefaultTypeName", null);
  1105   1119   
  1106   1120           if (value == null)
  1107   1121               return FallbackDefaultTypeName;
  1108   1122   
  1109   1123           return value;
................................................................................
  1207   1221           }
  1208   1222   
  1209   1223           if ((flags & SQLiteConnectionFlags.NoGlobalTypes) == SQLiteConnectionFlags.NoGlobalTypes)
  1210   1224           {
  1211   1225               if (defaultTypeName != null)
  1212   1226                   return defaultTypeName;
  1213   1227   
  1214         -            defaultTypeName = GetDefaultTypeName();
         1228  +            defaultTypeName = GetDefaultTypeName(connection);
  1215   1229   
  1216   1230   #if !NET_COMPACT_20 && TRACE_WARNING
  1217   1231               DefaultTypeNameWarning(dbType, flags, defaultTypeName);
  1218   1232   #endif
  1219   1233   
  1220   1234               return defaultTypeName;
  1221   1235           }
................................................................................
  1230   1244               if (_typeNames.TryGetValue(dbType, out value))
  1231   1245                   return value.typeName;
  1232   1246           }
  1233   1247   
  1234   1248           if (defaultTypeName != null)
  1235   1249               return defaultTypeName;
  1236   1250   
  1237         -        defaultTypeName = GetDefaultTypeName();
         1251  +        defaultTypeName = GetDefaultTypeName(connection);
  1238   1252   
  1239   1253   #if !NET_COMPACT_20 && TRACE_WARNING
  1240   1254           DefaultTypeNameWarning(dbType, flags, defaultTypeName);
  1241   1255   #endif
  1242   1256   
  1243   1257           return defaultTypeName;
  1244   1258       }
................................................................................
  1434   1448           }
  1435   1449       }
  1436   1450   
  1437   1451       /// <summary>
  1438   1452       /// Determines the default <see cref="DbType" /> value to be used when a
  1439   1453       /// per-connection value is not available.
  1440   1454       /// </summary>
         1455  +    /// <param name="connection">
         1456  +    /// The connection context for type mappings, if any.
         1457  +    /// </param>
  1441   1458       /// <returns>
  1442   1459       /// The default <see cref="DbType" /> value to use.
  1443   1460       /// </returns>
  1444         -    private static DbType GetDefaultDbType()
         1461  +    private static DbType GetDefaultDbType(
         1462  +        SQLiteConnection connection
         1463  +        )
  1445   1464       {
         1465  +        SQLiteConnectionFlags flags = (connection != null) ?
         1466  +            connection.Flags : SQLiteConnectionFlags.None;
         1467  +
         1468  +        if ((flags & SQLiteConnectionFlags.NoConvertSettings)
         1469  +                == SQLiteConnectionFlags.NoConvertSettings)
         1470  +        {
         1471  +            return FallbackDefaultDbType;
         1472  +        }
         1473  +
  1446   1474           string value = UnsafeNativeMethods.GetSettingValue(
  1447   1475               "Use_SQLiteConvert_DefaultDbType", null);
  1448   1476   
  1449   1477           if (value == null)
  1450   1478               return FallbackDefaultDbType;
  1451   1479   
  1452   1480           object enumValue = SQLiteConnection.TryParseEnum(
................................................................................
  1655   1683           }
  1656   1684   
  1657   1685           if ((flags & SQLiteConnectionFlags.NoGlobalTypes) == SQLiteConnectionFlags.NoGlobalTypes)
  1658   1686           {
  1659   1687               if (defaultDbType != null)
  1660   1688                   return (DbType)defaultDbType;
  1661   1689   
  1662         -            defaultDbType = GetDefaultDbType();
         1690  +            defaultDbType = GetDefaultDbType(connection);
  1663   1691   
  1664   1692   #if !NET_COMPACT_20 && TRACE_WARNING
  1665   1693               DefaultDbTypeWarning(typeName, flags, defaultDbType);
  1666   1694   #endif
  1667   1695   
  1668   1696               return (DbType)defaultDbType;
  1669   1697           }
................................................................................
  1693   1721                   }
  1694   1722               }
  1695   1723           }
  1696   1724   
  1697   1725           if (defaultDbType != null)
  1698   1726               return (DbType)defaultDbType;
  1699   1727   
  1700         -        defaultDbType = GetDefaultDbType();
         1728  +        defaultDbType = GetDefaultDbType(connection);
  1701   1729   
  1702   1730   #if !NET_COMPACT_20 && TRACE_WARNING
  1703   1731           DefaultDbTypeWarning(typeName, flags, defaultDbType);
  1704   1732   #endif
  1705   1733   
  1706   1734           return (DbType)defaultDbType;
  1707   1735       }

Changes to Tests/tkt-58ed318f2f.eagle.

    16     16   ###############################################################################
    17     17   
    18     18   package require System.Data.SQLite.Test
    19     19   runSQLiteTestPrologue
    20     20   
    21     21   ###############################################################################
    22     22   
    23         -reportSQLiteResources $test_channel true
    24         -
    25         -###############################################################################
    26         -
    27     23   proc getSettingReadCount { name } {
    28     24     if {[haveConstraint buildConfiguration.Debug] && [catch {
    29     25       object invoke -flags +NonPublic -alias \
    30     26           System.Data.SQLite.UnsafeNativeMethods settingReadCounts
    31     27     } settingReadCounts] == 0} then {
    32     28       if {[$settingReadCounts TryGetValue $name value]} then {
    33     29         tputs $::test_channel [appendArgs \
................................................................................
    41     37         "---- setting \"" $name "\" was not read\n"]
    42     38   
    43     39     return -1
    44     40   }
    45     41   
    46     42   ###############################################################################
    47     43   
           44  +reportSQLiteResources $test_channel true
           45  +
           46  +###############################################################################
           47  +
    48     48   runTest {test tkt-58ed318f2f-1.1 {standard GetDefaultDbType usage} -setup {
    49     49     setupDb [set fileName tkt-58ed318f2f-1.1.db]
    50     50   } -body {
    51     51     sql execute $db {
    52     52       CREATE TABLE t1(x, y);
    53     53       INSERT INTO t1 (x, y) VALUES(0, 1);
    54     54       INSERT INTO t1 (x, y) VALUES('0', '1');
    55     55     }
    56     56   
    57     57     sql execute -execute reader -format list $db "SELECT x, y FROM t1;"
    58         -  expr {[getSettingReadCount Use_SQLiteConvert_DefaultDbType] == 2}
           58  +
           59  +  expr {[getSettingReadCount Use_SQLiteConvert_DefaultDbType] == 2 && \
           60  +      [getSettingReadCount Use_SQLiteConvert_DefaultTypeName] == -1}
    59     61   } -cleanup {
    60     62     cleanupDb $fileName
    61     63   
    62     64     unset -nocomplain db fileName
    63     65   } -constraints \
    64     66   {eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite\
    65     67   buildConfiguration.Debug} -result {True}}
................................................................................
    76     78     sql execute $db {
    77     79       CREATE TABLE t1(x, y);
    78     80       INSERT INTO t1 (x, y) VALUES(0, 1);
    79     81       INSERT INTO t1 (x, y) VALUES('0', '1');
    80     82     }
    81     83   
    82     84     sql execute -execute reader -format list $db "SELECT x, y FROM t1;"
    83         -  expr {[getSettingReadCount Use_SQLiteConvert_DefaultDbType] == 2}
           85  +
           86  +  expr {[getSettingReadCount Use_SQLiteConvert_DefaultDbType] == 2 && \
           87  +      [getSettingReadCount Use_SQLiteConvert_DefaultTypeName] == -1}
    84     88   } -cleanup {
    85     89     cleanupDb $fileName
    86     90   
    87     91     unset -nocomplain db fileName
    88     92   } -constraints \
    89     93   {eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite\
    90     94   buildConfiguration.Debug} -result {True}}
................................................................................
   102    106     sql execute $db {
   103    107       CREATE TABLE t1(x, y);
   104    108       INSERT INTO t1 (x, y) VALUES(0, 1);
   105    109       INSERT INTO t1 (x, y) VALUES('0', '1');
   106    110     }
   107    111   
   108    112     sql execute -execute reader -format list $db "SELECT x, y FROM t1;"
   109         -  expr {[getSettingReadCount Use_SQLiteConvert_DefaultDbType] == -1}
          113  +
          114  +  expr {[getSettingReadCount Use_SQLiteConvert_DefaultDbType] == -1 && \
          115  +      [getSettingReadCount Use_SQLiteConvert_DefaultTypeName] == -1}
   110    116   } -cleanup {
   111    117     cleanupDb $fileName
   112    118   
   113    119     unset -nocomplain db fileName
   114    120   } -constraints \
   115    121   {eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite\
   116    122   buildConfiguration.Debug} -result {True}}
................................................................................
   128    134     sql execute $db {
   129    135       CREATE TABLE t1(x, y);
   130    136       INSERT INTO t1 (x, y) VALUES(0, 1);
   131    137       INSERT INTO t1 (x, y) VALUES('0', '1');
   132    138     }
   133    139   
   134    140     sql execute -execute reader -format list $db "SELECT x, y FROM t1;"
          141  +
          142  +  expr {[getSettingReadCount Use_SQLiteConvert_DefaultDbType] == -1 && \
          143  +      [getSettingReadCount Use_SQLiteConvert_DefaultTypeName] == -1}
          144  +} -cleanup {
          145  +  cleanupDb $fileName
          146  +
          147  +  unset -nocomplain db fileName
          148  +} -constraints \
          149  +{eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite\
          150  +buildConfiguration.Debug} -result {True}}
          151  +
          152  +###############################################################################
          153  +
          154  +reportSQLiteResources $test_channel true
          155  +
          156  +###############################################################################
          157  +
          158  +runTest {test tkt-58ed318f2f-1.5 {zero DefaultDbType settings read} -setup {
          159  +  setupDb [set fileName tkt-58ed318f2f-1.5.db] "" "" "" NoConvertSettings
          160  +} -body {
          161  +  sql execute $db {
          162  +    CREATE TABLE t1(x, y);
          163  +    INSERT INTO t1 (x, y) VALUES(0, 1);
          164  +    INSERT INTO t1 (x, y) VALUES('0', '1');
          165  +  }
          166  +
          167  +  sql execute -execute reader -format list $db "SELECT x, y FROM t1;"
          168  +
   135    169     expr {[getSettingReadCount Use_SQLiteConvert_DefaultDbType] == -1}
   136    170   } -cleanup {
   137    171     cleanupDb $fileName
   138    172   
   139    173     unset -nocomplain db fileName
          174  +} -constraints \
          175  +{eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite\
          176  +buildConfiguration.Debug} -result {True}}
          177  +
          178  +###############################################################################
          179  +
          180  +reportSQLiteResources $test_channel true
          181  +
          182  +###############################################################################
          183  +
          184  +runTest {test tkt-58ed318f2f-1.6 {zero DefaultTypeName settings read} -setup {
          185  +  setupDb [set fileName tkt-58ed318f2f-1.6.db] "" "" "" NoConvertSettings
          186  +} -body {
          187  +  set connection [getDbConnection]
          188  +
          189  +  sql execute $db {
          190  +    CREATE TABLE t1(x, y);
          191  +    INSERT INTO t1 (x, y) VALUES(0, 1);
          192  +    INSERT INTO t1 (x, y) VALUES('0', '1');
          193  +  }
          194  +
          195  +  set columns [$connection GetSchema COLUMNS]
          196  +
          197  +  expr {[getSettingReadCount Use_SQLiteConvert_DefaultTypeName] == -1}
          198  +} -cleanup {
          199  +  cleanupDb $fileName
          200  +
          201  +  freeDbConnection
          202  +
          203  +  unset -nocomplain columns connection db fileName
          204  +} -constraints \
          205  +{eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite\
          206  +buildConfiguration.Debug} -result {True}}
          207  +
          208  +###############################################################################
          209  +
          210  +reportSQLiteResources $test_channel true
          211  +
          212  +###############################################################################
          213  +
          214  +runTest {test tkt-58ed318f2f-1.7 {normal SQLiteConvert settings usage} -setup {
          215  +  setupDb [set fileName tkt-58ed318f2f-1.7.db]
          216  +} -body {
          217  +  set connection [getDbConnection]
          218  +
          219  +  sql execute $db {
          220  +    CREATE TABLE t1(x, y);
          221  +    INSERT INTO t1 (x, y) VALUES(0, 1);
          222  +    INSERT INTO t1 (x, y) VALUES('0', '1');
          223  +  }
          224  +
          225  +  sql execute -execute reader -format list $db "SELECT x, y FROM t1;"
          226  +  set columns [$connection GetSchema COLUMNS]
          227  +
          228  +  #
          229  +  # TODO: These counts may need to be updated in future versions.
          230  +  #
          231  +  expr {[getSettingReadCount Use_SQLiteConvert_DefaultDbType] == 7 && \
          232  +      [getSettingReadCount Use_SQLiteConvert_DefaultTypeName] == 2}
          233  +} -cleanup {
          234  +  cleanupDb $fileName
          235  +
          236  +  freeDbConnection
          237  +
          238  +  unset -nocomplain columns connection db fileName
          239  +} -constraints \
          240  +{eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite\
          241  +buildConfiguration.Debug} -result {True}}
          242  +
          243  +###############################################################################
          244  +
          245  +reportSQLiteResources $test_channel true
          246  +
          247  +###############################################################################
          248  +
          249  +runTest {test tkt-58ed318f2f-1.8 {zero SQLiteConvert settings usage} -setup {
          250  +  setupDb [set fileName tkt-58ed318f2f-1.8.db] "" "" "" NoConvertSettings
          251  +} -body {
          252  +  set connection [getDbConnection]
          253  +
          254  +  sql execute $db {
          255  +    CREATE TABLE t1(x, y);
          256  +    INSERT INTO t1 (x, y) VALUES(0, 1);
          257  +    INSERT INTO t1 (x, y) VALUES('0', '1');
          258  +  }
          259  +
          260  +  sql execute -execute reader -format list $db "SELECT x, y FROM t1;"
          261  +  set columns [$connection GetSchema COLUMNS]
          262  +
          263  +  expr {[getSettingReadCount Use_SQLiteConvert_DefaultDbType] == -1 && \
          264  +      [getSettingReadCount Use_SQLiteConvert_DefaultTypeName] == -1}
          265  +} -cleanup {
          266  +  cleanupDb $fileName
          267  +
          268  +  freeDbConnection
          269  +
          270  +  unset -nocomplain columns connection db fileName
   140    271   } -constraints \
   141    272   {eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite\
   142    273   buildConfiguration.Debug} -result {True}}
   143    274   
   144    275   ###############################################################################
   145    276   
   146    277   rename getSettingReadCount ""

Changes to readme.htm.

   212    212       <b>1.0.94.0 - August XX, 2014 <font color="red">(release scheduled)</font></b>
   213    213   </p>
   214    214   <ul>
   215    215       <li>Updated to <a href="http://www.nuget.org/packages/EntityFramework/6.1.1">Entity Framework 6.1.1</a>.</li>
   216    216       <li>Add RefreshFlags method to the SQLiteDataReader class to forcibly refresh its connection flags.</li>
   217    217       <li>Improve automatic detection and handling of the Entity Framework 6 assembly by the design-time components installer. Pursuant to [e634e330a6].&nbsp;<b>** Potentially Incompatible Change **</b></li>
   218    218       <li>Improve SQLiteDataReader performance slightly by caching the connection flags.&nbsp;<b>** Potentially Incompatible Change **</b></li>
          219  +    <li>Add NoConvertSettings connection flag to disable querying of runtime configuration settings from within the SQLiteConvert class. Pursuant to [58ed318f2f].</li>
   219    220       <li>Minimize usage of the &quot;Use_SQLiteConvert_DefaultDbType&quot; and &quot;Use_SQLiteConvert_DefaultTypeName&quot; settings. Fix for [58ed318f2f].&nbsp;<b>** Potentially Incompatible Change **</b></li>
   220    221   </ul>
   221    222   <p>
   222    223       <b>1.0.93.0 - June 23, 2014</b>
   223    224   </p>
   224    225   <ul>
   225    226       <li>Updated to <a href="http://www.sqlite.org/releaselog/3_8_5.html">SQLite 3.8.5</a>.</li>

Changes to www/news.wiki.

     6      6       <b>1.0.94.0 - August XX, 2014</b>
     7      7   </p>
     8      8   <ul>
     9      9       <li>Updated to <a href="http://www.nuget.org/packages/EntityFramework/6.1.1">Entity Framework 6.1.1</a>.</li>
    10     10       <li>Add RefreshFlags method to the SQLiteDataReader class to forcibly refresh its connection flags.</li>
    11     11       <li>Improve automatic detection and handling of the Entity Framework 6 assembly by the design-time components installer. Pursuant to [e634e330a6].&nbsp;<b>** Potentially Incompatible Change **</b></li>
    12     12       <li>Improve SQLiteDataReader performance slightly by caching the connection flags.&nbsp;<b>** Potentially Incompatible Change **</b></li>
           13  +    <li>Add NoConvertSettings connection flag to disable querying of runtime configuration settings from within the SQLiteConvert class. Pursuant to [58ed318f2f].</li>
    13     14       <li>Minimize usage of the &quot;Use_SQLiteConvert_DefaultDbType&quot; and &quot;Use_SQLiteConvert_DefaultTypeName&quot; settings. Fix for [58ed318f2f].&nbsp;<b>** Potentially Incompatible Change **</b></li>
    14     15   </ul>
    15     16   <p>
    16     17       <b>1.0.93.0 - June 23, 2014</b>
    17     18   </p>
    18     19   <ul>
    19     20       <li>Updated to [http://www.sqlite.org/releaselog/3_8_5.html|SQLite 3.8.5].</li>