System.Data.SQLite
Check-in [9c5dda4992]
Not logged in

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

Overview
Comment:Work in progress for feature request [3c00ec5b52].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tkt-3c00ec5b52
Files: files | file ages | folders
SHA1: 9c5dda49922c1c2f4392e48112713559ae40d971
User & Date: mistachkin 2014-05-14 18:45:18
References
2014-05-14
18:54 Ticket [3c00ec5b52] Columns without defined type are not identified as text status still Pending with 3 other changes artifact: 5c4d0a5405 user: mistachkin
Context
2014-05-14
20:13
Add tests and update version history docs. Closed-Leaf check-in: c09a345694 user: mistachkin tags: tkt-3c00ec5b52
18:45
Work in progress for feature request [3c00ec5b52]. check-in: 9c5dda4992 user: mistachkin tags: tkt-3c00ec5b52
2014-05-12
22:23
Update the Visual C++ 2013 redistributable packages in externals to Visual Studio 2013 Update 2. check-in: cdce870cee user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

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

   469    469       /// <summary>
   470    470       /// The extra behavioral flags for this connection, if any.  See the
   471    471       /// <see cref="SQLiteConnectionFlags" /> enumeration for a list of
   472    472       /// possible values.
   473    473       /// </summary>
   474    474       private SQLiteConnectionFlags _flags;
   475    475   
          476  +    /// <summary>
          477  +    /// The default databse type for this connection.  This value will only
          478  +    /// be used if the <see cref="SQLiteConnectionFlags.UseConnectionTypes" />
          479  +    /// flag is set.
          480  +    /// </summary>
          481  +    private DbType _defaultDbType;
          482  +
          483  +    /// <summary>
          484  +    /// The default databse type name for this connection.  This value will only
          485  +    /// be used if the <see cref="SQLiteConnectionFlags.UseConnectionTypes" />
          486  +    /// flag is set.
          487  +    /// </summary>
          488  +    private string _defaultTypeName;
          489  +
   476    490       /// <summary>
   477    491       /// Default command timeout
   478    492       /// </summary>
   479    493       private int _defaultTimeout = 30;
   480    494   
   481    495       /// <summary>
   482    496       /// Non-zero if the built-in (i.e. framework provided) connection string
................................................................................
   612    626                 SQLiteErrorCode.Ok, SQLiteConvert.ToUTF8("logging initialized."));
   613    627         }
   614    628   #endif
   615    629   
   616    630         _typeNames = new SQLiteDbTypeMap();
   617    631         _parseViaFramework = parseViaFramework;
   618    632         _flags = SQLiteConnectionFlags.Default;
          633  +      _defaultDbType = SQLiteConvert.FallbackDefaultDbType;
          634  +      _defaultTypeName = SQLiteConvert.FallbackDefaultTypeName;
   619    635         _connectionState = ConnectionState.Closed;
   620    636         _connectionString = null;
   621    637   
   622    638         if (connectionString != null)
   623    639           ConnectionString = connectionString;
   624    640       }
   625    641   
................................................................................
  2254   2270             null, _connectionString, new object[] { opts }));
  2255   2271   
  2256   2272         object enumValue;
  2257   2273   
  2258   2274         enumValue = TryParseEnum(typeof(SQLiteConnectionFlags), FindKey(opts, "Flags", DefaultFlags.ToString()), true);
  2259   2275         _flags = (enumValue is SQLiteConnectionFlags) ? (SQLiteConnectionFlags)enumValue : DefaultFlags;
  2260   2276   
         2277  +      enumValue = TryParseEnum(typeof(DbType), FindKey(opts, "DefaultDbType", SQLiteConvert.FallbackDefaultDbType.ToString()), true);
         2278  +      _defaultDbType = (enumValue is DbType) ? (DbType)enumValue : SQLiteConvert.FallbackDefaultDbType;
         2279  +      _defaultTypeName = FindKey(opts, "DefaultTypeName", SQLiteConvert.FallbackDefaultTypeName);
         2280  +
  2261   2281   #if !NET_COMPACT_20 && TRACE_WARNING
  2262   2282         bool uri = false;
  2263   2283   #endif
  2264   2284         bool fullUri = false;
  2265   2285         string fileName;
  2266   2286   
  2267   2287         if (Convert.ToInt32(FindKey(opts, "Version", DefaultVersion.ToString()), CultureInfo.InvariantCulture) != DefaultVersion)
