Index: System.Data.SQLite/SQLiteConvert.cs
==================================================================
--- System.Data.SQLite/SQLiteConvert.cs
+++ System.Data.SQLite/SQLiteConvert.cs
@@ -1106,13 +1106,72 @@
if (value == null)
return FallbackDefaultTypeName;
return value;
}
+
+#if !NET_COMPACT_20 && TRACE_WARNING
+ ///
+ /// If applicable, issues a trace log message warning about falling back to
+ /// the default database type name.
+ ///
+ ///
+ /// The database value type.
+ ///
+ ///
+ /// The flags associated with the parent connection object.
+ ///
+ ///
+ /// The textual name of the database type.
+ ///
+ private static void DefaultTypeNameWarning(
+ DbType dbType,
+ SQLiteConnectionFlags flags,
+ string typeName
+ )
+ {
+ if ((flags & SQLiteConnectionFlags.TraceWarning) == SQLiteConnectionFlags.TraceWarning)
+ {
+ Trace.WriteLine(String.Format(
+ CultureInfo.CurrentCulture,
+ "WARNING: Type mapping failed, returning default name \"{0}\" for type {1}.",
+ typeName, dbType));
+ }
+ }
+
+ ///
+ /// If applicable, issues a trace log message warning about falling back to
+ /// the default database value type.
+ ///
+ ///
+ /// The textual name of the database type.
+ ///
+ ///
+ /// The flags associated with the parent connection object.
+ ///
+ ///
+ /// The database value type.
+ ///
+ private static void DefaultDbTypeWarning(
+ string typeName,
+ SQLiteConnectionFlags flags,
+ DbType? dbType
+ )
+ {
+ if (!String.IsNullOrEmpty(typeName) &&
+ ((flags & SQLiteConnectionFlags.TraceWarning) == SQLiteConnectionFlags.TraceWarning))
+ {
+ Trace.WriteLine(String.Format(
+ CultureInfo.CurrentCulture,
+ "WARNING: Type mapping failed, returning default type {0} for name \"{1}\".",
+ dbType, typeName));
+ }
+ }
+#endif
///
- /// Determines the type name for the given database value type.
+ /// For a given database value type, return the "closest-match" textual database type name.
///
/// The connection context for custom type mappings, if any.
/// The database value type.
/// The flags associated with the parent connection object.
/// The type name or an empty string if it cannot be determined.
@@ -1146,11 +1205,22 @@
//
defaultTypeName = connection.DefaultTypeName;
}
if ((flags & SQLiteConnectionFlags.NoGlobalTypes) == SQLiteConnectionFlags.NoGlobalTypes)
- return (defaultTypeName != null) ? defaultTypeName : GetDefaultTypeName();
+ {
+ if (defaultTypeName != null)
+ return defaultTypeName;
+
+ defaultTypeName = GetDefaultTypeName();
+
+#if !NET_COMPACT_20 && TRACE_WARNING
+ DefaultTypeNameWarning(dbType, flags, defaultTypeName);
+#endif
+
+ return defaultTypeName;
+ }
lock (_syncRoot)
{
if (_typeNames == null)
_typeNames = GetSQLiteDbTypeMap();
@@ -1159,21 +1229,20 @@
if (_typeNames.TryGetValue(dbType, out value))
return value.typeName;
}
+ if (defaultTypeName != null)
+ return defaultTypeName;
+
+ defaultTypeName = GetDefaultTypeName();
+
#if !NET_COMPACT_20 && TRACE_WARNING
- if ((flags & SQLiteConnectionFlags.TraceWarning) == SQLiteConnectionFlags.TraceWarning)
- {
- Trace.WriteLine(String.Format(
- CultureInfo.CurrentCulture,
- "WARNING: Type mapping failed, returning default name \"{0}\" for type {1}.",
- defaultTypeName, dbType));
- }
+ DefaultTypeNameWarning(dbType, flags, defaultTypeName);
#endif
- return (defaultTypeName != null) ? defaultTypeName : GetDefaultTypeName();
+ return defaultTypeName;
}
///
/// Convert a DbType to a Type
///
@@ -1529,19 +1598,21 @@
return false;
}
///
- /// For a given type name, return a closest-match .NET type
+ /// For a given textual database type name, return the "closest-match" database type.
+ /// This method is called during query result processing; therefore, its performance
+ /// is critical.
///
/// The connection context for custom type mappings, if any.
- /// The name of the type to match
+ /// The textual name of the database type to match.
/// The flags associated with the parent connection object.
/// The .NET DBType the text evaluates to.
internal static DbType TypeNameToDbType(
SQLiteConnection connection,
- string name,
+ string typeName,
SQLiteConnectionFlags flags
)
{
DbType? defaultDbType = null;
@@ -1553,24 +1624,24 @@
{
SQLiteDbTypeMap connectionTypeNames = connection._typeNames;
if (connectionTypeNames != null)
{
- if (name != null)
+ if (typeName != null)
{
SQLiteDbTypeMapping value;
- if (connectionTypeNames.TryGetValue(name, out value))
+ if (connectionTypeNames.TryGetValue(typeName, out value))
{
return value.dataType;
}
else
{
- int index = name.IndexOf('(');
+ int index = typeName.IndexOf('(');
if ((index > 0) &&
- connectionTypeNames.TryGetValue(name.Substring(0, index).TrimEnd(), out value))
+ connectionTypeNames.TryGetValue(typeName.Substring(0, index).TrimEnd(), out value))
{
return value.dataType;
}
}
}
@@ -1582,50 +1653,59 @@
//
defaultDbType = connection.DefaultDbType;
}
if ((flags & SQLiteConnectionFlags.NoGlobalTypes) == SQLiteConnectionFlags.NoGlobalTypes)
- return (defaultDbType != null) ? (DbType)defaultDbType : GetDefaultDbType();
+ {
+ if (defaultDbType != null)
+ return (DbType)defaultDbType;
+
+ defaultDbType = GetDefaultDbType();
+
+#if !NET_COMPACT_20 && TRACE_WARNING
+ DefaultDbTypeWarning(typeName, flags, defaultDbType);
+#endif
+
+ return (DbType)defaultDbType;
+ }
lock (_syncRoot)
{
if (_typeNames == null)
_typeNames = GetSQLiteDbTypeMap();
- if (name != null)
+ if (typeName != null)
{
SQLiteDbTypeMapping value;
- if (_typeNames.TryGetValue(name, out value))
+ if (_typeNames.TryGetValue(typeName, out value))
{
return value.dataType;
}
else
{
- int index = name.IndexOf('(');
+ int index = typeName.IndexOf('(');
if ((index > 0) &&
- _typeNames.TryGetValue(name.Substring(0, index).TrimEnd(), out value))
+ _typeNames.TryGetValue(typeName.Substring(0, index).TrimEnd(), out value))
{
return value.dataType;
}
}
}
}
+ if (defaultDbType != null)
+ return (DbType)defaultDbType;
+
+ defaultDbType = GetDefaultDbType();
+
#if !NET_COMPACT_20 && TRACE_WARNING
- if (!String.IsNullOrEmpty(name) &&
- ((flags & SQLiteConnectionFlags.TraceWarning) == SQLiteConnectionFlags.TraceWarning))
- {
- Trace.WriteLine(String.Format(
- CultureInfo.CurrentCulture,
- "WARNING: Type mapping failed, returning default type {0} for name \"{1}\".",
- defaultDbType, name));
- }
+ DefaultDbTypeWarning(typeName, flags, defaultDbType);
#endif
- return (defaultDbType != null) ? (DbType)defaultDbType : GetDefaultDbType();
+ return (DbType)defaultDbType;
}
#endregion
private static object _syncRoot = new object();
private static SQLiteDbTypeMap _typeNames = null;