void ExecuteQuery(DBQuery q) { LogThread.Log(string.Format("ExecuteQuery - {0}", q.SqlString), LogThread.LogMessageType.Debug); MySqlCommand cmd = new MySqlCommand(q.SqlString, _sql); if (q.Read) { MySqlDataReader reader = cmd.ExecuteReader(); List<object[]> rows = new List<object[]>(); while (reader.Read()) { object[] row = new object[reader.FieldCount]; for (int i = 0; i < reader.FieldCount; i++) { row[i] = reader[i]; } rows.Add(row); } reader.Close(); q.Rows = rows; } else { cmd.ExecuteNonQuery(); } OnQueryComplete(q, null); }
public void AddQuery(DBQuery query) { _queriesLock.WaitOne(); _queries.Add(query); _queriesLock.ReleaseMutex(); }
GameDataArgs ReadGameData(DBQuery query) { GameDataArgs gameData = new GameDataArgs(); object[] row = query.Rows[0]; gameData.TowerFloors = new int[6]; for (int i = 0; i < gameData.TowerFloors.Length; i++) gameData.TowerFloors[i] = (int)row[i + 1]; gameData.Level = (int)row[7]; gameData.Exp = (int)row[8]; gameData.Tutorial = (ulong)row[9]; return gameData; }
public DBQuery AddDBQuery(string sql, Task task, bool read = true) { if( task == null ) task = new Task(-1); long key = UniqueKey(); DBQuery q = new DBQuery(sql, read, key); task.Query = q; _pqLock.WaitOne(); LogInterface.Log("Adding Query with key: " + key, LogInterface.LogMessageType.Debug, true); _pendingQueries[key] = task; _pqLock.ReleaseMutex(); _db.AddQuery(q); return q; }