summaryrefslogtreecommitdiffstats
path: root/tests/test_sqlcompletion.py
AgeCommit message (Collapse)Author
2022-06-08Fix typos (#1345)Kian-Meng Ang
Co-authored-by: Irina Truong <i.chernyavska@gmail.com>
2021-02-12Modernize code to Python 3.6+ (#1229)Miroslav Šedivý
1. `class A(object)` can be written as `class A:` 2. replace `dict([…])` and `set([…])` with `{…}` 3. use f-strings or compact `.format` 4. use `yield from` instead of `yield` in a `for` loop 5. import `mock` from `unittest` 6. expect `OSError` instead of `IOError` or `select` error 7. use Python3 defaults for file reading or `super()` 8. remove redundant parenthesis (keep those in tuples though) 9. shorten set intersection instead of creating lists 10. backslashes in strings do not have to be escaped if prepended with `r`
2020-12-01dependencies: add support for sqlparse 0.4.x (#1224)Kevin Marsh
2019-10-12Take account of table aliases when completing function args (#1048)Owen Stephens
2019-05-25black all the things. (#1049)Irina Truong
* added black to develop guide * no need for pep8radius. * changelog. * Add pre-commit checkbox. * Add pre-commit to dev reqs. * Add pyproject.toml for black. * Pre-commit config. * Add black to travis and dev reqs. * Install and run black in travis. * Remove black from dev reqs. * Lower black target version. * Re-format with black.
2019-05-06Upgrade to sqlparse 0.3.0.Amjith Ramanujam
2017-07-05Add defaults to column metadataJoakim Koljonen
2017-06-14Fix PEP8 empty line errorsÉtienne BERSAC
2017-04-27Fix PEP8 for #693Étienne BERSAC
2017-04-27Complete keywords depending on previous tokenÉtienne BERSAC
Keywords list is based on https://www.postgresql.org/docs/9.6/static/sql-commands.html.
2017-04-26Suggest columns for `ORDER BY` and `DISTINCT` (fixes #685)Owen Stephens
Having typed an alias name in an `ORDER BY` or (`SELECT`) `DISTINCT` clause, the alias was not taken account of, and the completion simply listed all columns. This change fixes that, and makes the autocompletion behave the same as in `SELECT` and `WHERE` clauses.
2017-03-09Find statements inside function bodykoljonen
Consider this script ``` CREATE FUNCTION foo() returns text LANGUAGE SQL AS $func$ SELECT 1 FROM Bar; SELECT <cursor> FROM Baz; $func$; ``` The change here is that `SELECT <cursor> FROM Baz;` will be seen as the current statement, instead of the whole function definition. This means we'll no longer get column suggestions from `Bar`.
2017-02-25Suggest keywords after ALTERDarik Gamble
2016-12-05Support for table-qualifying column suggestionskoljonen
... i.e. suggesting foo.fooid instead of just fooid Controlled using a config-file setting: **qualify_columns**: always/never/**if_more_than_one_table**. To enable the proper sorting of qualified column suggestions, we introduce the concept of synonyms for suggestions (in `pgcompleter.find_matches`). They way synonyms work is that a number of synonyms may be provided for a suggestion sent to `find_matches`. If synonyms are provided, sorting is based on how well the best synonym matches the input, instead of only comparing the input to the suggestion text. In this case, the unqualified name acts as a synonym. I have a couple of other ideas of use cases where we can use synonyms to get better completions with less typing for the user, which I intend to explore later.
2016-11-20Fix crash after `with`Joakim Koljonen
2016-10-17If prev_keyword is an unrecognized keyword, go backward until we find a ↵Darik Gamble
recognized one
2016-09-12Fix crash bug with leading parenthesisJoakim Koljonen
2016-08-23Temporary hack for sqlparse crashing after ASJoakim Koljonen
And a regression test.
2016-07-27Rename the suggestion field `tables` to `table_refs` so we can add more ↵Darik Gamble
table-specific properties without getting confused
2016-07-06Better scoping for tables in insert statementskoljonen
This commit makes it so that given `INSERT INTO foo(<cursor1>) SELECT <cursor2> FROM bar;`, we suggest `bar` columns for `<cursor2>` and `foo` columns for `<cursor1>`. Previous behaviour is sugggesting columns from both tables in both cases.
2016-06-27Suggest table aliases + add tests for casingkoljonen
If config.main.generate_aliases is True, for `SELECT * FROM `, we suggest `FooBar FB` and `foo_bar fb` instead of `FooBar` and `foo_bar`, respectively. To be able to add a test, I had to add support for testing with different settings, which meant I could also add tests for casing. There are two non-obvious changes that I can think of: 1. The lexical sorting of matches is modified so as to sort spaces and underscores before letters and to sort case-insensitively. This is so that e.g `Foob F` comes before 'FooBar FB' when `foob` is input. 2. We now suggest `some_func()` instead of `some_func` (because suggesting `some_func sf` didn't make any sense).
2016-06-27In test_sqlcompletion, remove some code duplicationkoljonen
2016-06-14Add a couple of tests suggested by @darikgkoljonen
2016-06-14Join conditions: alias tables already included in querykoljonen
If we have the input `SELECT * FROM Foo JOIN `, we now suggest `Foo Foo2 ON Foo2.ParentID = Foo.ID` (given the appropriate casing file and FK). There were also some problems with quoted tables and with the casing of table aliases, which are now fixed. I also made a few cosmetic changes to get_join_matches (pgcompleter.py) just to make it a bit easier to work with.
2016-06-10Various changes after reviewkoljonen
2016-06-09For 'JOIN <cursor>', suggest 'foo on foo.fooid = bar.fooid'koljonen
This is based on my previous work on suggesting join conditions, but here instead we suggest the whole join. What we do is simply check all the tables in the statement for FK relationships and then suggest joins based on those. I think this will not only save key presses, but also be rather useful when exploring an unfamiliar (part of a) database. There's one non-obvious change in this commit (that I can think of): When calling **sqlcompletion.text_before_cursor**, the **text_before_cursor** argument now no longer includes **word_before_cursor**. This is because for 'SELECT * FROM foo JOIN bar<cursor>', we would otherwise consider the table **bar** already included in the statement and thus suggest e.g. 'baz on baz.barid = bar.barid'.
2016-06-07`column` keyword suggests columnsDarik Gamble
2016-05-24Make join-condition suggestions work with multi-line querieskoljonen
2016-05-24Support for join-condition suggestions after ONkoljonen
The user types 'SELECT * FROM parenttable p JOIN childtable c on '. We then suggest ['c.parenttableid = p.parenttableid', 'c.createdby = p.createdby', ...] as completions. The suggestions are FK matches first, then name matches for int columns, then name matches for other columns, sorted by proximity from the cursor to the other table. Some changes: For "JOIN Foo USING(<cursor>)", now only columns present in Foo are suggested. For all suggestions after 'ON', now only the tables before the cursor are considered. meta[reltype]][relname] goes from being a list of columns to being an OrderedDict {column_name:ColumnMetadata}, where the ColumnMetaData contains the column's name, data type and a list of FKs involving the column. This entails modification of a number of functions dealing with columns.
2016-05-07Improve filtering of functions for FROM clausekoljonen
Change from filtering out all non-set-returning functions to only filteirng out windowing functions and aggregate functions. Non-set-returning functions are legal in the FROM clause and can be quite useful.
2015-11-25Add a bunch of tests for multiple joinsDarik Gamble
2015-11-23Add more tests for qualified table names with or without quotesDarik Gamble
2015-11-21Fix suggestions after a manually entered double quote escapeDarik Gamble
2015-11-16Replace suggestion dicts with namedtuplesDarik Gamble
2015-10-04Merge pull request #368 from dbcli/darikg/suggest-columns-from-functionsdarikg
Suggest columns from functions
2015-10-03Expand more join tests to check compound statementsDarik Gamble
2015-10-03Fix suggestions in compound join clausesDarik Gamble
Previously, this worked correctly, suggesting columns etc. from `a` `SELECT * FROM abc a JOIN def d ON a.` But this suggested only keywords: `SELECT * FROM abc a JOIN def d ON a.id = d.id AND a.`
2015-09-29Suggest fields from functions used as tablesDarik Gamble
2015-09-29Extract functions in the FROM clause as tablesDarik Gamble
2015-09-23Suggest set-returning functions as tablesDarik Gamble
2015-08-25Update the tests for named query.Amjith Ramanujam
2015-08-25Autocompletion in named queries. Connect #270.Iryna Cherniavska
2015-08-24Add tests for where clause with keywords.Amjith Ramanujam
2015-08-23Fix failing tests.Amjith Ramanujam
2015-08-05Merge pull request #323 from dbcli/darikg/bugfix-283Amjith Ramanujam
Fix #283
2015-08-05Test suggest_type with escaped table aliasesDarik Gamble
2015-08-05Add regression test for #317Darik Gamble
2015-08-01Add a test for the crashing bug fix.Amjith Ramanujam
2015-05-23Suggest datatypes from a hardcoded whitelistDarik Gamble
2015-05-20`drop schema` and `create schema` should suggest schemasDarik Gamble