mirror of
https://github.com/dbcli/pgcli.git
synced 2024-10-06 10:17:15 +03:00
Don't finish multiline query with an unopen quote
This commit is contained in:
parent
9be09b8bf4
commit
4e66819343
@ -1,5 +1,7 @@
|
||||
from prompt_toolkit.buffer import Buffer
|
||||
from prompt_toolkit.filters import Condition
|
||||
from .packages.parseutils import is_open_quote
|
||||
|
||||
|
||||
class PGBuffer(Buffer):
|
||||
def __init__(self, always_multiline, *args, **kwargs):
|
||||
@ -13,11 +15,19 @@ class PGBuffer(Buffer):
|
||||
super(self.__class__, self).__init__(*args, is_multiline=is_multiline,
|
||||
tempfile_suffix='.sql', **kwargs)
|
||||
|
||||
|
||||
def _is_complete(sql):
|
||||
# A complete command is an sql statement that ends with a semicolon, unless
|
||||
# there's an open quote surrounding it, as is common when writing a
|
||||
# CREATE FUNCTION command
|
||||
return sql.endswith(';') and not is_open_quote(sql)
|
||||
|
||||
|
||||
def _multiline_exception(text):
|
||||
text = text.strip()
|
||||
return (text.startswith('\\') or # Special Command
|
||||
text.endswith('\e') or # Ended with \e which should launch the editor.
|
||||
text.endswith(';') or # Ended with a semi-colon
|
||||
_is_complete(text) or # A complete SQL command
|
||||
(text == 'exit') or # Exit doesn't need semi-colon
|
||||
(text == 'quit') or # Quit doesn't need semi-colon
|
||||
(text == ':q') or # To all the vim fans out there
|
||||
|
Loading…
Reference in New Issue
Block a user