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

Commit 666ec72

Browse files
committed
Fixed options not being applied. Moved cli settings to sublime-settings file
1 parent 7c63bd9 commit 666ec72

File tree

6 files changed

+131
-112
lines changed

6 files changed

+131
-112
lines changed

SQLTools.sublime-settings

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,119 @@
2222
"indent_tabs" : false,
2323
"indent_width" : 4,
2424
"reindent" : true
25+
},
26+
/**
27+
* Client options for you SGBD.
28+
* In this file, the section cli has the names you can use here. Eg: "pgsql": "psql"
29+
* So here, you must have "psql with the same sections listed bellow (options, before, args and queries)"
30+
*
31+
* Avoid changing the brackets content in "args"
32+
*/
33+
"cli_options": {
34+
"pgsql": {
35+
"options": [],
36+
"before": [],
37+
"args": "-h {host} -p {port} -U {username} -d {database}",
38+
"queries": {
39+
"desc" : {
40+
"query": "SELECT '|' || CASE WHEN n.nspname = current_schema() THEN quote_ident(c.relname) ELSE quote_ident(n.nspname)||'.'||quote_ident(c.relname) END ||'|' AS tblname FROM pg_catalog.pg_class AS c INNER JOIN pg_catalog.pg_namespace AS n ON n.oid = c.relnamespace WHERE relkind = 'r' AND n.nspname NOT IN ('pg_catalog', 'pg_toast', 'information_schema') ORDER BY n.nspname = current_schema() DESC, pg_catalog.pg_table_is_visible(c.oid) DESC, n.nspname, c.relname",
41+
"options": ["-t", "--no-psqlrc"],
42+
"format" : "|%s|"
43+
},
44+
"desc table": {
45+
"query": "\\d+ %s",
46+
"options": [],
47+
"format" : "|%s|"
48+
},
49+
"show records": {
50+
"query": "select * from {0} limit {1}",
51+
"options": [],
52+
"format" : "|%s|"
53+
},
54+
"columns": {
55+
"query": "SELECT DISTINCT '|' || table_name || '.' || column_name || '|' FROM information_schema.columns WHERE table_schema = CURRENT_SCHEMA() GROUP BY table_name, column_name;",
56+
"options": ["-t", "--no-psqlrc"],
57+
"format" : "|%s|"
58+
}
59+
}
60+
},
61+
"oracle": {
62+
"options": ["-S"],
63+
"before": [
64+
"set sqlprompt ''",
65+
"set colsep '|'",
66+
"set pagesize 100",
67+
"set linesize 500",
68+
"set tab off"
69+
],
70+
"args": "{username}/{password}@\"(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST={host})(PORT={port})))(CONNECT_DATA=(SERVICE_NAME={service})))\"",
71+
"queries": {
72+
"desc" : {
73+
"query": "select CONCAT(CONCAT('| ', table_name), ' |') as tables from user_tables;",
74+
"options": ["-S"],
75+
"format" : "|%s|"
76+
},
77+
"desc table": {
78+
"query": "desc %s;",
79+
"options": ["-S"],
80+
"format" : "|%s|"
81+
},
82+
"show records": {
83+
"query": "select * from {0} limit {1};",
84+
"options": ["-S"],
85+
"format" : "|%s|"
86+
}
87+
}
88+
},
89+
"mysql": {
90+
"options": ["-f", "--table"],
91+
"before": [],
92+
"args": "-h{host} -P{port} -u\"{username}\" -p\"{password}\" -D\"{database}\"",
93+
"queries": {
94+
"desc" : {
95+
"query": "show tables",
96+
"options": ["-f", "--table", "--skip-column-names"],
97+
"format" : "|%s|"
98+
},
99+
"desc table": {
100+
"query": "desc `%s`",
101+
"options": ["-f", "--table"],
102+
"format" : "|%s|"
103+
},
104+
"show records": {
105+
"query": "select * from `{0}` limit {1}",
106+
"options": ["-f", "--table"],
107+
"format" : "|%s|"
108+
},
109+
"columns": {
110+
"query": "SELECT table_name, column_name FROM information_schema.columns WHERE table_schema = DATABASE();",
111+
"options": ["-f", "--table"],
112+
"format" : "|%s|"
113+
}
114+
}
115+
},
116+
"vertica": {
117+
"options": [],
118+
"before" : [],
119+
"args": "-h {host} -p {port} -U \"{username}\" -w \"{password}\" -d \"{database}\"",
120+
"queries": {
121+
"desc" : {
122+
"query": "\\dt",
123+
"options": ["-t"],
124+
"format" : "|%s|"
125+
},
126+
"desc table": {
127+
"query": "\\d %s",
128+
"options": [],
129+
"format" : "|%s|"
130+
},
131+
"show records": {
132+
"query": "select * from {0} limit {1}",
133+
"options": [],
134+
"format" : "|%s|"
135+
}
136+
}
137+
}
25138
}
139+
26140
}

