public bool Evaluate(HqlRecord record) { int counter = 0; if (_q == null || _q.Count == 0) { return(true); } bool?res = HqlEvaluator.Evaluate(record, _q, ref counter); return(HqlEvaluator.EvalNullableBool(res, false)); }
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 bool Evaluate(HqlRecord record) { switch (_type) { case HqlCompareTokenType.SINGLE: return(HqlEvaluator.EvalNullableBool(EvaluateSingle(record), false)); case HqlCompareTokenType.IN: return(HqlEvaluator.EvalNullableBool(EvaluateInValues(record), false)); case HqlCompareTokenType.NOT_IN: bool b = HqlEvaluator.EvalNullableBool(EvaluateInValues(record), false); // TODO, should this be true? return(!b); default: throw new NotSupportedException("Unknown type of COMPARETOKEN"); } }
public bool EvaluateJoin(HqlValues values, bool returnOnNull) { // I need the comparer to know if it's part of this table // then compare if against a literal and otherwise return true // example: if look for table (a) // 1) (a.field1 = 'bob') <= actually evaluate // 2) (a.field1 = b.field1) <= return true because we need to save this record for // later evaluation // 3) (b.field1 = 'joe') <= return false because i don't care about this record // 4) (b.field1 is NULL) <= return true because I can't evaluate this here int counter = 0; if (_q == null || _q.Count == 0) { return(true); } bool?res = HqlEvaluator.EvaluateJoin(values, _q, ref counter); //return EvalNullableBool(res, true); return(HqlEvaluator.EvalNullableBool(res, returnOnNull)); }
/////////////////////// // Private protected bool ParseCompare(HqlTokenProcessor processor, bool andorAllowed, ref int openParen, bool closedAllowed, HqlKeyword thisKeyword, HqlClause select) { #if DEBUG if (thisKeyword != HqlKeyword.WHERE && thisKeyword != HqlKeyword.HAVING && thisKeyword != HqlKeyword.ON) { throw new Exception("Cannot access ParseCompare with invalid keyword"); } #endif HqlToken token = processor.GetToken(); if (processor.MatchesEndOfProcessing()) { return(false); } if (token.WordType == HqlWordType.KEYWORD && token.Keyword == HqlKeyword.CLOSEDPAREN) { if (!closedAllowed) { throw new Exception("Empty Parens found"); } openParen--; return(false); } if (token.WordType == HqlWordType.KEYWORD && ( ( thisKeyword == HqlKeyword.ON && ( token.Keyword == HqlKeyword.WHERE || token.Keyword == HqlKeyword.INNER || token.Keyword == HqlKeyword.RIGHT_OUTER || token.Keyword == HqlKeyword.LEFT_OUTER || token.Keyword == HqlKeyword.FULL_OUTER || token.Keyword == HqlKeyword.WHERE || token.Keyword == HqlKeyword.GROUPBY || token.Keyword == HqlKeyword.HAVING || token.Keyword == HqlKeyword.ORDERBY || token.Keyword == HqlKeyword.WITH ) ) || ( thisKeyword == HqlKeyword.WHERE && ( token.Keyword == HqlKeyword.INNER || token.Keyword == HqlKeyword.RIGHT_OUTER || token.Keyword == HqlKeyword.LEFT_OUTER || token.Keyword == HqlKeyword.FULL_OUTER || token.Keyword == HqlKeyword.WHERE || token.Keyword == HqlKeyword.GROUPBY || token.Keyword == HqlKeyword.HAVING || token.Keyword == HqlKeyword.ORDERBY || token.Keyword == HqlKeyword.WITH ) ) || ( thisKeyword == HqlKeyword.HAVING && ( token.Keyword == HqlKeyword.ORDERBY || token.Keyword == HqlKeyword.WITH ) ) ) ) { return(false); } if (token.WordType == HqlWordType.KEYWORD && (token.Keyword == HqlKeyword.AND || token.Keyword == HqlKeyword.OR)) { if (!andorAllowed) { throw new Exception("Unexpected AND/OR"); } _q.Add(token); processor.MoveNextToken(); return(true); } if (token.WordType == HqlWordType.KEYWORD && token.Keyword == HqlKeyword.OPENPAREN) { openParen++; _q.Add(token); processor.MoveNextToken(); for (int i = 0; ; i++) { if (!ParseCompare(processor, (i > 0), ref openParen, (i > 0), thisKeyword, select)) { break; } } token = processor.GetToken(); if (token.WordType != HqlWordType.KEYWORD || token.Keyword != HqlKeyword.CLOSEDPAREN) { throw new Exception(String.Format("Unbalanced Parens in {0}", _name)); } _q.Add(token); processor.MoveNextToken(); } else { HqlToken token1 = token; if (token1.WordType == HqlWordType.UNKNOWN && !processor.CheckForTokenReference(ref token1)) { throw new Exception(String.Format("Unknown {0} reference to {1}", _name, token1.Data)); } // HACK - sort of a hack this says if I can't find this field // then add it to the select but make it not print out HqlEvaluator.VerifyFieldPresence(select, token1); // END HACK processor.MoveNextToken(); HqlToken compare = processor.GetToken(); // this could be // - a COMPARE such as |field > 0| // - an IN such as |field in ('A', 'B')| // - an IN such as |field in (select item from bob)| if (compare.WordType == HqlWordType.KEYWORD && compare.Keyword == HqlKeyword.COMPARE) { processor.MoveNextToken(); HqlToken token2 = processor.GetToken(); if (token2.WordType == HqlWordType.UNKNOWN && !processor.CheckForTokenReference(ref token2)) { throw new Exception(String.Format("Unknown WHERE reference to {0}", token2.Data)); } // HACK - sort of a hack this says if I can't find this field // then add it to the select but make it not print out HqlEvaluator.VerifyFieldPresence(select, token2); // END HACK HqlCompareToken comparetoken = new HqlCompareToken(token1, compare, token2); _q.Add(comparetoken); processor.MoveNextToken(); } else if (compare.WordType == HqlWordType.KEYWORD && (compare.Keyword == HqlKeyword.IN || compare.Keyword == HqlKeyword.NOT_IN)) { // now need to check for values or select processor.MoveNextToken(); HqlToken paren = processor.GetToken(); if (paren.WordType != HqlWordType.KEYWORD || paren.Keyword != HqlKeyword.OPENPAREN) { throw new Exception(String.Format("Expected an open paren after IN in {0}", _name)); } ArrayList compareValues = new ArrayList(); bool ExpectedValues = true; for (int count = 0; ; count++) { processor.MoveNextToken(); HqlToken val = processor.GetToken(); if (val.WordType == HqlWordType.KEYWORD && val.Keyword == HqlKeyword.CLOSEDPAREN) { break; } if (val.WordType == HqlWordType.KEYWORD && val.Keyword == HqlKeyword.COMMA) { ExpectedValues = true; continue; } if (val.WordType == HqlWordType.KEYWORD && val.Keyword == HqlKeyword.SELECT) { ExpectedValues = false; if (count != 0) { throw new Exception("You can only put a nested query in an IN statement if it is the only value present"); } HqlTokenProcessor.GetResultOfNestedQueryForInStatement(processor, compareValues); } else if ( val.WordType == HqlWordType.TEXT || val.WordType == HqlWordType.INT || val.WordType == HqlWordType.FLOAT || val.WordType == HqlWordType.LITERAL_STRING || val.WordType == HqlWordType.FIELD || val.WordType == HqlWordType.SCALAR ) { ExpectedValues = false; compareValues.Add(val); // HACK - sort of a hack this says if I can't find this field // then add it to the select but make it not print out HqlEvaluator.VerifyFieldPresence(select, val); // END HACK } else { throw new Exception("Found invalid value in IN clause"); } } if (ExpectedValues) { throw new Exception("Expected additional values in IN clause"); } if (compareValues.Count == 0) { throw new Exception("No values present in IN clause"); } HqlCompareToken comparetoken = new HqlCompareToken(token1, compare, compareValues); _q.Add(comparetoken); processor.MoveNextToken(); } else { throw new Exception(String.Format("Unknown {0} compare", _name)); } } return(true); }
public void CreateSortFields(HqlValuesComparer list) { HqlEvaluator.CreateSortFields(list, _q); }