public override void GetSuggestions(SuggestionList s) { SuggestionContext sc = s.suggestionContext; if (s.enableSuggestColumns) { if (parentQuery.select != null) { sc.AddColumnsInSelectList(); } if (s.textEntered.Length > 0) { sc.AddColumnsInFromTables(); } } if (columns.Count > 0 && s.enableSuggestKeywords) { if (sc.last.hasComma == false) { s.AddKeyword("desc"); s.AddKeyword("asc"); } sc.SuggestPrimaryKeywords(); } }
public void SuggestPrimaryKeywords() { if (suggestions.lenEntered > 0) { if (parent.parentQuery.from == null) { suggestions.AddKeyword("from", true); } if (parent.parentQuery.where == null) { suggestions.AddKeyword("where"); } if (parent.parentQuery.group == null) { suggestions.AddKeyword("group by"); } if (parent.parentQuery.order == null) { suggestions.AddKeyword("order by", true); } if (parent.parentQuery.group == null) { suggestions.AddKeyword("limit"); } } }
public override void GetSuggestions(SuggestionList s) { if (parentQuery.select == null) { return; } SuggestionContext sc = s.suggestionContext; Table rightTable = null; Table leftTable = null; if (sc.last == null) { sc.suggestTables = true; } else { rightTable = sc.lastTable.token != null ? sc.lastTable.token as Table : null; leftTable = rightTable == null ? null : sc.tokens.GetNearestTokenBefore(rightTable, TokenType.Table) as Table; if (rightTable == null) { sc.suggestTables = true; } else if (sc.last.type.IsOneOf("conjunction")) { sc.suggestColumns = true; } else if (sc.last.type == "operator") { sc.suggestColumns = true; if (sc.lastColumn.token != null) { Column c = sc.lastColumn.token as Column; sc.suggestColumnsDataType = c.dbColumn.dataType; } } else if (sc.last.type.IsOneOf("identifier", "column", "literal")) { sc.suggestOperators = sc.lastOperator.pos < sc.lastConjunction.pos; sc.suggestPrimaryKeywords = sc.suggestConjunctions = sc.lastOperator.pos == 0 || sc.lastOperator.pos > sc.lastConjunction.pos; sc.suggestJoin = sc.lastOperator.pos > sc.lastKeyword.pos; } else if (sc.last.type == "table") { sc.suggestPrimaryKeywords = (sc.lastKeyword.isJoin == false); if (sc.last.hasComma) { sc.suggestTables = true; } else { sc.suggestAlias = true; sc.suggestJoin = sc.lastKeyword.isJoin == false; sc.suggestJoinExpression = sc.suggestOn = !sc.suggestJoin; } } else if (sc.last.isOn) { sc.suggestColumns = true; sc.suggestJoinExpression = true; } else if (sc.last.isJoin) { sc.suggestTables = true; } } if (sc.suggestJoinExpression && s.enableSuggestJoins && rightTable != null && leftTable != null) { string join = leftTable.dbTable.RenderJoinCols(rightTable.name, s.includeAliases); if (join != null) { if (sc.suggestOn) { join = "on " + join; } s.Add(new Suggestion(TokenType.Expression, join)); } } if (sc.suggestJoin && s.enableSuggestKeywords) { s.AddKeyword("inner join", true); } if (sc.suggestOn && s.enableSuggestKeywords) { s.AddKeyword("on", true); } if (sc.suggestAlias && s.enableSuggestAliases && rightTable != null && rightTable.dbTable != null) { foreach (string alias in rightTable.dbTable.aliases.Keys) { s.Add(new Suggestion(TokenType.Identifier, alias)); } s.Add(new Suggestion(TokenType.Identifier, Db.GetAliasForTable(rightTable.dbTable.name, false))); } if (sc.suggestColumns && s.enableSuggestColumns) { if (rightTable != null && rightTable.dbTable != null) { sc.AddColumnsInTable(leftTable, true); sc.AddColumnsInTable(rightTable, true); sc.AddColumnsInTable(leftTable); sc.AddColumnsInTable(rightTable); sc.AddColumnsInFromTables(); } } if (sc.suggestTables && s.enableSuggestTables) { QList <string> names = new QList <string>(); QList <string> list = new QList <string>(); foreach (Column c in parentQuery.select.columns.tokens) { if (c.table != null && c.table.dbTable != null && (c.columnType == Column.ColumnType.Db)) { list.AddIfNotExists(c.table.dbTable.name); } sc.AddTable(c.tableName); } foreach (DbColumn c in Query.columnHints) { sc.AddTable(c.table.name); } if (rightTable != null && rightTable.dbTable != null) { /* * if (rightTable.tableAlias != null) * aliasFound = true; * // need to sort these tables by most recently used * names.MergeRange(Db.relationships.GetRelatedTables(rightTable.dbTable.name)); * foreach (string name in names.Each()) * sc.AddTable(name, aliasFound ? Db.GetAliasForTable(name, true) : ""); * names.Clear(); */ } if (s.textEntered.Trim() != "") { foreach (Column c in parentQuery.select.columns.tokens) { if ((c.tableAlias == null || c.columnType == Column.ColumnType.Proposed) && c.tableName != null && Db.tables.ContainsKey(c.tableName)) { list.AddIfNotExists(c.tableName); names.AddIfNotExists(c.tableName); } } foreach (string srcTable in list.Each()) { names.MergeRange(Db.TableNamesSortedByUsage(Db.tables[srcTable].accessibleTableNames)); } names.MergeRange(Db.tables.Keys); foreach (string name in names.Each()) { sc.AddTable(name); } } } }