1
1
mirror of https://github.com/dbcli/pgcli.git synced 2024-10-06 10:17:15 +03:00
Commit Graph

262 Commits

Author SHA1 Message Date
Amjith Ramanujam
fb23a1e4ec Merge pull request #554 from dbcli/koljonen/suggestion_sorting
Some changes to sorting of suggestions
2016-07-29 07:33:37 -07:00
Amjith Ramanujam
70323ea1c7 Fix failing tests. 2016-07-26 23:17:09 -07:00
Joakim Koljonen
f94bd6882d
Some changes to sorting of suggestions 2016-07-08 16:51:55 +02:00
koljonen
f09bb42d67
Better scoping for tables in insert statements
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-07-06 20:03:24 +02:00
darikg
1605bf1cdb Merge pull request #531 from dbcli/koljonen/generate_aliases
Suggest table aliases + add tests for casing
2016-07-06 07:39:56 -04:00
Eric Wald
ae0fcab9c9 Repair exception thrown on urls with ports
When the database URL contains a port, uri.port is (at least in Python 2.7.6) an integer, not a string, so urlparse.unquote chokes on it.
Fixes issue #536, but is probably worth verifying on Python 3.
2016-06-29 16:59:42 -06:00
koljonen
e15b3ec0a1
Suggest table aliases + add tests for casing
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-27 21:26:59 +02:00
koljonen
17f44545d8
In test_sqlcompletion, remove some code duplication 2016-06-27 21:15:29 +02:00
koljonen
ed4fcaf683
Smart completion tests: make every test have its own completer 2016-06-20 13:30:16 +02:00
koljonen
475796ab4f
Fix indentation of test_smart_completion_* metadata dicts 2016-06-18 21:25:59 +02:00
koljonen
69a6d0b38f
In completion tests, get columns from metadata instead of manually listing them 2016-06-18 21:25:55 +02:00
koljonen
932603130d
In completion tests, get functions from metadata instead of manually listing them 2016-06-18 21:24:02 +02:00
koljonen
a79e124025
In completion tests, get views from metadata instead of manually listing them 2016-06-18 21:24:00 +02:00
koljonen
d40bae021e
In completion tests, get tables from metadata instead of manually listing them 2016-06-18 21:23:12 +02:00
koljonen
42cf384ede
In completion tests, get datatypes from metadata instead of manually listing them 2016-06-18 21:21:17 +02:00
koljonen
c3c18bcebe
In completion tests, get schemas from metadata instead of manually listing them 2016-06-18 21:18:32 +02:00
koljonen
a784c7a158
Consolidate common code in smart_completion tests 2016-06-18 21:16:12 +02:00
koljonen
5b20e107b8
Fix some join-condition issues
When self-joining a table with an FK to or from some other table, we got a false FK-join suggestion for that column.
There was also a problem with quoted tables not being quoted in the join condition.
And there were a couple of problems when trying to join a non-existent table or using a non-existent qualifier (`SELECT * FROM Foo JOIN Bar ON Meow.`).

