From 85b71deddb8588e0b4bb42a5e4a31b340e6ad4a7 Mon Sep 17 00:00:00 2001 From: baishen Date: Fri, 12 Jul 2024 23:11:54 +0800 Subject: [PATCH 1/2] fix: allow select version() failed --- driver/src/conn.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/driver/src/conn.rs b/driver/src/conn.rs index 7708f881..aa4b1f99 100644 --- a/driver/src/conn.rs +++ b/driver/src/conn.rs @@ -93,13 +93,17 @@ pub trait Connection: DynClone + Send + Sync { async fn info(&self) -> ConnectionInfo; async fn version(&self) -> Result { - let row = self.query_row("SELECT version()").await?; + let row = self.query_row("SELECT version()").await; let version = match row { - Some(row) => { + Ok(Some(row)) => { let (version,): (String,) = row.try_into().map_err(Error::Parsing)?; version } - None => "".to_string(), + Ok(None) => "".to_string(), + Err(e) => { + eprintln!("select version() failed: {}", e); + "".to_string() + } }; Ok(version) } From 61dde103f62de3d00c532d7a1ab4b07777bf972c Mon Sep 17 00:00:00 2001 From: baishen Date: Mon, 15 Jul 2024 11:49:41 +0800 Subject: [PATCH 2/2] fix --- cli/src/session.rs | 6 +++--- driver/src/conn.rs | 10 +++------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/cli/src/session.rs b/cli/src/session.rs index 0edadea3..85d7f499 100644 --- a/cli/src/session.rs +++ b/cli/src/session.rs @@ -85,7 +85,7 @@ impl Session { ); } } - let version = conn.version().await?; + let version = conn.version().await.unwrap_or_default(); println!("Connected to {}", version); println!(); @@ -163,7 +163,7 @@ impl Session { // server version { - let version = self.conn.version().await?; + let version = self.conn.version().await.unwrap_or_default(); println!("Server version: {}", version); } @@ -540,7 +540,7 @@ impl Session { "reconnecting to {}:{} as user {}.", info.host, info.port, info.user ); - let version = self.conn.version().await?; + let version = self.conn.version().await.unwrap_or_default(); eprintln!("connected to {}", version); eprintln!(); } diff --git a/driver/src/conn.rs b/driver/src/conn.rs index aa4b1f99..7708f881 100644 --- a/driver/src/conn.rs +++ b/driver/src/conn.rs @@ -93,17 +93,13 @@ pub trait Connection: DynClone + Send + Sync { async fn info(&self) -> ConnectionInfo; async fn version(&self) -> Result { - let row = self.query_row("SELECT version()").await; + let row = self.query_row("SELECT version()").await?; let version = match row { - Ok(Some(row)) => { + Some(row) => { let (version,): (String,) = row.try_into().map_err(Error::Parsing)?; version } - Ok(None) => "".to_string(), - Err(e) => { - eprintln!("select version() failed: {}", e); - "".to_string() - } + None => "".to_string(), }; Ok(version) }