Runs *query*.
(
self,
query: str,
checkpoint: str | None = None,
new_line: bool = True,
)
| 72 | self.schema_prefetcher.start_configured() |
| 73 | |
| 74 | def run_query( |
| 75 | self, |
| 76 | query: str, |
| 77 | checkpoint: str | None = None, |
| 78 | new_line: bool = True, |
| 79 | ) -> None: |
| 80 | """Runs *query*.""" |
| 81 | assert self.sqlexecute is not None |
| 82 | self.log_query(query) |
| 83 | if checkpoint and not self.checkpoint: |
| 84 | self.checkpoint = click.open_file(checkpoint, mode='a') |
| 85 | results = self.sqlexecute.run(query) |
| 86 | for result in results: |
| 87 | self.main_formatter.query = query |
| 88 | self.redirect_formatter.query = query |
| 89 | output = self.format_sqlresult( |
| 90 | result, |
| 91 | is_expanded=special.is_expanded_output(), |
| 92 | is_redirected=special.is_redirected(), |
| 93 | null_string=self.null_string, |
| 94 | numeric_alignment=self.numeric_alignment, |
| 95 | binary_display=self.binary_display, |
| 96 | ) |
| 97 | for line in output: |
| 98 | self.log_output(line) |
| 99 | click.echo(line, nl=new_line) |
| 100 | |
| 101 | # get and display warnings if enabled |
| 102 | if special.is_show_warnings_enabled() and isinstance(result.rows, Cursor) and result.rows.warning_count > 0: |
| 103 | warnings = self.sqlexecute.run("SHOW WARNINGS") |
| 104 | for warning in warnings: |
| 105 | output = self.format_sqlresult( |
| 106 | warning, |
| 107 | is_expanded=special.is_expanded_output(), |
| 108 | is_redirected=special.is_redirected(), |
| 109 | null_string=self.null_string, |
| 110 | numeric_alignment=self.numeric_alignment, |
| 111 | binary_display=self.binary_display, |
| 112 | is_warnings_style=True, |
| 113 | ) |
| 114 | for line in output: |
| 115 | click.echo(line, nl=new_line) |
| 116 | if self.checkpoint: |
| 117 | self.checkpoint.write(query.rstrip('\n') + '\n') |
| 118 | self.checkpoint.flush() |
| 119 | |
| 120 | def get_last_query(self) -> str | None: |
| 121 | """Get the last query executed or None.""" |
no test coverage detected