Execute a special command and return the results. If the special command is not supported a CommandNotFound will be raised.
(cur: Cursor, sql: str)
| 185 | |
| 186 | |
| 187 | def execute(cur: Cursor, sql: str) -> list[SQLResult]: |
| 188 | """Execute a special command and return the results. If the special command |
| 189 | is not supported a CommandNotFound will be raised. |
| 190 | """ |
| 191 | command, command_verbosity, arg = parse_special_command(sql) |
| 192 | |
| 193 | if (command not in CASE_SENSITIVE_COMMANDS) and (command.lower() not in CASE_INSENSITIVE_COMMANDS): |
| 194 | raise CommandNotFound(f'Command not found: {command}') |
| 195 | |
| 196 | try: |
| 197 | special_cmd = COMMANDS[command] |
| 198 | except KeyError as exc: |
| 199 | special_cmd = COMMANDS[command.lower()] |
| 200 | if special_cmd.case_sensitive: |
| 201 | raise CommandNotFound(f'Command not found: {command}') from exc |
| 202 | |
| 203 | # "help <SQL KEYWORD> is a special case. We want built-in help, not |
| 204 | # mycli help here. |
| 205 | if command.lower().startswith(("help", "/help", "\\?", "/?", "?")) and arg: |
| 206 | return show_keyword_help(cur=cur, arg=arg) |
| 207 | |
| 208 | if special_cmd.arg_type == ArgType.NO_QUERY: |
| 209 | return special_cmd.handler() |
| 210 | elif special_cmd.arg_type == ArgType.PARSED_QUERY: |
| 211 | return special_cmd.handler(cur=cur, arg=arg, command_verbosity=(command_verbosity == CommandVerbosity.VERBOSE)) |
| 212 | elif special_cmd.arg_type == ArgType.RAW_QUERY: |
| 213 | return special_cmd.handler(cur=cur, query=sql) |
| 214 | |
| 215 | raise CommandNotFound(f"Command type not found: {command}") |
| 216 | |
| 217 | |
| 218 | @special_command( |
no test coverage detected