Closed snwflake closed 1 year ago
@snwflake I'm not sure what the question is here? The way that usql
works is that it parses up until a ;
or a \
character, assuming it's not within a set of (
/)
, is within a string, or is otherwise an "unbalanced" statement. It doesn't have any other concept of SQL. The behavior is more or less similar to how psql
works. Are you referring to the mysql
command line client's behavior? If so, please note that usql
is patterned after psql
command line tool, not the mysql
command line tool.
It would not make sense to continue appending to the raw query, because if there was two statements on a single line, a \g
would only execute the previous statement, not both:
$ psql postgres://postgres:P4ssw0rd@localhost
psql (15.2, server 15.1 (Debian 15.1-1.pgdg110+1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off)
Type "help" for help.
postgres=# select 1; select 2
?column?
----------
1
(1 row)
postgres-# \p
select 2
postgres-# \g
?column?
----------
2
(1 row)
postgres=# \g
?column?
----------
2
(1 row)
postgres=#
Compare the above psql
output to usql
's:
$ usql pg://
Connected with driver postgres (PostgreSQL 15.1 (Debian 15.1-1.pgdg110+1))
Type "help" for help.
pg:postgres@=> select 1; select 2
?column?
----------
1
(1 row)
pg:postgres@-> \p
select 2
pg:postgres@-> \g
?column?
----------
2
(1 row)
pg:postgres@=> \g
?column?
----------
2
(1 row)
pg:postgres@=>
@kenshaw
psql:
postgres=# select * <ENTER>
postgres-# from test <ENTER>
postgres-# ; <ENTER>
usql:
my:user@testnode/db=> select * <ENTER>
<BUFFER GETS CLEARED> ^^^ NO LONGER VISIBLE ^^^
my:user@testnode/db->
psql seems to behave exactly like mysql cli in this instance.
you enter parts of a query select *
in this case, press enter to get a newline, and you continue entering parts of your query.
mysqlcli, psql and any other sane sql client I've ever used preserved the parts of the query on the terminal that you've entered before pressing enter for a newline, usql does not. It seems to clear the buffer, if you press enter after inserting select *
the statement vanishes, your prompt changes from =>
to ->
and that's it.
I hope that makes more sense now.
Edit: didn't mean to close the issue, just forgot I had vim shortcuts enabled....
@snwflake this is not the behavior that I am getting:
$ usql my://
Connected with driver mysql (10.10.2-MariaDB-1:10.10.2+maria~ubu2204)
Type "help" for help.
my:root@=> select *
my:root@-> from test
my:root@-> ;
error: mysql: 1046: No database selected
my:root@=> \p
select *
from test
;
my:root@=>
@snwflake You might want to turn off syntax highlighting and try again. You might be using a funky terminal. Unfortunately, the syntax highlighting doesn't work on every terminal. Is this on Windows?
@snwflake to turn off syntax highlighting, do the following:
my:root@=> \set SYNTAX_HL false
Alright!
Yes, unfortunately this is windows using https://github.com/microsoft/terminal
@snwflake Myself, I've only ever tested usql
on the original Command Prompt, and Msys2's included terminal. Microsoft has made it difficult to run Windows 11 under a VM, but I will make a point in trying to get it running this weekend and will try to fix syntax highlighting on the new Windows Terminal.
thanks @kenshaw, apparently we both changed the title xd I appreciate your effort, cheers!
Edit: Win10 is perfectly capable to run the new terminal btw, it only ships with win11 by default
@snwflake I've pushed a change on the master branch of my personal fork -- https://github.com/kenshaw/usql -- that fixes this on Windows Terminal. Before I add it to master
here, I need to do more tests and ensure this doesn't break anything for other terminals. I should be able to check/test within the next day or so.
Thanks, I'll get a goenv going and check it out!
I don't know how pgsql handles multiline queries, but mariadb inserts a newline without flushing the previous buffer, hiding the parts before it.
usql:
![image](https://user-images.githubusercontent.com/10883751/224438554-5776bb85-8670-43b7-bd7c-685e70f4214b.png)
mariadb:
To me this seems like a natural feature to have, so I'm not sure if this is a bug, or actual intended behavior?