Esempio n. 1
0
        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();
            }
        }
Esempio n. 2
0
 public int BuildSuggestionList()
 {
     currentPos        = -1;
     wordStartPosition = -1;
     textEntered       = "";
     suggestionContext = new SuggestionContext(this, keyword);
     suggestionContext.AddColumnsByAffinity();
     return(suggestions.Count);
 }
Esempio n. 3
0
        public override void GetSuggestions(SuggestionList s)
        {
            SuggestionContext sc = s.suggestionContext;

            if (sc.last == null)
            {
                sc.suggestColumns = 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("column", "literal"))
                {
                    sc.suggestOperators       = sc.lastOperator.pos < sc.lastConjunction.pos;
                    sc.suggestPrimaryKeywords = sc.suggestConjunctions = sc.lastOperator.pos == 0 || sc.lastOperator.pos > sc.lastConjunction.pos;
                }
                else
                {
                    sc.suggestColumns = true;
                }
            }

            if (sc.suggestColumns && s.enableSuggestColumns)
            {
                sc.AddAllColumnsInQuery();
                sc.AddColumnsInFromTables();
            }
            if (s.enableSuggestKeywords)
            {
                if (sc.suggestConjunctions)
                {
                    sc.SuggestConjunctions();
                }
                if (sc.suggestOperators)
                {
                    sc.SuggestOperators();
                }
                if (sc.suggestPrimaryKeywords)
                {
                    sc.SuggestPrimaryKeywords();
                }
            }
        }
Esempio n. 4
0
        public int BuildSuggestionList(string text, int pos)
        {
            currentPos        = pos;
            wordStartPosition = FindWordStartPosition(text, pos);
            if (wordStartPosition < 0) // || wordStartPosition == pos)
            {
                return(0);
            }
            textEntered = text.Substring(wordStartPosition, pos - wordStartPosition);
            if (keyword != null)
            {
                suggestionContext = new SuggestionContext(this, keyword, wordStartPosition, textEntered);
                keyword.GetSuggestions(this);
            }
            if (Query.rootQuery.expressionLength < 5 && suggestions.Count == 0 && query != null && query.select == null)
            {
                AddKeyword("select");
            }

            return(suggestions.Count);
        }
Esempio n. 5
0
        public override void GetSuggestions(SuggestionList s)
        {
            SuggestionContext sc = s.suggestionContext;

            if (s.enableSuggestKeywords && sc.last != null && ((sc.last.type == "column" && sc.last.hasComma == false) ||
                                                               (sc.last.type == "identifier" && sc.lastColumn != null && sc.lastColumn.hasComma == false)))
            {
                sc.SuggestPrimaryKeywords();
            }
            else if (s.enableSuggestColumns)
            {
                if (columns.Count > 0 || candidateTables.Count > 0)
                {
                    sc.suggestPrimaryKeywords = true;
                }
                if (s.textEntered.Contains("."))
                {
                    s.includeAliases = s.enableSuggestAliases;
                    string alias = s.textEntered.Substring(0, s.textEntered.IndexOf("."));
                    string table = columns.GetTableNameForTableAlias(alias);
                    if (table == null)
                    {
                        table = Db.GetTableNameByAlias(alias, null);
                    }
                    if (table != null)
                    {
                        sc.AddColumnsInTable(table, alias);
                    }
                    foreach (string t in Db.GetPossibleTablesForAlias(alias))
                    {
                        sc.AddColumnsInTable(t, alias);
                    }
                }
                sc.AddColumnsInFromTables();
                sc.AddColumnsInSelectCandidateList();
                sc.AddAllColumns();
            }
        }
Esempio n. 6
0
        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);
                    }
                }
            }
        }