Index: System.Data.SQLite/SQLiteConnection.cs ================================================================== --- System.Data.SQLite/SQLiteConnection.cs +++ System.Data.SQLite/SQLiteConnection.cs @@ -471,10 +471,24 @@ /// enumeration for a list of /// possible values. /// private SQLiteConnectionFlags _flags; + /// + /// The default databse type for this connection. This value will only + /// be used if the + /// flag is set. + /// + private DbType _defaultDbType; + + /// + /// The default databse type name for this connection. This value will only + /// be used if the + /// flag is set. + /// + private string _defaultTypeName; + /// /// Default command timeout /// private int _defaultTimeout = 30; @@ -614,10 +628,12 @@ #endif _typeNames = new SQLiteDbTypeMap(); _parseViaFramework = parseViaFramework; _flags = SQLiteConnectionFlags.Default; + _defaultDbType = SQLiteConvert.FallbackDefaultDbType; + _defaultTypeName = SQLiteConvert.FallbackDefaultTypeName; _connectionState = ConnectionState.Closed; _connectionString = null; if (connectionString != null) ConnectionString = connectionString; @@ -2256,10 +2272,14 @@ object enumValue; enumValue = TryParseEnum(typeof(SQLiteConnectionFlags), FindKey(opts, "Flags", DefaultFlags.ToString()), true); _flags = (enumValue is SQLiteConnectionFlags) ? (SQLiteConnectionFlags)enumValue : DefaultFlags; + enumValue = TryParseEnum(typeof(DbType), FindKey(opts, "DefaultDbType", SQLiteConvert.FallbackDefaultDbType.ToString()), true); + _defaultDbType = (enumValue is DbType) ? (DbType)enumValue : SQLiteConvert.FallbackDefaultDbType; + _defaultTypeName = FindKey(opts, "DefaultTypeName", SQLiteConvert.FallbackDefaultTypeName); + #if !NET_COMPACT_20 && TRACE_WARNING bool uri = false; #endif bool fullUri = false; string fileName; @@ -2563,10 +2583,32 @@ public SQLiteConnectionFlags Flags { get { CheckDisposed(); return _flags; } set { CheckDisposed(); _flags = value; } } + + /// + /// Gets/sets the default database type for this connection. This value + /// will only be used if the + /// flag is set. + /// + public DbType DefaultDbType + { + get { CheckDisposed(); return _defaultDbType; } + set { CheckDisposed(); _defaultDbType = value; } + } + + /// + /// Gets/sets the default database type name for this connection. This value + /// will only be used if the + /// flag is set. + /// + public string DefaultTypeName + { + get { CheckDisposed(); return _defaultTypeName; } + set { CheckDisposed(); _defaultTypeName = value; } + } /// /// Returns non-zero if the underlying native connection handle is /// owned by this instance. /// Index: System.Data.SQLite/SQLiteConvert.cs ================================================================== --- System.Data.SQLite/SQLiteConvert.cs +++ System.Data.SQLite/SQLiteConvert.cs @@ -21,10 +21,22 @@ /// /// This base class provides datatype conversion services for the SQLite provider. /// public abstract class SQLiteConvert { + /// + /// The fallback default database type when one cannot be obtained from an + /// existing connection instance. + /// + internal static readonly DbType FallbackDefaultDbType = DbType.Object; + + /// + /// The fallback default database type name when one cannot be obtained from + /// an existing connection instance. + /// + internal static readonly string FallbackDefaultTypeName = String.Empty; + /// /// The value for the Unix epoch (e.g. January 1, 1970 at midnight, in UTC). /// protected static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); @@ -995,10 +1007,12 @@ SQLiteConnection connection, DbType dbType, SQLiteConnectionFlags flags ) { + string defaultTypeName = FallbackDefaultTypeName; + if (connection != null) { flags |= connection.Flags; if ((flags & SQLiteConnectionFlags.UseConnectionTypes) == SQLiteConnectionFlags.UseConnectionTypes) @@ -1010,15 +1024,18 @@ SQLiteDbTypeMapping value; if (connectionTypeNames.TryGetValue(dbType, out value)) return value.typeName; } + + // + // NOTE: Use the default database type name for the connection. + // + defaultTypeName = connection.DefaultTypeName; } } - string defaultTypeName = String.Empty; - if ((flags & SQLiteConnectionFlags.NoGlobalTypes) == SQLiteConnectionFlags.NoGlobalTypes) return defaultTypeName; lock (_syncRoot) { @@ -1220,10 +1237,12 @@ SQLiteConnection connection, string name, SQLiteConnectionFlags flags ) { + DbType defaultDbType = FallbackDefaultDbType; + if (connection != null) { flags |= connection.Flags; if ((flags & SQLiteConnectionFlags.UseConnectionTypes) == SQLiteConnectionFlags.UseConnectionTypes) @@ -1250,15 +1269,18 @@ return value.dataType; } } } } + + // + // NOTE: Use the default database type for the connection. + // + defaultDbType = connection.DefaultDbType; } } - DbType defaultDbType = DbType.Object; - if ((flags & SQLiteConnectionFlags.NoGlobalTypes) == SQLiteConnectionFlags.NoGlobalTypes) return defaultDbType; lock (_syncRoot) {