Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI - Fix sql --interactive case where returned rows are 0 #2359

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions crates/cli/src/subcommands/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,12 @@ pub(crate) async fn run_sql(builder: RequestBuilder, sql: &str, with_stats: bool
let mut table = stmt_result_to_table(stmt_result)?;
if with_stats {
// The `tabled::count_rows` add the header as a row, so subtract it.
let row_count = print_row_count(table.count_rows().wrapping_sub(1));
table.with(tabled::settings::panel::Footer::new(row_count));
let row_count = table.count_rows().wrapping_sub(1);
// For some reason, `table.with(...)` crashes if the row count is 0.
if row_count > 0 {
let row_count = print_row_count(row_count);
Comment on lines +98 to +99
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if row_count > 0 {
let row_count = print_row_count(row_count);
let row_count = print_row_count(row_count);
if row_count > 0 {

I think you should move this up one line outside of the if because then you would still get the output:

0 rows

Instead of getting no output.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function is poorly named. It doesn't actually print anything. It just formats it as a string.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

even if it were the case, I think that would be misleading. I believe we've just stopped returning the row count from the API calls, but in fact we are updating/deleting rows.

table.with(tabled::settings::panel::Footer::new(row_count));
}
}
anyhow::Ok(table)
})
Expand Down
Loading