System.Data.SQLite
Check-in [a354a124a5]
Not logged in

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

Overview
Comment:Enhance test case for ticket [e235a52c82] to demonstrate the effects that different default isolation levels have on created transactions.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tkt-e235a52c82
Files: files | file ages | folders
SHA1: a354a124a59fba77d6eb4442b71a1a9dce38af5c
User & Date: mistachkin 2013-01-29 05:33:02
Context
2013-01-29
06:35
Fix-up spacing on section separators. Closed-Leaf check-in: 4ebae8bc82 user: mistachkin tags: tkt-e235a52c82
05:33
Enhance test case for ticket [e235a52c82] to demonstrate the effects that different default isolation levels have on created transactions. check-in: a354a124a5 user: mistachkin tags: tkt-e235a52c82
03:35
Add test pursuant to ticket [e235a52c82]. check-in: 4647779e7a user: mistachkin tags: tkt-e235a52c82
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to Tests/tkt-e235a52c82.eagle.

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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173

174


175
176








177
178
179
180
181
###############################################################################

package require System.Data.SQLite.Test
runSQLiteTestPrologue

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

runTest {test tkt-e235a52c82-1.1 {transient command disposal} -setup {


  set fileName tkt-e235a52c82-1.1.db

} -body {
  setupDb $fileName

  sql execute $db {
    CREATE TABLE t1(x);
    INSERT INTO t1 (x) VALUES('1');
    INSERT INTO t1 (x) VALUES('2');
  }

  cleanupDb $fileName db true false false

  set id [object invoke Interpreter.GetActive NextId]
  set dataSource [file join [getDatabaseDirectory] $fileName]

  set sql { \
    SELECT x FROM t1 ORDER BY x; \
  }

  unset -nocomplain results errors

  set code [compileCSharpWith [subst {
    using System;
    using System.Data;
    using System.Data.SQLite;

    namespace _Dynamic${id}
    {
      public sealed class Query${id}
      {
        private IDbConnection connection;

        private bool opened;

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

        private void EnsureConnection()
        {
          if (connection == null)

            connection = new SQLiteConnection("Data Source=${dataSource};");



          if (connection.State == ConnectionState.Closed)
          {
            connection.Open();
            opened = true;

            using (IDbCommand command = CreateCommand("BEGIN IMMEDIATE;"))
            {
              command.ExecuteNonQuery();


            }
          }




























................................................................................
        }

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

        private void ReleaseConnection()
        {
          if (connection == null)
            throw new Exception("cannot release connection");

          if (opened)
          {
            connection.Close();
            opened = false;
          }
        }

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

        private IDbCommand CreateCommand(
          string commandText
          )
        {
          if (connection == null)
            throw new Exception("cannot create command");

          IDbCommand command = connection.CreateCommand();
          command.CommandText = commandText;

          return command;
        }

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

        public object ExecuteReader(
          string commandText
          )
        {
          object result;
          EnsureConnection();
          IDataReader reader = null;

          try
          {
            reader = CreateCommand(commandText).ExecuteReader();
          }
          catch
          {
            ReleaseConnection();
            throw;
          }

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

          try
          {
            result = reader.GetValue(0);
          }
          catch
          {
            reader.Dispose();
            ReleaseConnection();
            throw;
          }

          return result;
        }
      }

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

      public static class Test${id}
      {
        public static string\[\] GetData()
        {
          return new string\[\] {
            new Query${id}().ExecuteReader("${sql}").ToString(),
            new Query${id}().ExecuteReader("${sql}").ToString()
          };
        }

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

        public static void Main()
        {
          // do nothing.
        }
      }
    }
  }] true true true results errors System.Data.SQLite.dll]

  list $code $results \
      [expr {[info exists errors] ? $errors : ""}] \
      [expr {$code eq "Ok" ? [catch {
        object invoke _Dynamic${id}.Test${id} GetData
      } result] : [set result ""]}] $result
} -cleanup {
  cleanupDb $fileName

  unset -nocomplain result results errors code sql dataSource id db fileName
} -constraints \

{eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} \


-match regexp -result {^Ok System#CodeDom#Compiler#CompilerResults#\d+ \{\} 0\
\{1 1\}$}}









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

runSQLiteTestEpilogue
runTestEpilogue







|
>
>
|
>
|
|

|
|
|
|
|

|

|
|

