Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect to MS SQLServer using Vim dbext on Mac OSX?

I use MacVim and the dbext plugin to connect to Oracle and it works well. Now I need to connect to MS SQLServer, but it showed error:

Connection: T(SQLSRV) H(localhost) U(user) at 14:38 /bin/bash: osql: command not found

Anyone know how to do this?

like image 624
eureka Avatar asked Nov 26 '25 09:11

eureka


1 Answers

Make sure you have one of the FreeTDS CLI programs. I think tsql is more full featured then osql, but the same approach should work with either.

Create a shell script to wrap tsql. Put it somewhere in your path.

Then add the dbext config values to your .vimrc

" I'm using mssql.sh as the wrapper program. 
" Re-title to whatever you name yours

let g:dbext_default_SQLSRV_bin = "mssql.sh"

" FreeTDS options for osql/tsql are not as feature rich as dbext expects

let g:dbext_default_SQLSRV_cmd_options = ' '

" set 'host' in you profile to the FreeTDS server config, which will be altered in the script

The wrapper I whipped up is nothing special, but it's tested and works.

#!/bin/bash

# -S is better for FreeTDS then -H
options=$( echo $@ | sed -e 's/-H /-S /' -e 's/ -i.*//' )
# osql/tsql in freetds don't seem to accept a file flag
sql_scratch=$( echo $@ | sed 's|^.* -i||' )
# and execute...
cat $sql_scratch | tsql $options
like image 161
Joe Fortier Avatar answered Nov 29 '25 00:11

Joe Fortier



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!