Skip to content

Commit 2f21200

Browse files
jayjohnstonJay Johnston
andauthored
Move "Time Query Took" to statusline. Add support for \G queries. (#12)
Co-authored-by: Jay Johnston <[email protected]>
1 parent 4b71781 commit 2f21200

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

plugin/vim-mysql-plugin.vim

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,30 @@ if exists("g:vim_mysql_plugin_loaded") || &cp
88
endif
99

1010
let g:vim_mysql_plugin_loaded = 1
11+
let g:vim_mysql_plugin_sqleof = ';'
1112

1213
fun! g:RunShellCommand(shell_command)
13-
echohl String | echon '¦ $ ' . a:shell_command . '...' | echohl None
14+
echohl String | echon '$ ' . a:shell_command[0:winwidth(0)-11] . '...' | echohl None
1415

1516
silent! exe "noautocmd botright pedit ¦"
1617
noautocmd wincmd P
18+
setl stl =Running...please\ wait
19+
redraw
1720
setlocal modifiable
1821
setlocal nowrap
1922
normal ggdG
2023

2124
set buftype=nofile
2225
silent! exe "noautocmd .! " . a:shell_command
23-
normal gg
26+
normal ggG
27+
let time = getline(".")
28+
exe 'setl stl=Done\ in\ ' . time[6:]
29+
normal kdG
2430
setlocal nomodifiable
2531
noautocmd wincmd p
2632
redraw!
2733

28-
echohl Comment | echon 'Done! ' . a:shell_command | echohl None
34+
echohl Comment | echon '$ '. a:shell_command[0:winwidth(0)-11] . '...' | echohl None
2935
endfun
3036

3137
fun! g:GetSelection()
@@ -47,7 +53,7 @@ fun! g:RunArray(sqlarray, timing)
4753
endif
4854

4955
if a:timing
50-
let l:thesql = ['SELECT NOW(3)+0 INTO @startTime;'] + a:sqlarray + ['; SELECT CONCAT(ROUND(NOW(3) - @startTime, 3), "s") Took']
56+
let l:thesql = ['SELECT NOW(3)+0 INTO @startTime;'] + a:sqlarray + ['; SELECT CONCAT(ROUND(NOW(3) - @startTime, 3), "s") Took\G']
5157
else
5258
let l:thesql = a:sqlarray
5359
endif
@@ -64,27 +70,39 @@ endfun
6470

6571
func! g:SelectCursorTable()
6672
let l:Table = expand('<cword>')
67-
call RunArray(['SELECT * FROM `' . l:Table . '` LIMIT 100;'], 0)
73+
call RunArray(['SELECT * FROM `' . l:Table . '` LIMIT 100' . g:vim_mysql_plugin_sqleof], 0)
6874
endfun
6975

7076
func! g:DescriptCursorTable()
7177
let l:Table = expand('<cword>')
72-
call RunArray(['SHOW FULL COLUMNS FROM `' . l:Table . '`;'], 0)
78+
call RunArray(['SHOW FULL COLUMNS FROM `' . l:Table . '`' . g:vim_mysql_plugin_sqleof], 0)
79+
endfun
80+
81+
fun! s:SetEosql(line)
82+
let eosql = getline(a:line)
83+
let m = matchstr(eosql, ';')
84+
if (empty(m))
85+
let g:vim_mysql_plugin_sqleof = '\G'
86+
else
87+
let g:vim_mysql_plugin_sqleof = ';'
88+
endif
7389
endfun
7490

7591
fun! s:GetInstruction()
76-
let l:PrevSemicolon = search(';', 'bnW')
77-
let l:NextSemicolon = search(';', 'nW')
92+
let l:p = '\(\G\|;\)'
93+
let l:PrevSemicolon = search(l:p, 'bnW')
94+
let l:NextSemicolon = search(l:p, 'cnW')
95+
call s:SetEosql(l:NextSemicolon)
7896
return getline(l:PrevSemicolon, l:NextSemicolon)[1:]
7997
endfun
8098

8199
fun! g:RunInstruction()
82-
let l:Lines = s:GetInstruction()
100+
let l:Lines = s:GetInstruction()
83101
call g:RunArray(l:Lines, 1)
84102
endfun
85103

86104
fun! g:RunExplain()
87-
let l:Lines = s:GetInstruction()
105+
let l:Lines = s:GetInstruction()
88106
call g:RunArray(['explain '] + l:Lines, 1)
89107
endfun
90108

0 commit comments

Comments
 (0)