/// <summary> /// Update maze points /// </summary> /// <param name="points"></param> /// <returns> /// The successfulness of updating the points. /// </returns> public int UpdatePoints(int points) { SqlEncap sql = new SqlEncap(); int result = Constants.RESPONSE_CODE_SUCCESS; Dictionary <string, string> value = new Dictionary <string, string>(); Dictionary <string, string> condition = new Dictionary <string, string>(); try { value.Clear(); value.Add(Constants.MAZE_POINTS, points.ToString()); condition.Add(Constants.COLUMN_ID, actived_mazeId.ToString()); dbCommand = dbConnection.CreateCommand(); dbCommand.CommandText = sql.Update(Constants.TABLE_MAZE, value, condition); dbCommand.ExecuteNonQuery(); } catch (SqliteException sqlEx) { result = Constants.RESPONSE_CODE_FAILURE; Debug.LogError(sqlEx); } return(result); }
/// <summary> /// Update maze matrix /// </summary> /// <param name="updatedMaze"></param> /// <returns> /// The successfulness of updating the current maze. /// </returns> public int UpdateMaze(int[,] updatedMaze) { SqlEncap sql = new SqlEncap(); int result = Constants.RESPONSE_CODE_SUCCESS; Dictionary <string, string> value = new Dictionary <string, string>(); Dictionary <string, string> condition = new Dictionary <string, string>(); try { string str = "'"; for (int i = 0; i <= updatedMaze.GetUpperBound(0); i++) { str += ""; for (int j = 0; j <= updatedMaze.GetUpperBound(1); j++) { str += updatedMaze[i, j]; if (j != updatedMaze.GetUpperBound(1)) { str += ","; } } str += ""; if (i != updatedMaze.GetUpperBound(0)) { str += ";"; } } str += "'"; value.Clear(); value.Add(Constants.MAZE_MATRIX, str); condition.Add(Constants.COLUMN_ID, actived_mazeId.ToString()); dbCommand = dbConnection.CreateCommand(); dbCommand.CommandText = sql.Update(Constants.TABLE_MAZE, value, condition); dbCommand.ExecuteNonQuery(); } catch (SqliteException sqlEx) { result = Constants.RESPONSE_CODE_FAILURE; Debug.LogError(sqlEx); } return(result); }
/// <summary> /// Update maze move history /// </summary> /// <param name="path"></param> /// <returns> /// The successfulness of updating the move history. /// </returns> public int UpdateMoveHistory(String[] path) { SqlEncap sql = new SqlEncap(); int result = Constants.RESPONSE_CODE_SUCCESS; Dictionary <string, string> value = new Dictionary <string, string>(); Dictionary <string, string> condition = new Dictionary <string, string>(); try { string str = "'"; for (int i = 0; i < path.Length; i++) { if (i != 0) { str += ","; } str += path[i]; } str += "'"; value.Clear(); value.Add(Constants.MAZE_HISTORY, str); condition.Add(Constants.COLUMN_ID, actived_mazeId.ToString()); dbCommand = dbConnection.CreateCommand(); dbCommand.CommandText = sql.Update(Constants.TABLE_MAZE, value, condition); dbCommand.ExecuteNonQuery(); } catch (SqliteException sqlEx) { result = Constants.RESPONSE_CODE_FAILURE; Debug.LogError(sqlEx); } return(result); }
public void Test_Update() { SqlEncap sql = new SqlEncap(); string tableName = "Maze"; Dictionary <string, string> setValue = new Dictionary <string, string>(); setValue.Add("X", "1"); setValue.Add("Y", "1"); setValue.Add("Z", "2"); Dictionary <string, string> condition = new Dictionary <string, string>(); condition.Add("ID", "1"); condition.Add("MAZE_ID", "9"); Assert.AreEqual("UPDATE Maze SET X = 1, Y = 1, Z = 2 WHERE ID = 1 And MAZE_ID = 9;", sql.Update(tableName, setValue, condition)); }