joereynolds / SQHell.vim

An SQL wrapper for vim
MIT License
131 stars 9 forks source link

Add command and keybindings to sort results #30

Closed misterbuckley closed 6 years ago

misterbuckley commented 6 years ago

This does a few things:

A few things to note:

btw this is apola from reddit fyi :)

joereynolds commented 6 years ago

Hey, great idea, thanks for the pr!

I'm a MySQL user so I can test this in work tomorrow :D Once again, thanks!

Update:

on S in a MySQL result I get this

image

joereynolds commented 6 years ago

the S works fine however s does nothing on its own for me atleast. I am using vim-sandwich which overwrites the native s command.

Perhaps the plugin needs to be installed after vim-sandwich?

Also there's another issue here:

image

Here's another issue on how it sorts numbers:

image

Still, thanks for the work so far, it's looking good!

misterbuckley commented 6 years ago

Alright I've fixed that error with the SQHSortResults command.

For the mappings being overwritten, I thought the mappings being in the ftplugin for SQHResults would have taken care of that since the mappings get created on opening the buffer, but maybe vim-sandwich does something to overwrite them. Try it again with my new fixes and see if that works for you, otherwise we'll have to find another solution. I'll try and figure out why they might be getting overwritten like that.

As for the numbers being sorted incorrectly, I kinda saw that one coming. :SQHSortResults -n should sort it correctly.

joereynolds commented 6 years ago

This is looking way better! There are still a few small issues though

1) If you sort on a row that isn't valid, you get this error sort: field number is zero: invalid field specification ‘0’ Is it possible to check this beforehand to prevent this trying to sort invalid rows?

2) On a mysql result, if you sort with lowercase s It adds an extra row beneath the header (this is probably just the one from the bottom of the result). The result ends up looking like this

+------+--------------+
| __pk | _fk_id       |
+------+--------------+
+------+--------------+
| 1000 |            0 |
|  100 |            0 |

Whereas it should be

+------+--------------+
| __pk | _fk_id       |
+------+--------------+
| 1000 |            0 |
|  100 |            0 |

Thanks again for these pr's. It's a good feature to have

p.s. ignore the problem I'm having with sandwich, we can fix that forward, I'd like this feature in :)

misterbuckley commented 6 years ago

Yeah the issue with that extra row showing up was just the line from the bottom of the file. psql doesn't include a line around the outside of the table so I forgot to account for that. I've fixed it for now but I'm thinking I'll have to eventually come up with a better solution for determining which lines to sort, since inserting a row at the top of the file, for example, would cause it to sort the wrong lines.

joereynolds commented 6 years ago

A simple solution could be to just delete the bottom row from the mysql result anyway? It's not really offering much and then it doesn't screw up this formatting

I'll take another look at it now :D

joereynolds commented 6 years ago

Okay one more issue and I think that's it. I've pulled down the latest stuff and it seems to be a row 'behind' when I sort. i.e. if I press s or S column 3, it actually sorts column 2

Here's a gif that hopefully explains better than I can

sort-bug

misterbuckley commented 6 years ago

Oh boy, thought I'd tested for that already. Here's hoping this fixes it once and for all

joereynolds commented 6 years ago

You beaut, it works perfectly!