System.Data.SQLite
Check-in [4aa2360885]
Not logged in

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

Overview
Comment:When translating a DbType to a type name, be sure to prioritize the type names supported by the EDMX components. Fix for [47f4bac575].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 4aa236088586925e892f367ac8cc5cbc375afd13
User & Date: mistachkin 2013-05-28 09:34:15
References
2013-05-28
09:37 Pending ticket [47f4bac575]: Entity Data Model generator problem plus 7 other changes artifact: 88ef29888c user: mistachkin
Context
2013-05-28
09:55
Bump all versions to 1.0.87.0. check-in: 01ae5e862f user: mistachkin tags: trunk
09:34
When translating a DbType to a type name, be sure to prioritize the type names supported by the EDMX components. Fix for [47f4bac575]. check-in: 4aa2360885 user: mistachkin tags: trunk
08:19
Fix incorrect comment. check-in: 3a98512a05 user: mistachkin tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

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

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
...
971
972
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
....
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
....
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402

1403
1404
1405
1406

1407
1408
1409
1410
1411
1412
1413
      DBNull.Value  // Xml (25)
    };

    internal static string DbTypeToTypeName(DbType typ)
    {
      for (int n = 0; n < _dbtypeNames.Length; n++)
      {
        if (_dbtypeNames[n].dataType == typ)
          return _dbtypeNames[n].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 SQLiteTypeNames[] _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 SQLiteTypeNames[] GetSQLiteTypeNames()
    {
        return new SQLiteTypeNames[] {
            new SQLiteTypeNames("BIGINT", DbType.Int64),
            new SQLiteTypeNames("BIGUINT", DbType.UInt64),
            new SQLiteTypeNames("BINARY", DbType.Binary),
            new SQLiteTypeNames("BIT", DbType.Boolean),
            new SQLiteTypeNames("BLOB", DbType.Binary),
            new SQLiteTypeNames("BOOL", DbType.Boolean),
            new SQLiteTypeNames("BOOLEAN", DbType.Boolean),
            new SQLiteTypeNames("CHAR", DbType.AnsiStringFixedLength),
            new SQLiteTypeNames("COUNTER", DbType.Int64),
            new SQLiteTypeNames("CURRENCY", DbType.Decimal),
            new SQLiteTypeNames("DATE", DbType.DateTime),
            new SQLiteTypeNames("DATETIME", DbType.DateTime),
            new SQLiteTypeNames("DECIMAL", DbType.Decimal),
            new SQLiteTypeNames("DOUBLE", DbType.Double),
            new SQLiteTypeNames("FLOAT", DbType.Double),
            new SQLiteTypeNames("GENERAL", DbType.Binary),
            new SQLiteTypeNames("GUID", DbType.Guid),
            new SQLiteTypeNames("IDENTITY", DbType.Int64),
            new SQLiteTypeNames("IMAGE", DbType.Binary),
            new SQLiteTypeNames("INT", DbType.Int32),
            new SQLiteTypeNames("INT8", DbType.SByte),
            new SQLiteTypeNames("INT16", DbType.Int16),
            new SQLiteTypeNames("INT32", DbType.Int32),
            new SQLiteTypeNames("INT64", DbType.Int64),
            new SQLiteTypeNames("INTEGER", DbType.Int64),
            new SQLiteTypeNames("INTEGER8", DbType.SByte),
            new SQLiteTypeNames("INTEGER16", DbType.Int16),
            new SQLiteTypeNames("INTEGER32", DbType.Int32),
            new SQLiteTypeNames("INTEGER64", DbType.Int64),
            new SQLiteTypeNames("LOGICAL", DbType.Boolean),
            new SQLiteTypeNames("LONG", DbType.Int64),
            new SQLiteTypeNames("LONGCHAR", DbType.String),
            new SQLiteTypeNames("LONGTEXT", DbType.String),
            new SQLiteTypeNames("LONGVARCHAR", DbType.String),
            new SQLiteTypeNames("MEMO", DbType.String),
            new SQLiteTypeNames("MONEY", DbType.Decimal),
            new SQLiteTypeNames("NCHAR", DbType.StringFixedLength),
            new SQLiteTypeNames("NOTE", DbType.String),
            new SQLiteTypeNames("NTEXT", DbType.String),
            new SQLiteTypeNames("NUMERIC", DbType.Decimal),
            new SQLiteTypeNames("NVARCHAR", DbType.String),
            new SQLiteTypeNames("OLEOBJECT", DbType.Binary),
            new SQLiteTypeNames("REAL", DbType.Double),

            new SQLiteTypeNames("SMALLDATE", DbType.DateTime),
            new SQLiteTypeNames("SMALLINT", DbType.Int16),
            new SQLiteTypeNames("SMALLUINT", DbType.UInt16),
            new SQLiteTypeNames("STRING", DbType.String),
            new SQLiteTypeNames("TEXT", DbType.String),
            new SQLiteTypeNames("TIME", DbType.DateTime),
            new SQLiteTypeNames("TIMESTAMP", DbType.DateTime),
            new SQLiteTypeNames("TINYINT", DbType.Byte),
            new SQLiteTypeNames("TINYSINT", DbType.SByte),
            new SQLiteTypeNames("UINT", DbType.UInt32),
            new SQLiteTypeNames("UINT8", DbType.Byte),
            new SQLiteTypeNames("UINT16", DbType.UInt16),
            new SQLiteTypeNames("UINT32", DbType.UInt32),
            new SQLiteTypeNames("UINT64", DbType.UInt64),
            new SQLiteTypeNames("ULONG", DbType.UInt64),
            new SQLiteTypeNames("UNIQUEIDENTIFIER", DbType.Guid),
            new SQLiteTypeNames("UNSIGNEDINTEGER", DbType.UInt64),
            new SQLiteTypeNames("UNSIGNEDINTEGER8", DbType.Byte),
            new SQLiteTypeNames("UNSIGNEDINTEGER16", DbType.UInt16),
            new SQLiteTypeNames("UNSIGNEDINTEGER32", DbType.UInt32),
            new SQLiteTypeNames("UNSIGNEDINTEGER64", DbType.UInt64),
            new SQLiteTypeNames("VARBINARY", DbType.Binary),
            new SQLiteTypeNames("VARCHAR", DbType.AnsiString),
            new SQLiteTypeNames("YESNO", DbType.Boolean)
        };
    }

    /// <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, SQLiteTypeNames>(
              new TypeNameStringComparer());

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

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

      SQLiteTypeNames value;

      if (_typeNames.TryGetValue(Name, out value))
      {
        return value.dataType;
      }
      else
      {
................................................................................
#endif

      return defaultDbType;
    }
    #endregion

    private static object _syncRoot = new object();
    private static Dictionary<string, SQLiteTypeNames> _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
................................................................................
    internal DbType Type;
    /// <summary>
    /// The affinity of a column, used for expressions or when Type is DbType.Object
    /// </summary>
    internal TypeAffinity Affinity;
  }

  internal struct SQLiteTypeNames
  {
    internal SQLiteTypeNames(string newtypeName, DbType newdataType)
    {
      typeName = newtypeName;
      dataType = newdataType;

    }

    internal string typeName;
    internal DbType dataType;

  }

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







