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

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

Overview
Comment:Add 'AllowNestedTransactions' connection flag to enable nested transactions.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tkt-1f7bfff467
Files: files | file ages | folders
SHA1:ffd3c1b1d8170d1fe01d4c59e39a23ad4020618c
User & Date: mistachkin 2016-11-04 02:00:58
Context
2016-11-04
02:10
Remove duplicate method. check-in: 32b2f62864 user: mistachkin tags: tkt-1f7bfff467
02:00
Add 'AllowNestedTransactions' connection flag to enable nested transactions. check-in: ffd3c1b1d8 user: mistachkin tags: tkt-1f7bfff467
00:26
Disallow nested transactions by default. check-in: 6331a7209e user: mistachkin tags: trunk
00:21
Merge updates from trunk. check-in: d2fb66aefb user: mistachkin tags: tkt-1f7bfff467
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to Doc/Extra/Provider/version.html.

44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
    <div id="mainBody">
    <h1 class="heading">Version History</h1>
    <p><b>1.0.104.0 - December XX, 2016</b></p>
    <ul>
      <li>Updated to <a href="https://www.sqlite.org/releaselog/3_15_0.html">SQLite 3.15.0</a>.</li>
      <li>Add the &quot;%PreLoadSQLite_AssemblyDirectory%&quot;, &quot;%PreLoadSQLite_TargetFramework%&quot;, and &quot;%PreLoadSQLite_XmlConfigDirectory%&quot; <a href="https://system.data.sqlite.org/index.html/artifact?ci=trunk&filename=Doc/Extra/Provider/environment.html">replacement tokens</a> for use in configuration setting values. Pursuant to <a href="https://system.data.sqlite.org/index.html/info/d4728aecb7">[d4728aecb7]</a>.</li>
      <li>Prevent the GetByte, GetChar, and GetInt16 methods of the SQLiteDataReader class from throwing exceptions for large integer values. Pursuant to <a href="https://system.data.sqlite.org/index.html/info/5535448538">[5535448538]</a>.&nbsp;<b>** Potentially Incompatible Change **</b></li>
      <li>Use <a href="https://www.sqlite.org/lang_savepoint.html">SAVEPOINTs</a> to properly implement nested transactions. Fix for <a href="https://system.data.sqlite.org/index.html/info/1f7bfff467">[1f7bfff467]</a>.&nbsp;<b>** Potentially Incompatible Change **</b></li>
    </ul>
    <p><b>1.0.103.0 - September 15, 2016</b></p>
    <ul>
      <li>Updated to <a href="https://www.sqlite.org/releaselog/3_14_2.html">SQLite 3.14.2</a>.</li>
      <li>Add preliminary support for the .NET Framework 4.6.2.</li>
      <li>Change the SQLiteReadValueCallback delegate &quot;eventArgs&quot; parameter to be of type SQLiteReadEventArgs.&nbsp;<b>** Potentially Incompatible Change **</b></li>
      <li>Make SQLiteReadValueEventArgs and SQLiteReadArrayEventArgs derive from SQLiteReadEventArgs.&nbsp;<b>** Potentially Incompatible Change **</b></li>







|







44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
    <div id="mainBody">
    <h1 class="heading">Version History</h1>
    <p><b>1.0.104.0 - December XX, 2016</b></p>
    <ul>
      <li>Updated to <a href="https://www.sqlite.org/releaselog/3_15_0.html">SQLite 3.15.0</a>.</li>
      <li>Add the &quot;%PreLoadSQLite_AssemblyDirectory%&quot;, &quot;%PreLoadSQLite_TargetFramework%&quot;, and &quot;%PreLoadSQLite_XmlConfigDirectory%&quot; <a href="https://system.data.sqlite.org/index.html/artifact?ci=trunk&filename=Doc/Extra/Provider/environment.html">replacement tokens</a> for use in configuration setting values. Pursuant to <a href="https://system.data.sqlite.org/index.html/info/d4728aecb7">[d4728aecb7]</a>.</li>
      <li>Prevent the GetByte, GetChar, and GetInt16 methods of the SQLiteDataReader class from throwing exceptions for large integer values. Pursuant to <a href="https://system.data.sqlite.org/index.html/info/5535448538">[5535448538]</a>.&nbsp;<b>** Potentially Incompatible Change **</b></li>
      <li>Use <a href="https://www.sqlite.org/lang_savepoint.html">SAVEPOINTs</a> to properly implement nested transactions when the new AllowNestedTransactions connection flag is used. Fix for <a href="https://system.data.sqlite.org/index.html/info/1f7bfff467">[1f7bfff467]</a>.</li>
    </ul>
    <p><b>1.0.103.0 - September 15, 2016</b></p>
    <ul>
      <li>Updated to <a href="https://www.sqlite.org/releaselog/3_14_2.html">SQLite 3.14.2</a>.</li>
      <li>Add preliminary support for the .NET Framework 4.6.2.</li>
      <li>Change the SQLiteReadValueCallback delegate &quot;eventArgs&quot; parameter to be of type SQLiteReadEventArgs.&nbsp;<b>** Potentially Incompatible Change **</b></li>
      <li>Make SQLiteReadValueEventArgs and SQLiteReadArrayEventArgs derive from SQLiteReadEventArgs.&nbsp;<b>** Potentially Incompatible Change **</b></li>

Changes to Setup/data/verify.lst.

586
587
588
589
590
591
592


593
594
595
596
597
598
599
  System.Data.SQLite/SQLiteModuleEnumerable.cs
  System.Data.SQLite/SQLiteModuleNoop.cs
  System.Data.SQLite/SQLiteParameter.cs
  System.Data.SQLite/SQLiteParameterCollection.cs
  System.Data.SQLite/SQLitePatchLevel.cs
  System.Data.SQLite/SQLiteStatement.cs
  System.Data.SQLite/SQLiteTransaction.cs


  System.Data.SQLite/System.Data.SQLite.2005.csproj
  System.Data.SQLite/System.Data.SQLite.2008.csproj
  System.Data.SQLite/System.Data.SQLite.2010.csproj
  System.Data.SQLite/System.Data.SQLite.2012.csproj
  System.Data.SQLite/System.Data.SQLite.2013.csproj
  System.Data.SQLite/System.Data.SQLite.2015.csproj
  System.Data.SQLite/System.Data.SQLite.Compact.2005.csproj







>
>







