From 59d377458118d40ef53b663d688648ad7db6d344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Mon, 15 Nov 2021 09:26:52 +0100 Subject: [PATCH] Improve TiDB compatibility --- changelog.md | 1 + mycli/packages/special/dbcommands.py | 36 +++++++++++++++------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/changelog.md b/changelog.md index 0d7ea49d..4097dfe5 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,7 @@ TBD: Bug Fixes: --------- * Fix autocompletion for more than one JOIN +* Fix the status command when connected to TiDB or other servers that don't implement 'Threads\_connected' 1.24.1: ======= diff --git a/mycli/packages/special/dbcommands.py b/mycli/packages/special/dbcommands.py index ed90e4c3..45d70690 100644 --- a/mycli/packages/special/dbcommands.py +++ b/mycli/packages/special/dbcommands.py @@ -135,23 +135,25 @@ def status(cur, **_): else: output.append(('UNIX socket:', variables['socket'])) - output.append(('Uptime:', format_uptime(status['Uptime']))) - - # Print the current server statistics. - stats = [] - stats.append('Connections: {0}'.format(status['Threads_connected'])) - if 'Queries' in status: - stats.append('Queries: {0}'.format(status['Queries'])) - stats.append('Slow queries: {0}'.format(status['Slow_queries'])) - stats.append('Opens: {0}'.format(status['Opened_tables'])) - stats.append('Flush tables: {0}'.format(status['Flush_commands'])) - stats.append('Open tables: {0}'.format(status['Open_tables'])) - if 'Queries' in status: - queries_per_second = int(status['Queries']) / int(status['Uptime']) - stats.append('Queries per second avg: {:.3f}'.format( - queries_per_second)) - stats = ' '.join(stats) - footer.append('\n' + stats) + if 'Uptime' in status: + output.append(('Uptime:', format_uptime(status['Uptime']))) + + if 'Threads_connected' in status: + # Print the current server statistics. + stats = [] + stats.append('Connections: {0}'.format(status['Threads_connected'])) + if 'Queries' in status: + stats.append('Queries: {0}'.format(status['Queries'])) + stats.append('Slow queries: {0}'.format(status['Slow_queries'])) + stats.append('Opens: {0}'.format(status['Opened_tables'])) + stats.append('Flush tables: {0}'.format(status['Flush_commands'])) + stats.append('Open tables: {0}'.format(status['Open_tables'])) + if 'Queries' in status: + queries_per_second = int(status['Queries']) / int(status['Uptime']) + stats.append('Queries per second avg: {:.3f}'.format( + queries_per_second)) + stats = ' '.join(stats) + footer.append('\n' + stats) footer.append('--------------') return [('\n'.join(title), output, '', '\n'.join(footer))]