<
|
>
>
>













|







 







|

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|







 







|


|






|







 







|







 







|

|

|
|
>




>







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
...
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
....
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
....
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
      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
      {
................................................................................
#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
................................................................................
    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,

Added Tests/tkt-47f4bac575.eagle.





























































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
###############################################################################
#
# tkt-47f4bac575.eagle --
#
# Written by Joe Mistachkin.
# Released to the public domain, use at your own risk!
#
###############################################################################

package require Eagle
package require Eagle.Library
package require Eagle.Test

runTestPrologue

###############################################################################

package require System.Data.SQLite.Test
runSQLiteTestPrologue

###############################################################################

runTest {test tkt-47f4bac575-1.1 {SQLiteConvert DbTypeToTypeName} -body {
  foreach dbType [list \
      AnsiString Binary Byte Boolean Currency Date DateTime Decimal \
      Double Guid Int16 Int32 Int64 Object SByte Single String Time \
      UInt16 UInt32 UInt64 VarNumeric AnsiStringFixedLength \
      StringFixedLength Xml DateTime2 DateTimeOffset] {
    lappend result [list $dbType [object invoke -flags +NonPublic \
        System.Data.SQLite.SQLiteConvert DbTypeToTypeName $dbType]]
  }
  set result
} -cleanup {
  unset -nocomplain result dbType
} -constraints {eagle System.Data.SQLite} -result {{AnsiString VARCHAR} {Binary\
BLOB} {Byte TINYINT} {Boolean BIT} {Currency {}} {Date {}} {DateTime DATETIME}\
{Decimal DECIMAL} {Double REAL} {Guid UNIQUEIDENTIFIER} {Int16 SMALLINT} {Int32\
INT} {Int64 INTEGER} {Object {}} {SByte TINYSINT} {Single SINGLE} {String\
NVARCHAR} {Time {}} {UInt16 SMALLUINT} {UInt32 UINT} {UInt64 UNSIGNEDINTEGER}\
{VarNumeric {}} {AnsiStringFixedLength CHAR} {StringFixedLength NCHAR} {Xml {}}\
{DateTime2 {}} {DateTimeOffset {}}}}

###############################################################################

runSQLiteTestEpilogue
runTestEpilogue