586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
  System.Data.SQLite/SQLiteModuleEnumerable.cs
  System.Data.SQLite/SQLiteModuleNoop.cs
  System.Data.SQLite/SQLiteParameter.cs
  System.Data.SQLite/SQLiteParameterCollection.cs
  System.Data.SQLite/SQLitePatchLevel.cs
  System.Data.SQLite/SQLiteStatement.cs
  System.Data.SQLite/SQLiteTransaction.cs
  System.Data.SQLite/SQLiteTransaction2.cs
  System.Data.SQLite/SQLiteTransactionBase.cs
  System.Data.SQLite/System.Data.SQLite.2005.csproj
  System.Data.SQLite/System.Data.SQLite.2008.csproj
  System.Data.SQLite/System.Data.SQLite.2010.csproj
  System.Data.SQLite/System.Data.SQLite.2012.csproj
  System.Data.SQLite/System.Data.SQLite.2013.csproj
  System.Data.SQLite/System.Data.SQLite.2015.csproj
  System.Data.SQLite/System.Data.SQLite.Compact.2005.csproj

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

1233
1234
1235
1236
1237
1238
1239








1240
1241
1242
1243
1244
1245
1246
      UseParameterDbTypeForTypeName = 0x2000000000,

      /// <summary>
      /// When returning column values, skip verifying their affinity.
      /// </summary>
      NoVerifyTypeAffinity = 0x4000000000,









      /// <summary>
      /// When binding parameter values or returning column values, always
      /// treat them as though they were plain text (i.e. no numeric,
      /// date/time, or other conversions should be attempted).
      /// </summary>
      BindAndGetAllAsText = BindAllAsText | GetAllAsText,








>
>
>
>
>
>
>
>







1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
      UseParameterDbTypeForTypeName = 0x2000000000,

      /// <summary>
      /// When returning column values, skip verifying their affinity.
      /// </summary>
      NoVerifyTypeAffinity = 0x4000000000,

      /// <summary>
      /// Allow transactions to be nested.  The outermost transaction still
      /// controls whether or not any changes are ultimately committed or
      /// rolled back.  All non-outermost transactions are implemented using
      /// the SAVEPOINT construct.
      /// </summary>
      AllowNestedTransactions = 0x8000000000,

      /// <summary>
      /// When binding parameter values or returning column values, always
      /// treat them as though they were plain text (i.e. no numeric,
      /// date/time, or other conversions should be attempted).
      /// </summary>
      BindAndGetAllAsText = BindAllAsText | GetAllAsText,

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

2799
2800
2801
2802
2803
2804
2805
2806





2807






2808
2809
2810
2811
2812
2813
2814

      if (isolationLevel == IsolationLevel.Unspecified) isolationLevel = _defaultIsolation;
      isolationLevel = GetEffectiveIsolationLevel(isolationLevel);

      if (isolationLevel != ImmediateIsolationLevel && isolationLevel != DeferredIsolationLevel)
        throw new ArgumentException("isolationLevel");

      SQLiteTransaction transaction =





          new SQLiteTransaction(this, isolationLevel != ImmediateIsolationLevel);







      OnChanged(this, new ConnectionEventArgs(
          SQLiteConnectionEventType.NewTransaction, null, transaction,
          null, null, null, null, null));

      return transaction;
    }







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







2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825

      if (isolationLevel == IsolationLevel.Unspecified) isolationLevel = _defaultIsolation;
      isolationLevel = GetEffectiveIsolationLevel(isolationLevel);

      if (isolationLevel != ImmediateIsolationLevel && isolationLevel != DeferredIsolationLevel)
        throw new ArgumentException("isolationLevel");

      SQLiteTransaction transaction;

      if ((_flags & SQLiteConnectionFlags.AllowNestedTransactions)
            == SQLiteConnectionFlags.AllowNestedTransactions)
      {
          transaction = new SQLiteTransaction2(
              this, isolationLevel != ImmediateIsolationLevel);
      }
      else
      {
          transaction = new SQLiteTransaction(
              this, isolationLevel != ImmediateIsolationLevel);
      }

      OnChanged(this, new ConnectionEventArgs(
          SQLiteConnectionEventType.NewTransaction, null, transaction,
          null, null, null, null, null));

      return transaction;
    }

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

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
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
...
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
...
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268

269
270
271
272
273

274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300


301

302
303
304
305
306
307
308



309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335

336
337
338
339

340

341
342

343
344
345
346

347
348

349
350
351
352
353

354
355
356


357
358
359

360
361
362
363


364

365
366
367
368
369
 *
 * Released to the public domain, use at your own risk!
 ********************************************************/

