Skip to content

Commit e0bb9b4

Browse files
committed
v.1.5.0 pyodbc update, osx support, st2 dropped
1 parent 64f28f9 commit e0bb9b4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1896
-958
lines changed

Default (Linux).sublime-keymap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
{ "keys": ["ctrl+shift+f11"], "command": "tsql_easy_set_active_server" },
44
{ "keys": ["ctrl+alt+c"], "command": "tsql_easy_open_console" },
55
{ "keys": ["ctrl+alt+o"], "command": "tsql_easy_open_server_object" },
6-
{ "keys": ["r"], "command": "tsql_easy_activity_monitor", "args": {"is_refresh": true}, "context": [{"key": "setting.te_activity_monitor", "operand": true}] },
7-
{ "keys": ["r"], "command": "tsql_easy_long_queries", "args": {"is_refresh": true}, "context": [{"key": "setting.te_long_queries", "operand": true}] },
6+
{ "keys": ["r"], "command": "tsql_easy_activity_monitor_refresh", "context": [{"key": "setting.te_activity_monitor", "operand": true}] },
7+
{ "keys": ["r"], "command": "tsql_easy_long_queries_refresh", "context": [{"key": "setting.te_long_queries", "operand": true}] },
88
{ "keys": ["enter"], "command": "tsql_easy_show_query", "context": [{"key": "setting.te_activity_monitor", "operand": true} ] },
99
{ "keys": ["enter"], "command": "tsql_easy_show_query", "context": [{"key": "setting.te_long_queries", "operand": true} ] }
1010
]

Default (OSX).sublime-keymap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
{ "keys": ["ctrl+alt+f11"], "command": "tsql_easy_set_active_server" },
44
{ "keys": ["ctrl+alt+c"], "command": "tsql_easy_open_console" },
55
{ "keys": ["ctrl+alt+o"], "command": "tsql_easy_open_server_object" },
6-
{ "keys": ["r"], "command": "tsql_easy_activity_monitor", "args": {"is_refresh": true}, "context": [{"key": "setting.te_activity_monitor", "operand": true}] },
7-
{ "keys": ["r"], "command": "tsql_easy_long_queries", "args": {"is_refresh": true}, "context": [{"key": "setting.te_long_queries", "operand": true}] },
6+
{ "keys": ["r"], "command": "tsql_easy_activity_monitor_refresh", "context": [{"key": "setting.te_activity_monitor", "operand": true}] },
7+
{ "keys": ["r"], "command": "tsql_easy_long_queries_refresh", "context": [{"key": "setting.te_long_queries", "operand": true}] },
88
{ "keys": ["enter"], "command": "tsql_easy_show_query", "context": [{"key": "setting.te_activity_monitor", "operand": true} ] },
99
{ "keys": ["enter"], "command": "tsql_easy_show_query", "context": [{"key": "setting.te_long_queries", "operand": true} ] }
1010
]

Default (Windows).sublime-keymap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
{ "keys": ["ctrl+alt+f11"], "command": "tsql_easy_set_active_server" },
44
{ "keys": ["ctrl+alt+c"], "command": "tsql_easy_open_console" },
55
{ "keys": ["ctrl+alt+o"], "command": "tsql_easy_open_server_object" },
6-
{ "keys": ["r"], "command": "tsql_easy_activity_monitor", "args": {"is_refresh": true}, "context": [{"key": "setting.te_activity_monitor", "operand": true}] },
7-
{ "keys": ["r"], "command": "tsql_easy_long_queries", "args": {"is_refresh": true}, "context": [{"key": "setting.te_long_queries", "operand": true}] },
6+
{ "keys": ["r"], "command": "tsql_easy_activity_monitor_refresh", "context": [{"key": "setting.te_activity_monitor", "operand": true}] },
7+
{ "keys": ["r"], "command": "tsql_easy_long_queries_refresh", "context": [{"key": "setting.te_long_queries", "operand": true}] },
88
{ "keys": ["enter"], "command": "tsql_easy_show_query", "context": [{"key": "setting.te_activity_monitor", "operand": true} ] },
99
{ "keys": ["enter"], "command": "tsql_easy_show_query", "context": [{"key": "setting.te_long_queries", "operand": true} ] }
1010
]

Main.sublime-menu

