@@ -732,7 +732,7 @@ def run_cli(self) -> None:
732732 if self .smart_completion :
733733 self .refresh_completions ()
734734
735- history_file = os .path .expanduser (os .environ .get ("MYCLI_HISTFILE" , " ~/.mycli-history" ))
735+ history_file = os .path .expanduser (os .environ .get ("MYCLI_HISTFILE" , self . config . get ( "history_file" , " ~/.mycli-history") ))
736736 if dir_path_exists (history_file ):
737737 history = FileHistoryWithTimestamp (history_file )
738738 else :
@@ -952,10 +952,7 @@ def one_iteration(text: str | None = None) -> None:
952952 logger .debug ("sql: %r" , text )
953953
954954 special .write_tee (self .get_prompt (self .prompt_format ) + text )
955- if self .logfile :
956- self .logfile .write (f"\n # { datetime .now ()} \n " )
957- self .logfile .write (text )
958- self .logfile .write ("\n " )
955+ self .log_query (text )
959956
960957 successful = False
961958 start = time ()
@@ -1136,6 +1133,12 @@ def reconnect(self, database: str = "") -> bool:
11361133 self .echo (str (e ), err = True , fg = "red" )
11371134 return False
11381135
1136+ def log_query (self , query : str ) -> None :
1137+ if isinstance (self .logfile , TextIOWrapper ):
1138+ self .logfile .write (f"\n # { datetime .now ()} \n " )
1139+ self .logfile .write (query )
1140+ self .logfile .write ("\n " )
1141+
11391142 def log_output (self , output : str ) -> None :
11401143 """Log the output in the audit log, if it's enabled."""
11411144 if isinstance (self .logfile , TextIOWrapper ):
@@ -1315,6 +1318,7 @@ def get_prompt(self, string: str) -> str:
13151318 def run_query (self , query : str , new_line : bool = True ) -> None :
13161319 """Runs *query*."""
13171320 assert self .sqlexecute is not None
1321+ self .log_query (query )
13181322 results = self .sqlexecute .run (query )
13191323 for result in results :
13201324 title = result .title
@@ -1331,6 +1335,7 @@ def run_query(self, query: str, new_line: bool = True) -> None:
13311335 self .null_string ,
13321336 )
13331337 for line in output :
1338+ self .log_output (line )
13341339 click .echo (line , nl = new_line )
13351340
13361341 # get and display warnings if enabled
@@ -1623,12 +1628,17 @@ def cli(
16231628 sys .exit (0 )
16241629 if list_ssh_config :
16251630 ssh_config = read_ssh_config (ssh_config_path )
1626- for host in ssh_config .get_hostnames ():
1631+ try :
1632+ host_entries = ssh_config .get_hostnames ()
1633+ except KeyError :
1634+ click .secho ('Error reading ssh config' , err = True , fg = "red" )
1635+ sys .exit (1 )
1636+ for host_entry in host_entries :
16271637 if verbose :
1628- host_config = ssh_config .lookup (host )
1629- click .secho (f"{ host } : { host_config .get ('hostname' )} " )
1638+ host_config = ssh_config .lookup (host_entry )
1639+ click .secho (f"{ host_entry } : { host_config .get ('hostname' )} " )
16301640 else :
1631- click .secho (host )
1641+ click .secho (host_entry )
16321642 sys .exit (0 )
16331643 # Choose which ever one has a valid value.
16341644 database = dbname or database
0 commit comments