Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix status line display of the executed SQL command, part 2 #434

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion crate/crash/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import logging
import os
import re
import sys
from argparse import ArgumentParser, ArgumentTypeError
from collections import namedtuple
Expand Down Expand Up @@ -486,7 +487,9 @@ def _exec_and_print(self, expression: Union[str, sqlparse.sql.Statement]) -> boo
def stmt_type(expression: Union[str, sqlparse.sql.Statement]):
"""Extract type of statement, e.g. SELECT, INSERT, UPDATE, DELETE, ..."""
statement = to_statement(expression)
return str(statement.token_first(skip_ws=True, skip_cm=True)).upper()
command_with_args = str(statement.token_first(skip_ws=True, skip_cm=True))
effective_command = re.findall(r'[\w]+', command_with_args)[0]
return effective_command.upper()


def to_statement(expression: Union[str, sqlparse.sql.Statement]) -> sqlparse.sql.Statement:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ def test_stmt_type(self):
self.assertEqual(stmt_type('SELECT 1; /* foo */'), 'SELECT')
self.assertEqual(stmt_type('-- foo \n SELECT 1;'), 'SELECT')
self.assertEqual(stmt_type('SELECT 1; -- foo'), 'SELECT')
# statements with arguments as part of the command
self.assertEqual(stmt_type('/* foo */ DENY DQL, DML, DDL, AL ON SCHEMA sys TO test;'), 'DENY')

def test_decode_timeout_success(self):
self.assertEqual(_decode_timeout(None), None)
Expand Down