Runs commands in the interactive CLI mode.
(self, text)
| 319 | return text |
| 320 | |
| 321 | def _execute_interactive_command(self, text): |
| 322 | """ Runs commands in the interactive CLI mode. """ |
| 323 | |
| 324 | logger = self.logger |
| 325 | |
| 326 | # Initialize default metaquery in case execution fails |
| 327 | query = MetaQuery(query=text, successful=False) |
| 328 | |
| 329 | try: |
| 330 | output, query = self._evaluate_command(text) |
| 331 | except KeyboardInterrupt: |
| 332 | # Issue where Ctrl+C propagates to sql tools service process and kills it, |
| 333 | # so that query/cancel request can't be sent. |
| 334 | # Right now the sql_tools_service process is killed and we restart |
| 335 | # it with a new connection. |
| 336 | click.secho(u'Cancelling query...', err=True, fg='red') |
| 337 | self.reset() |
| 338 | logger.debug("cancelled query, sql: %r", text) |
| 339 | click.secho("Query cancelled.", err=True, fg='red') |
| 340 | |
| 341 | except NotImplementedError: |
| 342 | click.secho('Not Yet Implemented.', fg="yellow") |
| 343 | else: |
| 344 | if query.total_time > 1: |
| 345 | # pylint: disable=no-member |
| 346 | print('Time: %0.03fs (%s)' % (query.total_time, |
| 347 | humanize.time.naturaldelta(query.total_time))) |
| 348 | else: |
| 349 | print('Time: %0.03fs' % query.total_time) |
| 350 | |
| 351 | # Check if we need to update completions, in order of most |
| 352 | # to least drastic changes |
| 353 | if query.db_changed: |
| 354 | with self._completer_lock: |
| 355 | self.completer.reset_completions() |
| 356 | self.refresh_completions(persist_priorities='keywords') |
| 357 | elif query.meta_changed: |
| 358 | self.refresh_completions(persist_priorities='all') |
| 359 | |
| 360 | if not query.contains_secure_statement: |
| 361 | # Allow MssqlCompleter to learn user's preferred keywords, etc. |
| 362 | with self._completer_lock: |
| 363 | self.completer.extend_query_history(text) |
| 364 | |
| 365 | self.query_history.append(query) |
| 366 | |
| 367 | return output |
| 368 | |
| 369 | def execute_query(self, text): |
| 370 | """ Processes a query string and outputs to file or terminal """ |
no test coverage detected