Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Also support overriding the default DbType value and type name via a 'configuration setting' (i.e. via the environment or the DLL config file). |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
216889c23b4f3c3177b7147103a869e2 |
User & Date: | mistachkin 2014-05-15 00:05:51.432 |
Context
2014-05-15
| ||
18:58 | Fix a usage inconsistency where Convert.ToBoolean was being called instead of SQLiteConvert.ToBoolean. check-in: 4ea6f54d61 user: mistachkin tags: trunk | |
00:05 | Also support overriding the default DbType value and type name via a 'configuration setting' (i.e. via the environment or the DLL config file). check-in: 216889c23b user: mistachkin tags: trunk | |
2014-05-14
| ||
20:14 | Add support for setting the default DbType and type name used for mappings on a per-connection basis. Pursuant to [3c00ec5b52]. check-in: cf20301f89 user: mistachkin tags: trunk | |
Changes
Changes to Doc/Extra/Provider/environment.html.
︙ | ︙ | |||
155 156 157 158 159 160 161 162 163 164 165 166 167 168 | </tr> <tr valign="top"> <td>TypeName_SQLiteProviderServices</td> <td>If this environment variable is set [to anything], it will be used by the System.Data.SQLite.SQLiteFactory class as the type name containing the System.Data.Common.DbProviderServices implementation that should be used.</td> </tr> </table> <hr/> <div id="footer"> <p> <a href="mailto:sqlite-users@sqlite.org?subject=SQLite.NET%20Class%20Library%20Documentation%20Feedback:%20Environment%20Variables"> Send comments on this topic.</a> | > > > > > > > > > > > > > > | 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 182 | </tr> <tr valign="top"> <td>TypeName_SQLiteProviderServices</td> <td>If this environment variable is set [to anything], it will be used by the System.Data.SQLite.SQLiteFactory class as the type name containing the System.Data.Common.DbProviderServices implementation that should be used.</td> </tr> <tr valign="top"> <td>Use_SQLiteConvert_DefaultDbType</td> <td>If this environment variable is set [to anything], it will be used by the System.Data.SQLite.SQLiteConvert class as the default DbType value that should be used when a per-connection value is not available.</td> </tr> <tr valign="top"> <td>Use_SQLiteConvert_DefaultTypeName</td> <td>If this environment variable is set [to anything], it will be used by the System.Data.SQLite.SQLiteConvert class as the default type name that should be used when a per-connection value is not available.</td> </tr> </table> <hr/> <div id="footer"> <p> <a href="mailto:sqlite-users@sqlite.org?subject=SQLite.NET%20Class%20Library%20Documentation%20Feedback:%20Environment%20Variables"> Send comments on this topic.</a> |
︙ | ︙ |
Changes to System.Data.SQLite/Configurations/System.Data.SQLite.dll.config.
︙ | ︙ | |||
113 114 115 116 117 118 119 120 121 | used by the System.Data.SQLite.SQLiteFactory class as the type name containing the System.Data.Common.DbProviderServices implementation that should be used. --> <!-- <add key="TypeName_SQLiteProviderServices" value="" /> --> </appSettings> </configuration> | > > > > > > > > > > > > > > > > > > > > | 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 | used by the System.Data.SQLite.SQLiteFactory class as the type name containing the System.Data.Common.DbProviderServices implementation that should be used. --> <!-- <add key="TypeName_SQLiteProviderServices" value="" /> --> <!-- NOTE: If this environment variable is set [to anything], it will be used by the System.Data.SQLite.SQLiteConvert class as the default DbType value that should be used when a per-connection value is not available. --> <!-- <add key="Use_SQLiteConvert_DefaultDbType" value="Object" /> --> <!-- NOTE: If this environment variable is set [to anything], it will be used by the System.Data.SQLite.SQLiteConvert class as the default type name that should be used when a per-connection value is not available. --> <!-- <add key="Use_SQLiteConvert_DefaultTypeName" value="" /> --> </appSettings> </configuration> |
Changes to System.Data.SQLite/SQLiteConnection.cs.
︙ | ︙ | |||
1916 1917 1918 1919 1920 1921 1922 | /// <summary> /// Attempts to convert the string value to an enumerated value of the specified type. /// </summary> /// <param name="type">The enumerated type to convert the string value to.</param> /// <param name="value">The string value to be converted.</param> /// <param name="ignoreCase">Non-zero to make the conversion case-insensitive.</param> /// <returns>The enumerated value upon success or null upon error.</returns> | | | 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 | /// <summary> /// Attempts to convert the string value to an enumerated value of the specified type. /// </summary> /// <param name="type">The enumerated type to convert the string value to.</param> /// <param name="value">The string value to be converted.</param> /// <param name="ignoreCase">Non-zero to make the conversion case-insensitive.</param> /// <returns>The enumerated value upon success or null upon error.</returns> internal static object TryParseEnum( Type type, string value, bool ignoreCase ) { try { |
︙ | ︙ |
Changes to System.Data.SQLite/SQLiteConvert.cs.
︙ | ︙ | |||
991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 | 0, // UInt64 (20) 0, // VarNumeric (21) DBNull.Value, // AnsiStringFixedLength (22) DBNull.Value, // StringFixedLength (23) DBNull.Value, // ?? (24) DBNull.Value // Xml (25) }; /// <summary> /// Determines the type name for the given database value type. /// </summary> /// <param name="connection">The connection context for custom type mappings, if any.</param> /// <param name="dbType">The database value type.</param> /// <param name="flags">The flags associated with the parent connection object.</param> /// <returns>The type name or an empty string if it cannot be determined.</returns> internal static string DbTypeToTypeName( SQLiteConnection connection, DbType dbType, SQLiteConnectionFlags flags ) { | > > > > > > > > > > > > > > > > > > | | 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 | 0, // UInt64 (20) 0, // VarNumeric (21) DBNull.Value, // AnsiStringFixedLength (22) DBNull.Value, // StringFixedLength (23) DBNull.Value, // ?? (24) DBNull.Value // Xml (25) }; /// <summary> /// Determines the default database type name to be used when a /// per-connection value is not available. /// </summary> /// <returns> /// The default database type name to use. /// </returns> private static string GetDefaultTypeName() { string value = UnsafeNativeMethods.GetSettingValue( "Use_SQLiteConvert_DefaultTypeName", null); if (value == null) return FallbackDefaultTypeName; return value; } /// <summary> /// Determines the type name for the given database value type. /// </summary> /// <param name="connection">The connection context for custom type mappings, if any.</param> /// <param name="dbType">The database value type.</param> /// <param name="flags">The flags associated with the parent connection object.</param> /// <returns>The type name or an empty string if it cannot be determined.</returns> internal static string DbTypeToTypeName( SQLiteConnection connection, DbType dbType, SQLiteConnectionFlags flags ) { string defaultTypeName = GetDefaultTypeName(); if (connection != null) { flags |= connection.Flags; if ((flags & SQLiteConnectionFlags.UseConnectionTypes) == SQLiteConnectionFlags.UseConnectionTypes) { |
︙ | ︙ | |||
1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 | new SQLiteDbTypeMapping("UNSIGNEDINTEGER64", DbType.UInt64, false), new SQLiteDbTypeMapping("VARBINARY", DbType.Binary, false), new SQLiteDbTypeMapping("VARCHAR", DbType.AnsiString, true), new SQLiteDbTypeMapping("VARCHAR2", DbType.AnsiString, false), new SQLiteDbTypeMapping("YESNO", DbType.Boolean, false) }); } /// <summary> /// For a given type name, return a closest-match .NET type /// </summary> /// <param name="connection">The connection context for custom type mappings, if any.</param> /// <param name="name">The name of the type to match</param> /// <param name="flags">The flags associated with the parent connection object.</param> /// <returns>The .NET DBType the text evaluates to.</returns> internal static DbType TypeNameToDbType( SQLiteConnection connection, string name, SQLiteConnectionFlags flags ) { | > > > > > > > > > > > > > > > > > > > > > > > > | | 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 | new SQLiteDbTypeMapping("UNSIGNEDINTEGER64", DbType.UInt64, false), new SQLiteDbTypeMapping("VARBINARY", DbType.Binary, false), new SQLiteDbTypeMapping("VARCHAR", DbType.AnsiString, true), new SQLiteDbTypeMapping("VARCHAR2", DbType.AnsiString, false), new SQLiteDbTypeMapping("YESNO", DbType.Boolean, false) }); } /// <summary> /// Determines the default <see cref="DbType" /> value to be used when a /// per-connection value is not available. /// </summary> /// <returns> /// The default <see cref="DbType" /> value to use. /// </returns> private static DbType GetDefaultDbType() { string value = UnsafeNativeMethods.GetSettingValue( "Use_SQLiteConvert_DefaultDbType", null); if (value == null) return FallbackDefaultDbType; object enumValue = SQLiteConnection.TryParseEnum( typeof(DbType), value, true); if (!(enumValue is DbType)) return FallbackDefaultDbType; return (DbType)enumValue; } /// <summary> /// For a given type name, return a closest-match .NET type /// </summary> /// <param name="connection">The connection context for custom type mappings, if any.</param> /// <param name="name">The name of the type to match</param> /// <param name="flags">The flags associated with the parent connection object.</param> /// <returns>The .NET DBType the text evaluates to.</returns> internal static DbType TypeNameToDbType( SQLiteConnection connection, string name, SQLiteConnectionFlags flags ) { DbType defaultDbType = GetDefaultDbType(); if (connection != null) { flags |= connection.Flags; if ((flags & SQLiteConnectionFlags.UseConnectionTypes) == SQLiteConnectionFlags.UseConnectionTypes) { |
︙ | ︙ |
Changes to Tests/tkt-3c00ec5b52.eagle.
︙ | ︙ | |||
16 17 18 19 20 21 22 23 24 25 26 27 28 29 | ############################################################################### package require System.Data.SQLite.Test runSQLiteTestPrologue ############################################################################### runTest {test tkt-3c00ec5b52-1.1 {per-connection default types} -setup { setupDb [set fileName tkt-3c00ec5b52-1.1.db] "" "" "" UseConnectionTypes \ "DefaultDbType=String;DefaultTypeName=TEXT;" } -body { set connection [getDbConnection] set result [list] | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 16 17 18 19 20 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 | ############################################################################### package require System.Data.SQLite.Test runSQLiteTestPrologue ############################################################################### proc saveSQLiteConvertEnvironment {} { foreach name [list \ Use_SQLiteConvert_DefaultDbType Use_SQLiteConvert_DefaultTypeName] { # # NOTE: Does the live environment variable exist? If so, save the value # for later; otherwise, make sure the saved value does not exist # either. The live environment variables ARE NOT changed by this # procedure. # if {[uplevel 1 [list info exists env($name)]]} then { uplevel 1 [list set savedEnv($name) [uplevel 1 [list set env($name)]]] } else { uplevel 1 [list unset -nocomplain savedEnv($name)] } } } proc restoreSQLiteConvertEnvironment {} { foreach name [list \ Use_SQLiteConvert_DefaultDbType Use_SQLiteConvert_DefaultTypeName] { # # NOTE: Does the saved environment variable exist? If so, restore the # saved value and then unset it; otherwise, make sure the live # environment variable does not exist either (i.e. it was not set # to begin with). Both the saved and live environment variables # ARE changed by this procedure. # if {[uplevel 1 [list info exists savedEnv($name)]]} then { uplevel 1 [list set env($name) [uplevel 1 [list set savedEnv($name)]]] uplevel 1 [list unset -nocomplain savedEnv($name)] } else { uplevel 1 [list unset -nocomplain env($name)] } } } ############################################################################### runTest {test tkt-3c00ec5b52-1.1 {per-connection default types} -setup { setupDb [set fileName tkt-3c00ec5b52-1.1.db] "" "" "" UseConnectionTypes \ "DefaultDbType=String;DefaultTypeName=TEXT;" } -body { set connection [getDbConnection] set result [list] |
︙ | ︙ | |||
95 96 97 98 99 100 101 102 103 104 105 106 | cleanupDb $fileName unset -nocomplain db fileName } -constraints \ {eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} -result \ {Object {}}} ############################################################################### runSQLiteTestEpilogue runTestEpilogue | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 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 182 | cleanupDb $fileName unset -nocomplain db fileName } -constraints \ {eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} -result \ {Object {}}} ############################################################################### runTest {test tkt-3c00ec5b52-1.4 {per-connection default types} -setup { saveSQLiteConvertEnvironment set env(Use_SQLiteConvert_DefaultDbType) String set env(Use_SQLiteConvert_DefaultTypeName) TEXT setupDb [set fileName tkt-3c00ec5b52-1.4.db] } -body { set connection [getDbConnection] set result [list] lappend result [object invoke -flags +NonPublic \ System.Data.SQLite.SQLiteConvert TypeNameToDbType $connection "" None] lappend result [object invoke -flags +NonPublic \ System.Data.SQLite.SQLiteConvert DbTypeToTypeName $connection Object None] set result } -cleanup { freeDbConnection unset -nocomplain result connection cleanupDb $fileName restoreSQLiteConvertEnvironment unset -nocomplain db fileName savedEnv } -constraints \ {eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} -result \ {String TEXT}} ############################################################################### rename restoreSQLiteConvertEnvironment "" rename saveSQLiteConvertEnvironment "" ############################################################################### runSQLiteTestEpilogue runTestEpilogue |