@@ -144,6 +144,7 @@ def __init__(
144144 auto_vertical_output : bool = False ,
145145 warn : bool | None = None ,
146146 myclirc : str = "~/.myclirc" ,
147+ show_warnings : bool | None = None ,
147148 ) -> None :
148149 self .sqlexecute = sqlexecute
149150 self .logfile = logfile
@@ -178,6 +179,10 @@ def __init__(
178179 self .vi_ttimeoutlen = c ['keys' ].as_float ('vi_ttimeoutlen' )
179180 special .set_timing_enabled (c ["main" ].as_bool ("timing" ))
180181 special .set_show_favorite_query (c ["main" ].as_bool ("show_favorite_query" ))
182+ if show_warnings is not None :
183+ special .set_show_warnings_enabled (show_warnings )
184+ else :
185+ special .set_show_warnings_enabled (c ['main' ].as_bool ('show_warnings' ))
181186 self .beep_after_seconds = float (c ["main" ]["beep_after_seconds" ] or 0 )
182187 self .default_keepalive_ticks = c ['connection' ].as_int ('default_keepalive_ticks' )
183188
@@ -223,7 +228,6 @@ def __init__(
223228
224229 # read from cli argument or user config file
225230 self .auto_vertical_output = auto_vertical_output or c ["main" ].as_bool ("auto_vertical_output" )
226- self .show_warnings = c ["main" ].as_bool ("show_warnings" )
227231
228232 # Write user config if system config wasn't the last config loaded.
229233 if c .filename not in self .system_config_files and not os .path .exists (myclirc ):
@@ -328,22 +332,6 @@ def register_special_commands(self) -> None:
328332 aliases = ["\\ Tr" ],
329333 case_sensitive = True ,
330334 )
331- special .register_special_command (
332- self .disable_show_warnings ,
333- "nowarnings" ,
334- "nowarnings" ,
335- "Disable automatic warnings display." ,
336- aliases = ["\\ w" ],
337- case_sensitive = True ,
338- )
339- special .register_special_command (
340- self .enable_show_warnings ,
341- "warnings" ,
342- "warnings" ,
343- "Enable automatic warnings display." ,
344- aliases = ["\\ W" ],
345- case_sensitive = True ,
346- )
347335 special .register_special_command (
348336 self .execute_from_file , "source" , "source <filename>" , "Execute queries from a file." , aliases = ["\\ ." ]
349337 )
@@ -363,16 +351,6 @@ def manual_reconnect(self, arg: str = "", **_) -> Generator[SQLResult, None, Non
363351 else :
364352 yield self .change_db (arg ).send (None )
365353
366- def enable_show_warnings (self , ** _ ) -> Generator [SQLResult , None , None ]:
367- self .show_warnings = True
368- msg = "Show warnings enabled."
369- yield SQLResult (status = msg )
370-
371- def disable_show_warnings (self , ** _ ) -> Generator [SQLResult , None , None ]:
372- self .show_warnings = False
373- msg = "Show warnings disabled."
374- yield SQLResult (status = msg )
375-
376354 def change_table_format (self , arg : str , ** _ ) -> Generator [SQLResult , None , None ]:
377355 try :
378356 self .main_formatter .format_name = arg
@@ -557,7 +535,6 @@ def connect(
557535 use_keyring : bool | None = None ,
558536 reset_keyring : bool | None = None ,
559537 keepalive_ticks : int | None = None ,
560- show_warnings : bool | None = None ,
561538 ) -> None :
562539 cnf = {
563540 "database" : None ,
@@ -587,8 +564,6 @@ def connect(
587564 ssl_config : dict [str , Any ] = ssl or {}
588565 user_connection_config = self .config_without_package_defaults .get ('connection' , {})
589566 self .keepalive_ticks = keepalive_ticks
590- if show_warnings is not None :
591- self .show_warnings = show_warnings
592567
593568 int_port = port and int (port )
594569 if not int_port :
@@ -1088,7 +1063,7 @@ def run_query(
10881063 click .echo (line , nl = new_line )
10891064
10901065 # get and display warnings if enabled
1091- if self . show_warnings and isinstance (result .rows , Cursor ) and result .rows .warning_count > 0 :
1066+ if special . is_show_warnings_enabled () and isinstance (result .rows , Cursor ) and result .rows .warning_count > 0 :
10921067 warnings = self .sqlexecute .run ("SHOW WARNINGS" )
10931068 for warning in warnings :
10941069 output = self .format_sqlresult (
@@ -1555,6 +1530,7 @@ def get_password_from_file(password_file: str | None) -> str | None:
15551530 auto_vertical_output = cli_args .auto_vertical_output ,
15561531 warn = cli_args .warn ,
15571532 myclirc = cli_args .myclirc ,
1533+ show_warnings = cli_args .show_warnings ,
15581534 )
15591535
15601536 if cli_args .checkup :
@@ -1916,7 +1892,6 @@ def get_password_from_file(password_file: str | None) -> str | None:
19161892 use_keyring = use_keyring ,
19171893 reset_keyring = reset_keyring ,
19181894 keepalive_ticks = keepalive_ticks ,
1919- show_warnings = cli_args .show_warnings ,
19201895 )
19211896
19221897 if combined_init_cmd :
0 commit comments