//Get multiple rows where the value of the given column equals the given one public VDB_TableRow[] GetRowsWhereColumnEquals(string column, VDB_Value equal) { List<VDB_TableRow> foundRows = new List<VDB_TableRow>(); int columnNum = GetColumnNumberFromName(column); for (int i = 0; i < rows.Count; i++) { if (rows[i].values[columnNum].IsEqualTo(equal)) { foundRows.Add(rows[i]); } } return foundRows.ToArray(); }
static void AddRow(List<string> args) { Console.Write("Adding row... "); VDB_Database database = VDB_Database.Import(filename); VDB_Table table = database.GetTable(args[0]); VDB_Value[] values = new VDB_Value[args.Count - 1]; for(int i = 0; i < values.Length; i++) { values[i] = args[i + 1]; } table.InsertRow(values); database.Export(filename); WriteTestResult(true); }
public bool IsEqualTo(VDB_Value other) { return other.valueType == valueType && data.SequenceEqual<byte>(other.data); }
//Get the row where the value of the given column equals the given one public VDB_TableRow GetRowWhereColumnEquals(string column, VDB_Value equal) { int columnNum = GetColumnNumberFromName(column); for (int i = 0; i < rows.Count; i++) { if (rows[i].values[columnNum].IsEqualTo(equal)) { return rows[i]; } } throw new VDB_RowNotFoundException(); }
public void RemoveColumn(string columnName) { for (int i = 0; i < columnNames.Length; i++) { System.IO.File.WriteAllText("C:/Development/Temp/" + i.ToString() + ".txt", ""); if (columnNames[i] == columnName) { //Move values (x -> x -1) for (int j = 0; j < rows.Count; j++) { VDB_Value[] newValues = new VDB_Value[columnNames.Length - 1]; for (int k = 0; k < columnNames.Length - 1; k++) { if (k < i) { newValues[k] = rows[j].values[k]; continue; } newValues[k] = rows[j].values[k + 1]; } rows[j].values = new VDB_Value[newValues.Length]; rows[j].values = newValues; } //Move columns (x -> x - 1) string[] newColumnNames = new string[columnNames.Length - 1]; for (int j = 0; j < columnNames.Length - 1; j++) { if (j < i) { newColumnNames[j] = columnNames[j]; continue; } newColumnNames[j] = columnNames[j + 1]; } columnNames = new string[newColumnNames.Length]; columnNames = newColumnNames; columnCount = columnNames.Length; return; } } }
//Insert new column after other columns void InsertColumnSimple(string columnName) { //Make room for new column and set it's name Array.Resize<string>(ref columnNames, columnNames.Length + 1); columnNames[columnNames.Length - 1] = columnName; //Make room for the new column's values in old rows for(int i = 0; i < rows.Count; i++) { Array.Resize<VDB_Value>(ref rows[i].values, rows[i].values.Length + 1); VDB_Value newValue = new VDB_Value(); newValue.SetNull(); rows[i].values[rows[i].values.Length - 1] = newValue; } }
//Insert new column after the given one void InsertColumnComplex(string columnName, string afterColumn) { int afterColumnNumber = GetColumnNumberFromName(afterColumn); //Cast columnNames array to list to insert a new value in the middle of it List<string> tempColumnList = new List<string>(); tempColumnList.AddRange(columnNames); tempColumnList.Insert(afterColumnNumber + 1, columnName); //Then cast it back columnNames = tempColumnList.ToArray(); //Then do the same with all the values in rows for (int i = 0; i < rows.Count; i++) { VDB_TableRow row = rows[i]; List<VDB_Value> tempRowValues = new List<VDB_Value>(); tempRowValues.AddRange(row.values); VDB_Value newValue = new VDB_Value(); newValue.SetNull(); tempRowValues.Insert(afterColumnNumber + 1, newValue); row.values = tempRowValues.ToArray(); } }
public void RemoveColumn(string columnName) { float progressPercentage = 0; for (int i = 0; i < columnNames.Length; i++) { if (columnNames[i] == columnName) { //Move values (x -> x - 1) for (int j = 0; j < rows.Count; j++) { progressPercentage = (j + 1) / ((float)rows.Count / 100); VDB_Value[] newValues = new VDB_Value[columnNames.Length - 1]; for (int k = 0; k < columnNames.Length - 1; k++) { if (k < i) { newValues[k] = rows[j].values[k]; continue; } newValues[k] = rows[j].values[k + 1]; } rows[j].values = new VDB_Value[newValues.Length]; rows[j].values = newValues; } //Move columns (x -> x - 1) string[] newColumnNames = new string[columnNames.Length - 1]; for (int j = 0; j < columnNames.Length - 1; j++) { if (j < i) { newColumnNames[j] = columnNames[j]; continue; } newColumnNames[j] = columnNames[j + 1]; } columnNames = new string[newColumnNames.Length]; columnNames = newColumnNames; return; } } }