/// SetSensorMatrixById /// <summary> /// Set the environment record by the sensor. /// Could be any size. /// </summary> /// <param name="sensorId"></param> /// /// <param name="matrix"></param> /// <returns></returns> public int SetSensorMatrixById(int timestamp, int sensorId, int[,] matrix) { SqlEncap sql = new SqlEncap(); int result = Constants.RESPONSE_CODE_SUCCESS; List <string> columnName = new List <string>(); List <string> value = new List <string>(); try { columnName.Add(Constants.SENSOR_TIMESTAMP); columnName.Add(Constants.COLUMN_ID); columnName.Add(Constants.SENSOR_CONTENT); string str = "'"; for (int i = 0; i <= matrix.GetUpperBound(0); i++) { str += ""; for (int j = 0; j <= matrix.GetUpperBound(1); j++) { str += matrix[i, j]; if (j != matrix.GetUpperBound(1)) { str += ","; } } str += ""; if (i != matrix.GetUpperBound(0)) { str += ";"; } } str += "'"; value.Clear(); value.Add(timestamp.ToString()); value.Add(sensorId.ToString()); value.Add(str); //Debug.Log(str); dbCommand = dbConnection.CreateCommand(); dbCommand.CommandText = sql.Insert(Constants.TABLE_SENSOR, columnName, value); //Debug.Log(dbCommand.CommandText); dbCommand.ExecuteNonQuery(); } catch (SqliteException sqlEx) { result = Constants.RESPONSE_CODE_FAILURE; Debug.LogError(sqlEx); } return(result); }
/// <summary> /// Create a new maze by id and matrix /// </summary> /// <param name="mazeId"></param> /// <param name="exploredMaze"></param> /// <returns> /// The successfulness of creating explored maze. /// </returns> public int CreateExploredMaze(int mazeId, int[,] exploredMaze) { actived_mazeId = mazeId; SqlEncap sql = new SqlEncap(); int result = Constants.RESPONSE_CODE_SUCCESS; List <string> columnName = new List <string>(); List <string> value = new List <string>(); try { columnName.Add(Constants.COLUMN_ID); columnName.Add(Constants.MAZE_MATRIX); string str = "'"; for (int i = 0; i <= exploredMaze.GetUpperBound(0); i++) { str += ""; for (int j = 0; j <= exploredMaze.GetUpperBound(1); j++) { str += exploredMaze[i, j]; if (j != exploredMaze.GetUpperBound(1)) { str += ","; } } str += ""; if (i != exploredMaze.GetUpperBound(0)) { str += ";"; } } str += "'"; value.Clear(); value.Add(mazeId.ToString()); value.Add(str); dbCommand = dbConnection.CreateCommand(); dbCommand.CommandText = sql.Insert(Constants.TABLE_MAZE, columnName, value); dbCommand.ExecuteNonQuery(); } catch (SqliteException sqlEx) { result = Constants.RESPONSE_CODE_FAILURE; Debug.LogError(sqlEx); } return(result); }
public void Test_Insert() { SqlEncap sql = new SqlEncap(); string tableName = "Maze"; List <string> columnName = new List <string>(); columnName.Add("X"); columnName.Add("Y"); columnName.Add("Z"); List <string> value = new List <string>(); value.Add("1"); value.Add("2"); value.Add("'maze no.1'"); Assert.AreEqual("INSERT INTO Maze (X,Y,Z) VALUES (1,2,'maze no.1');", sql.Insert(tableName, columnName, value)); }