Git Product home page Git Product logo

Comments (39)

kristijanhusak avatar kristijanhusak commented on May 21, 2024

@ichirou2910 does executing the whole buffer work?

from vim-dadbod-ui.

ichirou2910 avatar ichirou2910 commented on May 21, 2024

Yes it works fine

from vim-dadbod-ui.

kristijanhusak avatar kristijanhusak commented on May 21, 2024

Can you just give me the format of your connection url? For example:

mysql://user:pass@host:port/dbname

from vim-dadbod-ui.

ichirou2910 avatar ichirou2910 commented on May 21, 2024

mysql://user@host/dbname
Edit: sry got the wrong one

from vim-dadbod-ui.

kristijanhusak avatar kristijanhusak commented on May 21, 2024

OK thanks, I'll look into it.

from vim-dadbod-ui.

kristijanhusak avatar kristijanhusak commented on May 21, 2024

I'm not able to reproduce this. I'll need more info.

  • Which OS?
  • Vim/Neovim?
  • Did you try with some other queries, for example having 3 select queries and trying to execute 2 of them?

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:

  • Create a noname file somewhere, anywhere (For example, /home/yourname/Documents/myquery)
  • add the lines you are trying to execute visually from dbui to this file, save
  • Open vim, connect to your mysql db, set up a new query, and do :DB < /home/yourname/Documents/myquery

Does it work?

from vim-dadbod-ui.

ichirou2910 avatar ichirou2910 commented on May 21, 2024
  • OS: Arch Linux (updated and upgraded before testing)
  • Editor: Neovim
  • Any multi-line queries doesn't work and throws the error I mentioned above
    A gif to better demonstrate the issue
    dbui
    As you can see, a multi-line create table query doesn't work, while a one-line create table query works just fine.
    And for your scenario, it worked normally

from vim-dadbod-ui.

kristijanhusak avatar kristijanhusak commented on May 21, 2024

@ichirou2910 I'll need you to test 2 more things:

  1. Select multiple lines and execute :DB command on that visual selection. Basically just use vim-dadbod's functionality.
  2. If that works, Try setting 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.

from vim-dadbod-ui.

kristijanhusak avatar kristijanhusak commented on May 21, 2024

@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.

from vim-dadbod-ui.

ichirou2910 avatar ichirou2910 commented on May 21, 2024

@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?
#57

from vim-dadbod-ui.

kristijanhusak avatar kristijanhusak commented on May 21, 2024

@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.

from vim-dadbod-ui.

ichirou2910 avatar ichirou2910 commented on May 21, 2024

That I tried too. Here are the what I found out

  • The correct config line is g:db_ui_tmp_query_location
  • Screenshot of what happened
    image
  • Somehow, only when I set tmp query location to home folder, query buffer is set to 'readonly' after executing, as shown also in the image above

from vim-dadbod-ui.

kristijanhusak avatar kristijanhusak commented on May 21, 2024

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.

from vim-dadbod-ui.

ichirou2910 avatar ichirou2910 commented on May 21, 2024

It's the same
image
Somehow when I created a file containing the same queries in home folder it works
image

from vim-dadbod-ui.

kristijanhusak avatar kristijanhusak commented on May 21, 2024

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?

from vim-dadbod-ui.

ichirou2910 avatar ichirou2910 commented on May 21, 2024

Here you go
image
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

from vim-dadbod-ui.

kristijanhusak avatar kristijanhusak commented on May 21, 2024

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) ?

from vim-dadbod-ui.

ichirou2910 avatar ichirou2910 commented on May 21, 2024

'kay I'm so confused rn 😕
image
As expected, :'<,'>DB worked while :DB < /tmp/nvim*****/sqlfile didn't work

from vim-dadbod-ui.

kristijanhusak avatar kristijanhusak commented on May 21, 2024

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.

from vim-dadbod-ui.

ichirou2910 avatar ichirou2910 commented on May 21, 2024

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

from vim-dadbod-ui.

kristijanhusak avatar kristijanhusak commented on May 21, 2024

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.

from vim-dadbod-ui.

ichirou2910 avatar ichirou2910 commented on May 21, 2024

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'''

from vim-dadbod-ui.

kristijanhusak avatar kristijanhusak commented on May 21, 2024

So confusing...

Sorry for bothering you so much, but this is really strange. I'll need few more things:

  1. What's the output for you when you do echo expand('/tmp/nvimU2VYBz/4.sql')? Put valid tmp path in there just to be sure.
  2. After this line https://github.com/tpope/vim-dadbod/blob/master/autoload/db.vim#L259, add this:
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.

from vim-dadbod-ui.

ichirou2910 avatar ichirou2910 commented on May 21, 2024
  1. Nothing, srsly, nothing. Tried with my test.sql file and it gave /home/ichirou2910/test.sql tho.
  2. <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

from vim-dadbod-ui.

kristijanhusak avatar kristijanhusak commented on May 21, 2024

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?

from vim-dadbod-ui.

ichirou2910 avatar ichirou2910 commented on May 21, 2024
  1. Again, nothing 😞
: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

from vim-dadbod-ui.

kristijanhusak avatar kristijanhusak commented on May 21, 2024

@ichirou2910 and what about this:

echo fnamemodify('/tmp/nvimkvRSfR/8.sql', ':p')

I'm using latest neovim from master. Will try the stable version.

from vim-dadbod-ui.

ichirou2910 avatar ichirou2910 commented on May 21, 2024

/tmp/nvimkvRSfR/8.sql

from vim-dadbod-ui.

kristijanhusak avatar kristijanhusak commented on May 21, 2024

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 chrisbra/SudoEdit.vim#17 (comment)

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.

from vim-dadbod-ui.

kristijanhusak avatar kristijanhusak commented on May 21, 2024

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.

from vim-dadbod-ui.

ichirou2910 avatar ichirou2910 commented on May 21, 2024
  • No, my /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
image
Don't know why 😞

$ 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

from vim-dadbod-ui.

kristijanhusak avatar kristijanhusak commented on May 21, 2024

Does vim work without the fix, where it also do "Execute multiple lines" ?

from vim-dadbod-ui.

ichirou2910 avatar ichirou2910 commented on May 21, 2024

Sadly no, I rolled back 1 commit and tried, still got that error

from vim-dadbod-ui.

kristijanhusak avatar kristijanhusak commented on May 21, 2024

Did you add custom mapping for executing visual selection?

from vim-dadbod-ui.

ichirou2910 avatar ichirou2910 commented on May 21, 2024

No, I don't map any extra key for dadbod-ui

from vim-dadbod-ui.

kristijanhusak avatar kristijanhusak commented on May 21, 2024

Ok I'll check.

from vim-dadbod-ui.

kristijanhusak avatar kristijanhusak commented on May 21, 2024

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?

from vim-dadbod-ui.

ichirou2910 avatar ichirou2910 commented on May 21, 2024

image
Just wanna say that, IT WORKED 🎉 Imma close this right now!
Still I don't quite understand how that commit made it work 😆 but nah it just works, that's enuff

from vim-dadbod-ui.

kristijanhusak avatar kristijanhusak commented on May 21, 2024

Great! :) Thanks for help in debugging.

from vim-dadbod-ui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.