System.Data.SQLite
Check-in [2413338b69]
Not logged in

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

Overview
Comment:Make sure default data type warnings are always issued when applicable.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 2413338b69d0d1bde2ba6d4be165599ff8350f6c
User & Date: mistachkin 2014-08-02 20:46:18
Context
2014-08-02
22:42
Make the versioning tests easier to manage and maintain. check-in: fb520cf55b user: mistachkin tags: trunk
20:46
Make sure default data type warnings are always issued when applicable. check-in: 2413338b69 user: mistachkin tags: trunk
17:33
Update documentation comments for the DefaultDbType and DefaultTypeName properties. check-in: f4af7db4f1 user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

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

  1105   1105   
  1106   1106           if (value == null)
  1107   1107               return FallbackDefaultTypeName;
  1108   1108   
  1109   1109           return value;
  1110   1110       }
  1111   1111   
         1112  +#if !NET_COMPACT_20 && TRACE_WARNING
  1112   1113       /// <summary>
  1113         -    /// Determines the type name for the given database value type.
         1114  +    /// If applicable, issues a trace log message warning about falling back to
         1115  +    /// the default database type name.
         1116  +    /// </summary>
         1117  +    /// <param name="dbType">
         1118  +    /// The database value type.
         1119  +    /// </param>
         1120  +    /// <param name="flags">
         1121  +    /// The flags associated with the parent connection object.
         1122  +    /// </param>
         1123  +    /// <param name="typeName">
         1124  +    /// The textual name of the database type.
         1125  +    /// </param>
         1126  +    private static void DefaultTypeNameWarning(
         1127  +        DbType dbType,
         1128  +        SQLiteConnectionFlags flags,
         1129  +        string typeName
         1130  +        )
         1131  +    {
         1132  +        if ((flags & SQLiteConnectionFlags.TraceWarning) == SQLiteConnectionFlags.TraceWarning)
         1133  +        {
         1134  +            Trace.WriteLine(String.Format(
         1135  +                CultureInfo.CurrentCulture,
         1136  +                "WARNING: Type mapping failed, returning default name \"{0}\" for type {1}.",
         1137  +                typeName, dbType));
         1138  +        }
         1139  +    }
         1140  +
         1141  +    /// <summary>
         1142  +    /// If applicable, issues a trace log message warning about falling back to
         1143  +    /// the default database value type.
         1144  +    /// </summary>
         1145  +    /// <param name="typeName">
         1146  +    /// The textual name of the database type.
         1147  +    /// </param>
         1148  +    /// <param name="flags">
         1149  +    /// The flags associated with the parent connection object.
         1150  +    /// </param>
         1151  +    /// <param name="dbType">
         1152  +    /// The database value type.
         1153  +    /// </param>
         1154  +    private static void DefaultDbTypeWarning(
         1155  +        string typeName,
         1156  +        SQLiteConnectionFlags flags,
         1157  +        DbType? dbType
         1158  +        )
         1159  +    {
         1160  +        if (!String.IsNullOrEmpty(typeName) &&
         1161  +            ((flags & SQLiteConnectionFlags.TraceWarning) == SQLiteConnectionFlags.TraceWarning))
         1162  +        {
         1163  +            Trace.WriteLine(String.Format(
         1164  +                CultureInfo.CurrentCulture,
         1165  +                "WARNING: Type mapping failed, returning default type {0} for name \"{1}\".",
         1166  +                dbType, typeName));
         1167  +        }
         1168  +    }
         1169  +#endif
         1170  +
         1171  +    /// <summary>
         1172  +    /// For a given database value type, return the "closest-match" textual database type name.
  1114   1173       /// </summary>
  1115   1174       /// <param name="connection">The connection context for custom type mappings, if any.</param>
  1116   1175       /// <param name="dbType">The database value type.</param>
  1117   1176       /// <param name="flags">The flags associated with the parent connection object.</param>
  1118   1177       /// <returns>The type name or an empty string if it cannot be determined.</returns>
  1119   1178       internal static string DbTypeToTypeName(
  1120   1179           SQLiteConnection connection,
................................................................................
  1144   1203               //
  1145   1204               // NOTE: Use the default database type name for the connection.
  1146   1205               //
  1147   1206               defaultTypeName = connection.DefaultTypeName;
  1148   1207           }
  1149   1208   
  1150   1209           if ((flags & SQLiteConnectionFlags.NoGlobalTypes) == SQLiteConnectionFlags.NoGlobalTypes)
  1151         -            return (defaultTypeName != null) ? defaultTypeName : GetDefaultTypeName();
         1210  +        {
         1211  +            if (defaultTypeName != null)
         1212  +                return defaultTypeName;
         1213  +
         1214  +            defaultTypeName = GetDefaultTypeName();
         1215  +
         1216  +#if !NET_COMPACT_20 && TRACE_WARNING
         1217  +            DefaultTypeNameWarning(dbType, flags, defaultTypeName);
         1218  +#endif
         1219  +
         1220  +            return defaultTypeName;
         1221  +        }
  1152   1222   
  1153   1223           lock (_syncRoot)
  1154   1224           {
  1155   1225               if (_typeNames == null)
  1156   1226                   _typeNames = GetSQLiteDbTypeMap();
  1157   1227   
  1158   1228               SQLiteDbTypeMapping value;
  1159   1229   
  1160   1230               if (_typeNames.TryGetValue(dbType, out value))
  1161   1231                   return value.typeName;
  1162   1232           }
  1163   1233   
         1234  +        if (defaultTypeName != null)
         1235  +            return defaultTypeName;
         1236  +
         1237  +        defaultTypeName = GetDefaultTypeName();
         1238  +
  1164   1239   #if !NET_COMPACT_20 && TRACE_WARNING
  1165         -        if ((flags & SQLiteConnectionFlags.TraceWarning) == SQLiteConnectionFlags.TraceWarning)
  1166         -        {
  1167         -            Trace.WriteLine(String.Format(
  1168         -                CultureInfo.CurrentCulture,
  1169         -                "WARNING: Type mapping failed, returning default name \"{0}\" for type {1}.",
  1170         -                defaultTypeName, dbType));
  1171         -        }
         1240  +        DefaultTypeNameWarning(dbType, flags, defaultTypeName);
  1172   1241   #endif
  1173   1242   
  1174         -        return (defaultTypeName != null) ? defaultTypeName : GetDefaultTypeName();
         1243  +        return defaultTypeName;
  1175   1244       }
  1176   1245   
  1177   1246       /// <summary>
  1178   1247       /// Convert a DbType to a Type
  1179   1248       /// </summary>
  1180   1249       /// <param name="typ">The DbType to convert from</param>
  1181   1250       /// <returns>The closest-match .NET type</returns>
