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
9 changes: 9 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Upcoming (TBD)
==============

Bug Fixes
--------
* Update the prompt display logic to handle an edge case where a socket is used without
a host being parsed from any other method (#707).


1.42.0 (2025/12/20)
==============

Features
--------
* Add support for the automatic displaying of warnings after a SQL statement is executed.
Expand Down
9 changes: 7 additions & 2 deletions mycli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1193,10 +1193,15 @@ def get_prompt(self, string: str) -> str:
assert sqlexecute is not None
assert sqlexecute.server_info is not None
assert sqlexecute.server_info.species is not None
host = self.login_path if self.login_path and self.login_path_as_host else sqlexecute.host
if self.login_path and self.login_path_as_host:
prompt_host = self.login_path
elif sqlexecute.host is not None:
prompt_host = sqlexecute.host
else:
prompt_host = "localhost"
now = datetime.now()
string = string.replace("\\u", sqlexecute.user or "(none)")
string = string.replace("\\h", host or "(none)")
string = string.replace("\\h", prompt_host or "(none)")
string = string.replace("\\d", sqlexecute.dbname or "(none)")
string = string.replace("\\t", sqlexecute.server_info.species.name)
string = string.replace("\\n", "\n")
Expand Down
17 changes: 16 additions & 1 deletion test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from mycli.main import MyCli, cli, thanks_picker
from mycli.packages.special.main import COMMANDS as SPECIAL_COMMANDS
from mycli.sqlexecute import ServerInfo
from mycli.sqlexecute import ServerInfo, SQLExecute
from test.utils import HOST, PASSWORD, PORT, USER, dbtest, run

test_dir = os.path.abspath(os.path.dirname(__file__))
Expand All @@ -37,6 +37,21 @@
]


@dbtest
def test_prompt_no_host_only_socket(executor):
mycli = MyCli()
mycli.prompt_format = "\\t \\u@\\h:\\d> "
mycli.sqlexecute = SQLExecute
mycli.sqlexecute.server_info = ServerInfo.from_version_string("8.0.44-0ubuntu0.24.04.1")
mycli.sqlexecute.host = None
mycli.sqlexecute.socket = "/var/run/mysqld/mysqld.sock"
mycli.sqlexecute.user = "root"
mycli.sqlexecute.dbname = "mysql"
mycli.sqlexecute.port = "3306"
prompt = mycli.get_prompt(mycli.prompt_format)
assert prompt == "MySQL root@localhost:mysql> "


@dbtest
def test_enable_show_warnings(executor):
mycli = MyCli()
Expand Down