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

Commit a695509

Browse files
committed
Review default DB settings, use set encoding
Since before and after SQL is run for all commands - review all of them. Improve usability and functionality of Oracle and MSSQL. Also, fix to take into consideration the encoding set in DB connection.
1 parent 04063b6 commit a695509

File tree

5 files changed

+225
-86
lines changed

5 files changed

+225
-86
lines changed

SQLTools.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ def run():
497497
return
498498

499499
Window().status_message(MESSAGE_RUNNING_CMD)
500-
ST.conn.execute(getSelection(), createOutput(), stream=settings.get('use_streams', False))
500+
ST.conn.execute(getSelection(), createOutput())
501501

502502

503503
class StExecuteAll(WindowCommand):
@@ -509,7 +509,7 @@ def run():
509509

510510
Window().status_message(MESSAGE_RUNNING_CMD)
511511
allText = View().substr(sublime.Region(0, View().size()))
512-
ST.conn.execute(allText, createOutput(), stream=settings.get('use_streams', False))
512+
ST.conn.execute(allText, createOutput())
513513

514514

515515
class StFormat(TextCommand):
@@ -543,8 +543,7 @@ def run():
543543
def cb(index):
544544
if index < 0:
545545
return None
546-
return ST.conn.execute(history.get(index), createOutput(),
547-
stream=settings.get('use_streams', False))
546+
return ST.conn.execute(history.get(index), createOutput())
548547

549548
Window().show_quick_panel(history.all(), cb)
550549

@@ -583,8 +582,7 @@ def cb(index):
583582

584583
alias, query = options[index]
585584
if mode == "run":
586-
ST.conn.execute(query, createOutput(),
587-
stream=settings.get('use_streams', False))
585+
ST.conn.execute(query, createOutput())
588586
elif mode == "insert":
589587
insertContent(query)
590588
else:

SQLTools.sublime-settings