|
|
|

|

|
|
|
|

|
|
|
|
|
>
|

|

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

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|

|

|
|
|
|
|
|
|
|
|
|

|
|
|

|

|
|
|
|
|
|
|
|
|

|

|
|
|
|
|
|
|

|
|
|
|
|
|
|

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





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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
...
109

110
111





























112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177

178
179
180
181
182

183
184
185
186
187
188
189
190
191
192
193
194
195
###############################################################################

package require System.Data.SQLite.Test
runSQLiteTestPrologue

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

for {set i 1} {$i < 3} {incr i} {
  runTest {test [appendArgs tkt-e235a52c82-1. $i] {isolation level} \
      -setup {
    set fileName [appendArgs tkt-e235a52c82-1. $i .db]
    set isolationLevel [expr {$i == 1 ? "ReadCommitted" : "Serializable"}]
  } -body {
    setupDb $fileName

    sql execute $db {
      CREATE TABLE t1(x);
      INSERT INTO t1 (x) VALUES('1');
      INSERT INTO t1 (x) VALUES('2');
    }

    cleanupDb $fileName db true false false

    set id [object invoke Interpreter.GetActive NextId]
    set dataSource [file join [getDatabaseDirectory] $fileName]

    set sql { \
      SELECT x FROM t1 ORDER BY x; \
    }

    unset -nocomplain results errors

    set code [compileCSharpWith [subst {
      using System;
      using System.Data;
      using System.Data.SQLite;

      namespace _Dynamic${id}
      {
        public sealed class Query${id}
        {
          private IDbConnection connection;
          private IDbTransaction transaction;
          private bool opened;

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

          private void EnsureConnection()
          {
            if (connection == null)
            {
              connection = new SQLiteConnection("Data Source=${dataSource};" +
                  "Default IsolationLevel=${isolationLevel};");
            }

            if (connection.State == ConnectionState.Closed)
            {
              connection.Open();
              opened = true;
            }



            if (transaction == null)
              transaction = connection.BeginTransaction();
          }

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

          private void ReleaseConnection()
          {
            if (connection == null)
              throw new Exception("cannot release connection");

            if (opened)
            {
              connection.Close();
              opened = false;
            }
          }

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

          private IDbCommand CreateCommand(
            string commandText
            )
          {
            if (connection == null)
              throw new Exception("cannot create command");

            IDbCommand command = connection.CreateCommand();
            command.CommandText = commandText;

            return command;
          }
................................................................................


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






























          public object ExecuteReader(
            string commandText
            )
          {
            object result;
            EnsureConnection();
            IDataReader reader = null;

            try
            {
              reader = CreateCommand(commandText).ExecuteReader();
            }
            catch
            {
              ReleaseConnection();
              throw;
            }

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

            try
            {
              result = reader.GetValue(0);
            }
            catch
            {
              reader.Dispose();
              ReleaseConnection();
              throw;
            }

            return result;
          }
        }

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

        public static class Test${id}
        {
          public static string\[\] GetData()
          {
            return new string\[\] {
              new Query${id}().ExecuteReader("${sql}").ToString(),
              new Query${id}().ExecuteReader("${sql}").ToString()
            };
          }

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

          public static void Main()
          {
            // do nothing.
          }
        }
      }
    }] true true true results errors System.Data.SQLite.dll]

    list $code $results \
        [expr {[info exists errors] ? $errors : ""}] \
        [expr {$code eq "Ok" ? [catch {
          object invoke _Dynamic${id}.Test${id} GetData
        } result] : [set result ""]}] $result
  } -cleanup {
    cleanupDb $fileName

    unset -nocomplain result results errors code sql dataSource id db \

        isolationLevel fileName
  } -constraints {eagle monoBug28 command.sql compile.DATA SQLite\
System.Data.SQLite} -match regexp -result [expr {$i == 1 ? {^Ok\
System#CodeDom#Compiler#CompilerResults#\d+ \{\} 0 \{1 1\}$} : {^Ok\
System#CodeDom#Compiler#CompilerResults#\d+ \{\} 1\

\{System\.Reflection\.TargetInvocationException: Exception has been thrown by\
the target of an invocation\. ---> System\.Data\.SQLite\.SQLiteException:\
database is locked.*$}}]}
}

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

unset -nocomplain i

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

runSQLiteTestEpilogue
runTestEpilogue