System.Data.SQLite
Check-in [13a3981ec0]
Not logged in

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

Overview
Comment:Lock access to the _typeNames dictionary. Fix for ticket [84718e79fa].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 13a3981ec0e600bcccde60de1dd25d1d29891e92
User & Date: mistachkin 2011-10-15 10:14:48
References
2011-10-28
13:31 Closed ticket [d4cc1cedcc]: SQLiteConvert.TypeNameToDbType is not threadsafe plus 2 other changes artifact: 966d3723c4 user: mistachkin
2011-10-15
10:15 Closed ticket [84718e79fa]: Exception loading DataTable from SQLiteDataReader (threaded) plus 4 other changes artifact: fe44b54cb4 user: mistachkin
Context
2011-10-15
12:38
Improve test thread cleanup in test for ticket [84718e79fa]. check-in: 9e77b34813 user: mistachkin tags: trunk
10:14
Lock access to the _typeNames dictionary. Fix for ticket [84718e79fa]. check-in: 13a3981ec0 user: mistachkin tags: trunk
2011-10-13
06:19
Both BOOLEAN and BOOL should end up being presented as the System.Boolean CLR type. Fix for ticket [544dba0a2f]. check-in: 453dc69391 user: mistachkin tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

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

798
799
800
801
802
803
804


805
806
807

808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858

859
860
861
862
863
864
865
...
875
876
877
878
879
880
881

882
883
884
885
886
887
888
    /// </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)
    {
      if (String.IsNullOrEmpty(Name)) return DbType.Object;



      if (_typeNames == null)
      {
        _typeNames = new Dictionary<string, SQLiteTypeNames>(new TypeNameStringComparer());


        foreach (SQLiteTypeNames typeName in new SQLiteTypeNames[] {
            new SQLiteTypeNames("COUNTER", DbType.Int64),
            new SQLiteTypeNames("AUTOINCREMENT", DbType.Int64),
            new SQLiteTypeNames("IDENTITY", DbType.Int64),
            new SQLiteTypeNames("LONGTEXT", DbType.String),
            new SQLiteTypeNames("LONGCHAR", DbType.String),
            new SQLiteTypeNames("LONGVARCHAR", DbType.String),
            new SQLiteTypeNames("LONG", DbType.Int64),
            new SQLiteTypeNames("TINYINT", DbType.Byte),
            new SQLiteTypeNames("INTEGER", DbType.Int64),
            new SQLiteTypeNames("INT", DbType.Int32),
            new SQLiteTypeNames("VARCHAR", DbType.String),
            new SQLiteTypeNames("NVARCHAR", DbType.String),
            new SQLiteTypeNames("CHAR", DbType.String),
            new SQLiteTypeNames("NCHAR", DbType.String),
            new SQLiteTypeNames("TEXT", DbType.String),
            new SQLiteTypeNames("NTEXT", DbType.String),
            new SQLiteTypeNames("STRING", DbType.String),
            new SQLiteTypeNames("DOUBLE", DbType.Double),
            new SQLiteTypeNames("FLOAT", DbType.Double),
            new SQLiteTypeNames("REAL", DbType.Double),
            new SQLiteTypeNames("BIT", DbType.Boolean),
            new SQLiteTypeNames("YESNO", DbType.Boolean),
            new SQLiteTypeNames("LOGICAL", DbType.Boolean),
            new SQLiteTypeNames("BOOL", DbType.Boolean),
            new SQLiteTypeNames("BOOLEAN", DbType.Boolean),
            new SQLiteTypeNames("NUMERIC", DbType.Decimal),
            new SQLiteTypeNames("DECIMAL", DbType.Decimal),
            new SQLiteTypeNames("MONEY", DbType.Decimal),
            new SQLiteTypeNames("CURRENCY", DbType.Decimal),
            new SQLiteTypeNames("TIME", DbType.DateTime),
            new SQLiteTypeNames("DATE", DbType.DateTime),
            new SQLiteTypeNames("DATETIME", DbType.DateTime),
            new SQLiteTypeNames("SMALLDATE", DbType.DateTime),
            new SQLiteTypeNames("BLOB", DbType.Binary),
            new SQLiteTypeNames("BINARY", DbType.Binary),
            new SQLiteTypeNames("VARBINARY", DbType.Binary),
            new SQLiteTypeNames("IMAGE", DbType.Binary),
            new SQLiteTypeNames("GENERAL", DbType.Binary),
            new SQLiteTypeNames("OLEOBJECT", DbType.Binary),
            new SQLiteTypeNames("GUID", DbType.Guid),
            new SQLiteTypeNames("UNIQUEIDENTIFIER", DbType.Guid),
            new SQLiteTypeNames("MEMO", DbType.String),
            new SQLiteTypeNames("NOTE", DbType.String),
            new SQLiteTypeNames("SMALLINT", DbType.Int16),
            new SQLiteTypeNames("BIGINT", DbType.Int64)
          })
          {
            _typeNames.Add(typeName.typeName, typeName);
          }

      }

      SQLiteTypeNames value;

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

      return DbType.Object;
    }
    #endregion


    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>







>
>
|
|
|
>

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



>







 







>







