Helper that wraps execution of SQL code. This is used both by the REPL and by direct execution from the CLI. 'c' may be a cursor or a connection. 'sql' is the SQL string to execute.
(c, sql, suppress_errors=True, theme=theme_no_color)
| 16 | |
| 17 | |
| 18 | def execute(c, sql, suppress_errors=True, theme=theme_no_color): |
| 19 | """Helper that wraps execution of SQL code. |
| 20 | |
| 21 | This is used both by the REPL and by direct execution from the CLI. |
| 22 | |
| 23 | 'c' may be a cursor or a connection. |
| 24 | 'sql' is the SQL string to execute. |
| 25 | """ |
| 26 | |
| 27 | try: |
| 28 | for row in c.execute(sql): |
| 29 | print(row) |
| 30 | except sqlite3.Error as e: |
| 31 | t = theme.traceback |
| 32 | tp = type(e).__name__ |
| 33 | try: |
| 34 | tp += f" ({e.sqlite_errorname})" |
| 35 | except AttributeError: |
| 36 | pass |
| 37 | print( |
| 38 | f"{t.type}{tp}{t.reset}: {t.message}{e}{t.reset}", file=sys.stderr |
| 39 | ) |
| 40 | if not suppress_errors: |
| 41 | sys.exit(1) |
| 42 | |
| 43 | |
| 44 | class SqliteInteractiveConsole(InteractiveConsole): |
searching dependent graphs…