我的缓冲区中的 .sql 文件中有此内容:
CREATE TABLE WH.dbo.customer(
id INTEGER NOT NULL,
cust_name VARCHAR(30) NOT NULL,
phone_nbr VARCHAR(30) NULL,
PRIMARY KEY(id)
);
如果我处于正常模式并且光标位于 TABLE
那么我应该能够点击 <Leader>se
或命令 gVim 至 :DBExecSQLUnderCursor
并且该语句应该执行,因为 dbext 应该找到 CREATE
和;
然后执行中间的脚本。但我收到以下消息:
Last SQL:
CREATE TABLE WHAnalysis.dbo.customer(
如果我突出显示所有脚本并从插件菜单中选择“执行 SQL”(可视化选择),则它可以正常运行。
这是怎么回事?难道是我的_vimrc
中的一个设置?:
set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin
set diffexpr=MyDiff()
" Use CTRL-S for saving, also in Insert mode
:nnoremap <C-S> :<C-U>update<CR>
:vnoremap <C-S> :<C-U>update<CR>gv
:cnoremap <C-S> <C-C>:update<CR>
:inoremap <C-S> <C-O>:update<CR>
" Microsoft SQL Server
let g:dbext_default_profile_WH = 'type=SQLSRV:user=dbuser:passwd=dbuserpassword:dsnname=SQLOLEDB.1:srvname=dwdb'
set nocp
call pathogen#infect()
syntax on
filetype plugin indent on
"Mouse and backspace
set mouse=a
function MyDiff()
let opt = '-a --binary '
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
let arg1 = v:fname_in
if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
let arg2 = v:fname_new
if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
let arg3 = v:fname_out
if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
let eq = ''
if $VIMRUNTIME =~ ' '
if &sh =~ '\<cmd'
let cmd = '""' . $VIMRUNTIME . '\diff"'
let eq = '"'
else
let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
endif
else
let cmd = $VIMRUNTIME . '\diff'
endif
silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction
nnoremap <Leader>p :pyf P:\Computer Applications\Python\
"quick quit command
noremap <Leader>e :quit<CR> "quits the current window
" Rebind <Leader> key
let mapleader = ","
map <Leader>n <esc>:tabprevious<CR>
map <Leader>m <esc>:tabnext<CR
最佳答案
我与插件维护者 David Fishburn 进行了交谈 - 我对他为帮助像我这样的新手而付出的努力感到惊讶:伟大的人。
最初他建议
I believe the cmd terminator for SQLSRV is "\ngo\n" not ";".
If you want to change it temporarily to try in this buffer run: :DBSetOption cmd_terminator=';'
Try the cmd again.
If that works you can either override the default or change your profile to override it.
然后回答一些进一步的相关问题:
Q1. What is "\ngo\n" ?
Because the string is enclosed in double quotes, Vim treats escaped characters differently. \n - newline go \n - newline
So for SQL Server this would be typical:
CREATE PROCEDURE BEGIN END go
Which is actually:
"END\ngo\n"In other words, "go" has to be on a newline, with only "go" on the line.
Q2. Do I just add the following to _vimrc for it to become permanent?:
DBSetOption cmd_terminator=';'
没有。 :DBSetOption 仅用于修改当前缓冲区设置,不用于修改 永久设置。
您能做的最好的事情就是通读 :h dbext.txt。
您的问题的具体答案在于:h dbext-configure-options
5.3 数据库特定选项dbext-configure-options 命令终止符会在命令执行之前自动添加到命令中 发送到数据库。命令选项也添加到命令中 用于执行语句的行。 >
dbext_default_SQLSRV_bin = "osql" dbext_default_SQLSRV_cmd_header = "" dbext_default_SQLSRV_cmd_terminator = "\ngo\n" dbext_default_SQLSRV_cmd_options = '-w 10000 -r -b -n' dbext_default_SQLSRV_extra = ''
因此,要永久覆盖 .vimrc 中的所有缓冲区,您需要 添加:
block 引用>
让 g:dbext_default_SQLSRV_cmd_terminator = ";"
关于sql - dbext 似乎认为 ( 是一个sql语句终止符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16512525/