static public void GetResultOfNestedQueryForInStatement(HqlTokenProcessor processor, ArrayList list) { try { HqlStream cs = new HqlStream(processor.GetRemainingSql(true), ")"); if (cs.CountReturnVisibleFields != 1) { throw new Exception("Internal Hql streams must return only one value"); } for (; !cs.EndOfStream;) { string s = cs.ReadLine(); if (s == null || s.Length == 0) { continue; } HqlToken token = new HqlToken(HqlWordType.UNKNOWN, s); HqlTokenProcessor.Categorize(ref token, false, false, true, false); if (token.WordType == HqlWordType.UNKNOWN) { token = new HqlToken(HqlWordType.LITERAL_STRING, token.Data); } list.Add(token); } cs.Close(); processor.SetRemainingSql(cs.RemainingSql); } catch (Exception ex) { throw new Exception("Unable to execute nested IN statement SQL", ex); } }
/////////////////////// // Overridden functions public override string ToString() { switch (_type) { case HqlCompareTokenType.SINGLE: return(String.Format("{0} {1} {2}", Token1.ToString(), Compare.Data, Token2.ToString())); case HqlCompareTokenType.IN: { StringBuilder sb = new StringBuilder("IN ("); for (int i = 0; i < _values.Count; ++i) { HqlToken token = (HqlToken)_values[i]; if (i > 0) { sb.Append(", "); } sb.Append(token.ToString()); } sb.Append(")"); return(sb.ToString()); } default: throw new NotSupportedException("Unknown type of COMPARETOKEN"); } }
private void LoadToken(HqlToken token) { if (token == null) { return; } switch (token.WordType) { case HqlWordType.FIELD: case HqlWordType.SCALAR: LoadField(token.Field); break; case HqlWordType.KEYWORD: case HqlWordType.FLOAT: case HqlWordType.INT: case HqlWordType.LITERAL_STRING: case HqlWordType.TEXT: case HqlWordType.NULL: // don't cares break; case HqlWordType.FUNCTION: default: throw new Exception(String.Format("Error. what sort of other data can be found in HqlDataSource:LoadToken|{0}|", token.WordType)); } }
public bool ContainsField(HqlField field) { for (int i = 0; i < _q.Count; ++i) { Object o = _q[i]; if (o is HqlToken) { HqlToken token = (HqlToken)o; if (token.Field != null && token.Field.ContainsField(field)) { return(true); } } else if (o is HqlCompareToken) { HqlCompareToken ct = (HqlCompareToken)o; if (ct.ContainsField(field)) { return(true); } } else { throw new Exception("Unknown object in list"); } } return(false); }
public bool ContainsRownum(bool OnlyWithoutTableReference) { for (int i = 0; i < _q.Count; ++i) { Object o = _q[i]; if (o is HqlToken) { HqlToken token = (HqlToken)o; if (token.Field != null && token.Field.ContainsRownum(OnlyWithoutTableReference)) { return(true); } } else if (o is HqlCompareToken) { HqlCompareToken ct = (HqlCompareToken)o; if (ct.ContainsRownum(OnlyWithoutTableReference)) { return(true); } } else { throw new Exception("Unknown object in list"); } } return(false); }
/////////////////////// // Overridden functions public override string ToString() { StringBuilder sb = new StringBuilder(); int depth = 0; int indent = 3; for (int i = 0; i < _q.Count; ++i) { object o = _q[i]; if (o is HqlCompareToken) { sb.Append(new String(' ', depth * indent) + ((HqlCompareToken)o).ToString() + System.Environment.NewLine); } else if (o is HqlToken) { HqlToken t = ((HqlToken)o); if (t.Keyword == HqlKeyword.CLOSEDPAREN) { depth--; } sb.Append(new String(' ', depth * indent) + t.Data + System.Environment.NewLine); if (t.Keyword == HqlKeyword.OPENPAREN) { depth++; } } else { sb.Append(new String(' ', depth * indent) + "What is " + o.GetType() + "????" + System.Environment.NewLine); } } return(sb.ToString()); }
private bool MoveNextTokenCheckASReference() { if (_token.WordType == HqlWordType.UNKNOWN && MatchNext(".")) { HqlToken tableReference = _token; MoveNextToken(); HqlToken dot = _token; if (dot.WordType != HqlWordType.UNKNOWN || !dot.Data.Equals(".")) { throw new Exception("Unknown dot in field reference"); } MoveNextToken(); if ( (_token.WordType == HqlWordType.FIELD) || (_token.WordType == HqlWordType.KEYWORD && _token.Keyword == HqlKeyword.STAR) ) { // pass through } else { throw new Exception("Unknown field referenced"); } _token.Field.TableReference = tableReference.Data; return(true); } return(false); }
/////////////////////// // Private private void ProcessOutFilename(HqlTokenProcessor processor) { if (OutputFilename == null || OutputFilename.Length == 0) { throw new Exception("Output filename cannot be empty"); } if (OutputFilename.Contains("{")) { _output = new HqlOutput(OutputFilename, this); int currloc = 0; int startloc = 0; for (; ;) { bool FoundEndBrace = false; currloc = OutputFilename.IndexOf('{', startloc); if (currloc < 0 || currloc >= OutputFilename.Length) { break; } startloc = currloc; string innerField = String.Empty; for (currloc++; currloc < OutputFilename.Length; currloc++) { if (OutputFilename[currloc] == '}') { // this means that in the string was {} because there is no gap between them for characters if (startloc + 1 == currloc) { throw new Exception(String.Format("Cannot have an empty field in OUTPUT name of |{0}|", OutputFilename)); } startloc = currloc; FoundEndBrace = true; break; } innerField += OutputFilename[currloc]; } if (!FoundEndBrace) { throw new Exception(String.Format("Need a closing brace in filename |{0}|", OutputFilename)); } HqlTokenProcessor newProcessor = new HqlTokenProcessor(innerField, processor); newProcessor.MoveNextToken(); HqlToken token = newProcessor.GetToken(); if (token.WordType == HqlWordType.UNKNOWN) { newProcessor.CheckForTokenReference(ref token); } if (token.WordType != HqlWordType.FIELD && token.WordType != HqlWordType.SCALAR) { throw new Exception("Info in braces is not a field"); } token.Field.FieldRename = innerField; // set the original name of the field for the {replace} _output.FieldGroup.AddField(token.Field); } } }
/// <summary> /// Created because there were originally more checks done in here /// </summary> /// <param name="token1"></param> /// <param name="token2"></param> /// <returns></returns> static bool NeedsJoinEvaluation(HqlToken token1, HqlToken token2) { if (!token1.NeedsEvaluation && !token2.NeedsEvaluation) { return(false); } return(true); }
static private bool NotNullAndContainsField(HqlToken t, HqlField field) { if (t == null || t.Field == null) { return(false); } return(t.Field.ContainsField(field)); }
static private bool NotNullAndContainsRownum(HqlToken t, bool OnlyWithoutTableReference) { if (t == null || t.Field == null) { return(false); } return(t.Field.ContainsRownum(OnlyWithoutTableReference)); }
/////////////////////// // Constructors public HqlCompareToken(HqlToken token1, HqlToken compare, HqlToken token2) { _type = HqlCompareTokenType.SINGLE; _token1 = token1; _compare = compare; _compare.Data = _compare.Data.ToLower(); _token2 = token2; // _values = null; // unnecessary }
public override bool Equals(object obj) { if (obj != null && obj is HqlToken) { HqlToken t = (HqlToken)obj; return(Equals(t)); } return(false); }
public override object GetValue(HqlToken t) { object o; if (HasValue(t, out o)) { return(o); } throw new Exception("Unknown type in Values"); }
public virtual object GetValue(HqlToken t) { if (t.NeedsEvaluation) { return(GetValue(t.Field)); } else { return(t.EvaluatedData); } }
public bool CheckForTokenReference(ref HqlToken token) { bool ret; ret = HqlTokenProcessor.CheckForTokenReference(_processor, ref token); if (ret) { return(ret); } return(HqlTokenProcessor.CheckForTokenReference(this, ref token)); }
public bool Equals(HqlToken token) { if (_type != token._type) { return(false); } if (_field == null && token._field == null) { } else if (!_field.Equals(token._field)) { return(false); } if (!_keyword.Equals(token._keyword)) { return(false); } if (_data == null && token._data == null) { } else if (!_data.Equals(token._data)) { return(false); } if (_parsed == null && token._parsed == null) { } else if (!_parsed.Equals(token._parsed)) { return(false); } if (_hadEquation != token._hadEquation) { return(false); } if (_hadQuotes != token._hadQuotes) { return(false); } if (_hadTicky != token._hadTicky) { return(false); } return(true); }
public bool HasValue(HqlToken t, out object o) { if (t.NeedsEvaluation) { return(HasValue(t.Field, out o)); } else { o = t.EvaluatedData; return(true); } }
private bool MoveNextTokenCheckScalar() { if (_token.WordType == HqlWordType.KEYWORD && _token.Keyword == HqlKeyword.SCALAR && MatchNext("(")) { HqlScalar scalar = new HqlScalar(); scalar.Parse(this); _token = new HqlToken(HqlWordType.SCALAR, new HqlField(HqlFieldType.SCALAR, scalar)); return(true); } return(false); }
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); //} } }
public bool MatchesEndOfProcessing() { HqlToken t = GetToken(); if (t.WordType == HqlWordType.END_OF_LINE) { return(true); } if (t.WordType != HqlWordType.LITERAL_STRING && t.Data != null && t.Data.Equals(_settings.ExpectedEndOfQuery)) { return(true); } return(false); }
private void ChangeTokenToField() { if (_token.WordType == HqlWordType.KEYWORD) { if (_token.Keyword == HqlKeyword.STAR) { _token = new HqlToken(HqlWordType.FIELD, new HqlField(HqlFieldType.STAR)); } else if (_token.Keyword == HqlKeyword.NULL) { _token = new HqlToken(HqlWordType.NULL); } } }
private bool EvaluateJoinInValues(HqlValues values) { object v1 = values.GetValue(Token1); for (int i = 0; i < _values.Count; ++i) { HqlToken t = (HqlToken)_values[i]; object v2 = values.GetValue(t); if (Evaluate(v1, v2, Compare)) { return(true); } } return(false); }
static public bool Evaluate(object v1, object v2, HqlToken compare) { switch (compare.Data) { case "not inlike": case "not in like": case "in not like": case "not like": return(!Like(v1, v2)); case "in like": case "inlike": case "like": return(Like(v1, v2)); } MakeAppropriateObjects(ref v1, ref v2); switch (compare.Data) { case "<": return(LessThan(v1, v2)); case ">": return(!(LessThan(v1, v2) || Equal(v1, v2))); case "<=": return(LessThan(v1, v2) || Equal(v1, v2)); case ">=": return(!LessThan(v1, v2)); case "in": case "=": case "not in": case "is": return(Equal(v1, v2)); case "<>": case "!=": case "is not": return(!Equal(v1, v2)); default: throw new NotSupportedException("Unknown type of compare"); } }
static private bool ExistsIn(HqlToken t, HqlFieldGroup group) { if (t.WordType != HqlWordType.FUNCTION && t.WordType != HqlWordType.SCALAR && t.WordType != HqlWordType.FIELD) { return(true); } for (int i = 0; i < group.Count; ++i) { if (group[i].Equals(t.Field)) { return(true); } } return(false); }
private bool ExistsInValues(HqlFieldGroup group) { if (!ExistsIn(Token1, group)) { return(false); } for (int i = 0; i < _values.Count; ++i) { HqlToken t = (HqlToken)_values[i]; if (!ExistsIn(t, group)) { return(false); } } return(true); }
public void SetOption(HqlToken token) { if (_options == null) { _options = new HqlCalcOptions(); } if (token.WordType == HqlWordType.INT) { _options.DecimalPrintPlaces = token.ParsedAsInt; } else if (token.WordType == HqlWordType.LITERAL_STRING) { _options.DecimalPrintFormat = (string)token.Data; } else { throw new Exception("Unknown option to Function"); } }
private void AddTokenToInternalList(HqlToken token) { if (_fixedwidthTokens == null) { _fixedwidthTokens = new ArrayList(); } for (int i = 0; i < _fixedwidthTokens.Count; ++i) { HqlToken t = (HqlToken)_fixedwidthTokens[i]; if (token.Field.Name.Equals(t.Field.Name)) { if (token.Field.Start != t.Field.Start || token.Field.Length != t.Field.Length) { throw new Exception("Same name given to more than one fixed-width field!"); } } } _fixedwidthTokens.Add(token); }
public HqlCompareToken(HqlToken token1, HqlToken compare, ArrayList values) { if (compare.Keyword == HqlKeyword.IN) { _type = HqlCompareTokenType.IN; } else if (compare.Keyword == HqlKeyword.NOT_IN) { _type = HqlCompareTokenType.NOT_IN; } else { throw new ArgumentException("Unknown 'IN' type"); } _token1 = token1; _compare = compare; _compare.Data = _compare.Data.ToLower(); // _token2 = null; // unnecessary _values = values; }
public HqlToken GetOptionData(string option) { MoveNextToken(); HqlToken token = GetToken(); // optional = sign if (token.WordType == HqlWordType.KEYWORD && token.Data.Equals("=")) { // that's fine, eat it! MoveNextToken(); token = GetToken(); } if (MatchesEndOfProcessing()) { throw new Exception(String.Format("Unexpected END-OF-LINE after {0}", option)); } return(token); }