Skip to content
Closed
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 @@ -5,6 +5,7 @@ Features
--------
* Update query processing functions to allow automatic show_warnings to work for more code paths like DDL.
* Rework reconnect logic to actually reconnect or create a new connection instead of simply changing the database (#746).
* Allow configuring the string used to display NULL values via myclirc (#1120)


Bug Fixes
Expand Down
9 changes: 8 additions & 1 deletion mycli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def __init__(
self.less_chatty = c["main"].as_bool("less_chatty")
self.cli_style = c["colors"]
self.output_style = style_factory_output(self.syntax_style, self.cli_style)
self.null_string = c["main"].get("null_string", "<null>")
self.wider_completion_menu = c["main"].as_bool("wider_completion_menu")
c_dest_warning = c["main"].as_bool("destructive_warning")
self.destructive_warning = c_dest_warning if warn is None else warn
Expand Down Expand Up @@ -1320,7 +1321,13 @@ def format_output(
expanded = expanded or use_formatter.format_name == "vertical"
output: itertools.chain[str] = itertools.chain()

output_kwargs = {"dialect": "unix", "disable_numparse": True, "preserve_whitespace": True, "style": self.output_style}
output_kwargs = {
"dialect": "unix",
"disable_numparse": True,
"preserve_whitespace": True,
"style": self.output_style,
"missing_value": self.null_string,
}

if use_formatter.format_name not in sql_format.supported_formats:
output_kwargs["preprocessors"] = (preprocessors.align_decimals,)
Expand Down
3 changes: 3 additions & 0 deletions mycli/myclirc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ beep_after_seconds = 0
# Recommended: ascii.
table_format = ascii

# The string used in place of a NULL value.
null_string = '<null>'

# Redirected otuput format
# Recommended: csv.
redirect_format = csv
Expand Down
3 changes: 3 additions & 0 deletions test/myclirc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ beep_after_seconds = 0
# Recommended: ascii
table_format = ascii

# The string used in place of a NULL value.
null_string = "<null>"

# Redirected otuput format
# Recommended: csv.
redirect_format = csv
Expand Down
10 changes: 10 additions & 0 deletions test/test_tabular_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from textwrap import dedent

from cli_helpers.utils import strip_ansi
from pymysql.constants import FIELD_TYPE
import pytest

Expand All @@ -18,6 +19,15 @@ def mycli():
return cli


def test_null_string_config_override(tmp_path):
config_path = tmp_path / "myclirc"
config_path.write_text("[main]\nnull_string = 'NULLISH'\n", encoding="utf8")
cli = MyCli(myclirc=str(config_path))
cli.output_style = None
output = list(cli.format_output(None, [(None, 1)], ["value", "number"], False, False))
assert any("NULLISH" in strip_ansi(line) for line in output)


@dbtest
def test_sql_output(mycli):
"""Test the sql output adapter."""
Expand Down
Loading