88from mycli import __version__
99from mycli .packages .special import iocommands
1010from mycli .packages .special .main import ArgType , special_command
11- from mycli .packages .special .utils import format_uptime , get_ssl_version
11+ from mycli .packages .special .utils import (
12+ format_uptime ,
13+ get_local_timezone ,
14+ get_server_timezone ,
15+ get_ssl_cipher ,
16+ get_ssl_version ,
17+ )
1218from mycli .packages .sqlresult import SQLResult
1319
1420logger = logging .getLogger (__name__ )
@@ -69,7 +75,7 @@ def status(cur: Cursor, **_) -> list[SQLResult]:
6975 try :
7076 cur .execute (query )
7177 except ProgrammingError :
72- # Fallback in case query fail , as it does with Mysql 4
78+ # Fallback in case query fails , as it does with Mysql 4
7379 query = "SHOW STATUS;"
7480 logger .debug (query )
7581 cur .execute (query )
@@ -78,15 +84,24 @@ def status(cur: Cursor, **_) -> list[SQLResult]:
7884 query = "SHOW GLOBAL VARIABLES;"
7985 logger .debug (query )
8086 cur .execute (query )
81- variables = dict (cur .fetchall ())
87+ global_variables = dict (cur .fetchall ())
8288
83- # prepare in case keys are bytes, as with Python 3 and Mysql 4
84- if isinstance (list (variables )[0 ], bytes ) and isinstance (list (status )[0 ], bytes ):
85- variables = {k .decode ("utf-8" ): v .decode ("utf-8" ) for k , v in variables .items ()}
89+ query = "SHOW SESSION VARIABLES;"
90+ logger .debug (query )
91+ cur .execute (query )
92+ session_variables = dict (cur .fetchall ())
93+
94+ # decode in case keys are bytes, as with Mysql 4
95+ if global_variables and isinstance (list (global_variables )[0 ], bytes ):
96+ global_variables = {k .decode ("utf-8" ): v .decode ("utf-8" ) for k , v in global_variables .items ()}
97+ if session_variables and isinstance (list (session_variables )[0 ], bytes ):
98+ session_variables = {k .decode ("utf-8" ): v .decode ("utf-8" ) for k , v in session_variables .items ()}
99+ if status and isinstance (list (status )[0 ], bytes ):
86100 status = {k .decode ("utf-8" ): v .decode ("utf-8" ) for k , v in status .items ()}
87101
88102 # Create output buffers.
89103 preamble = []
104+ header = ['Setting' , 'Value' ]
90105 output = []
91106 footer = []
92107
@@ -111,7 +126,6 @@ def status(cur: Cursor, **_) -> list[SQLResult]:
111126 else :
112127 db = ""
113128 user = ""
114-
115129 output .append (("Current database:" , db ))
116130 output .append (("Current user:" , user ))
117131
@@ -124,9 +138,16 @@ def status(cur: Cursor, **_) -> list[SQLResult]:
124138 pager = "stdout"
125139 output .append (("Current pager:" , pager ))
126140
127- output .append (("Server version:" , f'{ variables ["version" ]} { variables ["version_comment" ]} ' ))
128- output .append (("Protocol version:" , variables ["protocol_version" ]))
129- output .append (('SSL/TLS version:' , get_ssl_version (cur )))
141+ output .append (("Using delimiter:" , iocommands .get_current_delimiter ()))
142+ output .append (("Using outfile:" , iocommands .tee_file .name if iocommands .tee_file else '' ))
143+
144+ output .append (("Server version:" , f'{ global_variables ["version" ]} { global_variables ["version_comment" ]} ' ))
145+ output .append (("Protocol version:" , global_variables ["protocol_version" ]))
146+ if cipher := get_ssl_cipher (cur ):
147+ output .append (('SSL:' , f'Cipher in use is { cipher } ' ))
148+ else :
149+ output .append (('SSL:' , '' ))
150+ output .append (('SSL/TLS version:' , get_ssl_version (cur ) or '' ))
130151
131152 if getattr (cur .connection , 'unix_socket' , None ):
132153 host_info = cur .connection .host_info
@@ -135,23 +156,28 @@ def status(cur: Cursor, **_) -> list[SQLResult]:
135156
136157 output .append (("Connection:" , host_info ))
137158
138- query = "SELECT @@character_set_server, @@character_set_database, @@character_set_client, @@character_set_connection LIMIT 1;"
139- logger .debug (query )
140- cur .execute (query )
141- if one := cur .fetchone ():
142- charset = one
143- else :
144- charset = ("" , "" , "" , "" )
145- output .append (("Server characterset:" , charset [0 ]))
146- output .append (("Db characterset:" , charset [1 ]))
147- output .append (("Client characterset:" , charset [2 ]))
148- output .append (("Conn. characterset:" , charset [3 ]))
159+ charset_spec = [
160+ {'name' : 'Server characterset:' , 'variable' : 'character_set_server' },
161+ {'name' : 'Db characterset:' , 'variable' : 'character_set_database' },
162+ {'name' : 'Client characterset:' , 'variable' : 'character_set_client' },
163+ {'name' : 'Conn. characterset:' , 'variable' : 'character_set_connection' },
164+ {'name' : 'Result characterset:' , 'variable' : 'character_set_results' },
165+ ]
166+ for elt in charset_spec :
167+ if elt ['variable' ] in session_variables :
168+ value = session_variables [elt ['variable' ]]
169+ else :
170+ value = ''
171+ output .append ((elt ['name' ], value ))
149172
150173 if getattr (cur .connection , 'unix_socket' , None ):
151- output .append (('UNIX socket:' , variables ['socket' ]))
174+ output .append (('UNIX socket:' , global_variables ['socket' ]))
152175 else :
153176 output .append (('TCP port:' , cur .connection .port ))
154177
178+ output .append (('Server timezone:' , get_server_timezone (global_variables )))
179+ output .append (('Local timezone:' , get_local_timezone ()))
180+
155181 if "Uptime" in status :
156182 output .append (("Uptime:" , format_uptime (status ["Uptime" ])))
157183
@@ -174,4 +200,4 @@ def status(cur: Cursor, **_) -> list[SQLResult]:
174200
175201 footer .append ("--------------" )
176202
177- return [SQLResult (preamble = "\n " .join (preamble ), rows = output , postamble = "\n " .join (footer ))]
203+ return [SQLResult (preamble = "\n " .join (preamble ), header = header , rows = output , postamble = "\n " .join (footer ))]
0 commit comments