dbcli / mycli

A Terminal Client for MySQL with AutoCompletion and Syntax Highlighting.
http://mycli.net
Other
11.48k stars 663 forks source link

Exception while using special commands #704

Open pqiaohaoq opened 5 years ago

pqiaohaoq commented 5 years ago

Exception:

when I use command like below:

\t csv; \o ~/Downloads/output.csv; SELECT field1, field2 FROM t_table WHERE field1!=filed2;

throw exception:

image

but, it works fine like below:

SELECT field1, field2 FROM t_table WHERE field1!=filed2;

Environment:

meeuw commented 5 years ago

That's strange, I cannot reproduce this. You could try to update mycli using pip install --update mycli, it that doesn't work please post the output of pip freeze.

Notaduck commented 5 years ago

I was able to reproduce the issue, but it will only appear when you try to compare to fields in the where clause.

pip freeze:

alabaster==0.7.11
appdirs==1.4.3
asn1crypto==0.24.0
autopep8==1.4.3
Babel==2.6.0
backports.csv==1.0.6
beautifulsoup4==4.6.3
bs4==0.0.1
btrfsutil==1.1.0
CacheControl==0.12.5
cached-property==1.5.1
cffi==1.11.5
chardet==3.0.4
cli-helpers==1.0.2
Click==7.0
colorama==0.4.1
configobj==5.0.6
cryptography==2.4.2
cupshelpers==1.0
distlib==0.2.8
distro==1.3.0
docker==3.6.0
docker-compose==1.23.2
docker-pycreds==0.4.0
dockerpty==0.4.1
docopt==0.6.2
docutils==0.14
flake8==3.6.0
greenlet==0.4.15
gufw==18.10.0
html5lib==1.0.1
idna==2.8
imagesize==1.1.0
Jinja2==2.10
jsonschema==2.6.0
lensfun==0.3.2
lockfile==0.12.2
louis==3.8.0
MarkupSafe==1.1.0
mccabe==0.6.1
msgpack==0.5.6
mycli==1.19.0
neovim-remote==2.1.2
npyscreen==4.10.5
packaging==18.0
pacman-mirrors==4.14.0
pep517==0.5.0
pep8==1.7.1
ply==3.11
progress==1.4
prompt-toolkit==2.0.7
psutil==5.4.8
pycairo==1.18.0
pycodestyle==2.4.0
pycparser==2.19
pycups==1.9.74
pycurl==7.43.0.2
pyflakes==2.0.0
Pygments==2.3.1
PyGObject==3.30.4
PyMySQL==0.9.2
pynvim==0.3.1
pyparsing==2.3.0
PyQt5==5.11.3
PyQt5-sip==4.19.13
python-xapp==1.4.0
pytoml==0.1.20
pytz==2018.7
PyYAML==3.13
ranger-fm==1.9.2
requests==2.20.1
retrying==1.3.3
setproctitle==1.1.10
sip==4.19.13
six==1.12.0
snowballstemmer==1.2.1
speedtest-cli==2.0.2
Sphinx==1.8.1
sphinx-rtd-theme==0.4.1
sphinxcontrib-websupport==1.1.0
SQLAlchemy==1.2.15
sqlparse==0.2.4
syslogng==1.0
tabulate==0.8.2
team==1.0
terminaltables==3.1.0
texttable==1.5.0
trash-cli==0.17.1.14
ufw==0.36
urllib3==1.24.1
wcwidth==0.1.7
webencodings==0.5.1
websocket-client==0.54.0
Whoosh==2.7.4

query:

mariadb root@localhost:Games> \t csv; \o ~/Downloads/output.csv; SELECT g.id, g.name FROM `Game` g 
Timing is off.

80 rows in set

Unhandled exception in event loop:
  File "/usr/lib/python3.7/site-packages/prompt_toolkit/eventloop/coroutine.py", line 90, in step_next
    new_f = coroutine.throw(exc)
  File "/usr/lib/python3.7/site-packages/prompt_toolkit/buffer.py", line 1648, in new_coroutine
    yield From(coroutine(*a, **kw))
  File "/usr/lib/python3.7/site-packages/prompt_toolkit/eventloop/coroutine.py", line 90, in step_next
    new_f = coroutine.throw(exc)
  File "/usr/lib/python3.7/site-packages/prompt_toolkit/buffer.py", line 1500, in async_completer
    cancel=lambda: not proceed()))
  File "/usr/lib/python3.7/site-packages/prompt_toolkit/eventloop/coroutine.py", line 86, in step_next
    new_f = coroutine.send(None)
  File "/usr/lib/python3.7/site-packages/prompt_toolkit/eventloop/async_generator.py", line 114, in consume_async_generator
    item = iterator.send(send)
  File "/usr/lib/python3.7/site-packages/prompt_toolkit/completion/base.py", line 166, in get_completions_async
    for item in self.get_completions(document, complete_event):
  File "/usr/lib/python3.7/site-packages/mycli/sqlcompleter.py", line 258, in get_completions
    suggestions = suggest_type(document.text, document.text_before_cursor)
  File "/usr/lib/python3.7/site-packages/mycli/packages/completion_engine.py", line 93, in suggest_type
    full_text, identifier)
  File "/usr/lib/python3.7/site-packages/mycli/packages/completion_engine.py", line 143, in suggest_based_on_last_token
    full_text, identifier)
  File "/usr/lib/python3.7/site-packages/mycli/packages/completion_engine.py", line 145, in suggest_based_on_last_token
    token_v = token.value.lower()

Exception 'NoneType' object has no attribute 'value'
Press ENTER to continue...                                                                         

I wasn't even able to run the query but it cane when I typed WHERE g and then it crashed and deleted the line with the WHERE clause.