diff --git a/Cargo.toml b/Cargo.toml index b5dc9793..b4ae5e68 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ resolver = "2" [workspace.package] edition = "2021" -version = "0.10.22" +version = "0.10.23" authors = ["Linhe Huo "] categories = ["database", "api-bindings", "asynchronous"] diff --git a/taos-error/src/lib.rs b/taos-error/src/lib.rs index 4b587e4e..f751c117 100644 --- a/taos-error/src/lib.rs +++ b/taos-error/src/lib.rs @@ -168,13 +168,13 @@ impl Error { #[inline(always)] pub fn new_with_context( code: impl Into, - err: impl Display, - context: impl Display, + err: impl Into, + context: impl Into, ) -> Self { Self { code: code.into(), - context: Some(context.to_string()), - source: err.to_string().into(), + context: Some(context.into()), + source: err.into().into(), } } #[inline] @@ -187,10 +187,10 @@ impl Error { } #[inline] - pub fn context(mut self, context: impl Display) -> Self { + pub fn context(mut self, context: impl Into) -> Self { self.context = Some(match self.context { - Some(pre) => format!("{}: {}", context, pre), - None => format!("{}", context), + Some(pre) => format!("{}: {}", context.into(), pre), + None => context.into(), }); self } diff --git a/taos-optin/Cargo.toml b/taos-optin/Cargo.toml index 1b2e686b..4aada9d6 100644 --- a/taos-optin/Cargo.toml +++ b/taos-optin/Cargo.toml @@ -32,7 +32,7 @@ serde_repr = { version = "0.1.7", optional = true } tracing = { version = "0.1", features = ["log"] } # taos-error = { version = "0.2.0", path = "../taos-error" } taos-macros = { version = "0.*", path = "../taos-macros" } -taos-query = { version = "0.10.22", path = "../taos-query" } +taos-query = { version = "0.10.23", path = "../taos-query" } # time_this = "0.2.4" fun_time = "0.2.1" diff --git a/taos-optin/src/raw/mod.rs b/taos-optin/src/raw/mod.rs index fb8c7a9e..f6ccccc5 100644 --- a/taos-optin/src/raw/mod.rs +++ b/taos-optin/src/raw/mod.rs @@ -786,10 +786,10 @@ impl RawTaos { let ptr = unsafe { (self.c.taos_query)(self.as_ptr(), sql.as_ptr()) }; if ptr.is_null() { let code = self.c.errno(std::ptr::null_mut()); - let str = self.c.errno(std::ptr::null_mut()); + let str = self.c.err_str(std::ptr::null_mut()); return Err(RawError::new_with_context( code, - str, + str.to_string(), format!("Query with sql: {:?}", sql), )); } @@ -1313,42 +1313,42 @@ impl RawRes { Poll::Ready(item) } else { current.in_use = true; - let param = Box::new((Arc::downgrade(state), self.c.clone(), cx.waker().clone())); + let param = Box::new((state.clone(), self.c.clone(), cx.waker().clone())); #[no_mangle] unsafe extern "C" fn taos_optin_fetch_rows_callback( param: *mut c_void, res: *mut TAOS_RES, num_of_rows: c_int, ) { - let param = param as *mut (Weak>, Arc, Waker); + let param = param as *mut (Arc>, Arc, Waker); let param = Box::from_raw(param); - if let Some(state) = param.0.upgrade() { - let state = &mut *state.get(); - let api = &*param.1; - // state.done = true; - state.in_use = false; - if num_of_rows < 0 { - // error - state.result.replace(Err(RawError::new_with_context( - num_of_rows, - api.err_str(res), - "fetch_rows_a", - ))); + let state = param.0; + let state = &mut *state.get(); + let api = &*param.1; + // state.done = true; + state.in_use = false; + if num_of_rows < 0 { + // error + let old = state.result.replace(Err(RawError::new_with_context( + num_of_rows, + api.err_str(res), + "fetch_rows_a", + ))); + drop(old); + } else { + // success + if num_of_rows > 0 { + // has a block + let block = (param.1.taos_result_block.unwrap())(res).read() as _; + state + .result + .replace(Ok(Some((block, num_of_rows as usize)))); } else { - // success - if num_of_rows > 0 { - // has a block - let block = (param.1.taos_result_block.unwrap())(res).read() as _; - state - .result - .replace(Ok(Some((block, num_of_rows as usize)))); - } else { - // retrieving completed - state.result.replace(Ok(None)); - } + // retrieving completed + state.result.replace(Ok(None)); } - param.2.wake() } + param.2.wake() } unsafe { (self.c.taos_fetch_rows_a)( diff --git a/taos-query/Cargo.toml b/taos-query/Cargo.toml index 588a0e1d..ffe369e4 100644 --- a/taos-query/Cargo.toml +++ b/taos-query/Cargo.toml @@ -27,7 +27,7 @@ parse_duration = "2.1" prettytable = "0.10.0" rust_decimal = { version = "1", features = ["c-repr"] } rustversion = "1.0.6" -taos-error = { path = "../taos-error", version = "0.10.22" } +taos-error = { path = "../taos-error", version = "0.10.23" } thiserror = "1.0.47" url = "2.2.2" diff --git a/taos-sys/Cargo.toml b/taos-sys/Cargo.toml index a0ff6a85..afab22dc 100644 --- a/taos-sys/Cargo.toml +++ b/taos-sys/Cargo.toml @@ -31,7 +31,7 @@ serde_json = "1.0" serde_repr = { version = "0.1.7", optional = true } # taos-error = { path = "../taos-error", version = "0.2.9" } taos-macros = { path = "../taos-macros", version = "0.*" } -taos-query = { path = "../taos-query", version = "0.10.22" } +taos-query = { path = "../taos-query", version = "0.10.23" } [build-dependencies] dotenv = "0.15.0" diff --git a/taos-ws/Cargo.toml b/taos-ws/Cargo.toml index cc59f54a..cb39e044 100644 --- a/taos-ws/Cargo.toml +++ b/taos-ws/Cargo.toml @@ -27,7 +27,7 @@ serde = { version = "1", features = ["derive"] } serde_json = { version = "1" } serde_repr = "0.1.8" serde_with = "3.0.0" -taos-query = { path = "../taos-query", version = "0.10.22" } +taos-query = { path = "../taos-query", version = "0.10.23" } thiserror = "1.0.47" tokio = { version = "1", features = ["sync", "rt-multi-thread", "macros", "io-util", "time"] } tokio-tungstenite = { version = "0.20.1" } diff --git a/taos/Cargo.toml b/taos/Cargo.toml index 3b984775..10bfce95 100644 --- a/taos/Cargo.toml +++ b/taos/Cargo.toml @@ -19,10 +19,10 @@ no-default-features = true [dependencies] async-trait = "0.1" log = "0.4.17" -taos-optin = { path = "../taos-optin", version = "0.10.22", optional = true } -taos-query = { path = "../taos-query", version = "0.10.22", default-features = false } -taos-sys = { path = "../taos-sys", version = "0.10.22", optional = true } -taos-ws = { path = "../taos-ws", version = "0.10.22", optional = true } +taos-optin = { path = "../taos-optin", version = "0.10.23", optional = true } +taos-query = { path = "../taos-query", version = "0.10.23", default-features = false } +taos-sys = { path = "../taos-sys", version = "0.10.23", optional = true } +taos-ws = { path = "../taos-ws", version = "0.10.23", optional = true } futures = { version = "0.3", features = ["executor"] } [dev-dependencies]