(
mycli: 'MyCli',
state: ReplState,
text: str | None = None,
)
| 591 | |
| 592 | |
| 593 | def _one_iteration( |
| 594 | mycli: 'MyCli', |
| 595 | state: ReplState, |
| 596 | text: str | None = None, |
| 597 | ) -> None: |
| 598 | sqlexecute = mycli.sqlexecute |
| 599 | assert sqlexecute is not None |
| 600 | |
| 601 | inputhook = partial(_keepalive_hook, mycli) if mycli.keepalive_ticks and mycli.keepalive_ticks >= 1 else None |
| 602 | |
| 603 | if text is None: |
| 604 | try: |
| 605 | assert mycli.prompt_session is not None |
| 606 | loaded_message_fn = partial(_get_prompt_message, mycli, mycli.prompt_session.app) |
| 607 | text = mycli.prompt_session.prompt( |
| 608 | inputhook=inputhook, |
| 609 | message=loaded_message_fn, |
| 610 | ) |
| 611 | except KeyboardInterrupt: |
| 612 | return |
| 613 | |
| 614 | special.set_expanded_output(False) |
| 615 | special.set_forced_horizontal_output(False) |
| 616 | |
| 617 | try: |
| 618 | text = handle_editor_command( |
| 619 | mycli, |
| 620 | text, |
| 621 | inputhook, |
| 622 | loaded_message_fn, |
| 623 | ) |
| 624 | except RuntimeError as e: |
| 625 | mycli.logger.error('sql: %r, error: %r', text, e) |
| 626 | mycli.logger.error('traceback: %r', traceback.format_exc()) |
| 627 | mycli.echo(str(e), err=True, fg='red') |
| 628 | return |
| 629 | |
| 630 | try: |
| 631 | if handle_clip_command(mycli, text): |
| 632 | return |
| 633 | except RuntimeError as e: |
| 634 | mycli.logger.error('sql: %r, error: %r', text, e) |
| 635 | mycli.logger.error('traceback: %r', traceback.format_exc()) |
| 636 | mycli.echo(str(e), err=True, fg='red') |
| 637 | return |
| 638 | |
| 639 | while special.is_llm_command(text): |
| 640 | start = time.time() |
| 641 | try: |
| 642 | assert sqlexecute.conn is not None |
| 643 | cur = sqlexecute.conn.cursor() |
| 644 | context, sql, duration = special.handle_llm( |
| 645 | text, |
| 646 | cur, |
| 647 | sqlexecute.dbname or '', |
| 648 | mycli.llm_prompt_field_truncate, |
| 649 | mycli.llm_prompt_section_truncate, |
| 650 | ) |
no test coverage detected