Hi Akshay,
Attached is the patch to make autocomplete changes python 2.6 compatible.
Please note, this patch should be applied over your patch.
On Mon, Aug 27, 2018 at 2:28 PM Aditya Toshniwal <
[email protected]> wrote:
> Hi,
>
> Did a basic testing. Looks good to me. Test cases run successfully.
>
> On Fri, Aug 24, 2018 at 10:55 AM Akshay Joshi <
> [email protected]> wrote:
>
>> Hi Hackers
>>
>> I have merged the latest code of "*pgcli*" used for auto complete
>> feature in pgAdmin4. We haven't merged that code since last 2 years and
>> they have fixed some bugs and also provided some new features:
>>
>> - Add support for CTE aware auto-completion.
>> - Handle unrecognized keywords gracefully.
>> - Support for table-qualifying column suggestions.
>> - Add additional completion for ALTER keyword.
>> - Better suggestions when editing functions.
>> - Added MATERIALIZED VIEW keywords.
>> - Completions after ORDER BY and DISTINCT now take account of table
>> aliases.
>> - Include arguments in function suggestions.
>> - Add missing keyword COLUMN after DROP
>>
>> I have also added some feature test for auto complete. Attached is the
>> patch please review it.
>> --
>> *Akshay Joshi*
>>
>> *Sr. Software Architect *
>>
>>
>>
>> *Phone: +91 20-3058-9517Mobile: +91 976-788-8246*
>>
>
>
> --
> Thanks and Regards,
> Aditya Toshniwal
> Software Engineer | EnterpriseDB Software Solutions | Pune
> "Don't Complain about Heat, Plant a tree"
>
--
Thanks and Regards,
Aditya Toshniwal
Software Engineer | EnterpriseDB Software Solutions | Pune
"Don't Complain about Heat, Plant a tree"
diff --git a/web/pgadmin/feature_tests/query_tool_auto_complete_tests.py b/web/pgadmin/feature_tests/query_tool_auto_complete_tests.py
index 2e0dd4a..41710b9 100644
--- a/web/pgadmin/feature_tests/query_tool_auto_complete_tests.py
+++ b/web/pgadmin/feature_tests/query_tool_auto_complete_tests.py
@@ -7,6 +7,7 @@
#
##########################################################################
+from __future__ import print_function
import sys
import random
@@ -18,6 +19,7 @@ from regression.python_test_utils import test_utils
from regression.feature_utils.base_feature_test import BaseFeatureTest
+
class QueryToolAutoCompleteFeatureTest(BaseFeatureTest):
"""
This feature test will test the query tool auto complete feature.
diff --git a/web/pgadmin/utils/sqlautocomplete/autocomplete.py b/web/pgadmin/utils/sqlautocomplete/autocomplete.py
index 3efac77..a82976d 100644
--- a/web/pgadmin/utils/sqlautocomplete/autocomplete.py
+++ b/web/pgadmin/utils/sqlautocomplete/autocomplete.py
@@ -11,9 +11,15 @@
import re
import operator
+import sys
from itertools import count, repeat, chain
from .completion import Completion
-from collections import namedtuple, defaultdict, OrderedDict
+from collections import namedtuple, defaultdict
+if sys.version_info < (2, 7):
+ from ordereddict import OrderedDict
+else:
+ from collections import OrderedDict
+
from .sqlcompletion import (
FromClauseItem, suggest_type, Database, Schema, Table,
Function, Column, View, Keyword, Datatype, Alias, JoinCondition, Join)
@@ -286,15 +292,14 @@ class SQLAutoComplete(object):
# This is used when suggesting functions, to avoid the latency that
# would result if we'd recalculate the arg lists each time we suggest
# functions (in large DBs)
- self._arg_list_cache = {
- usage: {
- meta: self._arg_list(meta, usage)
- for sch, funcs in self.dbmetadata['functions'].items()
- for func, metas in funcs.items()
- for meta in metas
- }
- for usage in ('call', 'call_display', 'signature')
- }
+
+ self._arg_list_cache = \
+ dict((usage,
+ dict((meta, self._arg_list(meta, usage))
+ for sch, funcs in self.dbmetadata['functions'].items()
+ for func, metas in funcs.items()
+ for meta in metas))
+ for usage in ('call', 'call_display', 'signature'))
def extend_foreignkeys(self, fk_data):
@@ -532,11 +537,10 @@ class SQLAutoComplete(object):
c.name for t, cs in scoped_cols.items() if t.ref != ltbl
for c in cs
)
- scoped_cols = {
- t: [col for col in cols if col.name in other_tbl_cols]
- for t, cols in scoped_cols.items()
- if t.ref == ltbl
- }
+ scoped_cols = \
+ dict((t, [col for col in cols if col.name in other_tbl_cols])
+ for t, cols in scoped_cols.items() if t.ref == ltbl)
+
lastword = last_word(word_before_cursor, include='most_punctuations')
if lastword == '*':
if suggestion.context == 'insert':
@@ -547,10 +551,9 @@ class SQLAutoComplete(object):
p.match(col.default)
for p in self.insert_col_skip_patterns
)
- scoped_cols = {
- t: [col for col in cols if filter(col)]
- for t, cols in scoped_cols.items()
- }
+ scoped_cols = \
+ dict((t, [col for col in cols if filter(col)])
+ for t, cols in scoped_cols.items())
if self.asterisk_column_order == 'alphabetic':
for cols in scoped_cols.values():
cols.sort(key=operator.attrgetter('name'))
diff --git a/web/pgadmin/utils/sqlautocomplete/sqlcompletion.py b/web/pgadmin/utils/sqlautocomplete/sqlcompletion.py
index 5d18ce9..41641f4 100644
--- a/web/pgadmin/utils/sqlautocomplete/sqlcompletion.py
+++ b/web/pgadmin/utils/sqlautocomplete/sqlcompletion.py
@@ -458,7 +458,7 @@ def suggest_based_on_last_token(token, stmt):
if not schema:
suggestions.append(Schema())
return tuple(suggestions)
- elif token_v in {'alter', 'create', 'drop'}:
+ elif token_v in ['alter', 'create', 'drop']:
return (Keyword(token_v.upper()),)
elif token.is_keyword:
# token is a keyword we haven't implemented any special handling for