SQLToolsModels.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
class Const:
1010
SETTINGS_EXTENSION = "sublime-settings"
1111
SETTINGS_FILENAME = "SQLTools.{0}".format(SETTINGS_EXTENSION)
12+
SGDB_FILENAME = "SQLToolsSGBD.{0}".format(SETTINGS_EXTENSION)
1213
CONNECTIONS_FILENAME = "SQLToolsConnections.{0}".format(SETTINGS_EXTENSION)
1314
USER_QUERIES_FILENAME = "SQLToolsSavedQueries.{0}".format(SETTINGS_EXTENSION)
1415
pass
@@ -76,7 +77,6 @@ def getSavedQuery(alias):
7677
class Connection:
7778

7879
def __init__(self, name, options):
79-
self.cliSettings = sublime.load_settings('{0}.settings'.format(options['type']))
8080
self.cli = sublime.load_settings(Const.SETTINGS_FILENAME).get('cli')[options['type']]
8181
self.rowsLimit = sublime.load_settings(Const.SETTINGS_FILENAME).get('show_records').get('limit', 50)
8282
self.options = options
@@ -115,28 +115,28 @@ def loadDefaultConnectionName():
115115
return default
116116

117117
def getTables(self, callback):
118-
query = self.cliSettings.get('queries')['desc']['query']
118+
query = self.getOptionsForSgdbCli()['queries']['desc']['query']
119119
self.runCommand(self.builArgs('desc'), query, lambda result: Utils.getResultAsList(result, callback))
120120

121121
def getColumns(self, callback):
122122
try:
123-
query = self.cliSettings.get('queries')['columns']['query']
123+
query = self.getOptionsForSgdbCli()['queries']['columns']['query']
124124
self.runCommand(self.builArgs('columns'), query, lambda result: Utils.getResultAsList(result, callback))
125125
except Exception:
126126
pass
127127

128128
def getTableRecords(self, tableName, callback):
129-
query = self.cliSettings.get('queries')['show records']['query'].format(tableName, self.rowsLimit)
129+
query = self.getOptionsForSgdbCli()['queries']['show records']['query'].format(tableName, self.rowsLimit)
130130
self.runCommand(self.builArgs('show records'), query, lambda result: callback(result))
131131

132132
def getTableDescription(self, tableName, callback):
133-
query = self.cliSettings.get('queries')['desc table']['query'] % tableName
133+
query = self.getOptionsForSgdbCli()['queries']['desc table']['query'] % tableName
134134
self.runCommand(self.builArgs('desc table'), query, lambda result: callback(result))
135135

136136
def execute(self, queries, callback):
137137
queryToRun = ''
138138

139-
for query in self.cliSettings.get('before'):
139+
for query in self.getOptionsForSgdbCli()['before']:
140140
queryToRun += query + "\n"
141141

142142
if type(queries) is str:
@@ -165,11 +165,19 @@ def runCommand(self, args, query, callback):
165165

166166

167167
def builArgs(self, queryName=None):
168+
cliOptions = self.getOptionsForSgdbCli()
168169
args = [self.cli]
169-
if queryName and len(self.cliSettings.get('queries')[queryName]['options']) > 0:
170-
args = args + self.cliSettings.get('queries')[queryName]['options']
171170

172-
return args + shlex.split(self.cliSettings.get('args').format(**self.options))
171+
if len(cliOptions['options']) > 0:
172+
args = args + ' '.join(cliOptions['options'])
173+
174+
if queryName and len(cliOptions['queries'][queryName]['options']) > 0:
175+
args = args + cliOptions['queries'][queryName]['options']
176+
177+
return args + shlex.split(cliOptions['args'].format(**self.options))
178+
179+
def getOptionsForSgdbCli(self):
180+
return sublime.load_settings(Const.SETTINGS_FILENAME).get('cli_options')[self.type]
173181

174182

175183
class Selection:

sgbd/mysql.settings

Lines changed: 0 additions & 27 deletions
This file was deleted.

sgbd/oracle.settings

Lines changed: 0 additions & 27 deletions
This file was deleted.

sgbd/pgsql.settings

Lines changed: 0 additions & 27 deletions
This file was deleted.

sgbd/vertica.settings

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)