Closed ichirou2910 closed 4 years ago
@ichirou2910 does executing the whole buffer work?
Yes it works fine
Can you just give me the format of your connection url? For example:
mysql://user:pass@host:port/dbname
mysql://user@host/dbname
Edit: sry got the wrong one
OK thanks, I'll look into it.
I'm not able to reproduce this. I'll need more info.
I found this regarding the error https://stackoverflow.com/questions/28452021/error-cant-initialize-batch-readline-may-be-the-input-source-is-a-directory
But i can't figure out what's wrong.
If you can, test this scenario and let me know if it works:
:DB < /home/yourname/Documents/myquery
Does it work?
@ichirou2910 I'll need you to test 2 more things:
:DB
command on that visual selection. Basically just use vim-dadbod's functionality.let g:dbui_tmp_query_location
to some location, for example:
let g:dbui_tmp_query_location = '~/Documents/queries`
Restart neovim and give it a test from start. This will create queries in that folder instead of using temp folder.
It's really confusing that thing from previous comment (DB < filename
) works fine, and this isn't, because i'm doing the same thing internally.
Just try these 2 things and let me know how it goes.
@ichirou2910 I added a debug mode in order to get some information around things that are happening in queries.
Add let g:db_ui_debug = 1
to your init.vim, and reproduce the bug. Then give me the output of :messages
.
@kristijanhusak Hi, took some time looking into your code and found that you parsed selected lines to another file. You can use '<,'> prefix to do that instead. I created a pull request for that, can you check it out? https://github.com/kristijanhusak/vim-dadbod-ui/pull/57
@ichirou2910 I know, but I'm doing that for a reason, and vim-dadbod does the same thing internally. Can you debug it with current functionality and see what's happening? Thanks.
That I tried too. Here are the what I found out
g:db_ui_tmp_query_location
What happens when you try to execute the command
part from the debug message?
In this case :DB < /tmp/nvim32zTHl/3
, but path will different on next run.
It's the same Somehow when I created a file containing the same queries in home folder it works
can you cat
that file?
I just pushed a small change to add an extension to the temp name. Can you give it another try?
Here you go
I pretty much believe this is because you create temp file in /tmp
. I changed this line of code:
function! s:query.execute_lines(db, lines, is_visual_mode) abort
let filename = tempname().'.'.db#adapter#call(a:db.conn, 'input_extension', [], 'sql')
to:
function! s:query.execute_lines(db, lines, is_visual_mode) abort
let filename = 'temp.sql'
And it worked just fine
That shouldn't be the issue, because dadbod does exactly same thing when executing queries https://github.com/tpope/vim-dadbod/blob/master/autoload/db.vim#L213
If you execute :DB
on visual selection, and check the content of the tmp folder (/tmp/nvim****/
), you will see an .sql
file that dadbod generated to execute.
That's what confuses me here.
Can you try that and then manually execute that sql file generated by dadbod with same command (:DB < /tmp/nvim****/dadbodsql.sql
) ?
'kay I'm so confused rn :confused:
As expected, :'<,'>DB
worked while :DB < /tmp/nvim*****/sqlfile
didn't work
Yeah, same :/
I'll need your help to debug it, since i can't reproduce it.
First, pull latest changes.
Then, go to vim-dadbod folder, and add echom string(cmd)
after this line https://github.com/tpope/vim-dadbod/blob/master/autoload/db.vim#L114
Then, open up the query buffer, and do first visual selection command ':<,'>DB
, and then try doing it with dadbod-ui mapping. Compare the two, and if possible, send me both here.
Also, try executing that command directly from terminal to see what will happen.
Mesages when use <leader>S
(didn;t work)
[DBUI Debug] {'input_filename': '/tmp/nvimcLLTiS/4.sql', 'message': 'Executing multiple lines', 'lines': ['des
cribe student;', 'describe teacher;'], 'command': 'DB < /tmp/nvimcLLTiS/4.sql'}
'mysql -h ''localhost'' -u ''<username>'' ''-p<password>'' ''test'' -t < ''/home/ichirou2910/'''
Messages when use :'<,'>DB
(worked)
'mysql -h ''localhost'' -u ''<username>'' ''-p<password>'' ''test'' -t < ''/tmp/nvimcLLTiS/8.sql'''
Mesages when use :DB < /tmp/nvim....
(didn't work)
'mysql -h ''localhost'' -u ''<username>'' ''-p<password>'' ''test'' -t < ''/home/ichirou2910/'''
Mesages when use :DB < test.sql
(worked)
'mysql -h ''localhost'' -u ''<username>'' ''-p<password>'' ''test'' -t < ''/home/ichirou2910/test.sql'''
And mysql -u <username> -p <password> test < /tmp/nvim...
worked
For some reason it is not properly figuring out the input file in some cases, and it defaults to home folder.
Lets try this. Add this line:
echom 'MAYBE INFILE '.string(maybe_infile)
After this line https://github.com/tpope/vim-dadbod/blob/master/autoload/db.vim#L215
And give it another test. Let me know what it prints out for this line.
Mesages when use <leader>S
(didn;t work)
[DBUI Debug] {'input_filename': '/tmp/nvimU2VYBz/4.sql', 'message': 'Executing multiple lines', 'lines': ['describe employee;', 'des
cribe student;'], 'command': 'DB < /tmp/nvimU2VYBz/4.sql'}
MAYBE INFILE '/tmp/nvimU2VYBz/4.sql'
'mysql -h ''localhost'' -u ''username '' ''-ppassword'' ''test'' -t < ''/home/ichirou2910/'''
Messages when use :'<,'>DB
(worked)
MAYBE INFILE ''
'mysql -h ''localhost'' -u ''username'' ''-ppassword'' ''test'' -t < ''/tmp/nvimU2VYBz/8.sql'''
Mesages when use :DB < /tmp/nvim....
(didn't work)
MAYBE INFILE '/tmp/nvimU2VYBz/4.sql'
'mysql -h ''localhost'' -u ''username'' ''-ppassword'' ''test'' -t < ''/home/ichirou2910/'''
Mesages when use :DB < test.sql
(worked)
MAYBE INFILE 'test.sql'
'mysql -h ''localhost'' -u ''username'' ''-ppassword'' ''test'' -t < ''/home/ichirou2910/test.sql'''
So confusing...
Sorry for bothering you so much, but this is really strange. I'll need few more things:
echo expand('/tmp/nvimU2VYBz/4.sql')
? Put valid tmp path in there just to be sure.echom 'INFILE BEFORE '.string(infile)
And after line https://github.com/tpope/vim-dadbod/blob/master/autoload/db.vim#L260, add this:
echom 'INFILE AFTER '.string(infile)
and re-test it.
test.sql
file and it gave /home/ichirou2910/test.sql
tho.<leader>S
vs :'<,'>DB
[DBUI Debug] {'input_filename': '/tmp/nvimkvRSfR/4.sql', 'message': 'Executing multiple lines', 'lines': ['describe student;', 'desc
ribe student;'], 'command': 'DB < /tmp/nvimkvRSfR/4.sql'}
MAYBE INFILE '/tmp/nvimkvRSfR/4.sql'
INFILE BEFORE ''
INFILE AFTER '/home/ichirou2910/'
'mysql -h ''localhost'' -u ''ichirou2910'' ''-pmegamanzero2910'' ''test'' -t < ''/home/ichirou2910/'''
MAYBE INFILE ''
INFILE BEFORE '/tmp/nvimkvRSfR/8.sql'
INFILE AFTER '/tmp/nvimkvRSfR/8.sql'
'mysql -h ''localhost'' -u ''ichirou2910'' ''-pmegamanzero2910'' ''test'' -t < ''/tmp/nvimkvRSfR/8.sql'''
The other cases I guess it's not important anymore
Ok that's definitely the issue. It properly expands for me.
What does it print when you do echo expand('/tmp/nvimkvRSfR/8.sql', ':p')
?
Which neovim version are you using?
:version
NVIM v0.4.4
Build type: Release
LuaJIT 2.0.5
Compilation: /usr/bin/cc -D_FORTIFY_SOURCE=2 -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -
O2 -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wm
issing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_D
ECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/build/neovim/src/build/config -I/build/neovim/src/
neovim-0.4.4/src -I/usr/include -I/build/neovim/src/build/src/nvim/auto -I/build/neovim/src/build/include
Compiled by builduser
Features: +acl +iconv +tui See ":help feature-compile"
system vimrc file: "$VIM/sysinit.vim" fall-back for $VIM: "/usr/share/nvim"
Run :checkhealth for more info
@ichirou2910 and what about this:
echo fnamemodify('/tmp/nvimkvRSfR/8.sql', ':p')
I'm using latest neovim from master. Will try the stable version.
/tmp/nvimkvRSfR/8.sql
I just tried same version, everything works fine.
Do you have your tmp folder as a separate partition which you mount? Is it maybe a symlink?
I found this regarding failed expand() calls https://github.com/chrisbra/SudoEdit.vim/issues/17#issue-9338315
What does ls -la /tmp/nvim***
give after you try to execute these queries?
It would be good if you could try this on a different version of neovim, or in vim.
I pushed a fix. It uses dadbod's visual selection when available. So if you don't use bind parameters feature, which you don't (judging by the examples in this issue), it should work out for you.
We are still left with this issue, which should be fixed in vim-dadbod, so I would still appreciate if you could help me out on this. I just want to figure out why expand returns empty for you, so we can have an explanation why it needs fixing in vim-dadbod.
/tmp
is in the same partition as /
$ ls -la /tmp/nvimbT0WNc
total 8
drwx------ 3 ichirou2910 wheel 120 Aug 23 18:14 .
drwxrwxrwt 17 root root 380 Aug 23 18:14 ..
srwxr-xr-x 1 ichirou2910 wheel 0 Aug 23 18:14 0
-rw-r--r-- 1 ichirou2910 wheel 36 Aug 23 18:14 4.sql
-rw-r--r-- 1 ichirou2910 wheel 98 Aug 23 18:14 6.dbout
drwxr-xr-x 2 ichirou2910 wheel 60 Aug 23 18:14 coc.nvim-3304
On neovim it seems like the dadbod-ui cannot detect using visual selection, cuz the messages still said Executing multiple lines
while vim worked and the messages said Executing visual selection
Don't know why :disappointed:
$ ls -la /tmp/vQ1hfIz
total 8
drwx------ 3 ichirou2910 wheel 100 Aug 23 18:29 .
drwxrwxrwt 19 root root 420 Aug 23 18:29 ..
-rw-r--r-- 1 ichirou2910 wheel 769 Aug 23 18:29 18.dbout
-rw-r--r-- 1 ichirou2910 wheel 36 Aug 23 18:29 18.sql
drwxr-xr-x 2 ichirou2910 wheel 60 Aug 23 18:28 coc.nvim-23518
Does vim work without the fix, where it also do "Execute multiple lines" ?
Sadly no, I rolled back 1 commit and tried, still got that error
Did you add custom mapping for executing visual selection?
No, I don't map any extra key for dadbod-ui
Ok I'll check.
I can't reproduce it :/ I did push small change, but it shouldn't affect this. Give it a try anyway. It is detecting visual mode, but looks like it thinks there are some variables to inject.
If the latest change doesn't work for you, join all lines that you are trying to execute into one line, separated by a space, and try executing this search:
/[^:]:\w\+
Is it finding something?
Just wanna say that, IT WORKED :tada: Imma close this right now! Still I don't quite understand how that commit made it work :laughing: but nah it just works, that's enuff
Great! :) Thanks for help in debugging.
I found issue #30 about executing only selection as query, and while single line query works just fine, multiple-line doesn't seems to work and always throws out error as in the image.
ERROR: Can't initialize batch_readline - may be the input source is a directory or a block device.
It would be quite uncomfortable to move those lines to another query then execute them as a whole. Do you have any idea?