I also rewrote get_join_condition_matches a bit in the process, hopefully making it a bit simpler.
2016-06-16 19:27:57 +02:00
koljonen
b69404c215
Add a couple of tests suggested by @darikg 2016-06-14 22:44:36 +02:00
koljonen
6cb8c38628
Join conditions: alias tables already included in query
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-14 22:34:10 +02:00
koljonen
351a58554b
Also exclude NATURAL JOIN from join suggestions 2016-06-10 03:51:52 +02:00
koljonen
582852adb6
Various changes after review 2016-06-10 03:26:42 +02:00
koljonen
9b6a72e9e0
For 'JOIN <cursor>', suggest 'foo on foo.fooid = bar.fooid'
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-09 00:55:07 +02:00
Darik Gamble
e5cc38d835 column keyword suggests columns 2016-06-07 14:44:52 -04:00
darikg
92cc469b7b Merge pull request #512 from koljonen/casing
Custom casing of table/column/function/view names
2016-06-06 17:21:32 -04:00
Amjith Ramanujam
163b2e2087 Merge pull request #521 from Smotko/configure-row-limit
Make too many rows warning limit configurable
2016-06-05 14:50:39 -07:00
koljonen
7e45e893ca
Custom casing of table/column/function/view names
This adds support for defining the casing to be used in completions (for unquoted names). The casing is determined by the casing file, which consists of a \n-separated list of names using the preferred casing. This file can either be populated manually or created automatically (based on usage in SQL/PLPGSQL functions), with a config setting.
2016-06-04 23:05:32 +02:00
darikg
52bac9af85 Merge pull request #513 from koljonen/order_columns_by_db_column_order
Order columns by in-table order when expanding *
2016-06-04 07:34:35 -04:00
Anže Pečar
302d425609 Make sure low_count is never greater than over_default 2016-06-02 18:37:23 -07:00
Anže Pečar
1947e74c00 Add test for row_limit parameter 2016-06-02 18:37:23 -07:00
koljonen
5d9dfcdcc3
Use pg_proc.proargmodes &c. instead of parsing arg_list
Getting the parameters from proargnames, proallargtypes and proargmodes instead of from parsing the arg_list string simplifies FunctionMetadata quite a bit.
I also made the ColumnMetadata for table/view columns use the same format for the type (i.e. regtype instead of typname). This means we now get join-condition suggestions for joining tables/views to functions, which didn't work before.
2016-06-02 01:44:31 +02:00
darikg
f912633d6d Merge pull request #516 from dbcli/koljonen/fix_another_casing_issue
Fix issue with 'SELECT Foo.*<cursor> FROM Foo'
2016-06-01 16:30:06 -04:00
koljonen
e217bac439
Fix issue with 'SELECT Foo.*<cursor> FROM Foo'
In the expansion, we got '"Foo".<col>' when we should have gotten 'Foo.<col>'.
2016-05-31 23:45:11 +02:00
koljonen
740085dd23
Order columns by in-table order when expanding *
And add a setting to use alphabetic order instead.
We simply get the columns from the database in the canonical order, and then sort them if the user has opted for alphabetic order.
2016-05-31 01:29:44 +02:00
koljonen
843b859c1d
Fix two casing issues with schemas
1. In 'SELECT * FROM Foo.', Foo was not recognized as foo.
2. In 'SELECT * FROM "Foo"', objects in Foo were not suggested.
2016-05-27 11:29:23 +02:00
darikg
a9c209df7a Merge pull request #510 from koljonen/fixtablecasingissue2
Fix another problem where table names would not be recognized when nott in lower case
2016-05-25 19:11:07 -04:00
koljonen
59e3068a07
Fix another problem where table names would not be recognized when not in lower case
My previous fix didn't cover the case 'INSERT INTO Foo(<cursor>)', which is now covered.
2016-05-25 18:31:34 +02:00
koljonen
7f8bd9bbd4
Make join-condition suggestions work with multi-line queries 2016-05-24 16:11:36 +02:00
koljonen
8431b32166
Support for join-condition suggestions after ON
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-24 14:18:19 +02:00
koljonen
a5fa8ca1cb
Fix problem where table names would not be recognized when not in lower case 2016-05-20 00:00:31 +02:00
darikg
30de80223b Merge pull request #505 from koljonen/drop_asterisk_column_suggestion
Stop suggesting * as a column
2016-05-17 19:40:42 -04:00
Stuart Quin
d378ddf559 Merge pull request #504 from dbcli/amjith/unicode-notices
Support unicode strings in notices.
2016-05-17 20:32:10 +01:00
Amjith Ramanujam
0524e0adbf Disable the test for unicode notices. 2016-05-17 12:04:30 -07:00
koljonen
a60ee9a85f
Stop suggesting * as a column
I don't think suggesting * is of use to anyone, and it's in the way for anyone who just wants a column.
2016-05-17 12:27:33 +02:00
darikg
8d426c2db6 Merge pull request #502 from koljonen/cleanup
Remove dead code and fix a broken test
2016-05-16 18:44:25 -04:00
darikg
087fb1cb7d Merge pull request #492 from koljonen/master
Completion to column list when *  is entered
2016-05-16 18:36:46 -04:00
koljonen
0af862f1ff
Remove obsolete comments 2016-05-16 17:31:52 +02:00
koljonen
8e24cd41dc
Various small changes after code review 2016-05-16 13:48:46 +02:00
Amjith Ramanujam
69ee125bf1 Trying the command in a single line. 2016-05-15 22:59:53 -07:00
Amjith Ramanujam
2cfd9fc913 Add a test for unicode tests. 2016-05-15 22:39:41 -07:00