Closed bybor closed 3 years ago
- add option to use additional "filter" (as
xsv
) against the output before showing it. It may be better to use a file and not a pipe
The other stuff is maybe but this would require significant retooling and is almost certainly a no.
What I really want is a better way for displaying query results, the above is just one approach that I tried to implement wrapping
sqlcmd
in extracmd
(windows) file and failed.
With just the set nocount on
option, I would expect making a wrapper script to be a lot more tenable. I would encourage you to try adding a hard-coded version and see if you can crack this nut.
function! db#adapter#sqlserver#massage(input) abort
return "SET NOCOUNT ON;" . a:input
endfunction
Thanks, makes sense.
The above function! db#adapter#sqlserver#massage(input) abort
doesn't seem to work for me. I assumed that it gets called for every query executed with :DB
, is it right?
If I add function! db#adapter#sqlserver#massage(input) abort
into vim-dadbod\autoload\db\adapter\sqlserver.vim
is it enough?
I don't understand how it's called. I can see massage
functions in other adapters, but cannot figure it out.
Thank you for help!
Looks like it doesn't get called for operations on a range like :%DB
. Try passing a string argument and see if that works.
Yes, it does. Before that I ran DB
against visually selected lines.
Could you tell if there is a way to apply set nocount on;
everywhere "sql server"?
Thanks
There's not, and there's not really a good way to add that, because sometimes we directly pass a file name (it can give better error messages). I'm afraid you may be stuck with figuring out how to write a wrapper script. I can't speak for cmd
, but if you escalated to something like python
, it's probably pretty doable. Check for -i
as the next to last argument, and if it's found, replace the last argument with a temp file that adds the set nocount on;
.
Thanks!
The issue is probably specific to
sqlcmd
- if the column isvarchar(256)
then it will take 256 characters no matter if content is shorter.There is
-W
command line parameter (and it's used infunction! s:complete(url, query) abort
, filesqlserver.vim
) which removes trailing spaces. This doesn't work great since the visual columns are lost.I found
xsv
tool that does "elastic tabstops" (https://github.com/BurntSushi/xsv), which could be used as additional filter on sqlcmd's output. The point is to make every column long enough to fit every cell's content, but not longer.sqlcmd
allows to use a custom column delimiter with-s
parameter,Here is a pseudo code:
set nocount on; is also important (and it is also used in
s:complete
function, this removes a messageX rows affected
from the output.Could you extend
vim-dadbod
pleaseset nocount on
to all queries (sql server);xsv
) against the output before showing it. It may be better to use a file and not a pipe-W
and-s
forsqlcmd
delimiter) for underlying sql executable, so it makes possible to usexsv
What I really want is a better way for displaying query results, the above is just one approach that I tried to implement wrapping
sqlcmd
in extracmd
(windows) file and failed.Thanks!