private void ReloadControllerModels(QueryControllerModel fullQuery) { StoreParameters = fullQuery.StoreParameters; MainQuery = fullQuery.MainQuery; //MainQuery.FromTables = fullQuery.MainQuery.FromTables; SubQueryList = fullQuery.SubQueryList; SubQueryList.Insert(0, fullQuery.MainQuery); //RegenerateTableLinks(); UpdateLinksFromTableJoins(); //MainQuery.SelectionProperties = fullQuery.MainQuery.SelectionProperties; foreach (var sp in MainQuery.SelectionProperties) { // var t = FindFromTable(sp.); var prop = sp.FromTable.Properties.SingleOrDefault(p => p.Name == sp.StoreProperty.Name); if (prop != null) { prop.Selected = true; } } FullQuery = fullQuery; //MainQuery.WhereClause = fullQuery.MainQuery.WhereClause; }
public void CreateSubQuery(int index) { var q = new QueryModel { Name = $"Query{index}" }; SubQueryList.Add(q); }
public void RemoveSubQuery(int index) { SubQueryList.RemoveAt(index); if (SelectedQueryIndex >= SubQueryList.Count) { SelectedQueryIndex = SubQueryList.Count - 1; } }
public List<SubQuery> GetVisibleSubQueries(SubQueryList sqList, int position) { List<SubQuery> visible = new List<SubQuery>(); foreach (var sq in sqList.subQueries) { if (sqList.caretDepth >= sq.depth && (sq.startOffset <= position || sq.endOffset >= position)) { visible.Add(sq); } } return visible; }
public SubQueryList GetSubQueries(string query, int position) { ISimpleHQLLexer syntax = GetLexer( query ); int numericId = -1; List<SubQuery> subQueries = new List<SubQuery>(); int depth = 0; int caretDepth = 0; IDictionary<int,SubQuery> level2SubQuery = new Dictionary<int,SubQuery>(); SubQuery current = null; while ((numericId = syntax.NextTokenId()) != HqlLexer.EOF) { bool tokenAdded = false; if (numericId == HqlLexer.OPEN) { depth++; if (position > syntax.GetTokenOffset()) { caretDepth = depth; } if (!level2SubQuery.ContainsKey(depth)) { current = new SubQuery(); current.depth = depth; current.startOffset = syntax.GetTokenOffset(); level2SubQuery[depth] = current; } } else if (numericId == HqlLexer.CLOSE) { SubQuery currentDepthQuery = null; level2SubQuery.TryGetValue(depth,out currentDepthQuery); // We check if we have a query on the current depth. // If yes, we'll have to close it if (currentDepthQuery != null && currentDepthQuery.depth == depth) { currentDepthQuery.endOffset = syntax.GetTokenOffset(); currentDepthQuery.tokenIds.Add(numericId); currentDepthQuery.tokenText.Add(query.Substring(syntax.GetTokenOffset(), syntax.GetTokenLength())); subQueries.Add(currentDepthQuery); level2SubQuery.Remove(depth); tokenAdded = true; } depth--; if (position > syntax.GetTokenOffset()) { caretDepth = depth; } } switch (numericId) { case HqlLexer.FROM: case HqlLexer.UPDATE: case HqlLexer.DELETE: case HqlLexer.SELECT: if (!level2SubQuery.ContainsKey(depth)) { current = new SubQuery(); current.depth = depth; current.startOffset = syntax.GetTokenOffset(); level2SubQuery[depth]= current; } current.tokenIds.Add(numericId); current.tokenText.Add(query.Substring(syntax.GetTokenOffset(), syntax.GetTokenLength())); break; default: if (!tokenAdded && level2SubQuery.ContainsKey(depth)) { SubQuery sq = (SubQuery) level2SubQuery[depth]; int i = depth; while (sq == null && i >= 0) { sq = (SubQuery) level2SubQuery[i--]; } if (sq != null) { sq.tokenIds.Add(numericId); sq.tokenText.Add(query.Substring(syntax.GetTokenOffset(), syntax.GetTokenLength())); } } break; } } foreach (var sq in level2SubQuery.Values) { sq.endOffset = syntax.GetTokenOffset() + syntax.GetTokenLength(); subQueries.Add(sq); } subQueries.Sort(); SubQueryList sql = new SubQueryList(); sql.caretDepth = caretDepth; sql.subQueries = subQueries; return sql; }