namespace System.Data.SQLite
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;
    using System.Threading;

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

    /// <summary>
    /// SQLite implementation of DbTransaction.
    /// </summary>
    public sealed class SQLiteTransaction : DbTransaction
    {
        /// <summary>
        /// The connection to which this transaction is bound
        /// </summary>
        internal SQLiteConnection _cnn;

        /// <summary>
        /// Matches the version of the connection.
        /// </summary>
        private int _version;

        /// <summary>
        /// The isolation level for this transaction.
        /// </summary>
        private IsolationLevel _level;

        /// <summary>
        /// The original transaction level for the associated connection
        /// when this transaction was created (i.e. begun).
        /// </summary>
        private int _beginLevel;

        /// <summary>
        /// The SAVEPOINT name for this transaction, if any.  This will
        /// only be non-null if this transaction is a nested one.
        /// </summary>
        private string _savePointName;

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

        /// <summary>
        /// Constructs the transaction object, binding it to the supplied connection
        /// </summary>
        /// <param name="connection">The connection to open a transaction on</param>
        /// <param name="deferredLock">TRUE to defer the writelock, or FALSE to lock immediately</param>
        internal SQLiteTransaction(SQLiteConnection connection, bool deferredLock)
        {
            _cnn = connection;
            _version = _cnn._version;

            _level = (deferredLock == true) ?
                SQLiteConnection.DeferredIsolationLevel :
                SQLiteConnection.ImmediateIsolationLevel;

            int transactionLevel;

            if ((transactionLevel = _cnn._transactionLevel++) == 0)
            {
                try
                {
                    using (SQLiteCommand cmd = _cnn.CreateCommand())
                    {
                        if (!deferredLock)
                            cmd.CommandText = "BEGIN IMMEDIATE;";
                        else
                            cmd.CommandText = "BEGIN;";

                        cmd.ExecuteNonQuery();

                        _beginLevel = transactionLevel;
                    }
                }
                catch (SQLiteException)
                {
                    _cnn._transactionLevel--;
                    _cnn = null;

                    throw;
                }
            }
            else
            {
                try
                {
                    using (SQLiteCommand cmd = _cnn.CreateCommand())
                    {
                        _savePointName = GetSavePointName();

                        cmd.CommandText = String.Format(
                            "SAVEPOINT {0};", _savePointName);

                        cmd.ExecuteNonQuery();

                        _beginLevel = transactionLevel;
                    }
                }
                catch (SQLiteException)
                {
                    _cnn._transactionLevel--;
                    _cnn = null;

                    throw;
                }
            }

        }

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

        #region IDisposable "Pattern" Members
        private bool disposed;
        private void CheckDisposed() /* throw */
................................................................................
        /// </summary>
        public override void Commit()
        {
            CheckDisposed();
            SQLiteConnection.Check(_cnn);
            IsValid(true);

            if (_beginLevel == 0)
            {
                using (SQLiteCommand cmd = _cnn.CreateCommand())
                {
                    cmd.CommandText = "COMMIT;";
                    cmd.ExecuteNonQuery();
                }

                _cnn._transactionLevel = 0;
                _cnn = null;
            }
            else
            {
                using (SQLiteCommand cmd = _cnn.CreateCommand())
                {
                    if (String.IsNullOrEmpty(_savePointName))
                        throw new SQLiteException("Cannot commit, unknown SAVEPOINT");

                    cmd.CommandText = String.Format(
                        "RELEASE {0};", _savePointName);

                    cmd.ExecuteNonQuery();
                }

                _cnn._transactionLevel--;
                _cnn = null;
            }
        }

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

        /// <summary>
        /// Returns the underlying connection to which this transaction applies.
        /// </summary>
        public new SQLiteConnection Connection
        {
            get { CheckDisposed(); return _cnn; }
        }

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

        /// <summary>
        /// Forwards to the local Connection property
        /// </summary>
        protected override DbConnection DbConnection
        {
            get { return Connection; }
        }

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

        /// <summary>
        /// Gets the isolation level of the transaction.  SQLite only supports Serializable transactions.
        /// </summary>
        public override IsolationLevel IsolationLevel
        {
            get { CheckDisposed(); return _level; }
        }

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

        /// <summary>
        /// Rolls back the active transaction.
        /// </summary>
................................................................................
            IsValid(true);
            IssueRollback(true);
        }

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

        /// <summary>
        /// Issue a ROLLBACK command against the database connection,
        /// optionally re-throwing any caught exception.
        /// </summary>
        /// <param name="throwError">
        /// Non-zero to re-throw caught exceptions.
        /// </param>
        private void IssueRollback(bool throwError)
        {
            SQLiteConnection cnn = Interlocked.Exchange(ref _cnn, null);

            if (cnn != null)
            {
                if (_beginLevel == 0)

                {
                    try
                    {
                        using (SQLiteCommand cmd = cnn.CreateCommand())
                        {

                            cmd.CommandText = "ROLLBACK;";
                            cmd.ExecuteNonQuery();
                        }

                        cnn._transactionLevel = 0;
                    }
                    catch
                    {
                        if (throwError)
                            throw;
                    }
                }
                else
                {
                    try
                    {
                        using (SQLiteCommand cmd = cnn.CreateCommand())
                        {
                            if (String.IsNullOrEmpty(_savePointName))
                                throw new SQLiteException("Cannot rollback, unknown SAVEPOINT");

                            cmd.CommandText = String.Format(
                                "ROLLBACK TO {0};", _savePointName);

                            cmd.ExecuteNonQuery();
                        }



                        cnn._transactionLevel--;

                    }
                    catch
                    {
                        if (throwError)
                            throw;
                    }
                }



            }
        }

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

        /// <summary>
        /// Constructs the name of a new savepoint for this transaction.  It
        /// should only be called from the constructor of this class.
        /// </summary>
        /// <returns>
        /// The name of the new savepoint -OR- null if it cannot be constructed.
        /// </returns>
        private string GetSavePointName()
        {
            int sequence = ++_cnn._transactionSequence;

            return String.Format(
                "sqlite_dotnet_savepoint_{0}", sequence);
        }

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

        /// <summary>
        /// Checks the state of this transaction, optionally throwing an exception if a state inconsistency is found.
        /// </summary>
        /// <param name="throwError">
        /// Non-zero to throw an exception if a state inconsistency is found.

        /// </param>
        /// <returns>
        /// Non-zero if this transaction is valid; otherwise, false.
        /// </returns>

        internal bool IsValid(bool throwError)

        {
            if (_cnn == null)

            {
                if (throwError == true) throw new ArgumentNullException("No connection associated with this transaction");
                else return false;
            }


            if (_cnn._version != _version)

            {
                if (throwError == true) throw new SQLiteException("The connection was closed and re-opened, changes were already rolled back");
                else return false;
            }
            if (_cnn.State != ConnectionState.Open)

            {
                if (throwError == true) throw new SQLiteException("Connection was closed");
                else return false;


            }

            if (_cnn._transactionLevel == 0 || _cnn._sql.AutoCommit == true)

            {
                _cnn._transactionLevel = 0; // Make sure the transaction level is reset before returning
                if (throwError == true) throw new SQLiteException("No transaction is active on this connection");
                else return false;


            }


            return true;
        }
    }
}







<
<
<


|


|

|

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<






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







 







|






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







 







|
|

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

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






|
|

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<

<
>

<
<
<
>
|
>

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



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
..
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
















102
103































104
105
106
107
108
109
110
...
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
 *
 * Released to the public domain, use at your own risk!
 ********************************************************/

namespace System.Data.SQLite
{
    using System;



    using System.Threading;

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

    /// <summary>
    /// SQLite implementation of DbTransaction that does not support nested transactions.
    /// </summary>
    public class SQLiteTransaction : SQLiteTransactionBase
    {





























        /// <summary>
        /// Constructs the transaction object, binding it to the supplied connection
        /// </summary>
        /// <param name="connection">The connection to open a transaction on</param>
        /// <param name="deferredLock">TRUE to defer the writelock, or FALSE to lock immediately</param>
        internal SQLiteTransaction(SQLiteConnection connection, bool deferredLock)
















            : base(connection, deferredLock)



        {





































            // do nothing.
        }

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

        #region IDisposable "Pattern" Members
        private bool disposed;
        private void CheckDisposed() /* throw */
................................................................................
        /// </summary>
        public override void Commit()
        {
            CheckDisposed();
            SQLiteConnection.Check(_cnn);
            IsValid(true);

            if (_cnn._transactionLevel - 1 == 0)
            {
                using (SQLiteCommand cmd = _cnn.CreateCommand())
                {
                    cmd.CommandText = "COMMIT;";
                    cmd.ExecuteNonQuery();
                }
            }
















            _cnn._transactionLevel--;
            _cnn = null;































        }

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

        /// <summary>
        /// Rolls back the active transaction.
        /// </summary>
................................................................................
            IsValid(true);
            IssueRollback(true);
        }

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

        /// <summary>
        /// Attempts to start a transaction.  An exception will be thrown if the transaction cannot
        /// be started for any reason.
        /// </summary>
        /// <param name="deferredLock">TRUE to defer the writelock, or FALSE to lock immediately</param>
        protected override void Begin(
            bool deferredLock



            )

