Skip to content

Commit fa29f5a

Browse files
authored
Merge pull request #110 from dbcli/row_limit
Honor the row limit in config and env var.
2 parents 0c53051 + 98cda83 commit fa29f5a

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

mssqlcli/main.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -485,11 +485,9 @@ def get_continuation_tokens(cli, width):
485485

486486
return cli
487487

488-
def _should_show_limit_prompt(self, status, cur):
488+
def _should_show_limit_prompt(self, status, rows):
489489
"""returns True if limit prompt should be shown, False otherwise."""
490-
if not is_select(status):
491-
return False
492-
return self.row_limit > 0 and cur and cur.rowcount > self.row_limit
490+
return self.row_limit > 0 and len(rows) > self.row_limit
493491

494492
def _evaluate_command(self, text):
495493
"""Used to run a command entered by the user during CLI operation
@@ -519,6 +517,12 @@ def _evaluate_command(self, text):
519517
for rows, columns, status, sql, is_error in self.mssqlcliclient_query_execution.execute_multi_statement_single_batch(
520518
text):
521519
total = time() - start
520+
if self._should_show_limit_prompt(status, rows):
521+
click.secho('The result set has more than %s rows.'
522+
% self.row_limit, fg='red')
523+
if not click.confirm('Do you want to continue?'):
524+
click.secho("Aborted!", err=True, fg='red')
525+
break
522526

523527
if is_error:
524528
output.append(status)
@@ -746,13 +750,6 @@ def is_mutating(status):
746750
return status.split(None, 1)[0].lower() in mutating
747751

748752

749-
def is_select(status):
750-
"""Returns true if the first word in status is 'select'."""
751-
if not status:
752-
return False
753-
return status.split(None, 1)[0].lower() == 'select'
754-
755-
756753
def quit_command(sql):
757754
return (sql.strip().lower() == 'exit' or
758755
sql.strip().lower() == 'quit' or

0 commit comments

Comments
 (0)