pgcli icon indicating copy to clipboard operation
pgcli copied to clipboard

Not able to submit a query in multiline mode

Open snuyanzin opened this issue 6 years ago • 3 comments

Description

Sometimes while multiline mode it is impossible to submit a query with single quotes inside multiline comments. After playing with that I was able to find a simple query to reproduce

select 1 /*'/* */'*/
;

Moreover it is impossible to finish editing this query (the only option I found is CTRL+C)

At the same time in case one-line mode the same query is submitted successfully

select 1 /*'/* */'*/
+------------+
| ?column?   |
|------------|
| 1          |
+------------+
SELECT 1
Time: 0.024s

Your environment

  • [x] Please provide your OS and version information. Ubuntu 19.04
  • [x] Please provide your CLI version. v2.1.1
  • [x] What is the output of pip freeze command.
arandr==0.1.9
asn1crypto==0.24.0
backports.functools-lru-cache==1.5
beautifulsoup4==4.7.1
bs4==0.0.1
certifi==2019.6.16
click==6.7
configparser==3.5.0b2
cryptography==2.3
entrypoints==0.3
enum34==1.1.6
fuzzyfinder==2.1.0
httplib2==0.13.0
idna==2.6
ipaddress==1.0.17
keyring==17.1.1
keyrings.alt==3.1.1
kube-shell==0.0.23
kubernetes==2.0.0
lxml==4.3.3
oauth2client==4.1.3
prompt-toolkit==1.0.16
pyasn1==0.4.5
pyasn1-modules==0.2.5
pycairo==1.16.2
pycrypto==2.6.1
Pygments==2.4.2
PyGObject==3.32.0
python-dateutil==2.8.0
pyxdg==0.25
PyYAML==5.1.1
rsa==4.0
SecretStorage==2.3.1
six==1.12.0
snxvpn==1.2
soupsieve==1.9
urllib3==1.25.3
wcwidth==0.1.7
websocket-client==0.56.0

snuyanzin avatar Sep 11 '19 05:09 snuyanzin

Thanks for the report @snuyanzin.

The example is a bit tricky, since I don't think C-style comments can be nested, so the query actually does contain an unmatched ' as the first one is commented out. As I understand it:

select 
1 
/*'/* */ <- comment ends after first */
'*/      <- this ' is unmatched
;

Do you have another example without nested multi-line comment delimiters that exhibits the problem?

Without looking into it, I wonder if it's possible to indicate after pressing Enter that the query wasn't executed due to an unmatched quote, which might help identify issues like this a bit more clearly, rather than Enter seemingly not working

owst avatar Oct 23 '19 23:10 owst

I don't think C-style comments can be nested

according postgresql documentation it could be https://www.postgresql.org/docs/8.0/sql-syntax.html#SQL-SYNTAX-COMMENTS

there are a number of other more complicated examples with such comments. Here I just posted the simplest one. If it helps I could provide others

snuyanzin avatar Oct 23 '19 23:10 snuyanzin

Thanks for the link @snuyanzin - I didn't know about this feature of C-style comments in SQL!

Having looked into it a bit more, the cause of this issue is a bug in the sqlparse library that we use - I've commented with some background on the open issue regarding nested comments https://github.com/andialbrecht/sqlparse/issues/410#issuecomment-547688075 and I had a quick look at the sqlparse code, but it wasn't going to be a quick fix for me to make.

owst avatar Oct 30 '19 00:10 owst