mirror of https://github.com/dbcli/pgcli
Fix the bug when just pressing enter without any text.
This commit is contained in:
parent
93be168c25
commit
881555cf25
|
@ -88,12 +88,13 @@ def cli(database, user, password, host, port):
|
|||
for rows, headers, status in res:
|
||||
if rows:
|
||||
print(tabulate(rows, headers, tablefmt='psql'))
|
||||
print(status)
|
||||
if status: # Only print the status if it's not None.
|
||||
print(status)
|
||||
except Exception as e:
|
||||
click.secho(e.message, err=True, fg='red')
|
||||
|
||||
# Refresh the table names and column names if necessary.
|
||||
if need_completion_refresh(document.text):
|
||||
if document.text and need_completion_refresh(document.text):
|
||||
completer.reset_completions()
|
||||
completer.extend_table_names(pgexecute.tables())
|
||||
completer.extend_column_names(pgexecute.all_columns())
|
||||
|
@ -101,5 +102,8 @@ def cli(database, user, password, host, port):
|
|||
print ('GoodBye!')
|
||||
|
||||
def need_completion_refresh(sql):
|
||||
first_token = sql.split()[0]
|
||||
return first_token in ('alter', 'create', 'use', '\c', 'drop')
|
||||
try:
|
||||
first_token = sql.split()[0]
|
||||
return first_token in ('alter', 'create', 'use', '\c', 'drop')
|
||||
except Exception:
|
||||
return False
|
||||
|
|
|
@ -62,6 +62,9 @@ class PGExecute(object):
|
|||
are a list of tuples. Each tuple has 3 values (rows, headers, status).
|
||||
"""
|
||||
|
||||
if not sql: # Empty string
|
||||
return [(None, None, None)]
|
||||
|
||||
# Remove spaces, eol and semi-colons.
|
||||
sql = sql.strip()
|
||||
sql = sql.rstrip(';')
|
||||
|
|
|
@ -24,6 +24,7 @@ def _multiline_exception(text):
|
|||
text = text.strip()
|
||||
return (text.startswith('\\') or # Special Command
|
||||
text.endswith(';') or # Ended with a semi-colon
|
||||
(text == 'exit') or # Exit and Quit doesn't need semi-colon
|
||||
(text == 'quit')
|
||||
(text == 'exit') or # Exit doesn't need semi-colon
|
||||
(text == 'quit') or # Quit doesn't need semi-colon
|
||||
(text == '') # Just a plain enter without any text
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue