System.Data.SQLite
Check-in [48b50f802e]
Not logged in

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

Overview
Comment:Further refactoring work on the DbType/TypeName map handling.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 48b50f802ed2e35c71d257072b2885ea26575022
User & Date: mistachkin 2013-05-29 10:04:28
Context
2013-05-29
10:21
Seal various internal classes that are never derived from. check-in: e8abe75ff5 user: mistachkin tags: trunk
10:04
Further refactoring work on the DbType/TypeName map handling. check-in: 48b50f802e user: mistachkin tags: trunk
2013-05-28
09:55
Bump all versions to 1.0.87.0. check-in: 01ae5e862f user: mistachkin tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

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

865
866
867
868
869
870
871
872
873
874

875
876



877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
...
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
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
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063

1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075

1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091

1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
....
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400

1401

















































































1402



1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
      DBNull.Value, // StringFixedLength (23)
      DBNull.Value, // ?? (24)
      DBNull.Value  // Xml (25)
    };

    internal static string DbTypeToTypeName(DbType typ)
    {
      for (int n = 0; n < _dbtypeNames.Length; n++)
      {
        SQLiteTypeName typeName = _dbtypeNames[n];


        if ((typeName.dataType == typ) && typeName.primary)



          return typeName.typeName;
      }

      string defaultTypeName = String.Empty;

#if !NET_COMPACT_20 && TRACE_WARNING
      Trace.WriteLine(String.Format(
          "WARNING: Type mapping failed, returning default name \"{0}\" for type {1}.",
          defaultTypeName, typ));
#endif

      return defaultTypeName;
    }

    private static SQLiteTypeName[] _dbtypeNames = GetSQLiteTypeNames();

    /// <summary>
    /// Convert a DbType to a Type
    /// </summary>
    /// <param name="typ">The DbType to convert from</param>
    /// <returns>The closest-match .NET type</returns>
    internal static Type DbTypeToType(DbType typ)
    {
................................................................................
    /// Builds and returns an array containing the database column types
    /// recognized by this provider.
    /// </summary>
    /// <returns>
    /// An array containing the database column types recognized by this
    /// provider.
    /// </returns>
    private static SQLiteTypeName[] GetSQLiteTypeNames()
    {
        return new SQLiteTypeName[] {
            new SQLiteTypeName("BIGINT", DbType.Int64, false),
            new SQLiteTypeName("BIGUINT", DbType.UInt64, false),
            new SQLiteTypeName("BINARY", DbType.Binary, false),
            new SQLiteTypeName("BIT", DbType.Boolean, true),
            new SQLiteTypeName("BLOB", DbType.Binary, true),
            new SQLiteTypeName("BOOL", DbType.Boolean, false),
            new SQLiteTypeName("BOOLEAN", DbType.Boolean, false),
            new SQLiteTypeName("CHAR", DbType.AnsiStringFixedLength, true),
            new SQLiteTypeName("COUNTER", DbType.Int64, false),
            new SQLiteTypeName("CURRENCY", DbType.Decimal, false),
            new SQLiteTypeName("DATE", DbType.DateTime, false),
            new SQLiteTypeName("DATETIME", DbType.DateTime, true),
            new SQLiteTypeName("DECIMAL", DbType.Decimal, true),
            new SQLiteTypeName("DOUBLE", DbType.Double, false),
            new SQLiteTypeName("FLOAT", DbType.Double, false),
            new SQLiteTypeName("GENERAL", DbType.Binary, false),
            new SQLiteTypeName("GUID", DbType.Guid, false),
            new SQLiteTypeName("IDENTITY", DbType.Int64, false),
            new SQLiteTypeName("IMAGE", DbType.Binary, false),
            new SQLiteTypeName("INT", DbType.Int32, true),
            new SQLiteTypeName("INT8", DbType.SByte, false),
            new SQLiteTypeName("INT16", DbType.Int16, false),
            new SQLiteTypeName("INT32", DbType.Int32, false),
            new SQLiteTypeName("INT64", DbType.Int64, false),
            new SQLiteTypeName("INTEGER", DbType.Int64, true),
            new SQLiteTypeName("INTEGER8", DbType.SByte, false),
            new SQLiteTypeName("INTEGER16", DbType.Int16, false),
            new SQLiteTypeName("INTEGER32", DbType.Int32, false),
            new SQLiteTypeName("INTEGER64", DbType.Int64, false),
            new SQLiteTypeName("LOGICAL", DbType.Boolean, false),
            new SQLiteTypeName("LONG", DbType.Int64, false),
            new SQLiteTypeName("LONGCHAR", DbType.String, false),
            new SQLiteTypeName("LONGTEXT", DbType.String, false),
            new SQLiteTypeName("LONGVARCHAR", DbType.String, false),
            new SQLiteTypeName("MEMO", DbType.String, false),
            new SQLiteTypeName("MONEY", DbType.Decimal, false),
            new SQLiteTypeName("NCHAR", DbType.StringFixedLength, true),
            new SQLiteTypeName("NOTE", DbType.String, false),
            new SQLiteTypeName("NTEXT", DbType.String, false),
            new SQLiteTypeName("NUMERIC", DbType.Decimal, false),
            new SQLiteTypeName("NVARCHAR", DbType.String, true),
            new SQLiteTypeName("OLEOBJECT", DbType.Binary, false),
            new SQLiteTypeName("REAL", DbType.Double, true),
            new SQLiteTypeName("SINGLE", DbType.Single, true),
            new SQLiteTypeName("SMALLDATE", DbType.DateTime, false),
            new SQLiteTypeName("SMALLINT", DbType.Int16, true),
            new SQLiteTypeName("SMALLUINT", DbType.UInt16, true),
            new SQLiteTypeName("STRING", DbType.String, false),
            new SQLiteTypeName("TEXT", DbType.String, false),
            new SQLiteTypeName("TIME", DbType.DateTime, false),
            new SQLiteTypeName("TIMESTAMP", DbType.DateTime, false),
            new SQLiteTypeName("TINYINT", DbType.Byte, true),
            new SQLiteTypeName("TINYSINT", DbType.SByte, true),
            new SQLiteTypeName("UINT", DbType.UInt32, true),
            new SQLiteTypeName("UINT8", DbType.Byte, false),
            new SQLiteTypeName("UINT16", DbType.UInt16, false),
            new SQLiteTypeName("UINT32", DbType.UInt32, false),
            new SQLiteTypeName("UINT64", DbType.UInt64, false),
            new SQLiteTypeName("ULONG", DbType.UInt64, false),
            new SQLiteTypeName("UNIQUEIDENTIFIER", DbType.Guid, true),
            new SQLiteTypeName("UNSIGNEDINTEGER", DbType.UInt64, true),
            new SQLiteTypeName("UNSIGNEDINTEGER8", DbType.Byte, false),
            new SQLiteTypeName("UNSIGNEDINTEGER16", DbType.UInt16, false),
            new SQLiteTypeName("UNSIGNEDINTEGER32", DbType.UInt32, false),
            new SQLiteTypeName("UNSIGNEDINTEGER64", DbType.UInt64, false),
            new SQLiteTypeName("VARBINARY", DbType.Binary, false),
            new SQLiteTypeName("VARCHAR", DbType.AnsiString, true),
            new SQLiteTypeName("YESNO", DbType.Boolean, false)
        };
    }

    /// <summary>
    /// For a given type name, return a closest-match .NET type
    /// </summary>
    /// <param name="Name">The name of the type to match</param>
    /// <returns>The .NET DBType the text evaluates to.</returns>
    internal static DbType TypeNameToDbType(string Name)
    {
      lock (_syncRoot)
      {
        if (_typeNames == null)

        {
          _typeNames = new Dictionary<string, SQLiteTypeName>(
              new TypeNameStringComparer());

          foreach (SQLiteTypeName typeName in GetSQLiteTypeNames())
            _typeNames.Add(typeName.typeName, typeName);
        }
      }

      if (String.IsNullOrEmpty(Name)) return DbType.Object;

      SQLiteTypeName value;


      if (_typeNames.TryGetValue(Name, out value))
      {
        return value.dataType;
      }
      else
      {
        int index = Name.IndexOf('(');

        if ((index > 0) &&
            _typeNames.TryGetValue(Name.Substring(0, index).TrimEnd(), out value))
        {
          return value.dataType;
        }
      }


      DbType defaultDbType = DbType.Object;

#if !NET_COMPACT_20 && TRACE_WARNING
      Trace.WriteLine(String.Format(
          "WARNING: Type mapping failed, returning default type {0} for name \"{1}\".",
          defaultDbType, Name));
#endif

      return defaultDbType;
    }
    #endregion

    private static object _syncRoot = new object();
    private static Dictionary<string, SQLiteTypeName> _typeNames = null;
  }

  /// <summary>
  /// SQLite has very limited types, and is inherently text-based.  The first 5 types below represent the sum of all types SQLite
  /// understands.  The DateTime extension to the spec is for internal use only.
  /// </summary>
  public enum TypeAffinity
................................................................................
      /// Use the default command execution type.  Using this value is the same
      /// as using the <see cref="SQLiteExecuteType.NonQuery" /> value.
      /// </summary>
      Default = NonQuery /* TODO: Good default? */
  }

  /// <summary>
  /// Struct used internally to determine the datatype of a column in a resultset
  /// </summary>
  internal class SQLiteType
  {
    /// <summary>
    /// The DbType of the column, or DbType.Object if it cannot be determined
    /// </summary>
    internal DbType Type;
    /// <summary>
    /// The affinity of a column, used for expressions or when Type is DbType.Object
    /// </summary>
    internal TypeAffinity Affinity;
  }

  internal struct SQLiteTypeName

  {

















































































    internal SQLiteTypeName(string newTypeName, DbType newDataType, bool newPrimary)



    {
      typeName = newTypeName;
      dataType = newDataType;
      primary = newPrimary;
    }

    internal string typeName;
    internal DbType dataType;
    internal bool primary;
  }

  internal class TypeNameStringComparer : IEqualityComparer<string>
  {
    #region IEqualityComparer<string> Members
    public bool Equals(
      string left,
      string right
      )
    {







|
|
|
>

<
>
>
>
|
|

|


|
|
|


|


<
<







 







|

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|









|
|
|
>
|
<
<
<
<
<
<
<
<
|

<
>

|
|
|
|
|
|
|

|
|
|
|
|
|
|
>
|


|
|
|


|




|







 







|

|











<
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>











|







865
866
867
868
869
870
871
872
873
874
875
876

877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893


894
895
896
897
898
899
900
...
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
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
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066








1067
1068

1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
....
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394

1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
      DBNull.Value, // StringFixedLength (23)
      DBNull.Value, // ?? (24)
      DBNull.Value  // Xml (25)
    };

    internal static string DbTypeToTypeName(DbType typ)
    {
        lock (_syncRoot)
        {
            if (_typeNames == null)
                _typeNames = GetSQLiteDbTypeMap();


            SQLiteDbTypeMapping value;

            if (_typeNames.TryGetValue(typ, out value))
                return value.typeName;
        }

        string defaultTypeName = String.Empty;

#if !NET_COMPACT_20 && TRACE_WARNING
        Trace.WriteLine(String.Format(
            "WARNING: Type mapping failed, returning default name \"{0}\" for type {1}.",
            defaultTypeName, typ));
#endif

        return defaultTypeName;
    }



    /// <summary>
    /// Convert a DbType to a Type
    /// </summary>
    /// <param name="typ">The DbType to convert from</param>
    /// <returns>The closest-match .NET type</returns>
    internal static Type DbTypeToType(DbType typ)
    {
................................................................................
    /// Builds and returns an array containing the database column types
    /// recognized by this provider.
    /// </summary>
    /// <returns>
    /// An array containing the database column types recognized by this
    /// provider.
    /// </returns>
    private static SQLiteDbTypeMap GetSQLiteDbTypeMap()
    {
        return new SQLiteDbTypeMap(new SQLiteDbTypeMapping[] {
            new SQLiteDbTypeMapping("BIGINT", DbType.Int64, false),
            new SQLiteDbTypeMapping("BIGUINT", DbType.UInt64, false),
            new SQLiteDbTypeMapping("BINARY", DbType.Binary, false),
            new SQLiteDbTypeMapping("BIT", DbType.Boolean, true),
            new SQLiteDbTypeMapping("BLOB", DbType.Binary, true),
            new SQLiteDbTypeMapping("BOOL", DbType.Boolean, false),
            new SQLiteDbTypeMapping("BOOLEAN", DbType.Boolean, false),
            new SQLiteDbTypeMapping("CHAR", DbType.AnsiStringFixedLength, true),
            new SQLiteDbTypeMapping("COUNTER", DbType.Int64, false),
            new SQLiteDbTypeMapping("CURRENCY", DbType.Decimal, false),
            new SQLiteDbTypeMapping("DATE", DbType.DateTime, false),
            new SQLiteDbTypeMapping("DATETIME", DbType.DateTime, true),
            new SQLiteDbTypeMapping("DECIMAL", DbType.Decimal, true),
            new SQLiteDbTypeMapping("DOUBLE", DbType.Double, false),
            new SQLiteDbTypeMapping("FLOAT", DbType.Double, false),
            new SQLiteDbTypeMapping("GENERAL", DbType.Binary, false),
            new SQLiteDbTypeMapping("GUID", DbType.Guid, false),
            new SQLiteDbTypeMapping("IDENTITY", DbType.Int64, false),
            new SQLiteDbTypeMapping("IMAGE", DbType.Binary, false),
            new SQLiteDbTypeMapping("INT", DbType.Int32, true),
            new SQLiteDbTypeMapping("INT8", DbType.SByte, false),
            new SQLiteDbTypeMapping("INT16", DbType.Int16, false),
            new SQLiteDbTypeMapping("INT32", DbType.Int32, false),
            new SQLiteDbTypeMapping("INT64", DbType.Int64, false),
            new SQLiteDbTypeMapping("INTEGER", DbType.Int64, true),
            new SQLiteDbTypeMapping("INTEGER8", DbType.SByte, false),
            new SQLiteDbTypeMapping("INTEGER16", DbType.Int16, false),
            new SQLiteDbTypeMapping("INTEGER32", DbType.Int32, false),
            new SQLiteDbTypeMapping("INTEGER64", DbType.Int64, false),
            new SQLiteDbTypeMapping("LOGICAL", DbType.Boolean, false),
            new SQLiteDbTypeMapping("LONG", DbType.Int64, false),
            new SQLiteDbTypeMapping("LONGCHAR", DbType.String, false),
            new SQLiteDbTypeMapping("LONGTEXT", DbType.String, false),
            new SQLiteDbTypeMapping("LONGVARCHAR", DbType.String, false),
            new SQLiteDbTypeMapping("MEMO", DbType.String, false),
            new SQLiteDbTypeMapping("MONEY", DbType.Decimal, false),
            new SQLiteDbTypeMapping("NCHAR", DbType.StringFixedLength, true),
            new SQLiteDbTypeMapping("NOTE", DbType.String, false),
            new SQLiteDbTypeMapping("NTEXT", DbType.String, false),
            new SQLiteDbTypeMapping("NUMERIC", DbType.Decimal, false),
            new SQLiteDbTypeMapping("NVARCHAR", DbType.String, true),
            new SQLiteDbTypeMapping("OLEOBJECT", DbType.Binary, false),
            new SQLiteDbTypeMapping("REAL", DbType.Double, true),
            new SQLiteDbTypeMapping("SINGLE", DbType.Single, true),
            new SQLiteDbTypeMapping("SMALLDATE", DbType.DateTime, false),
            new SQLiteDbTypeMapping("SMALLINT", DbType.Int16, true),
            new SQLiteDbTypeMapping("SMALLUINT", DbType.UInt16, true),
            new SQLiteDbTypeMapping("STRING", DbType.String, false),
            new SQLiteDbTypeMapping("TEXT", DbType.String, false),
            new SQLiteDbTypeMapping("TIME", DbType.DateTime, false),
            new SQLiteDbTypeMapping("TIMESTAMP", DbType.DateTime, false),
            new SQLiteDbTypeMapping("TINYINT", DbType.Byte, true),
            new SQLiteDbTypeMapping("TINYSINT", DbType.SByte, true),
            new SQLiteDbTypeMapping("UINT", DbType.UInt32, true),
            new SQLiteDbTypeMapping("UINT8", DbType.Byte, false),
            new SQLiteDbTypeMapping("UINT16", DbType.UInt16, false),
            new SQLiteDbTypeMapping("UINT32", DbType.UInt32, false),
            new SQLiteDbTypeMapping("UINT64", DbType.UInt64, false),
            new SQLiteDbTypeMapping("ULONG", DbType.UInt64, false),
            new SQLiteDbTypeMapping("UNIQUEIDENTIFIER", DbType.Guid, true),
            new SQLiteDbTypeMapping("UNSIGNEDINTEGER", DbType.UInt64, true),
            new SQLiteDbTypeMapping("UNSIGNEDINTEGER8", DbType.Byte, false),
            new SQLiteDbTypeMapping("UNSIGNEDINTEGER16", DbType.UInt16, false),
            new SQLiteDbTypeMapping("UNSIGNEDINTEGER32", DbType.UInt32, false),
            new SQLiteDbTypeMapping("UNSIGNEDINTEGER64", DbType.UInt64, false),
            new SQLiteDbTypeMapping("VARBINARY", DbType.Binary, false),
            new SQLiteDbTypeMapping("VARCHAR", DbType.AnsiString, true),
            new SQLiteDbTypeMapping("YESNO", DbType.Boolean, false)
        });
    }

    /// <summary>
    /// For a given type name, return a closest-match .NET type
    /// </summary>
    /// <param name="Name">The name of the type to match</param>
    /// <returns>The .NET DBType the text evaluates to.</returns>
    internal static DbType TypeNameToDbType(string Name)
    {
        lock (_syncRoot)
        {
            if (_typeNames == null)
                _typeNames = GetSQLiteDbTypeMap();









            if (String.IsNullOrEmpty(Name)) return DbType.Object;


            SQLiteDbTypeMapping value;

            if (_typeNames.TryGetValue(Name, out value))
            {
                return value.dataType;
            }
            else
            {
                int index = Name.IndexOf('(');

                if ((index > 0) &&
                    _typeNames.TryGetValue(Name.Substring(0, index).TrimEnd(), out value))
                {
                    return value.dataType;
                }
            }
        }

        DbType defaultDbType = DbType.Object;

#if !NET_COMPACT_20 && TRACE_WARNING
        Trace.WriteLine(String.Format(
            "WARNING: Type mapping failed, returning default type {0} for name \"{1}\".",
            defaultDbType, Name));
#endif

        return defaultDbType;
    }
    #endregion

    private static object _syncRoot = new object();
    private static SQLiteDbTypeMap _typeNames = null;
  }

  /// <summary>
  /// SQLite has very limited types, and is inherently text-based.  The first 5 types below represent the sum of all types SQLite
  /// understands.  The DateTime extension to the spec is for internal use only.
  /// </summary>
  public enum TypeAffinity
................................................................................
      /// Use the default command execution type.  Using this value is the same
      /// as using the <see cref="SQLiteExecuteType.NonQuery" /> value.
      /// </summary>
      Default = NonQuery /* TODO: Good default? */
  }

  /// <summary>
  /// Class used internally to determine the datatype of a column in a resultset
  /// </summary>
  internal sealed class SQLiteType
  {
    /// <summary>
    /// The DbType of the column, or DbType.Object if it cannot be determined
    /// </summary>
    internal DbType Type;
    /// <summary>
    /// The affinity of a column, used for expressions or when Type is DbType.Object
    /// </summary>
    internal TypeAffinity Affinity;
  }


  /////////////////////////////////////////////////////////////////////////////

  internal sealed class SQLiteDbTypeMap
      : Dictionary<string, SQLiteDbTypeMapping>
  {
      private Dictionary<DbType, SQLiteDbTypeMapping> reverse;

      /////////////////////////////////////////////////////////////////////////

      private SQLiteDbTypeMap()
          : base(new TypeNameStringComparer())
      {
          reverse = new Dictionary<DbType, SQLiteDbTypeMapping>();
      }

      /////////////////////////////////////////////////////////////////////////

      public SQLiteDbTypeMap(
          IEnumerable<SQLiteDbTypeMapping> collection
          )
          : this()
      {
          Add(collection);
      }

      /////////////////////////////////////////////////////////////////////////

      public void Add(
          IEnumerable<SQLiteDbTypeMapping> collection
          )
      {
          if (collection == null)
              throw new ArgumentNullException("collection");

          foreach (SQLiteDbTypeMapping item in collection)
              Add(item);
      }

      /////////////////////////////////////////////////////////////////////////

      public new void Add(
          string key, /* IGNORED */
          SQLiteDbTypeMapping value
          )
      {
          Add(value);
      }

      /////////////////////////////////////////////////////////////////////////

      public void Add(SQLiteDbTypeMapping item)
      {
          if (item == null)
              throw new ArgumentNullException("item");

          if (item.typeName == null)
              throw new ArgumentException("item type name cannot be null");

          base.Add(item.typeName, item);

          if (item.primary)
              reverse.Add(item.dataType, item);
      }

      /////////////////////////////////////////////////////////////////////////

      public bool TryGetValue(DbType key, out SQLiteDbTypeMapping value)
      {
          if (reverse == null)
          {
              value = null;
              return false;
          }

          return reverse.TryGetValue(key, out value);
      }
  }

  /////////////////////////////////////////////////////////////////////////////

  internal sealed class SQLiteDbTypeMapping
  {
    internal SQLiteDbTypeMapping(
        string newTypeName,
        DbType newDataType,
        bool newPrimary
        )
    {
      typeName = newTypeName;
      dataType = newDataType;
      primary = newPrimary;
    }

    internal string typeName;
    internal DbType dataType;
    internal bool primary;
  }

  internal sealed class TypeNameStringComparer : IEqualityComparer<string>
  {
    #region IEqualityComparer<string> Members
    public bool Equals(
      string left,
      string right
      )
    {