        {

            if (_cnn._transactionLevel++ == 0)
            {
                try
                {
                    using (SQLiteCommand cmd = _cnn.CreateCommand())
                    {
                        if (!deferredLock)
                            cmd.CommandText = "BEGIN IMMEDIATE;";











                        else








                            cmd.CommandText = "BEGIN;";


                        cmd.ExecuteNonQuery();
                    }
                }
                catch (SQLiteException)
                {
                    _cnn._transactionLevel--;
                    _cnn = null;




                    throw;
                }
            }
            else
            {
                throw new SQLiteException("Transaction is already active on this connection");
            }
        }

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

        /// <summary>
        /// Issue a ROLLBACK command against the database connection,
        /// optionally re-throwing any caught exception.
        /// </summary>
















        /// <param name="throwError">

        /// Non-zero to re-throw caught exceptions.
        /// </param>



        protected override void IssueRollback(
            bool throwError
            )
        {

            SQLiteConnection cnn = Interlocked.Exchange(ref _cnn, null);




            if (cnn != null)
            {

                try
                {




                    using (SQLiteCommand cmd = cnn.CreateCommand())
                    {


                        cmd.CommandText = "ROLLBACK;";
                        cmd.ExecuteNonQuery();
                    }
                }

                catch
                {



                    if (throwError)
                        throw;
                }
                cnn._transactionLevel = 0;
            }

        }
    }
}

Added System.Data.SQLite/SQLiteTransaction2.cs.









































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/********************************************************
 * ADO.NET 2.0 Data Provider for SQLite Version 3.X
 * Written by Robert Simpson (robert@blackcastlesoft.com)
 *
 * Released to the public domain, use at your own risk!
 ********************************************************/

namespace System.Data.SQLite
{
    using System;
    using System.Threading;

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

    /// <summary>
    /// SQLite implementation of DbTransaction that does support nested transactions.
    /// </summary>
    public sealed class SQLiteTransaction2 : SQLiteTransaction
    {
        /// <summary>
        /// The original transaction level for the associated connection
        /// when this transaction was created (i.e. begun).
        /// </summary>
        private int _beginLevel;

        /// <summary>
        /// The SAVEPOINT name for this transaction, if any.  This will
        /// only be non-null if this transaction is a nested one.
        /// </summary>
        private string _savePointName;

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

        /// <summary>
        /// Constructs the transaction object, binding it to the supplied connection
        /// </summary>
        /// <param name="connection">The connection to open a transaction on</param>
        /// <param name="deferredLock">TRUE to defer the writelock, or FALSE to lock immediately</param>
        internal SQLiteTransaction2(SQLiteConnection connection, bool deferredLock)
            : base(connection, deferredLock)
        {
            // do nothing.
        }

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

        #region IDisposable "Pattern" Members
        private bool disposed;
        private void CheckDisposed() /* throw */
        {
#if THROW_ON_DISPOSED
            if (disposed)
                throw new ObjectDisposedException(typeof(SQLiteTransaction2).Name);
#endif
        }

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

        /// <summary>
        /// Disposes the transaction.  If it is currently active, any changes are rolled back.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            try
            {
                if (!disposed)
                {
                    if (disposing)
                    {
                        ////////////////////////////////////
                        // dispose managed resources here...
                        ////////////////////////////////////

                        if (IsValid(false))
                        {
                            IssueRollback(false);
                        }
                    }

                    //////////////////////////////////////
                    // release unmanaged resources here...
                    //////////////////////////////////////
                }
            }
            finally
            {
                base.Dispose(disposing);

                //
                // NOTE: Everything should be fully disposed at this point.
                //
                disposed = true;
            }
        }
        #endregion

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

        /// <summary>
        /// Commits the current transaction.
        /// </summary>
        public override void Commit()
        {
            CheckDisposed();
            SQLiteConnection.Check(_cnn);
            IsValid(true);

            if (_beginLevel == 0)
            {
                using (SQLiteCommand cmd = _cnn.CreateCommand())
                {
                    cmd.CommandText = "COMMIT;";
                    cmd.ExecuteNonQuery();
                }

                _cnn._transactionLevel = 0;
                _cnn = null;
            }
            else
            {
                using (SQLiteCommand cmd = _cnn.CreateCommand())
                {
                    if (String.IsNullOrEmpty(_savePointName))
                        throw new SQLiteException("Cannot commit, unknown SAVEPOINT");

                    cmd.CommandText = String.Format(
                        "RELEASE {0};", _savePointName);

                    cmd.ExecuteNonQuery();
                }

                _cnn._transactionLevel--;
                _cnn = null;
            }
        }

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

        /// <summary>
        /// Attempts to start a transaction.  An exception will be thrown if the transaction cannot
        /// be started for any reason.
        /// </summary>
        /// <param name="deferredLock">TRUE to defer the writelock, or FALSE to lock immediately</param>
        protected override void Begin(
            bool deferredLock
            )
        {
            int transactionLevel;

            if ((transactionLevel = _cnn._transactionLevel++) == 0)
            {
                try
                {
                    using (SQLiteCommand cmd = _cnn.CreateCommand())
                    {
                        if (!deferredLock)
                            cmd.CommandText = "BEGIN IMMEDIATE;";
                        else
                            cmd.CommandText = "BEGIN;";

                        cmd.ExecuteNonQuery();

                        _beginLevel = transactionLevel;
                    }
                }
                catch (SQLiteException)
                {
                    _cnn._transactionLevel--;
                    _cnn = null;

                    throw;
                }
            }
            else
            {
                try
                {
                    using (SQLiteCommand cmd = _cnn.CreateCommand())
                    {
                        _savePointName = GetSavePointName();

                        cmd.CommandText = String.Format(
                            "SAVEPOINT {0};", _savePointName);

                        cmd.ExecuteNonQuery();

                        _beginLevel = transactionLevel;
                    }
                }
                catch (SQLiteException)
                {
                    _cnn._transactionLevel--;
                    _cnn = null;

                    throw;
                }
            }
        }

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

