Azure / Azure/azure-cli-extensions
rdbms-connect execute does not show output when using input from file (but it does using a direct query)
- Dominant language
- Python
- Stars
- 454
- Forks
- 1.7k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 64
Description
### Describe the bug
When running the command `az mysql flexible-server execute` using the file input option `-f query.sql`, it does not show the output of the query as it does when using the query option `-q "SELECT 'HELLO WORLD'"` because the code that shows the output is not present in the `_connect_execute_file` method:
https://github.com/Azure/azure-cli-extensions/blob/d16f53341af591d8a4697c01b895f528e4d17650/src/rdbms-connect/azext_rdbms_connect/custom.py#L256
### Related command
az mysql flexible-server execute
### Errors
NAME -f /tmp/test.sql --database-name 'airsonic'
Running sql file '/tmp/test.sql'...
Successfully executed the file.
Closed the connection to airsdeleteme
### Issue script & Debug output
cli.knack.cli: Command arguments: ['mysql', 'flexible-server', 'execute', '--admin-user', '', '--admin-password', '', '--name', 'airsdeleteme', '-f', '/tmp/test.sql', '--database-name', 'airsonic', '--debug']
cli.knack.cli: __init__ debug log:
Enable color in terminal.
cli.knack.cli: Event: Cli.PreExecute []
cli.knack.cli: Event: CommandParser.OnGlobalArgumentsCreate [, , ]
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableCreate []
cli.azure.cli.core: Modules found from index for 'mysql': ['azure.cli.command_modules.rdbms', 'azext_rdbms_connect']
cli.azure.cli.core: Loading command modules:
cli.azure.cli.core: Name Load Time Groups Commands
cli.azure.cli.core: rdbms 0.151 55 230
cli.azure.cli.core: Total (1) 0.151 55 230
cli.azure.cli.core: These extensions are not installed and will be skipped: ['azext_ai_examples', 'azext_next']
cli.azure.cli.core: Loading extensions:
cli.azure.cli.core: Name Load Time Groups Commands Directory
cli.azure.cli.core: rdbms-connect 0.373 4 4 /home/jmservera/.azure/cliextensions/rdbms-connect
cli.azure.cli.core: Total (1) 0.373 4 4
cli.azure.cli.core: Loaded 55 groups, 234 commands.
cli.azure.cli.core: Found a match in the command table.
cli.azure.cli.core: Raw command : mysql flexible-server execute
cli.azure.cli.core: Command table: mysql flexible-server execute
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableTruncate []
cli.azure.cli.core.azlogging: metadata file logging enabled - writing logs to '/home/jmservera/.azure/commands/2023-06-02.09-30-35.mysql_flexible-server_execute.1442.log'.
az_command_data_logger: command args: mysql flexible-server execute --admin-user {} --admin-password {} --name {} -f {} --database-name {} --debug
cli.knack.cli: Event: CommandInvoker.OnPreArgumentLoad [.add_subscription_parameter at 0x7faa3b6e3880>]
cli.knack.cli: Event: CommandInvoker.OnPostArgumentLoad []
cli.knack.cli: Event: CommandInvoker.OnPostCommandTableCreate [.add_ids_arguments at 0x7faa3b7417e0>, .add_cache_arguments at 0x7faa3b741900>]
cli.knack.cli: Event: CommandInvoker.OnCommandTableLoaded []
cli.knack.cli: Event: CommandInvoker.OnPreParseArgs []
cli.knack.cli: Event: CommandInvoker.OnPostParseArgs [, , .parse_ids_arguments at 0x7faa3b741870>]
az_command_data_logger: extension name: rdbms-connect
az_command_data_logger: extension version: 1.0.4
cli.azext_rdbms_connect.custom: Running sql file '/tmp/test.sql'...
cli.azext_rdbms_connect.custom: Successfully executed the file.
cli.azext_rdbms_connect.custom: Closed the connection to airsdeleteme
cli.knack.cli: Event: CommandInvoker.OnTransformResult [, ]
cli.knack.cli: Event: CommandInvoker.OnFilterResult []
cli.knack.cli: Event: Cli.SuccessfulExecute []
cli.knack.cli: Event: Cli.PostExecute []
az_command_data_logger: exit code: 0
cli.__main__: Command ran in 2.438 seconds (init: 0.228, invoke: 2.210)
telemetry.main: Begin splitting cli events and extra events, total events: 1
telemetry.client: Accumulated 0 events. Flush the clients.
telemetry.main: Finish splitting cli events and extra events, cli events: 1
telemetry.save: Save telemetry record of length 3552 in cache
telemetry.check: Negative: The /home/jmservera/.azure/telemetry.txt was modified at 2023-06-02 09:29:50, which in less than 600.000000 s
### Expected behavior
The same result when using the --query option. It is already implemented there in [line 201](https://github.com/Azure/azure-cli-extensions/blob/d16f53341af591d8a4697c01b895f528e4d17650/src/rdbms-connect/azext_rdbms_connect/custom.py#L201)
```python
# only print out if rows were returned
if cursor.description:
result = cursor.fetchmany(30) # limit to 30 rows of output for now
row_headers = [x[0] for x in cursor.description] # this will extract row headers
# format the result for a clean display
json_data = []
for rv in result:
json_data.append(dict(zip(row_headers, rv)))
```
using the command ` az mysql flexible-server execute --admin-user $CURRENT_USERNAME --admin-password "$TOKEN" --name $MYSQL_SERVER_NAME -q "SELECT 'HELLO WORLD';" --database-name 'airsonic' -o table` shows:
```
Successfully connected to airsdeleteme.
Ran Database Query: 'SELECT 'HELLO WORLD';'
Retrieving first 30 rows of query output, if applicable.
Closed the connection to airsdeleteme
HELLO WORLD
-------------
HELLO WORLD
```
### Environment Summary
azure-cli 2.49.0
core 2.49.0
telemetry 1.0.8
Extensions:
rdbms-connect 1.0.4
Dependencies:
msal 1.20.0
azure-mgmt-resource 22.0.0
Python location '/opt/az/bin/python3'
Extensions directory '/home/jmservera/.azure/cliextensions'
Python (Linux) 3.10.10 (main, May 19 2023, 08:20:31) [GCC 11.3.0]
Legal docs and information: aka.ms/AzureCliLegal
Your CLI is up-to-date.
### Additional context
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.