Skip to content
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
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Features
Bug Fixes
--------
* Better respect case when `keyword_casing` is `auto`.
* Fix error when selecting from an empty table.
* Let favorite queries contain special commands.
* Render binary values more consistently as hex literals.

Expand Down
7 changes: 5 additions & 2 deletions mycli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1422,8 +1422,11 @@ def get_col_type(col) -> type:
col_type = FIELD_TYPES.get(col[1], str)
return col_type if type(col_type) is type else str

column_types = [get_col_type(tup) for tup in cur.description]
colalign = [numeric_alignment if x in (int, float, Decimal) else 'left' for x in column_types]
if cur.rowcount > 0:
column_types = [get_col_type(tup) for tup in cur.description]
colalign = [numeric_alignment if x in (int, float, Decimal) else 'left' for x in column_types]
else:
column_types, colalign = [], []

if max_width is not None and isinstance(cur, Cursor):
cur = list(cur)
Expand Down
14 changes: 14 additions & 0 deletions test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@
]


@dbtest
def test_select_from_empty_table(executor):
run(executor, """create table t1(id int)""")
sql = "select * from t1"
runner = CliRunner()
result = runner.invoke(cli, args=CLI_ARGS + ["-t"], input=sql)
expected = dedent("""\
+----+
| id |
+----+
+----+""")
assert expected in result.output


def test_is_valid_connection_scheme_valid(executor, capsys):
is_valid, scheme = is_valid_connection_scheme("mysql://test@localhost:3306/dev")
assert is_valid
Expand Down