Lines changed: 137 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"PGPASSWORD": "{password}"
7575
},
7676
"queries": {
77-
"exec": {
77+
"execute": {
7878
"options": []
7979
},
8080
"desc": {
@@ -109,52 +109,123 @@
109109
},
110110
"oracle": {
111111
"options": ["-S"],
112-
"before": [
113-
"SET AUTO OFF",
114-
"SET COLSEP '|'",
115-
"SET FEED ON",
116-
"SET FEEDBACK ON",
117-
"SET HEADING ON",
118-
"SET LINESIZE 32767",
119-
"SET LONG 100",
120-
"SET NULL @",
121-
"SET PAGESIZE 0 EMBEDDED ON",
122-
"SET SERVEROUTPUT ON",
123-
"SET SQLBLANKLINES ON",
124-
"SET SQLPROMPT ''",
125-
"SET TAB OFF",
126-
"SET TI ON",
127-
"SET TIMI OFF",
128-
"SET TRIMSPOOL OFF",
129-
"SET UND '-'",
130-
"SET VERIFY OFF ",
131-
"SET WRAP OFF"
132-
],
112+
"before": [],
133113
"after": [],
114+
"env_optional": {
115+
"NLS_LANG": "{nls_lang}"
116+
},
134117
"args": "{username}/{password}@\"(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST={host})(PORT={port})))(CONNECT_DATA=(SERVICE_NAME={service})))\"",
135118
"queries": {
136-
"exec": {
137-
"options": []
119+
"execute": {
120+
"options": [],
121+
"before": [
122+
// "SET TIMING ON",
123+
"SET LINESIZE 32767",
124+
"SET PAGESIZE 0",
125+
"SET EMBEDDED ON",
126+
"SET WRAP OFF",
127+
"SET TAB OFF",
128+
"SET TRIMOUT ON",
129+
"SET TRIMSPOOL ON",
130+
"SET NULL '@'",
131+
"SET COLSEP '|'",
132+
"SET FEEDBACK ON",
133+
"SET SERVEROUT ON",
134+
"SET SQLBLANKLINES ON"
135+
]
138136
},
139137
"desc" : {
140-
"query": "select concat(concat(concat(concat('|', owner), '.'), table_name), '|') as tbls from all_tables UNION ALL select concat(concat(concat(concat('|', owner), '.'), view_name), '|') as tbls from all_views;",
141-
"options": []
138+
"query": "select owner || '.' || name as obj from (select owner, table_name as name from all_tables union all select owner, view_name as name from all_views) o where owner not in ('ANONYMOUS','APPQOSSYS','CTXSYS','DBSNMP','EXFSYS', 'LBACSYS', 'MDSYS','MGMT_VIEW','OLAPSYS','OWBSYS','ORDPLUGINS', 'ORDSYS','OUTLN', 'SI_INFORMTN_SCHEMA','SYS','SYSMAN','SYSTEM', 'TSMSYS','WK_TEST','WKSYS', 'WKPROXY','WMSYS','XDB','APEX_040000', 'APEX_PUBLIC_USER','DIP', 'FLOWS_30000','FLOWS_FILES','MDDATA', 'ORACLE_OCM','SPATIAL_CSW_ADMIN_USR', 'SPATIAL_WFS_ADMIN_USR', 'XS$NULL','PUBLIC');",
139+
"options": [],
140+
"before": [
141+
"SET LINESIZE 32767",
142+
"SET PAGESIZE 0",
143+
"SET EMBEDDED ON",
144+
"SET WRAP OFF",
145+
"SET HEADING OFF",
146+
"SET FEEDBACK OFF",
147+
"SET TRIMOUT ON"
148+
]
142149
},
143150
"columns": {
144-
"query": "SELECT concat(concat(concat(concat('|', c.table_name), '.'), c.column_name), '|') AS cols FROM all_tab_columns c INNER JOIN all_tables t ON c.owner = t.owner AND c.table_name = t.table_name UNION ALL SELECT concat(concat(concat(concat('|', c.table_name), '.'), c.column_name), '|') AS cols FROM all_tab_columns c INNER JOIN all_views t ON c.owner = t.owner AND c.table_name = t.view_name;",
145-
"options": []
151+
"query": "select table_name || '.' || column_name as obj from (select c.table_name, c.column_name, t.owner from all_tab_columns c inner join all_tables t on c.owner = t.owner and c.table_name = t.table_name union all select c.table_name, c.column_name, t.owner from all_tab_columns c inner join all_views t on c.owner = t.owner and c.table_name = t.view_name) o where owner not in ('ANONYMOUS','APPQOSSYS','CTXSYS','DBSNMP','EXFSYS', 'LBACSYS', 'MDSYS','MGMT_VIEW','OLAPSYS','OWBSYS','ORDPLUGINS', 'ORDSYS','OUTLN', 'SI_INFORMTN_SCHEMA','SYS','SYSMAN','SYSTEM', 'TSMSYS','WK_TEST','WKSYS', 'WKPROXY','WMSYS','XDB','APEX_040000', 'APEX_PUBLIC_USER','DIP', 'FLOWS_30000','FLOWS_FILES','MDDATA', 'ORACLE_OCM','SPATIAL_CSW_ADMIN_USR', 'SPATIAL_WFS_ADMIN_USR', 'XS$NULL','PUBLIC');",
152+
"options": [],
153+
"before": [
154+
"SET LINESIZE 32767",
155+
"SET PAGESIZE 0",
156+
"SET EMBEDDED ON",
157+
"SET WRAP OFF",
158+
"SET HEADING OFF",
159+
"SET FEEDBACK OFF",
160+
"SET TRIMOUT ON"
161+
]
162+
},
163+
"functions": {
164+
"query": "select case when object_type = 'PACKAGE' then object_name||'.'||procedure_name else owner || '.' || object_name end || '()' as obj from all_procedures where object_type in ('FUNCTION','PROCEDURE','PACKAGE') and owner = sys_context('USERENV', 'CURRENT_SCHEMA');",
165+
"options": [],
166+
"before": [
167+
"SET LINESIZE 32767",
168+
"SET PAGESIZE 0",
169+
"SET EMBEDDED ON",
170+
"SET WRAP OFF",
171+
"SET HEADING OFF",
172+
"SET FEEDBACK OFF",
173+
"SET TRIMOUT ON"
174+
]
146175
},
147176
"desc table": {
148177
"query": "desc {0};",
149-
"options": []
178+
"options": [],
179+
"before": [
180+
"SET LINESIZE 80", // altered for readability
181+
"SET PAGESIZE 0",
182+
"SET EMBEDDED ON",
183+
"SET WRAP OFF",
184+
"SET TAB OFF",
185+
"SET TRIMOUT ON",
186+
"SET TRIMSPOOL ON",
187+
"SET NULL '@'",
188+
"SET COLSEP '|'",
189+
"SET FEEDBACK ON",
190+
"SET SERVEROUT ON",
191+
"SET SQLBLANKLINES ON"
192+
]
150193
},
151194
"show records": {
152195
"query": "select * from {0} WHERE ROWNUM <= {1};",
153-
"options": []
196+
"options": [],
197+
"before": [
198+
"SET LINESIZE 32767",
199+
"SET PAGESIZE 0",
200+
"SET EMBEDDED ON",
201+
"SET WRAP OFF",
202+
"SET TAB OFF",
203+
"SET TRIMOUT ON",
204+
"SET TRIMSPOOL ON",
205+
"SET NULL '@'",
206+
"SET COLSEP '|'",
207+
"SET FEEDBACK ON",
208+
"SET SERVEROUT ON",
209+
"SET SQLBLANKLINES ON"
210+
]
154211
},
155212
"explain plan": {
156213
"query": "explain plan for {0};\nselect plan_table_output from table(dbms_xplan.display());",
157-
"options": []
214+
"options": [],
215+
"before": [
216+
"SET LINESIZE 32767",
217+
"SET PAGESIZE 0",
218+
"SET EMBEDDED ON",
219+
"SET WRAP OFF",
220+
"SET TAB OFF",
221+
"SET TRIMOUT ON",
222+
"SET TRIMSPOOL ON",
223+
"SET NULL '@'",
224+
"SET COLSEP '|'",
225+
"SET FEEDBACK ON",
226+
"SET SERVEROUT ON",
227+
"SET SQLBLANKLINES ON"
228+
]
158229
}
159230
}
160231
},
@@ -165,7 +236,7 @@
165236
"args": "-h{host} -P{port} -u\"{username}\" -D\"{database}\"",
166237
"args_optional": ["--login-path=\"{login-path}\"", "--defaults-extra-file=\"{defaults-extra-file}\"", "-p\"{password}\""],
167238
"queries": {
168-
"exec": {
239+
"execute": {
169240
"options": ["--table", "-f"]
170241
},
171242
"desc" : {
@@ -201,28 +272,45 @@
201272
"mssql": {
202273
"options": [],
203274
"before": [],
204-
"after": ["GO", "QUIT"],
275+
"after": ["go", "quit"],
205276
"args": "-d \"{database}\"",
206277
"args_optional": ["-S \"{host},{port}\"", "-S \"{host}\\{instance}\"", "-U \"{username}\"", "-P \"{password}\""],
207278
"queries": {
208-
"exec": {
279+
"execute": {
280+
"options": ["-k"]
281+
},
282+
"show records": {
283+
"query": "select top {1} * from {0};",
209284
"options": []
210285
},
286+
"desc table": {
287+
"query": "exec sp_help N'{0}';",
288+
"options": ["-y30", "-Y30"]
289+
},
290+
"desc function": {
291+
"query": "exec sp_helptext N'{0}';",
292+
"options": ["-h-1"]
293+
},
211294
"desc": {
212-
"query": "set nocount on; select concat(table_schema, '.', table_name) from information_schema.tables order by table_name;",
213-
"options": ["-h", "-1"]
295+
"query": "set nocount on; select concat(table_schema, '.', table_name) as obj from information_schema.tables order by table_schema, table_name;",
296+
"options": ["-h-1"]
214297
},
215298
"columns": {
216-
"query": "set nocount on; select concat(table_name, '.', column_name) from information_schema.columns order by table_name, ordinal_position;",
217-
"options": ["-h", "-1"]
218-
},
219-
"desc table": {
220-
"query": "exec sp_help \"{0}\";",
221-
"options": []
299+
"query": "set nocount on; select distinct concat(table_name, '.', column_name) as obj from information_schema.columns;",
300+
"options": ["-h-1"]
222301
},
223-
"show records": {
224-
"query": "select top {1} * from {0};",
225-
"options": []
302+
"functions": {
303+
"query": "set nocount on; select concat(routine_schema, '.', routine_name) as obj from information_schema.routines order by routine_schema, routine_name;",
304+
"options": ["-h-1"]
305+
},
306+
"explain plan": {
307+
"query": "{0};",
308+
"options": ["-k"],
309+
"before": [
310+
"SET STATISTICS PROFILE ON",
311+
"SET STATISTICS IO ON",
312+
"SET STATISTICS TIME ON"
313+
]
226314
}
227315
}
228316
},
@@ -232,7 +320,7 @@
232320
"after": [],
233321
"args": "-h {host} -p {port} -U \"{username}\" -w \"{password}\" -d \"{database}\"",
234322
"queries": {
235-
"exec": {
323+
"execute": {
236324
"options": []
237325
},
238326
"desc" : {
@@ -263,7 +351,7 @@
263351
"after": [],
264352
"args": "-S {host}:{port} -U\"{username}\" -P\"{password}\" -D{database}",
265353
"queries": {
266-
"exec": {
354+
"execute": {
267355
"options": [],
268356
"before": ["\\set semicolon_cmd=\"\\go -mpretty -l\""]
269357
},
@@ -295,7 +383,7 @@
295383
"after": [],
296384
"args": "\"{database}\"",
297385
"queries": {
298-
"exec": {
386+
"execute": {
299387
"options": ["-column", "-header"]
300388
},
301389
"desc" : {
@@ -322,7 +410,7 @@
322410
"after": [],
323411
"args": "-u \"{username}\" -p \"{password}\" \"{host}/{port}:{database}\"",
324412
"queries": {
325-
"exec": {
413+
"execute": {
326414
"options": []
327415
},
328416
"desc" : {

0 commit comments

Comments
 (0)