        /// <summary>
        /// Issue a ROLLBACK command against the database connection,
        /// optionally re-throwing any caught exception.
        /// </summary>
        /// <param name="throwError">
        /// Non-zero to re-throw caught exceptions.
        /// </param>
        protected override void IssueRollback(bool throwError)
        {
            SQLiteConnection cnn = Interlocked.Exchange(ref _cnn, null);

            if (cnn != null)
            {
                if (_beginLevel == 0)
                {
                    try
                    {
                        using (SQLiteCommand cmd = cnn.CreateCommand())
                        {
                            cmd.CommandText = "ROLLBACK;";
                            cmd.ExecuteNonQuery();
                        }

                        cnn._transactionLevel = 0;
                    }
                    catch
                    {
                        if (throwError)
                            throw;
                    }
                }
                else
                {
                    try
                    {
                        using (SQLiteCommand cmd = cnn.CreateCommand())
                        {
                            if (String.IsNullOrEmpty(_savePointName))
                                throw new SQLiteException("Cannot rollback, unknown SAVEPOINT");

                            cmd.CommandText = String.Format(
                                "ROLLBACK TO {0};", _savePointName);

                            cmd.ExecuteNonQuery();
                        }

                        cnn._transactionLevel--;
                    }
                    catch
                    {
                        if (throwError)
                            throw;
                    }
                }
            }
        }

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

        /// <summary>
        /// Constructs the name of a new savepoint for this transaction.  It
        /// should only be called from the constructor of this class.
        /// </summary>
        /// <returns>
        /// The name of the new savepoint -OR- null if it cannot be constructed.
        /// </returns>
        private string GetSavePointName()
        {
            int sequence = ++_cnn._transactionSequence;

            return String.Format(
                "sqlite_dotnet_savepoint_{0}", sequence);
        }
    }
}

Added System.Data.SQLite/SQLiteTransactionBase.cs.













































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/********************************************************
 * ADO.NET 2.0 Data Provider for SQLite Version 3.X
 * Written by Robert Simpson (robert@blackcastlesoft.com)
 *
 * Released to the public domain, use at your own risk!
 ********************************************************/

namespace System.Data.SQLite
{
    using System;
    using System.Data;
    using System.Data.Common;

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

    /// <summary>
    /// Base class used by to implement DbTransaction for SQLite.
    /// </summary>
    public abstract class SQLiteTransactionBase : DbTransaction
    {
        /// <summary>
        /// The connection to which this transaction is bound.
        /// </summary>
        internal SQLiteConnection _cnn;

        /// <summary>
        /// Matches the version of the connection.
        /// </summary>
        internal int _version;

        /// <summary>
        /// The isolation level for this transaction.
        /// </summary>
        private IsolationLevel _level;

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

        /// <summary>
        /// Constructs the transaction object, binding it to the supplied connection
        /// </summary>
        /// <param name="connection">The connection to open a transaction on</param>
        /// <param name="deferredLock">TRUE to defer the writelock, or FALSE to lock immediately</param>
        internal SQLiteTransactionBase(SQLiteConnection connection, bool deferredLock)
        {
            _cnn = connection;
            _version = _cnn._version;

            _level = (deferredLock == true) ?
                SQLiteConnection.DeferredIsolationLevel :
                SQLiteConnection.ImmediateIsolationLevel;

            Begin(deferredLock);
        }

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

        /// <summary>
        /// Gets the isolation level of the transaction.  SQLite only supports Serializable transactions.
        /// </summary>
        public override IsolationLevel IsolationLevel
        {
            get { CheckDisposed(); return _level; }
        }
 
        ///////////////////////////////////////////////////////////////////////////////////////////////

        #region IDisposable "Pattern" Members
        private bool disposed;
        private void CheckDisposed() /* throw */
        {
#if THROW_ON_DISPOSED
            if (disposed)
            {
                throw new ObjectDisposedException(
                    typeof(SQLiteTransactionBase).Name);
            }
#endif
        }

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

        /// <summary>
        /// Disposes the transaction.  If it is currently active, any changes are rolled back.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            try
            {
                if (!disposed)
                {
                    if (disposing)
                    {
                        ////////////////////////////////////
                        // dispose managed resources here...
                        ////////////////////////////////////

                        if (IsValid(false))
                        {
                            IssueRollback(false);
                        }
                    }

                    //////////////////////////////////////
                    // release unmanaged resources here...
                    //////////////////////////////////////
                }
            }
            finally
            {
                base.Dispose(disposing);

                //
                // NOTE: Everything should be fully disposed at this point.
                //
                disposed = true;
            }
        }
        #endregion

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

        /// <summary>
        /// Returns the underlying connection to which this transaction applies.
        /// </summary>
        public new SQLiteConnection Connection
        {
            get { CheckDisposed(); return _cnn; }
        }

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

        /// <summary>
        /// Forwards to the local Connection property
        /// </summary>
        protected override DbConnection DbConnection
        {
            get { return Connection; }
        }

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

        /// <summary>
        /// Rolls back the active transaction.
        /// </summary>
        public override void Rollback()
        {
            CheckDisposed();
            SQLiteConnection.Check(_cnn);
            IsValid(true);
            IssueRollback(true);
        }

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

        /// <summary>
        /// Attempts to start a transaction.  An exception will be thrown if the transaction cannot
        /// be started for any reason.
        /// </summary>
        /// <param name="deferredLock">TRUE to defer the writelock, or FALSE to lock immediately</param>
        protected abstract void Begin(bool deferredLock);

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

        /// <summary>
        /// Issue a ROLLBACK command against the database connection,
        /// optionally re-throwing any caught exception.
        /// </summary>
        /// <param name="throwError">
        /// Non-zero to re-throw caught exceptions.
        /// </param>
        protected abstract void IssueRollback(bool throwError);

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

        /// <summary>
        /// Checks the state of this transaction, optionally throwing an exception if a state
        /// inconsistency is found.
        /// </summary>
        /// <param name="throwError">
        /// Non-zero to throw an exception if a state inconsistency is found.
        /// </param>
        /// <returns>
        /// Non-zero if this transaction is valid; otherwise, false.
        /// </returns>
        internal bool IsValid(bool throwError)
        {
            if (_cnn == null)
            {
                if (throwError == true) throw new ArgumentNullException("No connection associated with this transaction");
                else return false;
            }

            if (_cnn._version != _version)
            {
                if (throwError == true) throw new SQLiteException("The connection was closed and re-opened, changes were already rolled back");
                else return false;
            }
            if (_cnn.State != ConnectionState.Open)
            {
                if (throwError == true) throw new SQLiteException("Connection was closed");
                else return false;
            }

            if (_cnn._transactionLevel == 0 || _cnn._sql.AutoCommit == true)
            {
                _cnn._transactionLevel = 0; // Make sure the transaction level is reset before returning
                if (throwError == true) throw new SQLiteException("No transaction is active on this connection");
                else return false;
            }

            return true;
        }
    }
}

Changes to System.Data.SQLite/Targets/System.Data.SQLite.Files.targets.

47
48
49
50
51
52
53


