2727from cli_helpers .utils import strip_ansi
2828from .explain_output_formatter import ExplainOutputFormatter
2929import click
30+ import sqlparse
31+ from sqlparse import tokens as sqlparse_tokens
3032import tzlocal
3133
3234try :
@@ -654,7 +656,7 @@ def connect(self, database="", host="", user="", port="", passwd="", dsn="", **k
654656 if self .force_passwd_prompt and not passwd :
655657 passwd = click .prompt ("Password for %s" % user , hide_input = True , show_default = False , type = str )
656658
657- key = f"{ user } @{ host } "
659+ key = f"{ user } @{ host } @ { port } "
658660
659661 if not passwd and auth .keyring :
660662 passwd = auth .keyring_get_password (key )
@@ -937,7 +939,7 @@ def _check_ongoing_transaction_and_allow_quitting(self):
937939 while 1 :
938940 try :
939941 choice = click .prompt (
940- "A transaction is ongoing. Choose `c` to COMMIT, `r` to ROLLBACK, `a` to abort exit." ,
942+ "A transaction is ongoing. Choose `c` to COMMIT, `r` to ROLLBACK, `a` to abort exit, `force` to exit anyway ." ,
941943 default = "a" ,
942944 )
943945 except click .Abort :
@@ -949,6 +951,8 @@ def _check_ongoing_transaction_and_allow_quitting(self):
949951 choice = choice .lower ()
950952 if choice == "a" :
951953 return False # do not quit
954+ if choice == "force" :
955+ return True # quit anyway
952956 if choice == "c" :
953957 query = self .execute_command ("commit" )
954958 return query .successful # quit only if query is successful
@@ -1116,7 +1120,7 @@ def _should_limit_output(self, sql, cur):
11161120 def _has_limit (self , sql ):
11171121 if not sql :
11181122 return False
1119- return "limit " in sql . lower ( )
1123+ return any ( token . match ( sqlparse_tokens . Keyword , "LIMIT" ) for statement in sqlparse . parse ( sql ) for token in statement . flatten () )
11201124
11211125 def _limit_output (self , cur ):
11221126 limit = min (self .row_limit , cur .rowcount )
0 commit comments