Lines changed: 8 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -39,63 +39,20 @@
3939
},
4040
{ "caption": "-" },
4141
{
42-
"command": "open_file",
43-
"args": {"file": "${packages}/TSQLEasy/TSQLEasy.sublime-settings"},
44-
"caption": "Settings - Default"
45-
},
46-
{
47-
"command": "open_file",
48-
"args": {"file": "${packages}/User/TSQLEasy.sublime-settings"},
49-
"caption": "Settings – User"
50-
},
51-
{ "caption": "-" },
52-
{
53-
"command": "open_file",
42+
"command": "edit_settings",
5443
"args": {
55-
"file": "${packages}/TSQLEasy/Default (Windows).sublime-keymap",
56-
"platform": "Windows"
44+
"base_file": "${packages}/TSQLEasy/TSQLEasy.sublime-settings",
45+
"default": "{\n\t$0\n}\n"
5746
},
58-
"caption": "Key Bindings – Default"
47+
"caption": "Settings"
5948
},
6049
{
61-
"command": "open_file",
62-
"args": {
63-
"file": "${packages}/TSQLEasy/Default (OSX).sublime-keymap",
64-
"platform": "OSX"
65-
},
66-
"caption": "Key Bindings – Default"
67-
},
68-
{
69-
"command": "open_file",
70-
"args": {
71-
"file": "${packages}/TSQLEasy/Default (Linux).sublime-keymap",
72-
"platform": "Linux"
73-
},
74-
"caption": "Key Bindings – Default"
75-
},
76-
{
77-
"command": "open_file",
78-
"args": {
79-
"file": "${packages}/User/Default (Windows).sublime-keymap",
80-
"platform": "Windows"
81-
},
82-
"caption": "Key Bindings – User"
83-
},
84-
{
85-
"command": "open_file",
86-
"args": {
87-
"file": "${packages}/User/Default (OSX).sublime-keymap",
88-
"platform": "OSX"
89-
},
90-
"caption": "Key Bindings – User"
91-
},
92-
{
93-
"command": "open_file",
50+
"command": "edit_settings",
9451
"args": {
95-
"file": "${packages}/User/Default (Linux).sublime-keymap",
96-
"platform": "Linux"
52+
"base_file": "${packages}/TSQLEasy/Default ($platform).sublime-keymap",
53+
"default": "[\n\t$0\n]\n"
9754
},
98-
"caption": "Key Bindings – User"
55+
"caption": "Key Bindings"
9956
}
10057
]
10158
}

README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# Sublime Text plugin: TSQL Easy
22

3-
[TSQL Easy](https://github.com/tosher/TSQLEasy) is a plugin for Sublime Text editor (ver. 2/3) that adds possibility to read/write/execute sql requests to Microsoft SQL Server and some IDE-like functionality.
3+
[TSQL Easy](https://github.com/tosher/TSQLEasy) is a plugin for Sublime Text 3 editor that adds possibility to read/write/execute sql requests to Microsoft SQL Server and some IDE-like functionality.
44
Server connections based on [pyODBC](https://code.google.com/p/pyodbc/) library.
55

6+
**NOTE**: Sublime text 2 is not supported anymore. Please use Sublime text 3.
7+
68
## Main features
79
* Manage connections to SQL Servers.
810
* Execute sql requests on SQL Server.
@@ -11,19 +13,20 @@ Server connections based on [pyODBC](https://code.google.com/p/pyodbc/) library.
1113
* Possibility to receive code of procedure, functions by text under cursor.
1214
* Possibility to open local files with the same name as stored procedure (function, etc.): **ProcedureName** -> **ProcedureName.sql**.
1315
* Improved syntax highlighting for TSQL.
14-
* Reports: **Activity monitor**, **Long running queries**
16+
* Reports:
17+
- Activity monitor
18+
- Long running queries
1519

1620
**Warning!** Server connection required for full functionality or use fake server with empty **driver** value for work offline without completions, etc.
1721

1822
### PyODBC
19-
Now, package includes pyODBC (3.0.7) binaries:
23+
Now, package includes [pyODBC](https://code.google.com/p/pyodbc/) (4.0.22) binaries:
2024

21-
* Windows: ST2/3 x32/x64
22-
* Linux: ST2/3 x64
23-
* Pull requests are welcome! :)
25+
* Windows: ST3 x64 (x32 with old pyodbc 3.0.7)
26+
* Linux: ST3 x64
27+
* OSX: ST3 x64
2428

2529
## Commands
26-
2730
* Open console - open new console for sql requests
2831
* Server select - change predefined sql server connection
2932
* Execute - execute the request (<kbd>F5</kbd>)
@@ -40,6 +43,6 @@ The easiest way to install this is with [Package Control](http://wbond.net/subli
4043
* If you just went and installed Package Control, you probably need to restart Sublime Text before doing this next bit.
4144
* Bring up the Command Palette (<kbd>Command</kbd>+<kbd>Shift</kbd>+<kbd>p</kbd> on OS X, <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>p</kbd> on Linux/Windows).
4245
* Select "Package Control: Install Package" (it'll take a few seconds)
43-
* Select TSQL Easy when the list appears.
46+
* Select `TSQL Easy` when the list appears.
4447

45-
Package Control will automatically keep **TSQL Easy** up to date with the latest version.
48+
Package Control will automatically keep `TSQL Easy` up to date with the latest version.

TSQLEasy.sublime-settings

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,34 @@
22
"te_sql_server":
33
{
44
"Main": {
5-
"driver": "SQL Server",
5+
"dsn": "", // based on system connectivity settings, use odbc `dsn` or `server` name/ip
6+
"driver": "SQL Server", // FreeTDS
67
"server": "127.0.0.1",
78
"server_port": 1433,
89
"username": "",
910
"password": "",
1011
"database": "",
11-
"autocommit": true
12+
"autocommit": true,
13+
"timeout": 0
1214
},
1315
"Offline": {
1416
"driver": ""
1517
}
1618
},
1719
"te_server_active": "Main",
18-
"te_encodings":
19-
{
20-
"main_profile": "utf-8"
21-
},
22-
"te_sql_profile": "main_profile",
23-
"te_procedure_path": [],
20+
// deprecated
21+
// "te_encodings":
22+
// {
23+
// "main_profile": "utf-8"
24+
// },
25+
// "te_sql_profile": "main_profile",
26+
"te_procedure_path": [], // pathes to local source files
2427
"te_result_in_tab": false,
2528
"te_result_in_new_tab": false,
2629
"te_show_request_in_result": false,
2730
"te_syntax": "Packages/TSQLEasy/TSQL.tmLanguage",
2831
"te_report_syntax": "Packages/Markdown/Markdown.tmLanguage",
29-
"te_activity_monitor_min_pid": 50,
32+
"te_activity_monitor_min_pid": 50, // show/hide system processes
3033

3134
"te_activity_monitor_columns": [
3235
{ "prop": "spid", "colname": "SPID", "align": "right" },

base/__init__.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python\n
2+
# -*- coding: utf-8 -*-
3+
4+
from .te_set_active_server import TsqlEasySetActiveServerCommand
5+
from .te_utils import TsqlEasyInsertTextCommand
6+
from .te_sql_exec import TsqlEasyExecSqlCommand
7+
from .te_open_console import TsqlEasyOpenConsoleCommand
8+
from .te_open_server_obj import TsqlEasyOpenServerObjectCommand
9+
from .te_open_local_obj import TsqlEasyOpenLocalObjectCommand
10+
from .te_activity_monitor import TsqlEasyActivityMonitorCommand
11+
from .te_activity_monitor import TsqlEasyActivityMonitorRefreshCommand
12+
from .te_long_queries import TsqlEasyLongQueriesCommand
13+
from .te_long_queries import TsqlEasyLongQueriesRefreshCommand
14+
from .te_show_query import TsqlEasyShowQueryCommand
15+
16+
__all__ = [
17+
'TsqlEasySetActiveServerCommand',
18+
'TsqlEasyInsertTextCommand',
19+
'TsqlEasyExecSqlCommand',
20+
'TsqlEasyOpenConsoleCommand',
21+
'TsqlEasyOpenServerObjectCommand',
22+
'TsqlEasyOpenLocalObjectCommand',
23+
'TsqlEasyActivityMonitorCommand',
24+
'TsqlEasyActivityMonitorRefreshCommand',
25+
'TsqlEasyLongQueriesCommand',
26+
'TsqlEasyLongQueriesRefreshCommand',
27+
'TsqlEasyShowQueryCommand'
28+
]

sqlodbccon.py renamed to base/sqlodbccon.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,20 @@
55
import os.path
66
import sublime
77

8-
pythonver = sys.version_info[0]
8+
odbc_lib_path = os.path.normpath(
9+
os.path.join(
10+
os.path.dirname(__file__),
11+
'..',
12+
'lib',
13+
'st3_%s_%s' % (sublime.platform(), sublime.arch())
14+
)
15+
)
916

10-
st_version = 2
11-
if int(sublime.version()) > 3000:
12-
st_version = 3
13-
14-
odbc_lib_path = os.path.join(os.path.dirname(__file__), 'lib', 'st%d_%s_%s' % (st_version, sublime.platform(), sublime.arch()))
1517
sys.path.append(odbc_lib_path)
18+
19+
# macos workable hint to use system lib
20+
# sys.path.append('~/.pyenv/versions/3.3.6/lib/python3.3/site-packages')
21+
1622
try:
1723
import pyodbc
1824
print('TSQLEasy: PyODBC was loaded successfully.')
@@ -75,6 +81,7 @@ def dbconnect(self):
7581
self.sqlcursor = None
7682
try:
7783
self.sqlconnection = pyodbc.connect(self.connection_string, autocommit=self.autocommit, timeout=self.timeout)
84+
# self.sqlconnection.setencoding('utf-8')
7885
if self.autocommit:
7986
self.sqlconnection.autocommit = True
8087
self.sqlcursor = self.sqlconnection.cursor()
@@ -102,7 +109,7 @@ def dbexec(self, sql_string, sql_params=None):
102109
try:
103110
self.sqlcursor.execute(sql_string, sql_params)
104111
except Exception as e:
105-
raise
112+
raise Exception('Error while request execution: %s, query: %s, params: %s' % (e, sql_string, sql_params))
106113

107114
try:
108115
self.sqlcolumns = self.sqlcursor.description
@@ -111,6 +118,6 @@ def dbexec(self, sql_string, sql_params=None):
111118
if str(e).startswith('No results'):
112119
pass
113120
else:
114-
raise
121+
raise(e)
115122
except Exception as e:
116-
raise
123+
raise(e)

base/te_activity_monitor.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env python\n
2+
# -*- coding: utf-8 -*-
3+
4+
from datetime import datetime
5+
import sublime
6+
import sublime_plugin
7+
from . import te_utils as utils
8+
9+
10+
class TsqlEasyActivityMonitorCommand(sublime_plugin.TextCommand):
11+
# OUTER APPLY Fn_get_sql(sp.sql_handle)
12+
# NOTE: pyodbc return empty result with comment like:
13+
# -- OUTER APPLY sys.dm_exec_sql_text(sp.sql_handle)
14+
sql_query = '''
15+
SELECT
16+
sp.spid,
17+
/* TEXT as query, */
18+
Db_name(sp.dbid) as dbname,
19+
sp.cpu,
20+
sp.memusage,
21+
sp.status,
22+
sp.loginame,
23+
sp.hostname,
24+
sp.blocked,
25+
sp.waittime,
26+
sp.lastwaittype,
27+
sp.waitresource,
28+
convert(varchar(255), sp.login_time) as login_time,
29+
convert(varchar(255), sp.last_batch) as last_batch,
30+
sp.cmd,
31+
sp.open_tran,
32+
sp.program_name
33+
FROM sys.sysprocesses as sp
34+
/* OUTER APPLY sys.dm_exec_sql_text(sp.sql_handle) */
35+
WHERE sp.spid > ?
36+
ORDER BY sp.spid
37+
'''
38+
39+
def run(self, edit):
40+
view = self.prepare_view(edit)
41+
self.show(view)
42+
43+
def set_title(self, view):
44+
current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
45+
self.title = 'Activity monitor (at %s)' % current_time
46+
view.set_name(self.title)
47+
48+
def prepare_view(self, edit):
49+
view = self.view.window().new_file()
50+
view.settings().set('te_activity_monitor', True)
51+
syntax_file = utils.te_get_setting('te_report_syntax', utils.DEFAULT_REPORT_SYNTAX)
52+
view.set_syntax_file(syntax_file)
53+
return view
54+
55+
def show(self, view):
56+
self.set_title(view)
57+
min_pid = utils.te_get_setting('te_activity_monitor_min_pid', 50)
58+
sql_params = (min_pid,)
59+
text = utils.te_show_data(title=self.title, sql_query=self.sql_query, sql_params=sql_params, setup_columns='te_activity_monitor_columns')
60+
view.settings().set("word_wrap", False)
61+
view.run_command('tsql_easy_insert_text', {'position': 0, 'text': text + '\n\n'})
62+
view.set_scratch(True)
63+
view.set_read_only(True)
64+
65+
66+
class TsqlEasyActivityMonitorRefreshCommand(TsqlEasyActivityMonitorCommand):
67+
68+
def prepare_view(self, edit):
69+
view = self.view
70+
view.set_read_only(False)
71+
view.erase(edit, sublime.Region(0, view.size()))
72+
return view
73+
74+
def is_visible(self, *args):
75+
is_actmon = self.view.settings().get('te_activity_monitor', False)
76+
77+
if is_actmon:
78+
return True
79+
return False

0 commit comments

Comments
 (0)