54
55
56
57
58
59
60
    <Compile Include="SQLiteLog.cs" />
    <Compile Include="SQLiteMetaDataCollectionNames.cs" />
    <Compile Include="SQLiteParameter.cs" />
    <Compile Include="SQLiteParameterCollection.cs" />
    <Compile Include="SQLitePatchLevel.cs" />
    <Compile Include="SQLiteStatement.cs" />
    <Compile Include="SQLiteTransaction.cs" />


    <Compile Include="UnsafeNativeMethods.cs" />
    <Compile Include="Resources\SR.Designer.cs">
      <DependentUpon>SR.resx</DependentUpon>
      <AutoGen>True</AutoGen>
      <DesignTime>True</DesignTime>
    </Compile>
    <EmbeddedResource Include="Resources\SR.resx">







>
>







47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
    <Compile Include="SQLiteLog.cs" />
    <Compile Include="SQLiteMetaDataCollectionNames.cs" />
    <Compile Include="SQLiteParameter.cs" />
    <Compile Include="SQLiteParameterCollection.cs" />
    <Compile Include="SQLitePatchLevel.cs" />
    <Compile Include="SQLiteStatement.cs" />
    <Compile Include="SQLiteTransaction.cs" />
    <Compile Include="SQLiteTransaction2.cs" />
    <Compile Include="SQLiteTransactionBase.cs" />
    <Compile Include="UnsafeNativeMethods.cs" />
    <Compile Include="Resources\SR.Designer.cs">
      <DependentUpon>SR.resx</DependentUpon>
      <AutoGen>True</AutoGen>
      <DesignTime>True</DesignTime>
    </Compile>
    <EmbeddedResource Include="Resources\SR.resx">

Changes to Tests/tkt-1f7bfff467.eagle.

16
17
18
19
20
21
22





























































23
24
25
26
27
28
29
30
31
..
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
...
144
145
146
147
148
149
150
151

152
153
154
155
156
157
158
...
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
196
...
225
226
227
228
229
230
231
232

233
234
235
236
237
238
239
...
254
255
256
257
258
259
260

261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
...
323
324
325
326
327
328
329
330

331
332
333
334
335
336
337
...
352
353
354
355
356
357
358

359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
...
421
422
423
424
425
426
427
428

429
430
431
432
433
434
435
436
###############################################################################

package require System.Data.SQLite.Test
runSQLiteTestPrologue

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






























































