static internal void VerifyFieldPresence(HqlClause select, HqlToken token) { if (select != null && token.WordType == HqlWordType.FIELD) { select.VerifyFieldsPresent(token.Field); //if (!select.ContainsField(token.Field)) //{ // token.Field.PrintResult = false; // select.AddField(token.Field); //} } }
static private void SanityCheckTableReferences(HqlClause clause, HqlFrom from) { if (clause == null || clause.FieldGroup == null) { return; } for (int i = 0; i < clause.FieldGroup.Count; ++i) { if (clause.FieldGroup[i].HasTableReference) { if (!from.ContainsTableReference(clause.FieldGroup[i].TableReference)) { throw new Exception(String.Format("Unable to find table reference for |{0}| in the FROM clause", clause.FieldGroup[i].TableReference)); } } } }
/////////////////////// // Static Functions private static object[] CreateRecordKey(HqlRecord record, HqlOrderBy order, HqlClause group, HqlClause output, int linenum) { int orderlength = order.Count; int grouplength = (group.Count == 0) ? 1: group.Count; int outputlength = ((output == null) ? 0 : output.Count); int length = orderlength + grouplength + outputlength; object[] keys = new object[length]; object[] orderarray = order.GetKeyValues(record); object[] grouparray; if (group.Count > 0) { grouparray = group.GetValues(record); } else { grouparray = new object[1] { linenum } }; object[] outputarray = ((output == null) ? null : output.GetValues(record)); int counter = 0; orderarray.CopyTo(keys, counter); counter += orderarray.Length; grouparray.CopyTo(keys, counter); counter += grouparray.Length; if (outputarray != null) { outputarray.CopyTo(keys, counter); //counter += outputarray.Length; } return(keys); }
/////////////////////// // Static Functions /////////////////////// // Constructors public HqlHaving(HqlClause select) : base(NAME_HAVING) { _select = select; }
public void Parse(HqlTokenProcessor processor, HqlKeyword firstToken, HqlKeyword thisKeyword, HqlClause select) { HqlToken token; int openParen = 0; // first thing should be WHERE token = processor.GetToken(); if (token.WordType != HqlWordType.KEYWORD || token.Keyword != firstToken) { return; } // now pull back things until you get to EOF or GROUP processor.MoveNextToken(); for (int i = 0; ; i++) { if (!ParseCompare(processor, (i > 0), ref openParen, true, thisKeyword, select)) { break; } } if (openParen != 0) { throw new Exception("Unbalanced parens"); } }
/////////////////////// // 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); }
private static HqlResultRow CreateObjectArrayValue(HqlClause order, HqlClause select, HqlClause output) { HqlResultRow row = new HqlResultRow(order.FieldGroup, select.FieldGroup, ((output == null) ? null : output.FieldGroup)); return(row); }