1
1
#if ! NETSTANDARD1_3
2
+ using System ;
2
3
using System . Transactions ;
3
4
using MySql . Data . MySqlClient ;
5
+ using MySqlConnector . Utilities ;
4
6
5
7
namespace MySqlConnector . Core
6
8
{
7
9
internal sealed class StandardImplicitTransaction : ImplicitTransactionBase
8
10
{
9
- public StandardImplicitTransaction ( MySqlConnection connection ) : base ( connection )
11
+ public StandardImplicitTransaction ( Transaction transaction , MySqlConnection connection )
12
+ : base ( transaction , connection )
10
13
{
11
14
}
12
15
13
16
protected override void OnStart ( )
14
17
{
15
- System . Data . IsolationLevel isolationLevel ;
18
+ string isolationLevel ;
16
19
switch ( Transaction . IsolationLevel )
17
20
{
18
21
case IsolationLevel . Serializable :
19
- isolationLevel = System . Data . IsolationLevel . Serializable ;
20
- break ;
21
- case IsolationLevel . RepeatableRead :
22
- isolationLevel = System . Data . IsolationLevel . RepeatableRead ;
22
+ isolationLevel = "serializable" ;
23
23
break ;
24
24
case IsolationLevel . ReadCommitted :
25
- isolationLevel = System . Data . IsolationLevel . ReadCommitted ;
25
+ isolationLevel = "read committed" ;
26
26
break ;
27
27
case IsolationLevel . ReadUncommitted :
28
- isolationLevel = System . Data . IsolationLevel . ReadUncommitted ;
28
+ isolationLevel = "read uncommitted" ;
29
29
break ;
30
30
case IsolationLevel . Snapshot :
31
- isolationLevel = System . Data . IsolationLevel . Snapshot ;
32
- break ;
33
31
case IsolationLevel . Chaos :
34
- isolationLevel = System . Data . IsolationLevel . Chaos ;
35
- break ;
32
+ throw new NotSupportedException ( "IsolationLevel.{0} is not supported." . FormatInvariant ( Transaction . IsolationLevel ) ) ;
33
+ // "In terms of the SQL:1992 transaction isolation levels, the default InnoDB level is REPEATABLE READ." - http://dev.mysql.com/doc/refman/5.7/en/innodb-transaction-model.html
36
34
case IsolationLevel . Unspecified :
35
+ case IsolationLevel . RepeatableRead :
37
36
default :
38
- isolationLevel = System . Data . IsolationLevel . Unspecified ;
37
+ isolationLevel = "repeatable read" ;
39
38
break ;
40
39
}
41
- m_transaction = Connection . BeginTransaction ( isolationLevel ) ;
40
+
41
+ using ( var cmd = new MySqlCommand ( "set transaction isolation level " + isolationLevel + "; start transaction;" , Connection ) )
42
+ cmd . ExecuteNonQuery ( ) ;
42
43
}
43
44
44
45
protected override void OnPrepare ( PreparingEnlistment enlistment )
@@ -47,17 +48,15 @@ protected override void OnPrepare(PreparingEnlistment enlistment)
47
48
48
49
protected override void OnCommit ( Enlistment enlistment )
49
50
{
50
- m_transaction . Commit ( ) ;
51
- m_transaction = null ;
51
+ using ( var cmd = new MySqlCommand ( "commit;" , Connection ) )
52
+ cmd . ExecuteNonQuery ( ) ;
52
53
}
53
54
54
55
protected override void OnRollback ( Enlistment enlistment )
55
56
{
56
- m_transaction . Rollback ( ) ;
57
- m_transaction = null ;
57
+ using ( var cmd = new MySqlCommand ( "rollback;" , Connection ) )
58
+ cmd . ExecuteNonQuery ( ) ;
58
59
}
59
-
60
- MySqlTransaction m_transaction ;
61
60
}
62
61
}
63
62
#endif
0 commit comments