1- using MySql . Data . MySqlClient ;
1+ #if USE_MYSQLCONNECTOR
2+ using MySqlConnector ;
3+ #else
4+ using MySql . Data . MySqlClient ;
5+ #endif
26using Oxide . Core . Database ;
37using Oxide . Core . Libraries ;
48using Oxide . Core . Plugins ;
@@ -17,10 +21,10 @@ public class MySql : Library, IDatabaseProvider
1721 private readonly object _syncroot = new object ( ) ;
1822 private readonly AutoResetEvent _workevent = new AutoResetEvent ( false ) ;
1923 private readonly HashSet < Connection > _runningConnections = new HashSet < Connection > ( ) ;
20- private bool _running = true ;
2124 private readonly Dictionary < string , Dictionary < string , Connection > > _connections = new Dictionary < string , Dictionary < string , Connection > > ( ) ;
2225 private readonly Thread _worker ;
2326 private readonly Dictionary < Plugin , Event . Callback < Plugin , PluginManager > > _pluginRemovedFromManager ;
27+ private bool _running = true ;
2428
2529 /// <summary>
2630 /// Represents a single MySqlQuery instance
@@ -54,7 +58,6 @@ public class MySqlQuery
5458
5559 private MySqlCommand _cmd ;
5660 private MySqlConnection _connection ;
57- private IAsyncResult _result ;
5861
5962 private void Cleanup ( )
6063 {
@@ -77,8 +80,7 @@ public bool Handle()
7780 {
7881 throw new Exception ( "Connection is null" ) ;
7982 }
80- //if (_result == null)
81- //{
83+
8284 _connection = ( MySqlConnection ) Connection . Con ;
8385 if ( _connection . State == ConnectionState . Closed )
8486 {
@@ -89,17 +91,14 @@ public bool Handle()
8991 _cmd . CommandTimeout = 120 ;
9092 _cmd . CommandText = Sql . SQL ;
9193 Sql . AddParams ( _cmd , Sql . Arguments , "@" ) ;
92- _result = NonQuery ? _cmd . BeginExecuteNonQuery ( ) : _cmd . BeginExecuteReader ( ) ;
93- //}
94- _result . AsyncWaitHandle . WaitOne ( ) ;
95- //if (!_result.IsCompleted) return false;
94+
9695 if ( NonQuery )
9796 {
98- nonQueryResult = _cmd . EndExecuteNonQuery ( _result ) ;
97+ nonQueryResult = _cmd . ExecuteNonQuery ( ) ;
9998 }
10099 else
101100 {
102- using ( MySqlDataReader reader = _cmd . EndExecuteReader ( _result ) )
101+ using ( MySqlDataReader reader = _cmd . ExecuteReader ( ) )
103102 {
104103 list = new List < Dictionary < string , object > > ( ) ;
105104 while ( reader . Read ( ) )
@@ -108,15 +107,18 @@ public bool Handle()
108107 {
109108 break ;
110109 }
110+
111111 var dict = new Dictionary < string , object > ( ) ;
112112 for ( int i = 0 ; i < reader . FieldCount ; i ++ )
113113 {
114114 dict . Add ( reader . GetName ( i ) , reader . GetValue ( i ) ) ;
115115 }
116+
116117 list . Add ( dict ) ;
117118 }
118119 }
119120 }
121+
120122 lastInsertRowId = _cmd . LastInsertedId ;
121123 Cleanup ( ) ;
122124 }
@@ -131,6 +133,7 @@ public bool Handle()
131133 Interface . Oxide . LogException ( message , ex ) ;
132134 Cleanup ( ) ;
133135 }
136+
134137 Interface . Oxide . NextTick ( ( ) =>
135138 {
136139 Connection ? . Plugin ? . TrackStart ( ) ;
@@ -160,6 +163,7 @@ public bool Handle()
160163
161164 Interface . Oxide . LogException ( message , ex ) ;
162165 }
166+
163167 Connection ? . Plugin ? . TrackEnd ( ) ;
164168 } ) ;
165169 return true ;
@@ -200,6 +204,7 @@ private void Worker()
200204 _runningConnections . Clear ( ) ;
201205 }
202206 }
207+
203208 if ( query != null )
204209 {
205210 query . Handle ( ) ;
@@ -251,6 +256,7 @@ public Connection OpenDb(string conStr, Plugin plugin, bool persistent = false)
251256 } ;
252257 connections [ conStr ] = connection ;
253258 }
259+
254260 if ( plugin != null && ! _pluginRemovedFromManager . ContainsKey ( plugin ) )
255261 {
256262 _pluginRemovedFromManager [ plugin ] = plugin . OnRemovedFromManager . Add ( OnRemovedFromManager ) ;
@@ -279,8 +285,10 @@ private void OnRemovedFromManager(Plugin sender, PluginManager manager)
279285 connection . Value . Con ? . Close ( ) ;
280286 connection . Value . Plugin = null ;
281287 }
288+
282289 _connections . Remove ( sender . Name ) ;
283290 }
291+
284292 Event . Callback < Plugin , PluginManager > event_callback ;
285293 if ( _pluginRemovedFromManager . TryGetValue ( sender , out event_callback ) )
286294 {
@@ -315,6 +323,7 @@ public void CloseDb(Connection db)
315323 }
316324 }
317325 }
326+
318327 db . Con ? . Close ( ) ;
319328 db . Plugin = null ;
320329 }
0 commit comments