................................................................................
  1527   1596               // do nothing.
  1528   1597           }
  1529   1598   
  1530   1599           return false;
  1531   1600       }
  1532   1601   
  1533   1602       /// <summary>
  1534         -    /// For a given type name, return a closest-match .NET type
         1603  +    /// For a given textual database type name, return the "closest-match" database type.
         1604  +    /// This method is called during query result processing; therefore, its performance
         1605  +    /// is critical.
  1535   1606       /// </summary>
  1536   1607       /// <param name="connection">The connection context for custom type mappings, if any.</param>
  1537         -    /// <param name="name">The name of the type to match</param>
         1608  +    /// <param name="typeName">The textual name of the database type to match.</param>
  1538   1609       /// <param name="flags">The flags associated with the parent connection object.</param>
  1539   1610       /// <returns>The .NET DBType the text evaluates to.</returns>
  1540   1611       internal static DbType TypeNameToDbType(
  1541   1612           SQLiteConnection connection,
  1542         -        string name,
         1613  +        string typeName,
  1543   1614           SQLiteConnectionFlags flags
  1544   1615           )
  1545   1616       {
  1546   1617           DbType? defaultDbType = null;
  1547   1618   
  1548   1619           if (connection != null)
  1549   1620           {
................................................................................
  1551   1622   
  1552   1623               if ((flags & SQLiteConnectionFlags.UseConnectionTypes) == SQLiteConnectionFlags.UseConnectionTypes)
  1553   1624               {
  1554   1625                   SQLiteDbTypeMap connectionTypeNames = connection._typeNames;
  1555   1626   
  1556   1627                   if (connectionTypeNames != null)
  1557   1628                   {
  1558         -                    if (name != null)
         1629  +                    if (typeName != null)
  1559   1630                       {
  1560   1631                           SQLiteDbTypeMapping value;
  1561   1632   
  1562         -                        if (connectionTypeNames.TryGetValue(name, out value))
         1633  +                        if (connectionTypeNames.TryGetValue(typeName, out value))
  1563   1634                           {
  1564   1635                               return value.dataType;
  1565   1636                           }
  1566   1637                           else
  1567   1638                           {
  1568         -                            int index = name.IndexOf('(');
         1639  +                            int index = typeName.IndexOf('(');
  1569   1640   
  1570   1641                               if ((index > 0) &&
  1571         -                                connectionTypeNames.TryGetValue(name.Substring(0, index).TrimEnd(), out value))
         1642  +                                connectionTypeNames.TryGetValue(typeName.Substring(0, index).TrimEnd(), out value))
  1572   1643                               {
  1573   1644                                   return value.dataType;
  1574   1645                               }
  1575   1646                           }
  1576   1647                       }
  1577   1648                   }
  1578   1649               }
................................................................................
  1580   1651               //
  1581   1652               // NOTE: Use the default database type for the connection.
  1582   1653               //
  1583   1654               defaultDbType = connection.DefaultDbType;
  1584   1655           }
  1585   1656   
  1586   1657           if ((flags & SQLiteConnectionFlags.NoGlobalTypes) == SQLiteConnectionFlags.NoGlobalTypes)
  1587         -            return (defaultDbType != null) ? (DbType)defaultDbType : GetDefaultDbType();
         1658  +        {
         1659  +            if (defaultDbType != null)
         1660  +                return (DbType)defaultDbType;
         1661  +
         1662  +            defaultDbType = GetDefaultDbType();
         1663  +
         1664  +#if !NET_COMPACT_20 && TRACE_WARNING
         1665  +            DefaultDbTypeWarning(typeName, flags, defaultDbType);
         1666  +#endif
         1667  +
         1668  +            return (DbType)defaultDbType;
         1669  +        }
  1588   1670   
  1589   1671           lock (_syncRoot)
  1590   1672           {
  1591   1673               if (_typeNames == null)
  1592   1674                   _typeNames = GetSQLiteDbTypeMap();
  1593   1675   
  1594         -            if (name != null)
         1676  +            if (typeName != null)
  1595   1677               {
  1596   1678                   SQLiteDbTypeMapping value;
  1597   1679   
  1598         -                if (_typeNames.TryGetValue(name, out value))
         1680  +                if (_typeNames.TryGetValue(typeName, out value))
  1599   1681                   {
  1600   1682                       return value.dataType;
  1601   1683                   }
  1602   1684                   else
  1603   1685                   {
  1604         -                    int index = name.IndexOf('(');
         1686  +                    int index = typeName.IndexOf('(');
  1605   1687   
  1606   1688                       if ((index > 0) &&
  1607         -                        _typeNames.TryGetValue(name.Substring(0, index).TrimEnd(), out value))
         1689  +                        _typeNames.TryGetValue(typeName.Substring(0, index).TrimEnd(), out value))
  1608   1690                       {
  1609   1691                           return value.dataType;
  1610   1692                       }
  1611   1693                   }
  1612   1694               }
  1613   1695           }
  1614   1696   
         1697  +        if (defaultDbType != null)
         1698  +            return (DbType)defaultDbType;
         1699  +
         1700  +        defaultDbType = GetDefaultDbType();
         1701  +
  1615   1702   #if !NET_COMPACT_20 && TRACE_WARNING
  1616         -        if (!String.IsNullOrEmpty(name) &&
  1617         -            ((flags & SQLiteConnectionFlags.TraceWarning) == SQLiteConnectionFlags.TraceWarning))
  1618         -        {
  1619         -            Trace.WriteLine(String.Format(
  1620         -                CultureInfo.CurrentCulture,
  1621         -                "WARNING: Type mapping failed, returning default type {0} for name \"{1}\".",
  1622         -                defaultDbType, name));
  1623         -        }
         1703  +        DefaultDbTypeWarning(typeName, flags, defaultDbType);
  1624   1704   #endif
  1625   1705   
  1626         -        return (defaultDbType != null) ? (DbType)defaultDbType : GetDefaultDbType();
         1706  +        return (DbType)defaultDbType;
  1627   1707       }
  1628   1708       #endregion
  1629   1709   
  1630   1710       private static object _syncRoot = new object();
  1631   1711       private static SQLiteDbTypeMap _typeNames = null;
  1632   1712     }
  1633   1713