@@ -16,6 +16,8 @@ internal class MySQLDriver : IAnyBase
1616 private CommitMode commit_mode ;
1717 private bool trans_started ;
1818 private DbTransaction transaction ;
19+ private string builder ;
20+
1921
2022 public void Set ( CommitMode commit_mode , string db_name , string db_host , string db_user = "" , string db_pass = "" )
2123 {
@@ -28,7 +30,7 @@ public void Set(CommitMode commit_mode, string db_name, string db_host, string d
2830 db_port = uint . Parse ( db_host_arr [ 1 ] ) ;
2931
3032
31- var builder = new MySqlConnectionStringBuilder
33+ builder = new MySqlConnectionStringBuilder
3234 {
3335 Server = db_server ,
3436 Database = db_name ,
@@ -37,9 +39,9 @@ public void Set(CommitMode commit_mode, string db_name, string db_host, string d
3739 SslMode = MySqlSslMode . Preferred ,
3840 Port = db_port
3941
40- } ;
42+ } . ConnectionString ;
4143
42- dbConn = new MySqlConnection ( builder . ConnectionString ) ;
44+ dbConn = GetNewConn ( false ) ;
4345
4446 if ( commit_mode != CommitMode . AutoCommit )
4547 new Task ( TimerCommit ) . Start ( ) ;
@@ -52,12 +54,13 @@ private void TimerCommit()
5254 if ( trans_started )
5355 SetTransState ( false ) ;
5456 Thread . Sleep ( 5000 ) ;
57+ //Task.Delay(5000);
5558 }
5659 }
5760
5861 public List < List < string > > Query ( string q , List < string > args , bool non_query = false )
5962 {
60- if ( commit_mode != CommitMode . AutoCommit )
63+ if ( commit_mode == CommitMode . TimerCommit )
6164 {
6265 if ( ! trans_started && non_query ) SetTransState ( true ) ;
6366 else
@@ -72,16 +75,27 @@ public List<List<string>> Query(string q, List<string> args, bool non_query = fa
7275
7376 public void QueryAsync ( string q , List < string > args , Action < List < List < string > > > action = null , bool non_query = false )
7477 {
75- if ( commit_mode != CommitMode . AutoCommit )
78+ /*
79+ if (commit_mode == CommitMode.TimerCommit)
7680 {
7781 if (!trans_started && non_query) SetTransState(true);
7882 else
7983 {
8084 if (trans_started && !non_query) SetTransState(false);
8185 }
8286 }
87+ */
88+
8389
84- Common . QueryAsync ( dbConn , Common . _PrepareClear ( q , args ) , action , non_query ) ;
90+ Common . QueryAsync ( GetNewConn ( ) , Common . _PrepareClear ( q , args ) , action , non_query ) ;
91+ }
92+
93+ private MySqlConnection GetNewConn ( bool open = true )
94+ {
95+ var conn = new MySqlConnection ( builder ) ;
96+
97+ if ( open ) conn . Open ( ) ;
98+ return conn ;
8599 }
86100
87101 public DbConnection GetConn ( )
@@ -101,7 +115,7 @@ private void SetTransState(bool state)
101115 transaction . Rollback ( ) ;
102116 else
103117 transaction . Commit ( ) ;
104- transaction . Dispose ( ) ;
118+ // transaction.Dispose();
105119 trans_started = false ;
106120 }
107121 }
0 commit comments