Skip to content

Commit

Permalink
fix(cli): only print one time for multiple queries (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
everpcpc authored Apr 28, 2023
1 parent f055fad commit 26b4513
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bendsql"
version = "0.3.6"
version = "0.3.7"
edition = "2021"
license = "Apache-2.0"
description = "Databend Native Command Line Tool"
Expand Down
3 changes: 0 additions & 3 deletions cli/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,6 @@ impl<'a> FormatDisplay<'a> {
if let Some(pb) = self.progress.take() {
pb.finish_and_clear();
}
if self.settings.time {
println!("{:.3}", self.start.elapsed().as_secs_f64());
}
Ok(())
}

Expand Down
16 changes: 10 additions & 6 deletions cli/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ impl Session {
}

pub async fn handle_reader<R: BufRead>(&mut self, r: R) {
let start = Instant::now();
let mut lines = r.lines();
while let Some(Ok(line)) = lines.next() {
let queries = self.append_query(&line);
Expand All @@ -165,6 +166,9 @@ impl Session {
eprintln!("{}", e);
}
}
if self.settings.time {
println!("{:.3}", start.elapsed().as_secs_f64());
}
}

pub fn append_query(&mut self, line: &str) -> Vec<String> {
Expand Down Expand Up @@ -226,15 +230,15 @@ impl Session {
let affected = self.conn.exec(query).await?;
if is_repl {
if affected > 0 {
println!(
eprintln!(
"{} rows affected in ({:.3} sec)",
affected,
start.elapsed().as_secs_f64()
);
} else {
println!("Processed in ({:.3} sec)", start.elapsed().as_secs_f64());
eprintln!("Processed in ({:.3} sec)", start.elapsed().as_secs_f64());
}
println!();
eprintln!();
}
Ok(false)
}
Expand Down Expand Up @@ -300,13 +304,13 @@ impl Session {
self.conn = new_connection(&self.dsn)?;
if self.is_repl {
let info = self.conn.info();
println!(
eprintln!(
"Trying reconnect to {}:{} as user {}.",
info.host, info.port, info.user
);
let version = self.conn.version().await?;
println!("Connected to {}", version);
println!();
eprintln!("Connected to {}", version);
eprintln!();
}
Ok(())
}
Expand Down

0 comments on commit 26b4513

Please sign in to comment.