private Table Select(Node Root) { From(Root.Children[1]); SelectKeys(Root.Children[0]); Key ForeignKey = Tables.Last().Keys.First(); for (int i = 2; i < Root.Children.Count; i++) { if (Joiners.ContainsKey(Root.Children[i].HostedToken.Type)) { ForeignKey = Joiners[Root.Children[i].HostedToken.Type](Root.Children[i]).Keys.First(); SelectKeys(Root.Children[0]); } else if (Conditionals.ContainsKey(Root.Children[i].HostedToken.Type)) { Conditionals[Root.Children[i].HostedToken.Type](Root.Children[i]); } } Table Response = new Table(Tables[0].Name + ((Tables.Count > 1)?"featuring " + Tables[1].Name:"")); Response.Records = Filters.Last().Value.Count; //the last table is treated as a reference point for joiners //therfore left join inverse the 2 tables to maintain //Where the last table will be joined completely Dictionary <string, List <int> > KIndices = new Dictionary <string, List <int> >(); foreach (Table Ti in Tables) { KIndices.Add(Ti.Name, new List <int>()); foreach (Key Ki in KeyIDs[Ti.Name]) { Response.Keys.Add(new Key(Ki, true)); KIndices[Ti.Name].Add(Ti.getKeyIndex(Ki.Name)); } } Dictionary <int, int> assistiveIndex = indexFilter(ForeignKey); byte[] nullarr = { 0, 0, 0, 0, 0, 0, 0, 0 }; // \u0000 standard null for (int i = 0; i < Response.Records; i++) { List <byte[]> Record = new List <byte[]>(); //Assembling records that span multiple tables if (assistiveIndex.ContainsKey(BitConverter.ToInt32(Tables.Last().Keys[0].DATA[Filters[Tables.Last().Name][i]], 0)) && i < Filters[Tables.First().Name].Count) { Record.AddRange(Tables.First().RetrieveRecord(KIndices[Tables.First().Name], assistiveIndex[BitConverter.ToInt32(Tables.Last().Keys[0].DATA[Filters[Tables.Last().Name][i]], 0)])); if (Tables.Count > 1) { Record.AddRange(Tables.Last().RetrieveRecord(KIndices[Tables.Last().Name], Filters[Tables.Last().Name][i])); } } else { Record.AddRange(Enumerable.Repeat(nullarr, (KIndices[Tables.First().Name].Count))); Record.AddRange(Tables.Last().RetrieveRecord(KIndices[Tables.Last().Name], Filters[Tables.Last().Name][i])); } Response.AppendRecord(Enumerable.Range(0, Response.KeysCount).ToList(), Record); } return(Response); }