798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
...
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
    /// </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)
    {
      if (String.IsNullOrEmpty(Name)) return DbType.Object;

      lock (_syncRoot)
      {
        if (_typeNames == null)
        {
          _typeNames = new Dictionary<string, SQLiteTypeNames>(
              new TypeNameStringComparer());

          foreach (SQLiteTypeNames typeName in new SQLiteTypeNames[] {
              new SQLiteTypeNames("COUNTER", DbType.Int64),
              new SQLiteTypeNames("AUTOINCREMENT", DbType.Int64),
              new SQLiteTypeNames("IDENTITY", DbType.Int64),
              new SQLiteTypeNames("LONGTEXT", DbType.String),
              new SQLiteTypeNames("LONGCHAR", DbType.String),
              new SQLiteTypeNames("LONGVARCHAR", DbType.String),
              new SQLiteTypeNames("LONG", DbType.Int64),
              new SQLiteTypeNames("TINYINT", DbType.Byte),
              new SQLiteTypeNames("INTEGER", DbType.Int64),
              new SQLiteTypeNames("INT", DbType.Int32),
              new SQLiteTypeNames("VARCHAR", DbType.String),
              new SQLiteTypeNames("NVARCHAR", DbType.String),
              new SQLiteTypeNames("CHAR", DbType.String),
              new SQLiteTypeNames("NCHAR", DbType.String),
              new SQLiteTypeNames("TEXT", DbType.String),
              new SQLiteTypeNames("NTEXT", DbType.String),
              new SQLiteTypeNames("STRING", DbType.String),
              new SQLiteTypeNames("DOUBLE", DbType.Double),
              new SQLiteTypeNames("FLOAT", DbType.Double),
              new SQLiteTypeNames("REAL", DbType.Double),
              new SQLiteTypeNames("BIT", DbType.Boolean),
              new SQLiteTypeNames("YESNO", DbType.Boolean),
              new SQLiteTypeNames("LOGICAL", DbType.Boolean),
              new SQLiteTypeNames("BOOL", DbType.Boolean),
              new SQLiteTypeNames("BOOLEAN", DbType.Boolean),
              new SQLiteTypeNames("NUMERIC", DbType.Decimal),
              new SQLiteTypeNames("DECIMAL", DbType.Decimal),
              new SQLiteTypeNames("MONEY", DbType.Decimal),
              new SQLiteTypeNames("CURRENCY", DbType.Decimal),
              new SQLiteTypeNames("TIME", DbType.DateTime),
              new SQLiteTypeNames("DATE", DbType.DateTime),
              new SQLiteTypeNames("DATETIME", DbType.DateTime),
              new SQLiteTypeNames("SMALLDATE", DbType.DateTime),
              new SQLiteTypeNames("BLOB", DbType.Binary),
              new SQLiteTypeNames("BINARY", DbType.Binary),
              new SQLiteTypeNames("VARBINARY", DbType.Binary),
              new SQLiteTypeNames("IMAGE", DbType.Binary),
              new SQLiteTypeNames("GENERAL", DbType.Binary),
              new SQLiteTypeNames("OLEOBJECT", DbType.Binary),
              new SQLiteTypeNames("GUID", DbType.Guid),
              new SQLiteTypeNames("UNIQUEIDENTIFIER", DbType.Guid),
              new SQLiteTypeNames("MEMO", DbType.String),
              new SQLiteTypeNames("NOTE", DbType.String),
              new SQLiteTypeNames("SMALLINT", DbType.Int16),
              new SQLiteTypeNames("BIGINT", DbType.Int64)
            })
          {
            _typeNames.Add(typeName.typeName, typeName);
          }
        }
      }

      SQLiteTypeNames value;

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

      return DbType.Object;
    }
    #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>

Added Tests/tkt-84718e79fa.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
###############################################################################
#
# tkt-84718e79fa.eagle --
#
# Written by Joe Mistachkin.
# Released to the public domain, use at your own risk!
#
###############################################################################

package require Eagle
package require EagleLibrary
package require EagleTest

runTestPrologue

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

package require System.Data.SQLite.Test
runSQLiteTestPrologue

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

set c 10

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

runTest {test tkt-84718e79fa-1.1 {SQLiteConvert thread safety} -setup {
  proc threadStart { args } {
    lappend ::results [sql execute -execute reader -format list $::db \
        "SELECT x FROM t1;"]
  }

  object import System.Threading

  setupDb [set fileName tkt-84718e79fa-1.1.db]
} -body {
  sql execute $db "CREATE TABLE t1(x INTEGER PRIMARY KEY ASC);"
  sql execute $db "INSERT INTO t1 (x) VALUES(1);"

  for {set i 0} {$i < $c} {incr i} {
    set t($i) [object create -alias Thread threadStart]
  }

  set ::results [list]

  for {set i 0} {$i < $c} {incr i} {
    $t($i) Start
  }

  after 4000; # wait for other threads to do something...

  for {set i 0} {$i < $c} {incr i} {
    $t($i) Join
  }

  set ::results
} -cleanup {
  cleanupDb $fileName

  object unimport -importpattern System.Threading

  catch {object removecallback threadStart}

  unset -nocomplain results t i c db fileName

  rename threadStart ""
} -constraints \
{eagle shell monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} \
-result [lrepeat $c 1]}

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

unset -nocomplain c

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

runSQLiteTestEpilogue
runTestEpilogue