Skip to content
This repository was archived by the owner on Mar 12, 2020. It is now read-only.

Commit 8481ca0

Browse files
authored
Merge branch 'master' into feature/mssql-support
2 parents 82a2fd2 + 25d49a7 commit 8481ca0

File tree

9 files changed

+77
-36
lines changed

9 files changed

+77
-36
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.9.4
2+
current_version = 0.9.7
33
files = SQLTools.py
44
tag = True
55
commit = True

ISSUE_TEMPLATE.md

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
1-
> This is a guideline to help us to understand SQLTools Issues.
1+
> This issue template helps us understand your SQLTools issues better.
2+
>
3+
> You don't need to stick to this template, but please try to guide us to reproduce the errors or understand your feature requests.
24
>
3-
> You don't need to stick to this, but please try to guide us to reproduce the errors or understand your feature requests.
5+
> Before submitting an issue, please consider these things first:
6+
> * Are you running the latest version? If not, try to upgrade.
7+
> * Did you check the [Setup Guide](http://mtxr.github.io/SQLTools/)?
8+
> * Did you check the logs in console (``Ctrl+` `` or select *View → Show Console*)?
49
510
### Issue Type
611

7-
* [ ] Feature Request
8-
* [ ] Bugfix/Errors
9-
* [ ] Questions
10-
* [ ] Other
12+
Feature Request |
13+
Bug/Error |
14+
Question |
15+
Other
1116

12-
### Prerequisites (For bugfixes)
17+
### Description
1318

14-
* [ ] Are you running the latest version?
15-
* [ ] Did you check the logs?
16-
* [ ] Did you check the Setup?
19+
[Description of the bug / feature / question]
1720

18-
### Description
21+
### Version
22+
23+
- *SQLTools Version*: vX.Y.Z
24+
- *OS*: (Windows, Mac, Linux)
25+
- *RDBMS*: (MySQL, PostgreSQL, Oracle, MSSQL, SQLite, Vertica, ...)
1926

20-
[Description of the bug or feature]
27+
> You can get this information by executing `ST: About` from Sublime `Command Palette`.
2128
2229
### Steps to Reproduce (For bugfixes)
2330

@@ -28,11 +35,3 @@
2835
**Expected behavior:** [What you expected to happen]
2936

3037
**Actual behavior:** [What actually happened]
31-
32-
### Versions
33-
34-
- *Version*: vX.Y.Z
35-
- *OS*: ...
36-
- *RDBMS*: (MySQL, PostgreSQL, Oracle, MSSQL, SQLite, Vertica, ...)
37-
38-
You can get this information from executing `ST: About` from Sublime `Command Palette`.

SQLTools.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "v0.9.4"
1+
__version__ = "v0.9.7"
22

33
import sys
44
import os
@@ -57,9 +57,21 @@ def startPlugin():
5757
QUERIES_FILENAME = os.path.join(USER_FOLDER, SQLTOOLS_QUERIES_FILE)
5858
QUERIES_FILENAME_DEFAULT = os.path.join(DEFAULT_FOLDER, SQLTOOLS_QUERIES_FILE)
5959

60-
settings = Settings(SETTINGS_FILENAME, default=SETTINGS_FILENAME_DEFAULT)
60+
try:
61+
settings = Settings(SETTINGS_FILENAME, default=SETTINGS_FILENAME_DEFAULT)
62+
except Exception as e:
63+
msg = __package__ + ": Failed to parse " + SQLTOOLS_SETTINGS_FILE + " file"
64+
print(msg + "\nError: " + str(e))
65+
Window().status_message(msg)
66+
67+
try:
68+
connections = Settings(CONNECTIONS_FILENAME, default=CONNECTIONS_FILENAME_DEFAULT)
69+
except Exception as e:
70+
msg = __package__ + ": Failed to parse " + SQLTOOLS_CONNECTIONS_FILE + " file"
71+
print(msg + "\nError: " + str(e))
72+
Window().status_message(msg)
73+
6174
queries = Storage(QUERIES_FILENAME, default=QUERIES_FILENAME_DEFAULT)
62-
connections = Settings(CONNECTIONS_FILENAME, default=CONNECTIONS_FILENAME_DEFAULT)
6375
history = History(settings.get('history_size', 100))
6476

6577
Logger.setPackageVersion(__version__)
@@ -356,7 +368,7 @@ def on_query_completions(view, prefix, locations):
356368
lineStartToLocation = sublime.Region(lineStartPoint, currentPoint)
357369
try:
358370
lineStr = view.substr(lineStartToLocation)
359-
prefix = re.split('[^`\"\w.]+', lineStr).pop()
371+
prefix = re.split('[^`\"\w.\$]+', lineStr).pop()
360372
except Exception as e:
361373
Log(e)
362374

SQLTools.sublime-settings

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
},
7575
"queries": {
7676
"desc" : {
77-
"query": "select '|' || quote_ident(table_schema)||'.'||quote_ident(table_name) ||'|' as tblname from information_schema.tables where table_schema = any(current_schemas(false)) and table_schema not in ('pg_catalog', 'information_schema') order by table_schema = current_schema() desc, table_schema, table_name",
77+
"query": "select '|' || quote_ident(table_schema)||'.'||quote_ident(table_name) ||'|' as tblname from information_schema.tables where table_schema not in ('pg_catalog', 'information_schema') order by table_schema = current_schema() desc, table_schema, table_name",
7878
"options": ["--tuples-only", "--no-psqlrc"]
7979
},
8080
"desc table": {
@@ -86,11 +86,11 @@
8686
"options": ["--no-password"]
8787
},
8888
"columns": {
89-
"query": "select '|' || quote_ident(table_name) || '.' || quote_ident(column_name) || '|' from information_schema.columns where table_schema = any(current_schemas(false)) and table_schema not in ('pg_catalog', 'information_schema') order by table_name, ordinal_position",
89+
"query": "select '|' || quote_ident(table_name) || '.' || quote_ident(column_name) || '|' from information_schema.columns where table_schema not in ('pg_catalog', 'information_schema') order by table_name, ordinal_position",
9090
"options": ["--no-password", "--tuples-only", "--no-psqlrc"]
9191
},
9292
"functions": {
93-
"query": "select '|' || quote_ident(n.nspname)||'.'||quote_ident(f.proname) || '(' || pg_get_function_identity_arguments(f.oid) || ')' || '|' as funname from pg_catalog.pg_proc as f inner join pg_catalog.pg_namespace as n on n.oid = f.pronamespace where f.proisagg = false and n.nspname = any(current_schemas(false)) and n.nspname not in ('pg_catalog', 'information_schema')",
93+
"query": "select '|' || quote_ident(n.nspname)||'.'||quote_ident(f.proname) || '(' || pg_get_function_identity_arguments(f.oid) || ')' || '|' as funname from pg_catalog.pg_proc as f inner join pg_catalog.pg_namespace as n on n.oid = f.pronamespace where f.proisagg = false and n.nspname not in ('pg_catalog', 'information_schema')",
9494
"options": ["--no-password", "--tuples-only", "--no-psqlrc"]
9595
},
9696
"desc function": {
@@ -157,7 +157,7 @@
157157
"args_optional": ["--login-path=\"{login-path}\"", "--defaults-extra-file=\"{defaults-extra-file}\"", "-p\"{password}\""],
158158
"queries": {
159159
"desc" : {
160-
"query": "select concat('|', table_schema, '.', table_name, '|') from information_schema.tables where table_schema = database() order by table_name;",
160+
"query": "select concat('|', case when table_schema REGEXP '[^0-9a-zA-Z$_]' then concat('`',table_schema,'`') else table_schema end, '.', case when table_name REGEXP '[^0-9a-zA-Z$_]' then concat('`',table_name,'`') else table_name end, '|') from information_schema.tables where table_schema = database() order by table_name;",
161161
"options": ["-f", "--silent", "--raw"]
162162
},
163163
"desc table": {
@@ -169,15 +169,15 @@
169169
"options": ["-f", "--table"]
170170
},
171171
"columns": {
172-
"query": "select concat('|', table_name, '.', column_name, '|') from information_schema.columns where table_schema = database() order by table_name, ordinal_position;",
172+
"query": "select concat('|', case when table_name REGEXP '[^0-9a-zA-Z$_]' then concat('`',table_name,'`') else table_name end, '.', case when column_name REGEXP '[^0-9a-zA-Z$_]' then concat('`',column_name,'`') else column_name end, '|') from information_schema.columns where table_schema = database() order by table_name, ordinal_position;",
173173
"options": ["-f", "--silent", "--raw"]
174174
},
175175
"functions": {
176-
"query": "select concat('|', routine_schema, '.', routine_name, '()', '|') from information_schema.routines where routine_schema = database();",
176+
"query": "select concat('|', case when routine_schema REGEXP '[^0-9a-zA-Z$_]' then concat('`',routine_schema,'`') else routine_schema end, '.', case when routine_name REGEXP '[^0-9a-zA-Z$_]' then concat('`',routine_name,'`') else routine_name end, '()', '|') from information_schema.routines where routine_schema = database();",
177177
"options": ["-f", "--silent", "--raw"]
178178
},
179179
"desc function": {
180-
"query": "select routine_definition from information_schema.routines where concat(routine_schema, '.', routine_name) = '%s';",
180+
"query": "select routine_definition from information_schema.routines where concat(case when routine_schema REGEXP '[^0-9a-zA-Z$_]' then concat('`',routine_schema,'`') else routine_schema end, '.', case when routine_name REGEXP '[^0-9a-zA-Z$_]' then concat('`',routine_name,'`') else routine_name end) = '%s';",
181181
"options": ["-f", "--silent", "--raw"]
182182
},
183183
"explain plan": {

SQLToolsAPI/Completion.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ def _stripPrefix(text, prefix):
3939
return text
4040

4141

42+
# escape $ sign when formatting output
43+
def _escapeDollarSign(ident):
44+
return ident.replace("$", "\$")
45+
46+
4247
class CompletionItem(namedtuple('CompletionItem', ['type', 'ident'])):
4348
"""
4449
Represents a potential or actual completion item.
@@ -149,10 +154,10 @@ def format(self, stripQuotes=False):
149154
part = self.ident.split('.')
150155
if len(part) > 1:
151156
return ("{0}\t({1} {2})".format(part[1], part[0], typeDisplay),
152-
_stripQuotesOnDemand(part[1], stripQuotes))
157+
_stripQuotesOnDemand(_escapeDollarSign(part[1]), stripQuotes))
153158

154159
return ("{0}\t({1})".format(self.ident, typeDisplay),
155-
_stripQuotesOnDemand(self.ident, stripQuotes))
160+
_stripQuotesOnDemand(_escapeDollarSign(self.ident), stripQuotes))
156161

157162

158163
class Completion:
@@ -381,7 +386,7 @@ def _singleDotCompletions(self, prefix, identifiers, joinAlias=None):
381386

382387
# we use set, as we are interested only in unique identifiers
383388
for ident in identifiers:
384-
if ident.has_alias() and ident.alias == prefixParent:
389+
if ident.has_alias() and ident.alias.lower() == prefixParent:
385390
if ident.is_query_alias:
386391
sqlQueryAliases.add(ident.alias)
387392

messages.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@
99
"0.9.1": "messages/v0.9.1.md",
1010
"0.9.2": "messages/v0.9.2.md",
1111
"0.9.3": "messages/v0.9.3.md",
12-
"0.9.4": "messages/v0.9.4.md"
12+
"0.9.4": "messages/v0.9.4.md",
13+
"0.9.5": "messages/v0.9.5.md",
14+
"0.9.6": "messages/v0.9.6.md",
15+
"0.9.7": "messages/v0.9.7.md"
1316
}

messages/v0.9.5.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## v0.9.5 Notes
2+
3+
### Improvements
4+
5+
* New Feature: List and Insert Saved Queries (ctrl+e ctrl+i) [#126]
6+
* Better error messages if setting json file could not be parsed
7+
8+
### Fixes
9+
10+
* Display completions for upper case aliases [#142]
11+
* Fix the display of status bar message when query is executed [#130]
12+
* Open Saved Queries executed the query if not connected to a database prior [#125]

messages/v0.9.6.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## v0.9.6 Notes
2+
3+
### Fixes
4+
5+
* [MySQL] Added basic backtick escaping of identifiers [#147]

messages/v0.9.7.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## v0.9.7 Notes
2+
3+
### Fixes
4+
5+
* Completions not working with identifiers containing $ symbol [#152]

0 commit comments

Comments
 (0)