public void insert(string tableName, object[] item) { //find the table that they want to insert into var table = Tables.FirstOrDefault(x => x.Item1.ToLower() == tableName.ToLower()); if (table != null) { //put it into a temp variable until we know that all the columns are in the correct format var tempTable = table.Item2.Columns.ToArray(); var temp = new Row(tempTable.Length); //Make sure they gave us the right amount of columns if (tempTable.Length != item.Length) { //Some fun speech synth stuff return; } for (var i = 0; i < item.Length; i++) { //Make sure that it isn't null if it wasn't suppose too if (!tempTable[i].Nullable && (item[i] == null || item[i].ToString() == "")) { return; } //Make sure that if it is null that we don't go through the other checks. //the array at the end will get incremented and the one that was missed will be put to null anyway if (!(item[i] == null || item[i].ToString() == "")) { //Make sure the data is in the correct length if (item[i].ToString().Length > tempTable[i].Length) { return; } //Make sure the Item is the correct type that they specified if (checkType(item[i].GetType().ToString(), tempTable[i].Type)) { return; } //add it to the array if passed all those checks temp.Cellsssss[i] = item[i]; } } //put it to the table if every column for that row passed inspection table.Item2.Rows.Add(temp); } }
public Relation union(string table1, string table2, string column1, string column2) { var tempColumns = new List<ColumnProperties>(); var tempColumnIndex1 = 0; var tempColumnIndex2 = 0; var tempTable1 = Tables.FirstOrDefault(x => x.Item1 == table1); foreach (var column in tempTable1.Item2.Columns) { tempColumns.Add(column); if (column.Name.Equals(column1)) { tempColumnIndex1 = tempTable1.Item2.Columns.IndexOf(column); } } var tempTable2 = Tables.FirstOrDefault(x => x.Item1 == table2); foreach (var column in tempTable2.Item2.Columns) { tempColumns.Add(column); if (column.Name.Equals(column2)) { tempColumnIndex2 = tempTable2.Item2.Columns.IndexOf(column); } } Relation tempRelation = new Relation(tempColumns); foreach (var row1 in tempTable1.Item2.Rows) { var tempRowsFromTable = new List<Row>(); for (int i = 0; i < tempTable2.Item2.Rows.Count; i++) { if (row1.Cellsssss[tempColumnIndex1].ToString().Equals(tempTable2.Item2.Rows[i].Cellsssss[tempColumnIndex2].ToString())) { tempRowsFromTable.Add(tempTable2.Item2.Rows[i]); } } //var temp = tempTable2.Item2.Rows.Where(x => x.Cellsssss[tempColumnIndex2] == row1.Cellsssss[tempColumnIndex1]); foreach (var table in tempRowsFromTable) { var tempRow = new Row(tempRelation.Columns.Count); for (int i = 0; i < row1.Cellsssss.Length; i++) { tempRow.Cellsssss[i] = row1.Cellsssss[i]; } for (int i = 0, j = row1.Cellsssss.Length; i < table.Cellsssss.Length; i++, j++) { tempRow.Cellsssss[j] = table.Cellsssss[i]; } tempRelation.Rows.Add(tempRow); } } return tempRelation; }
public Relation union(string table1, string table2, string column1, string column2) { var tempColumns = new List<ColumnProperties>(); var tempColumnIndex1 = 0; var tempColumnIndex2 = 0; var tempTable1 = Tables.FirstOrDefault(x => x.Item1.ToLower() == table1.ToLower()); if (tempTable1 != null) { //Get the index of the columns and add it to the tempColumns list foreach (var column in tempTable1.Item2.Columns) { tempColumns.Add(column); if (column.Name.Equals(column1)) { tempColumnIndex1 = tempTable1.Item2.Columns.IndexOf(column); } } var tempTable2 = Tables.FirstOrDefault(x => x.Item1.ToLower() == table2.ToLower()); if (tempTable2 != null) { //get the index of the second table and put it to the list also foreach (var column in tempTable2.Item2.Columns) { tempColumns.Add(column); if (column.Name.Equals(column2)) { tempColumnIndex2 = tempTable2.Item2.Columns.IndexOf(column); } } //Make a new relation from the list var tempRelation = new Relation(tempColumns); //Grab all the rows that match and put it to the relation foreach (var row1 in tempTable1.Item2.Rows) { //Grab all the rows from table 2 var tempRowsFromTable = new List<Row>(); for (var i = 0; i < tempTable2.Item2.Rows.Count; i++) { if ( row1.Cellsssss[tempColumnIndex1].ToString() .Equals(tempTable2.Item2.Rows[i].Cellsssss[tempColumnIndex2].ToString())) { tempRowsFromTable.Add(tempTable2.Item2.Rows[i]); } } //Find all the values that match and put it to the relation foreach (var table in tempRowsFromTable) { var tempRow = new Row(tempRelation.Columns.Count); for (var i = 0; i < row1.Cellsssss.Length; i++) { tempRow.Cellsssss[i] = row1.Cellsssss[i]; } for (int i = 0, j = row1.Cellsssss.Length; i < table.Cellsssss.Length; i++, j++) { tempRow.Cellsssss[j] = table.Cellsssss[i]; } tempRelation.Rows.Add(tempRow); } } return tempRelation; } } return null; }