runTest {test tkt-1f7bfff467-1.1 {rollback nested transaction} -setup {
  setupDb [set fileName tkt-1f7bfff467-1.1.db]
} -body {
  sql execute $db {
    CREATE TABLE t1(x);
    INSERT INTO t1(x) VALUES(1);
    INSERT INTO t1(x) VALUES(2);
    INSERT INTO t1(x) VALUES(3);
  }
................................................................................

  set sql(2) { \
    INSERT INTO t1(x) VALUES(3); \
  }

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


  unset -nocomplain results errors

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

    namespace _Dynamic${id}
    {
      public static class Test${id}
      {
        public static void Main()
        {
          using (SQLiteConnection connection = new SQLiteConnection(
              "Data Source=${dataSource};[getFlagsProperty]"))
          {
            connection.Open();

            using (SQLiteTransaction transaction1 =
                connection.BeginTransaction())
            {
              using (SQLiteCommand command1 = new SQLiteCommand(
................................................................................
        object invoke _Dynamic${id}.Test${id} Main
      } result] : [set result ""]}] $result \
      [sql execute -execute reader -format list $db \
          "SELECT x FROM t1 ORDER BY x;"]
} -cleanup {
  cleanupDb $fileName

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

} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
System.Data.SQLite compileCSharp} -match regexp -result {^Ok\
System#CodeDom#Compiler#CompilerResults#\d+ \{\} 0 \{\} \{1 2 3\}$}}

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

runTest {test tkt-1f7bfff467-1.3 {rollback outer transaction} -setup {
................................................................................

  set sql(2) { \
    INSERT INTO t1(x) VALUES(3); \
  }

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


  unset -nocomplain results errors

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

    namespace _Dynamic${id}
    {
      public static class Test${id}
      {
        public static void Main()
        {
          using (SQLiteConnection connection = new SQLiteConnection(
              "Data Source=${dataSource};[getFlagsProperty]"))
          {
            connection.Open();

            using (SQLiteTransaction transaction1 =
                connection.BeginTransaction())
            {
              using (SQLiteCommand command1 = new SQLiteCommand(
................................................................................
        object invoke _Dynamic${id}.Test${id} Main
      } result] : [set result ""]}] $result \
      [sql execute -execute reader -format list $db \
          "SELECT x FROM t1 ORDER BY x;"]
} -cleanup {
  cleanupDb $fileName

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

} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
System.Data.SQLite compileCSharp} -match regexp -result {^Ok\
System#CodeDom#Compiler#CompilerResults#\d+ \{\} 0 \{\} 1$}}

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

runTest {test tkt-1f7bfff467-1.4 {commit middle transaction} -setup {
................................................................................

  set sql(3) { \
    INSERT INTO t1(x) VALUES(4); \
  }

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


  unset -nocomplain results errors

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

    namespace _Dynamic${id}
    {
      public static class Test${id}
      {
        public static void Main()
        {
          using (SQLiteConnection connection = new SQLiteConnection(
              "Data Source=${dataSource};[getFlagsProperty]"))
          {
            connection.Open();

            using (SQLiteTransaction transaction1 =
                connection.BeginTransaction())
            {
              using (SQLiteCommand command1 = new SQLiteCommand(
................................................................................
        object invoke _Dynamic${id}.Test${id} Main
      } result] : [set result ""]}] $result \
      [sql execute -execute reader -format list $db \
          "SELECT x FROM t1 ORDER BY x;"]
} -cleanup {
  cleanupDb $fileName

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

} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
System.Data.SQLite compileCSharp} -match regexp -result {^Ok\
System#CodeDom#Compiler#CompilerResults#\d+ \{\} 0 \{\} \{1 2 3 4\}$}}

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

runTest {test tkt-1f7bfff467-1.5 {rollback middle transaction} -setup {
................................................................................

  set sql(3) { \
    INSERT INTO t1(x) VALUES(4); \
  }

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


  unset -nocomplain results errors

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

    namespace _Dynamic${id}
    {
      public static class Test${id}
      {
        public static void Main()
        {
          using (SQLiteConnection connection = new SQLiteConnection(
              "Data Source=${dataSource};[getFlagsProperty]"))
          {
            connection.Open();

            using (SQLiteTransaction transaction1 =
                connection.BeginTransaction())
            {
              using (SQLiteCommand command1 = new SQLiteCommand(
................................................................................
        object invoke _Dynamic${id}.Test${id} Main
      } result] : [set result ""]}] $result \
      [sql execute -execute reader -format list $db \
          "SELECT x FROM t1 ORDER BY x;"]
} -cleanup {
  cleanupDb $fileName

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

} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
System.Data.SQLite compileCSharp} -match regexp -result {^Ok\
System#CodeDom#Compiler#CompilerResults#\d+ \{\} 0 \{\} \{1 2\}$}}

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

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
...
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
...
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
...
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
...
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
...
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
...
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
...
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
...
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
###############################################################################

package require System.Data.SQLite.Test
runSQLiteTestPrologue

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

runTest {test tkt-1f7bfff467-1.0 {rollback nested transaction} -setup {
  setupDb [set fileName tkt-1f7bfff467-1.0.db]
} -body {
  sql execute $db {
    CREATE TABLE t1(x);
    INSERT INTO t1(x) VALUES(1);
    INSERT INTO t1(x) VALUES(2);
    INSERT INTO t1(x) VALUES(3);
  }

  catch {
    set result [list]

    lappend result [sql execute \
        -execute scalar $db "SELECT COUNT(*) FROM t1;"]

    set transaction(1) [sql transaction begin $db]

    sql execute -transaction $transaction(1) $db \
        "INSERT INTO t1(x) VALUES(4);"

    lappend result [sql execute -transaction $transaction(1) \
        -execute reader -format list $db \
        "SELECT x FROM t1 ORDER BY x;"]

    set transaction(2) [sql transaction begin $db]

    sql execute -transaction $transaction(2) $db \
        "DELETE FROM t1 WHERE x = 2;"

    lappend result [sql execute -transaction $transaction(2) \
        -execute reader -format list $db \
        "SELECT x FROM t1 ORDER BY x;"]

    sql transaction rollback $transaction(2)

    sql execute -transaction $transaction(1) $db \
        "UPDATE t1 SET x = 9 WHERE x = 3;"

    sql transaction commit $transaction(1)

    lappend result [sql execute \
        -execute reader -format list $db \
        "SELECT x FROM t1 ORDER BY x;"]

    set result
  } error

  extractSystemDataSQLiteExceptionMessage $error
} -cleanup {
  catch {sql transaction rollback $transaction(1)}

  cleanupDb $fileName

  unset -nocomplain error result transaction db fileName
} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
System.Data.SQLite} -result {unknown error -- Transaction is already active on\
this connection}}

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

runTest {test tkt-1f7bfff467-1.1 {rollback nested transaction} -setup {
  setupDb [set fileName tkt-1f7bfff467-1.1.db] "" "" "" AllowNestedTransactions
} -body {
  sql execute $db {
    CREATE TABLE t1(x);
    INSERT INTO t1(x) VALUES(1);
    INSERT INTO t1(x) VALUES(2);
    INSERT INTO t1(x) VALUES(3);
  }
................................................................................

  set sql(2) { \
    INSERT INTO t1(x) VALUES(3); \
  }

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

  unset -nocomplain results errors

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

    namespace _Dynamic${id}
    {
      public static class Test${id}
      {
        public static void Main()
        {
          using (SQLiteConnection connection = new SQLiteConnection(
              "Data Source=${dataSource};[getFlagsProperty ${flags}]"))
          {
            connection.Open();

            using (SQLiteTransaction transaction1 =
                connection.BeginTransaction())
            {
              using (SQLiteCommand command1 = new SQLiteCommand(
................................................................................
        object invoke _Dynamic${id}.Test${id} Main
      } result] : [set result ""]}] $result \
      [sql execute -execute reader -format list $db \
          "SELECT x FROM t1 ORDER BY x;"]
} -cleanup {
  cleanupDb $fileName

  unset -nocomplain result results errors code
  unset -nocomplain sql flags dataSource id db fileName
} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
System.Data.SQLite compileCSharp} -match regexp -result {^Ok\
System#CodeDom#Compiler#CompilerResults#\d+ \{\} 0 \{\} \{1 2 3\}$}}

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

runTest {test tkt-1f7bfff467-1.3 {rollback outer transaction} -setup {
................................................................................

  set sql(2) { \
    INSERT INTO t1(x) VALUES(3); \
  }

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

  unset -nocomplain results errors

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

    namespace _Dynamic${id}
    {
      public static class Test${id}
      {
        public static void Main()
        {
          using (SQLiteConnection connection = new SQLiteConnection(
              "Data Source=${dataSource};[getFlagsProperty ${flags}]"))
          {
            connection.Open();

            using (SQLiteTransaction transaction1 =
                connection.BeginTransaction())
            {
              using (SQLiteCommand command1 = new SQLiteCommand(
................................................................................
        object invoke _Dynamic${id}.Test${id} Main
      } result] : [set result ""]}] $result \
      [sql execute -execute reader -format list $db \
          "SELECT x FROM t1 ORDER BY x;"]
} -cleanup {
  cleanupDb $fileName

  unset -nocomplain result results errors code
  unset -nocomplain sql flags dataSource id db fileName
} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
System.Data.SQLite compileCSharp} -match regexp -result {^Ok\
System#CodeDom#Compiler#CompilerResults#\d+ \{\} 0 \{\} 1$}}

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

runTest {test tkt-1f7bfff467-1.4 {commit middle transaction} -setup {
................................................................................

  set sql(3) { \
    INSERT INTO t1(x) VALUES(4); \
  }

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

  unset -nocomplain results errors

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

    namespace _Dynamic${id}
    {
      public static class Test${id}
      {
        public static void Main()
        {
          using (SQLiteConnection connection = new SQLiteConnection(
              "Data Source=${dataSource};[getFlagsProperty ${flags}]"))
          {
            connection.Open();

            using (SQLiteTransaction transaction1 =
                connection.BeginTransaction())
            {
              using (SQLiteCommand command1 = new SQLiteCommand(
................................................................................
        object invoke _Dynamic${id}.Test${id} Main
      } result] : [set result ""]}] $result \
      [sql execute -execute reader -format list $db \
          "SELECT x FROM t1 ORDER BY x;"]
} -cleanup {
  cleanupDb $fileName

  unset -nocomplain result results errors code
  unset -nocomplain sql flags dataSource id db fileName
} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
System.Data.SQLite compileCSharp} -match regexp -result {^Ok\
System#CodeDom#Compiler#CompilerResults#\d+ \{\} 0 \{\} \{1 2 3 4\}$}}

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

runTest {test tkt-1f7bfff467-1.5 {rollback middle transaction} -setup {
................................................................................

  set sql(3) { \
    INSERT INTO t1(x) VALUES(4); \
  }

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

  unset -nocomplain results errors

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

    namespace _Dynamic${id}
    {
      public static class Test${id}
      {
        public static void Main()
        {
          using (SQLiteConnection connection = new SQLiteConnection(
              "Data Source=${dataSource};[getFlagsProperty ${flags}]"))
          {
            connection.Open();

            using (SQLiteTransaction transaction1 =
                connection.BeginTransaction())
            {
              using (SQLiteCommand command1 = new SQLiteCommand(
................................................................................
        object invoke _Dynamic${id}.Test${id} Main
      } result] : [set result ""]}] $result \
      [sql execute -execute reader -format list $db \
          "SELECT x FROM t1 ORDER BY x;"]
} -cleanup {
  cleanupDb $fileName

  unset -nocomplain result results errors code
  unset -nocomplain sql flags dataSource id db fileName
} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
System.Data.SQLite compileCSharp} -match regexp -result {^Ok\
System#CodeDom#Compiler#CompilerResults#\d+ \{\} 0 \{\} \{1 2\}$}}

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

runSQLiteTestEpilogue
runTestEpilogue

Changes to readme.htm.

211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<p>
    <b>1.0.104.0 - December XX, 2016</b>
</p>
<ul>
    <li>Updated to <a href="https://www.sqlite.org/releaselog/3_15_0.html">SQLite 3.15.0</a>.</li>
    <li>Add the &quot;%PreLoadSQLite_AssemblyDirectory%&quot;, &quot;%PreLoadSQLite_TargetFramework%&quot;, and &quot;%PreLoadSQLite_XmlConfigDirectory%&quot; <a href="https://system.data.sqlite.org/index.html/artifact?ci=trunk&filename=Doc/Extra/Provider/environment.html">replacement tokens</a> for use in configuration setting values. Pursuant to [d4728aecb7].</li>
    <li>Prevent the GetByte, GetChar, and GetInt16 methods of the SQLiteDataReader class from throwing exceptions for large integer values. Pursuant to [5535448538].&nbsp;<b>** Potentially Incompatible Change **</b></li>
    <li>Use <a href="https://www.sqlite.org/lang_savepoint.html">SAVEPOINTs</a> to properly implement nested transactions. Fix for [1f7bfff467].&nbsp;<b>** Potentially Incompatible Change **</b></li>
</ul>
<p>
    <b>1.0.103.0 - September 15, 2016</b>
</p>
<ul>
    <li>Updated to <a href="https://www.sqlite.org/releaselog/3_14_2.html">SQLite 3.14.2</a>.</li>
    <li>Add preliminary support for the .NET Framework 4.6.2.</li>







|







211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<p>
    <b>1.0.104.0 - December XX, 2016</b>
</p>
<ul>
    <li>Updated to <a href="https://www.sqlite.org/releaselog/3_15_0.html">SQLite 3.15.0</a>.</li>
    <li>Add the &quot;%PreLoadSQLite_AssemblyDirectory%&quot;, &quot;%PreLoadSQLite_TargetFramework%&quot;, and &quot;%PreLoadSQLite_XmlConfigDirectory%&quot; <a href="https://system.data.sqlite.org/index.html/artifact?ci=trunk&filename=Doc/Extra/Provider/environment.html">replacement tokens</a> for use in configuration setting values. Pursuant to [d4728aecb7].</li>
    <li>Prevent the GetByte, GetChar, and GetInt16 methods of the SQLiteDataReader class from throwing exceptions for large integer values. Pursuant to [5535448538].&nbsp;<b>** Potentially Incompatible Change **</b></li>
    <li>Use <a href="https://www.sqlite.org/lang_savepoint.html">SAVEPOINTs</a> to properly implement nested transactions when the new AllowNestedTransactions connection flag is used. Fix for [1f7bfff467].</li>
</ul>
<p>
    <b>1.0.103.0 - September 15, 2016</b>
</p>
<ul>
    <li>Updated to <a href="https://www.sqlite.org/releaselog/3_14_2.html">SQLite 3.14.2</a>.</li>
    <li>Add preliminary support for the .NET Framework 4.6.2.</li>

Changes to www/news.wiki.

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<p>
    <b>1.0.104.0 - December XX, 2016</b>
</p>
<ul>
    <li>Updated to [https://www.sqlite.org/releaselog/3_15_0.html|SQLite 3.15.0].</li>
    <li>Add the &quot;%PreLoadSQLite_AssemblyDirectory%&quot;, &quot;%PreLoadSQLite_TargetFramework%&quot;, and &quot;%PreLoadSQLite_XmlConfigDirectory%&quot; [https://system.data.sqlite.org/index.html/artifact?ci=trunk&filename=Doc/Extra/Provider/environment.html|replacement tokens] for use in configuration setting values. Pursuant to [d4728aecb7].</li>
    <li>Prevent the GetByte, GetChar, and GetInt16 methods of the SQLiteDataReader class from throwing exceptions for large integer values. Pursuant to [5535448538].&nbsp;<b>** Potentially Incompatible Change **</b></li>
    <li>Use [https://www.sqlite.org/lang_savepoint.html|SAVEPOINTs] to properly implement nested transactions. Fix for [1f7bfff467].&nbsp;<b>** Potentially Incompatible Change **</b></li>
</ul>
<p>
    <b>1.0.103.0 - September 15, 2016</b>
</p>
<ul>
    <li>Updated to [https://www.sqlite.org/releaselog/3_14_2.html|SQLite 3.14.2].</li>
    <li>Add preliminary support for the .NET Framework 4.6.2.</li>







|







5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<p>
    <b>1.0.104.0 - December XX, 2016</b>
</p>
<ul>
    <li>Updated to [https://www.sqlite.org/releaselog/3_15_0.html|SQLite 3.15.0].</li>
    <li>Add the &quot;%PreLoadSQLite_AssemblyDirectory%&quot;, &quot;%PreLoadSQLite_TargetFramework%&quot;, and &quot;%PreLoadSQLite_XmlConfigDirectory%&quot; [https://system.data.sqlite.org/index.html/artifact?ci=trunk&filename=Doc/Extra/Provider/environment.html|replacement tokens] for use in configuration setting values. Pursuant to [d4728aecb7].</li>
    <li>Prevent the GetByte, GetChar, and GetInt16 methods of the SQLiteDataReader class from throwing exceptions for large integer values. Pursuant to [5535448538].&nbsp;<b>** Potentially Incompatible Change **</b></li>
    <li>Use [https://www.sqlite.org/lang_savepoint.html|SAVEPOINTs] to properly implement nested transactions when the new AllowNestedTransactions connection flag is used. Fix for [1f7bfff467].</li>
</ul>
<p>
    <b>1.0.103.0 - September 15, 2016</b>
</p>
<ul>
    <li>Updated to [https://www.sqlite.org/releaselog/3_14_2.html|SQLite 3.14.2].</li>
    <li>Add preliminary support for the .NET Framework 4.6.2.</li>