static internal void CreateSortFields(HqlValuesComparer list, ArrayList q) { int counter = 0; int current = 0; if (q == null || q.Count == 0) { return; } // every level within braces are at the same level, and each nested query gets it's own // example: // dim = 0 dim = 0 dim = 1 dim = 1 dim = 2 dim = 2 dim = 0 dim = 3 dim = 3 // ON a.field1 = "A" and a.field1 = "B" and (a.field1 = "C" and a.field1 = "D") and (a.field1 = "E" or a.field1 = "F") and a.field1 = "G" and (a.field1 = "H" and a.field1 = "I")"); // result of above: A, B, D, E // see how many dim can be added for (int dim = 0; ; dim++) { int countElement = 0; int countOr = 0; counter = 0; current = 0; HqlEvaluator.CountOrs(q, ref counter, dim, ref current, ref countElement, ref countOr, null); if (countElement == 0) { break; } if (countOr == 0) { // Add this dim counter = 0; current = 0; CountOrs(q, ref counter, dim, ref current, ref countElement, ref countOr, list); } else { // found ORs in this dim break; // In the above case, I am leaving out the DIM3 from the join but this is a small // percentage case and I'm not really worried it about since if i just get DIM 0 on most queries // that is PLENTY good joining. } } }
public void CreateSortFields(HqlValuesComparer list) { HqlEvaluator.CreateSortFields(list, _q); }
static internal void CountOrs(ArrayList q, ref int counter, int expectedDim, ref int currentDim, ref int countElements, ref int countOrs, HqlValuesComparer list) { if (counter > q.Count) { throw new Exception("Unexpected end of WHERE evaluation"); } int thisDim = currentDim; for (; ;) { if (counter >= q.Count) { break; } Object o = q[counter]; counter++; if (o is HqlToken) { // open paren := token.Type == HqlWordType.KEYWORD && token.Keyword == HqlKeyword.OPENPAREN // closed paren := token.Type == HqlWordType.KEYWORD && token.Keyword == HqlKeyword.CLOSEDPAREN // and_or := token.Type == HqlWordType.KEYWORD && token.Keyword == HqlKeyword.AND_OR // HqlToken token = (HqlToken)o; if (token.WordType == HqlWordType.KEYWORD && token.Keyword == HqlKeyword.OPENPAREN) { currentDim++; CountOrs(q, ref counter, expectedDim, ref currentDim, ref countElements, ref countOrs, list); continue; } else if (token.WordType == HqlWordType.KEYWORD && token.Keyword == HqlKeyword.CLOSEDPAREN) { return; } else if (token.WordType == HqlWordType.KEYWORD && token.Keyword == HqlKeyword.OR) { if (thisDim == expectedDim) { countOrs++; } continue; } else if (token.WordType == HqlWordType.KEYWORD && token.Keyword == HqlKeyword.AND) { continue; } else { throw new Exception("Unknown type of HqlToken in WHERE clause"); } } else if (o is HqlCompareToken) { if (thisDim == expectedDim) { countElements++; if (list != null) { list.Add((HqlCompareToken)o); } } continue; } else { throw new Exception("Unknown type of object in WHERE evaluation."); } } return; }