@@ -143,6 +143,7 @@ def __init__(
143143 auto_vertical_output : bool = False ,
144144 warn : bool | None = None ,
145145 myclirc : str = "~/.myclirc" ,
146+ show_warnings : bool | None = None ,
146147 ) -> None :
147148 self .sqlexecute = sqlexecute
148149 self .logfile = logfile
@@ -176,6 +177,10 @@ def __init__(
176177 self .vi_ttimeoutlen = c ['keys' ].as_float ('vi_ttimeoutlen' )
177178 special .set_timing_enabled (c ["main" ].as_bool ("timing" ))
178179 special .set_show_favorite_query (c ["main" ].as_bool ("show_favorite_query" ))
180+ if show_warnings is not None :
181+ special .set_show_warnings_enabled (show_warnings )
182+ else :
183+ special .set_show_warnings_enabled (c ['main' ].as_bool ('show_warnings' ))
179184 self .beep_after_seconds = float (c ["main" ]["beep_after_seconds" ] or 0 )
180185 self .default_keepalive_ticks = c ['connection' ].as_int ('default_keepalive_ticks' )
181186
@@ -221,7 +226,6 @@ def __init__(
221226
222227 # read from cli argument or user config file
223228 self .auto_vertical_output = auto_vertical_output or c ["main" ].as_bool ("auto_vertical_output" )
224- self .show_warnings = c ["main" ].as_bool ("show_warnings" )
225229
226230 # Write user config if system config wasn't the last config loaded.
227231 if c .filename not in self .system_config_files and not os .path .exists (myclirc ):
@@ -326,22 +330,6 @@ def register_special_commands(self) -> None:
326330 aliases = ["\\ Tr" ],
327331 case_sensitive = True ,
328332 )
329- special .register_special_command (
330- self .disable_show_warnings ,
331- "nowarnings" ,
332- "nowarnings" ,
333- "Disable automatic warnings display." ,
334- aliases = ["\\ w" ],
335- case_sensitive = True ,
336- )
337- special .register_special_command (
338- self .enable_show_warnings ,
339- "warnings" ,
340- "warnings" ,
341- "Enable automatic warnings display." ,
342- aliases = ["\\ W" ],
343- case_sensitive = True ,
344- )
345333 special .register_special_command (
346334 self .execute_from_file , "source" , "source <filename>" , "Execute queries from a file." , aliases = ["\\ ." ]
347335 )
@@ -361,16 +349,6 @@ def manual_reconnect(self, arg: str = "", **_) -> Generator[SQLResult, None, Non
361349 else :
362350 yield self .change_db (arg ).send (None )
363351
364- def enable_show_warnings (self , ** _ ) -> Generator [SQLResult , None , None ]:
365- self .show_warnings = True
366- msg = "Show warnings enabled."
367- yield SQLResult (status = msg )
368-
369- def disable_show_warnings (self , ** _ ) -> Generator [SQLResult , None , None ]:
370- self .show_warnings = False
371- msg = "Show warnings disabled."
372- yield SQLResult (status = msg )
373-
374352 def change_table_format (self , arg : str , ** _ ) -> Generator [SQLResult , None , None ]:
375353 try :
376354 self .main_formatter .format_name = arg
@@ -555,7 +533,6 @@ def connect(
555533 use_keyring : bool | None = None ,
556534 reset_keyring : bool | None = None ,
557535 keepalive_ticks : int | None = None ,
558- show_warnings : bool | None = None ,
559536 ) -> None :
560537 cnf = {
561538 "database" : None ,
@@ -585,8 +562,6 @@ def connect(
585562 ssl_config : dict [str , Any ] = ssl or {}
586563 user_connection_config = self .config_without_package_defaults .get ('connection' , {})
587564 self .keepalive_ticks = keepalive_ticks
588- if show_warnings is not None :
589- self .show_warnings = show_warnings
590565
591566 int_port = port and int (port )
592567 if not int_port :
@@ -1070,7 +1045,7 @@ def run_query(
10701045 click .echo (line , nl = new_line )
10711046
10721047 # get and display warnings if enabled
1073- if self . show_warnings and isinstance (result .rows , Cursor ) and result .rows .warning_count > 0 :
1048+ if special . is_show_warnings_enabled () and isinstance (result .rows , Cursor ) and result .rows .warning_count > 0 :
10741049 warnings = self .sqlexecute .run ("SHOW WARNINGS" )
10751050 for warning in warnings :
10761051 output = self .format_sqlresult (
@@ -1537,6 +1512,7 @@ def get_password_from_file(password_file: str | None) -> str | None:
15371512 auto_vertical_output = cli_args .auto_vertical_output ,
15381513 warn = cli_args .warn ,
15391514 myclirc = cli_args .myclirc ,
1515+ show_warnings = cli_args .show_warnings ,
15401516 )
15411517
15421518 if cli_args .checkup :
@@ -1898,7 +1874,6 @@ def get_password_from_file(password_file: str | None) -> str | None:
18981874 use_keyring = use_keyring ,
18991875 reset_keyring = reset_keyring ,
19001876 keepalive_ticks = keepalive_ticks ,
1901- show_warnings = cli_args .show_warnings ,
19021877 )
19031878
19041879 if combined_init_cmd :
0 commit comments