................................................................................
  2561   2581       /// possible values.
  2562   2582       /// </summary>
  2563   2583       public SQLiteConnectionFlags Flags
  2564   2584       {
  2565   2585         get { CheckDisposed(); return _flags; }
  2566   2586         set { CheckDisposed(); _flags = value; }
  2567   2587       }
         2588  +
         2589  +    /// <summary>
         2590  +    /// Gets/sets the default database type for this connection.  This value
         2591  +    /// will only be used if the <see cref="SQLiteConnectionFlags.UseConnectionTypes" />
         2592  +    /// flag is set.
         2593  +    /// </summary>
         2594  +    public DbType DefaultDbType
         2595  +    {
         2596  +      get { CheckDisposed(); return _defaultDbType; }
         2597  +      set { CheckDisposed(); _defaultDbType = value; }
         2598  +    }
         2599  +
         2600  +    /// <summary>
         2601  +    /// Gets/sets the default database type name for this connection.  This value
         2602  +    /// will only be used if the <see cref="SQLiteConnectionFlags.UseConnectionTypes" />
         2603  +    /// flag is set.
         2604  +    /// </summary>
         2605  +    public string DefaultTypeName
         2606  +    {
         2607  +      get { CheckDisposed(); return _defaultTypeName; }
         2608  +      set { CheckDisposed(); _defaultTypeName = value; }
         2609  +    }
  2568   2610   
  2569   2611       /// <summary>
  2570   2612       /// Returns non-zero if the underlying native connection handle is
  2571   2613       /// owned by this instance.
  2572   2614       /// </summary>
  2573   2615       public bool OwnHandle
  2574   2616       {

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

    19     19     using System.Text;
    20     20   
    21     21     /// <summary>
    22     22     /// This base class provides datatype conversion services for the SQLite provider.
    23     23     /// </summary>
    24     24     public abstract class SQLiteConvert
    25     25     {
           26  +    /// <summary>
           27  +    /// The fallback default database type when one cannot be obtained from an
           28  +    /// existing connection instance.
           29  +    /// </summary>
           30  +    internal static readonly DbType FallbackDefaultDbType = DbType.Object;
           31  +
           32  +    /// <summary>
           33  +    /// The fallback default database type name when one cannot be obtained from
           34  +    /// an existing connection instance.
           35  +    /// </summary>
           36  +    internal static readonly string FallbackDefaultTypeName = String.Empty;
           37  +
    26     38       /// <summary>
    27     39       /// The value for the Unix epoch (e.g. January 1, 1970 at midnight, in UTC).
    28     40       /// </summary>
    29     41       protected static readonly DateTime UnixEpoch =
    30     42           new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
    31     43   
    32     44       /// <summary>
................................................................................
   993   1005       /// <returns>The type name or an empty string if it cannot be determined.</returns>
   994   1006       internal static string DbTypeToTypeName(
   995   1007           SQLiteConnection connection,
   996   1008           DbType dbType,
   997   1009           SQLiteConnectionFlags flags
   998   1010           )
   999   1011       {
         1012  +        string defaultTypeName = FallbackDefaultTypeName;
         1013  +
  1000   1014           if (connection != null)
  1001   1015           {
  1002   1016               flags |= connection.Flags;
  1003   1017   
  1004   1018               if ((flags & SQLiteConnectionFlags.UseConnectionTypes) == SQLiteConnectionFlags.UseConnectionTypes)
  1005   1019               {
  1006   1020                   SQLiteDbTypeMap connectionTypeNames = connection._typeNames;
................................................................................
  1008   1022                   if (connectionTypeNames != null)
  1009   1023                   {
  1010   1024                       SQLiteDbTypeMapping value;
  1011   1025   
  1012   1026                       if (connectionTypeNames.TryGetValue(dbType, out value))
  1013   1027                           return value.typeName;
  1014   1028                   }
         1029  +
         1030  +                //
         1031  +                // NOTE: Use the default database type name for the connection.
         1032  +                //
         1033  +                defaultTypeName = connection.DefaultTypeName;
  1015   1034               }
  1016   1035           }
  1017   1036   
  1018         -        string defaultTypeName = String.Empty;
  1019         -
  1020   1037           if ((flags & SQLiteConnectionFlags.NoGlobalTypes) == SQLiteConnectionFlags.NoGlobalTypes)
  1021   1038               return defaultTypeName;
  1022   1039   
  1023   1040           lock (_syncRoot)
  1024   1041           {
  1025   1042               if (_typeNames == null)
  1026   1043                   _typeNames = GetSQLiteDbTypeMap();
................................................................................
  1218   1235       /// <returns>The .NET DBType the text evaluates to.</returns>
  1219   1236       internal static DbType TypeNameToDbType(
  1220   1237           SQLiteConnection connection,
  1221   1238           string name,
  1222   1239           SQLiteConnectionFlags flags
  1223   1240           )
  1224   1241       {
         1242  +        DbType defaultDbType = FallbackDefaultDbType;
         1243  +
  1225   1244           if (connection != null)
  1226   1245           {
  1227   1246               flags |= connection.Flags;
  1228   1247   
  1229   1248               if ((flags & SQLiteConnectionFlags.UseConnectionTypes) == SQLiteConnectionFlags.UseConnectionTypes)
  1230   1249               {
  1231   1250                   SQLiteDbTypeMap connectionTypeNames = connection._typeNames;
................................................................................
  1248   1267                                   connectionTypeNames.TryGetValue(name.Substring(0, index).TrimEnd(), out value))
  1249   1268                               {
  1250   1269                                   return value.dataType;
  1251   1270                               }
  1252   1271                           }
  1253   1272                       }
  1254   1273                   }
         1274  +
         1275  +                //
         1276  +                // NOTE: Use the default database type for the connection.
         1277  +                //
         1278  +                defaultDbType = connection.DefaultDbType;
  1255   1279               }
  1256   1280           }
  1257   1281   
  1258         -        DbType defaultDbType = DbType.Object;
  1259         -
  1260   1282           if ((flags & SQLiteConnectionFlags.NoGlobalTypes) == SQLiteConnectionFlags.NoGlobalTypes)
  1261   1283               return defaultDbType;
  1262   1284   
  1263   1285           lock (_syncRoot)
  1264   1286           {
  1265   1287               if (_typeNames == null)
  1266   1288                   _typeNames = GetSQLiteDbTypeMap();