diff --git a/taos-optin/src/conn/mod.rs b/taos-optin/src/conn/mod.rs index bd89495c..3f4cfac0 100644 --- a/taos-optin/src/conn/mod.rs +++ b/taos-optin/src/conn/mod.rs @@ -98,7 +98,7 @@ impl RawTaos { pub fn query_a<'a, S: IntoCStr<'a>>( &self, sql: S, - fp: taos_async_query_cb, + fp: TaosAsyncQueryCb, param: *mut c_void, ) { unsafe { taos_query_a(self.as_ptr(), sql.into_c_str().as_ptr(), fp, param) } diff --git a/taos-optin/src/ffi.rs b/taos-optin/src/ffi.rs index 2b4b4fef..3e2053ec 100644 --- a/taos-optin/src/ffi.rs +++ b/taos-optin/src/ffi.rs @@ -49,12 +49,12 @@ extern "C" { extern "C" { - pub fn taos_fetch_rows_a(res: *mut TAOS_RES, fp: taos_async_fetch_cb, param: *mut c_void); + pub fn taos_fetch_rows_a(res: *mut TaosRes, fp: TaosAsyncFetchCb, param: *mut c_void); pub fn taos_query_a( taos: *mut TAOS, sql: *const c_char, - fp: taos_async_query_cb, + fp: TaosAsyncQueryCb, param: *mut c_void, ); } @@ -62,89 +62,89 @@ extern "C" { extern "C" { pub fn taos_load_table_info(taos: *mut TAOS, tableNameList: *const c_char) -> c_int; - pub fn taos_stmt_init(taos: *mut TAOS) -> *mut TAOS_STMT; + pub fn taos_stmt_init(taos: *mut TAOS) -> *mut TaosStmt; - pub fn taos_stmt_prepare(stmt: *mut TAOS_STMT, sql: *const c_char, length: c_ulong) -> c_int; + pub fn taos_stmt_prepare(stmt: *mut TaosStmt, sql: *const c_char, length: c_ulong) -> c_int; pub fn taos_stmt_set_tbname_tags( - stmt: *mut TAOS_STMT, + stmt: *mut TaosStmt, name: *const c_char, tags: *mut TaosBind, ) -> c_int; - pub fn taos_stmt_set_tbname(stmt: *mut TAOS_STMT, name: *const c_char) -> c_int; + pub fn taos_stmt_set_tbname(stmt: *mut TaosStmt, name: *const c_char) -> c_int; - pub fn taos_stmt_set_tags(stmt: *mut TAOS_STMT, tags: *mut TaosBind) -> c_int; + pub fn taos_stmt_set_tags(stmt: *mut TaosStmt, tags: *mut TaosBind) -> c_int; - pub fn taos_stmt_set_sub_tbname(stmt: *mut TAOS_STMT, name: *const c_char) -> c_int; + pub fn taos_stmt_set_sub_tbname(stmt: *mut TaosStmt, name: *const c_char) -> c_int; - pub fn taos_stmt_is_insert(stmt: *mut TAOS_STMT, insert: *mut c_int) -> c_int; + pub fn taos_stmt_is_insert(stmt: *mut TaosStmt, insert: *mut c_int) -> c_int; - pub fn taos_stmt_num_params(stmt: *mut TAOS_STMT, nums: *mut c_int) -> c_int; + pub fn taos_stmt_num_params(stmt: *mut TaosStmt, nums: *mut c_int) -> c_int; pub fn taos_stmt_get_param( - stmt: *mut TAOS_STMT, + stmt: *mut TaosStmt, idx: c_int, type_: *mut c_int, bytes: *mut c_int, ) -> c_int; - pub fn taos_stmt_bind_param(stmt: *mut TAOS_STMT, bind: *const TaosBind) -> c_int; + pub fn taos_stmt_bind_param(stmt: *mut TaosStmt, bind: *const TaosBind) -> c_int; - pub fn taos_stmt_bind_param_batch(stmt: *mut TAOS_STMT, bind: *const TaosMultiBind) -> c_int; + pub fn taos_stmt_bind_param_batch(stmt: *mut TaosStmt, bind: *const TaosMultiBind) -> c_int; pub fn taos_stmt_bind_single_param_batch( - stmt: *mut TAOS_STMT, + stmt: *mut TaosStmt, bind: *const TaosMultiBind, colIdx: c_int, ) -> c_int; - pub fn taos_stmt_add_batch(stmt: *mut TAOS_STMT) -> c_int; + pub fn taos_stmt_add_batch(stmt: *mut TaosStmt) -> c_int; - pub fn taos_stmt_execute(stmt: *mut TAOS_STMT) -> c_int; + pub fn taos_stmt_execute(stmt: *mut TaosStmt) -> c_int; - pub fn taos_stmt_affected_rows(stmt: *mut TAOS_STMT) -> c_int; + pub fn taos_stmt_affected_rows(stmt: *mut TaosStmt) -> c_int; - pub fn taos_stmt_use_result(stmt: *mut TAOS_STMT) -> *mut TAOS_RES; + pub fn taos_stmt_use_result(stmt: *mut TaosStmt) -> *mut TaosRes; - pub fn taos_stmt_close(stmt: *mut TAOS_STMT) -> c_int; + pub fn taos_stmt_close(stmt: *mut TaosStmt) -> c_int; - pub fn taos_stmt_errstr(stmt: *mut TAOS_STMT) -> *const c_char; + pub fn taos_stmt_errstr(stmt: *mut TaosStmt) -> *const c_char; } extern "C" { - pub fn taos_query(taos: *mut TAOS, sql: *const c_char) -> *mut TAOS_RES; + pub fn taos_query(taos: *mut TAOS, sql: *const c_char) -> *mut TaosRes; - pub fn taos_fetch_row(res: *mut TAOS_RES) -> TAOS_ROW; + pub fn taos_fetch_row(res: *mut TaosRes) -> TaosRow; - pub fn taos_result_precision(res: *mut TAOS_RES) -> c_int; + pub fn taos_result_precision(res: *mut TaosRes) -> c_int; - pub fn taos_free_result(res: *mut TAOS_RES); + pub fn taos_free_result(res: *mut TaosRes); - pub fn taos_field_count(res: *mut TAOS_RES) -> c_int; + pub fn taos_field_count(res: *mut TaosRes) -> c_int; - pub fn taos_affected_rows(res: *mut TAOS_RES) -> c_int; + pub fn taos_affected_rows(res: *mut TaosRes) -> c_int; - pub fn taos_fetch_fields(res: *mut TAOS_RES) -> *mut TAOS_FIELD; + pub fn taos_fetch_fields(res: *mut TaosRes) -> *mut TAOS_FIELD; pub fn taos_select_db(taos: *mut TAOS, db: *const c_char) -> c_int; pub fn taos_print_row( str_: *mut c_char, - row: TAOS_ROW, + row: TaosRow, fields: *mut TAOS_FIELD, num_fields: c_int, ) -> c_int; - pub fn taos_stop_query(res: *mut TAOS_RES); + pub fn taos_stop_query(res: *mut TaosRes); - pub fn taos_is_null(res: *mut TAOS_RES, row: i32, col: i32) -> bool; + pub fn taos_is_null(res: *mut TaosRes, row: i32, col: i32) -> bool; - pub fn taos_is_update_query(res: *mut TAOS_RES) -> bool; + pub fn taos_is_update_query(res: *mut TaosRes) -> bool; - pub fn taos_fetch_block(res: *mut TAOS_RES, rows: *mut TAOS_ROW) -> c_int; + pub fn taos_fetch_block(res: *mut TaosRes, rows: *mut TaosRow) -> c_int; - pub fn taos_fetch_lengths(res: *mut TAOS_RES) -> *mut c_int; + pub fn taos_fetch_lengths(res: *mut TaosRes) -> *mut c_int; pub fn taos_validate_sql(taos: *mut TAOS, sql: *const c_char) -> c_int; @@ -152,44 +152,44 @@ extern "C" { pub fn taos_get_server_info(taos: *mut TAOS) -> *mut c_char; - pub fn taos_errstr(tres: *mut TAOS_RES) -> *mut c_char; + pub fn taos_errstr(tres: *mut TaosRes) -> *mut c_char; - pub fn taos_errno(tres: *mut TAOS_RES) -> c_int; + pub fn taos_errno(tres: *mut TaosRes) -> c_int; } #[c_cfg(taos_v3)] extern "C" { - pub fn taos_get_column_data_offset(res: *mut TAOS_RES, col: i32) -> *mut i32; + pub fn taos_get_column_data_offset(res: *mut TaosRes, col: i32) -> *mut i32; - pub fn taos_fetch_raw_block(res: *mut TAOS_RES, num: *mut i32, data: *mut *mut c_void) + pub fn taos_fetch_raw_block(res: *mut TaosRes, num: *mut i32, data: *mut *mut c_void) -> c_int; - pub fn taos_fetch_raw_block_a(res: *mut TAOS_RES, fp: taos_async_fetch_cb, param: *mut c_void); + pub fn taos_fetch_raw_block_a(res: *mut TaosRes, fp: TaosAsyncFetchCb, param: *mut c_void); - pub fn taos_get_raw_block(taos: *mut TAOS_RES) -> *mut c_void; + pub fn taos_get_raw_block(taos: *mut TaosRes) -> *mut c_void; } #[c_cfg(taos_result_block)] extern "C" { - pub fn taos_result_block(res: *mut TAOS_RES) -> *mut TAOS_ROW; + pub fn taos_result_block(res: *mut TaosRes) -> *mut TaosRow; } #[cfg(taos_fetch_block_s)] extern "C" { pub fn taos_fetch_block_s( - res: *mut TAOS_RES, + res: *mut TaosRes, num_of_rows: *mut c_int, - rows: *mut TAOS_ROW, + rows: *mut TaosRow, ) -> c_int; } #[cfg(not(taos_fetch_block_s))] #[no_mangle] pub unsafe extern "C" fn taos_fetch_block_s( - res: *mut TAOS_RES, + res: *mut TaosRes, num_of_rows: *mut c_int, - rows: *mut TAOS_ROW, + rows: *mut TaosRow, ) -> c_int { *num_of_rows = taos_fetch_block(res, rows); return 0; @@ -201,25 +201,25 @@ extern "C" { restart: c_int, topic: *const c_char, sql: *const c_char, - fp: Option, + fp: Option, param: *mut c_void, interval: c_int, - ) -> *mut TAOS_SUB; + ) -> *mut TaosSub; - pub fn taos_consume(tsub: *mut TAOS_SUB) -> *mut TAOS_RES; + pub fn taos_consume(tsub: *mut TaosSub) -> *mut TaosRes; - pub fn taos_unsubscribe(tsub: *mut TAOS_SUB, keep_progress: c_int); + pub fn taos_unsubscribe(tsub: *mut TaosSub, keep_progress: c_int); } extern "C" { pub fn taos_open_stream( taos: *mut TAOS, sql: *const c_char, - fp: Option, + fp: Option, stime: i64, param: *mut c_void, - callback: Option, - ) -> *mut TAOS_STREAM; + callback: Option, + ) -> *mut TaosStream; - pub fn taos_close_stream(stream: *mut TAOS_STREAM); + pub fn taos_close_stream(stream: *mut TaosStream); } diff --git a/taos-optin/src/into_c_str.rs b/taos-optin/src/into_c_str.rs index 98cd124f..191728f1 100644 --- a/taos-optin/src/into_c_str.rs +++ b/taos-optin/src/into_c_str.rs @@ -1,6 +1,6 @@ use std::borrow::Cow; use std::ffi::{c_void, CStr, CString}; -use std::os::raw::c_char; +// use std::os::raw::c_char; /// Helper trait to auto convert Rust strings to CStr. pub trait IntoCStr<'a> { @@ -62,12 +62,12 @@ _impl_for_str!(&str); pub struct NullableCStr<'a>(Option>); impl<'a> NullableCStr<'a> { - pub fn as_ptr(&self) -> *const c_char { - match self.0.as_ref() { - Some(c) => c.as_ptr(), - None => std::ptr::null(), - } - } + // pub fn as_ptr(&self) -> *const c_char { + // match self.0.as_ref() { + // Some(c) => c.as_ptr(), + // None => std::ptr::null(), + // } + // } } pub trait IntoNullableCStr<'a> { diff --git a/taos-optin/src/lib.rs b/taos-optin/src/lib.rs index d64dc238..8f55fc03 100644 --- a/taos-optin/src/lib.rs +++ b/taos-optin/src/lib.rs @@ -37,37 +37,37 @@ mod version { } impl Version { - pub(crate) const fn new(mainline: u8, major: u8, minor: u8, patch: u8) -> Self { - Self { - mainline, - major, - minor, - patch, - } - } - fn parse(version: &str) -> Result> { - let version_items: Vec<_> = version.split('.').collect(); - let items = version_items.len(); - if items == 0 || items > 4 { - Err("parse version error: {version}")? - } - - let mainline = version_items[0].parse()?; - let major = version_items - .get(1) - .and_then(|s| s.parse().ok()) - .unwrap_or_default(); - let minor = version_items - .get(2) - .and_then(|s| s.parse().ok()) - .unwrap_or_default(); - let patch = version_items - .get(3) - .and_then(|s| s.parse().ok()) - .unwrap_or_default(); - - Ok(Self::new(mainline, major, minor, patch)) - } + // pub(crate) const fn new(mainline: u8, major: u8, minor: u8, patch: u8) -> Self { + // Self { + // mainline, + // major, + // minor, + // patch, + // } + // } + // fn parse(version: &str) -> Result> { + // let version_items: Vec<_> = version.split('.').collect(); + // let items = version_items.len(); + // if items == 0 || items > 4 { + // Err("parse version error: {version}")? + // } + + // let mainline = version_items[0].parse()?; + // let major = version_items + // .get(1) + // .and_then(|s| s.parse().ok()) + // .unwrap_or_default(); + // let minor = version_items + // .get(2) + // .and_then(|s| s.parse().ok()) + // .unwrap_or_default(); + // let patch = version_items + // .get(3) + // .and_then(|s| s.parse().ok()) + // .unwrap_or_default(); + + // Ok(Self::new(mainline, major, minor, patch)) + // } } } mod into_c_str; @@ -217,7 +217,7 @@ impl taos_query::AsyncQueryable for Taos { /// ``` #[derive(Debug, Default)] pub struct TaosBuilder { - dsn: Dsn, + _dsn: Dsn, auth: Auth, lib: Arc, inner_conn: OnceCell, @@ -336,7 +336,7 @@ impl TBuilder for TaosBuilder { lib.options(types::TSDB_OPTION::ShellActivityTimer, "3600"); Ok(Self { - dsn, + _dsn: dsn, auth, lib: Arc::new(lib), inner_conn: OnceCell::new(), @@ -440,13 +440,13 @@ impl ResultSet { self.fields.get_or_init(|| self.raw.fetch_fields()) } - fn ncols(&self) -> usize { - self.raw.field_count() - } + // fn ncols(&self) -> usize { + // self.raw.field_count() + // } - fn names(&self) -> impl Iterator { - self.fields().iter().map(|f| f.name()) - } + // fn names(&self) -> impl Iterator { + // self.fields().iter().map(|f| f.name()) + // } fn update_summary(&mut self, nrows: usize) { let summary = self.summary.get_mut(); diff --git a/taos-optin/src/query/blocks.rs b/taos-optin/src/query/blocks.rs index afc4e17f..bc480398 100644 --- a/taos-optin/src/query/blocks.rs +++ b/taos-optin/src/query/blocks.rs @@ -9,7 +9,7 @@ use futures::Stream; use taos_error::Error; use taos_query::common::{Field, Precision, RawBlock}; -use crate::ffi::{taos_get_raw_block, TAOS_RES}; +use crate::ffi::{taos_get_raw_block, TaosRes}; use super::raw_res::RawRes; @@ -90,7 +90,7 @@ impl Stream for Blocks { let param = Box::new((&self.shared_state, cx.waker().clone())); unsafe extern "C" fn async_fetch_callback( param: *mut c_void, - res: *mut TAOS_RES, + res: *mut TaosRes, num_of_rows: c_int, ) { let param = param as *mut (&UnsafeCell, Waker); diff --git a/taos-optin/src/query/future.rs b/taos-optin/src/query/future.rs index 55dac47b..b79d1212 100644 --- a/taos-optin/src/query/future.rs +++ b/taos-optin/src/query/future.rs @@ -7,7 +7,7 @@ use std::os::raw::{c_int, c_void}; use std::pin::Pin; use std::task::{Context, Poll, Waker}; -use crate::ffi::TAOS_RES; +use crate::ffi::TaosRes; use crate::into_c_str::IntoCStr; use crate::{RawRes, RawTaos}; use taos_query::prelude::RawError; @@ -20,7 +20,7 @@ pub struct QueryFuture<'a> { /// Shared state between the future and the waiting thread struct State { - result: *mut TAOS_RES, + result: *mut TaosRes, code: i32, done: bool, } @@ -39,7 +39,7 @@ impl<'a> Future for QueryFuture<'a> { } else { unsafe extern "C" fn async_query_callback( param: *mut c_void, - res: *mut TAOS_RES, + res: *mut TaosRes, code: c_int, ) { let state = Box::from_raw(param as *mut (&UnsafeCell, Waker)); diff --git a/taos-optin/src/query/old.rs b/taos-optin/src/query/old.rs index e68a0b53..7cc3bbfc 100644 --- a/taos-optin/src/query/old.rs +++ b/taos-optin/src/query/old.rs @@ -13,7 +13,7 @@ use taos_query::common::{Field, Precision, RawData}; use crate::{ ffi::{ taos_errstr, taos_fetch_fields, taos_fetch_raw_block, taos_fetch_raw_block_a, - taos_field_count, taos_get_raw_block, taos_result_precision, TAOS_RES, + taos_field_count, taos_get_raw_block, taos_result_precision, TaosRes, }, tmq_get_db_name, tmq_get_json_meta, tmq_get_res_type, tmq_get_table_name, tmq_res_t, }; @@ -24,7 +24,7 @@ pub struct BlockStream { precision: Precision, fields: *const Field, cols: usize, - res: *mut TAOS_RES, + res: *mut TaosRes, shared_state: UnsafeCell, } @@ -149,7 +149,7 @@ impl BlockStream { let param = Box::new((&self.shared_state, cx.waker().clone())); unsafe extern "C" fn async_fetch_callback( param: *mut c_void, - res: *mut TAOS_RES, + res: *mut TaosRes, num_of_rows: c_int, ) { let param = param as *mut (&UnsafeCell, Waker); @@ -203,8 +203,8 @@ impl Stream for BlockStream { fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { match self.msg_type { - tmq_res_t::TMQ_RES_DATA => self.poll_next_tmq_data(cx), - tmq_res_t::TMQ_RES_TABLE_META => self.poll_next_tmq_meta(cx), + tmq_res_t::TmqResData => self.poll_next_tmq_data(cx), + tmq_res_t::TmqResTableMeta => self.poll_next_tmq_meta(cx), _ => self.poll_next_query_data(cx), } } @@ -214,7 +214,7 @@ impl BlockStream { /// Create a new `TimerFuture` which will complete after the provided /// timeout. #[inline(always)] - pub fn new(res: *mut TAOS_RES, fields: &[Field], precision: Precision) -> Self { + pub fn new(res: *mut TaosRes, fields: &[Field], precision: Precision) -> Self { let shared_state = UnsafeCell::new(SharedState { done: false, block: std::ptr::null_mut(), @@ -223,7 +223,7 @@ impl BlockStream { }); let msg_type = unsafe { tmq_get_res_type(res) }; - // let msg_type = tmq_res_t::TMQ_RES_INVALID; + // let msg_type = tmq_res_t::TmqResInvalid; BlockStream { res, msg_type, diff --git a/taos-optin/src/query/raw_res.rs b/taos-optin/src/query/raw_res.rs index b12e9ecf..b3a41cc4 100644 --- a/taos-optin/src/query/raw_res.rs +++ b/taos-optin/src/query/raw_res.rs @@ -17,14 +17,14 @@ use super::{blocks::Blocks, message::MessageStream}; #[derive(Debug, Clone, Copy)] #[repr(transparent)] -pub struct RawRes(pub *mut TAOS_RES); +pub struct RawRes(pub *mut TaosRes); unsafe impl Send for RawRes {} unsafe impl Sync for RawRes {} impl RawRes { #[inline] - pub fn as_ptr(&self) -> *mut TAOS_RES { + pub fn as_ptr(&self) -> *mut TaosRes { self.0 } @@ -44,19 +44,19 @@ impl RawRes { } #[inline] - pub fn from_ptr(ptr: *mut TAOS_RES) -> Result { + pub fn from_ptr(ptr: *mut TaosRes) -> Result { let raw = unsafe { Self::from_ptr_unchecked(ptr) }; let code = raw.errno(); raw.with_code(code) } #[inline] - pub unsafe fn from_ptr_unchecked(ptr: *mut TAOS_RES) -> RawRes { + pub unsafe fn from_ptr_unchecked(ptr: *mut TaosRes) -> RawRes { Self(ptr) } #[inline] - pub fn from_ptr_with_code(ptr: *mut TAOS_RES, code: Code) -> Result { + pub fn from_ptr_with_code(ptr: *mut TaosRes, code: Code) -> Result { unsafe { RawRes::from_ptr_unchecked(ptr) }.with_code(code) } @@ -95,7 +95,7 @@ impl RawRes { } #[inline] - pub fn fetch_block(&self) -> Result, Error> { + pub fn fetch_block(&self) -> Result, Error> { let block = Box::into_raw(Box::new(std::ptr::null_mut())); // let mut num = 0; let num = unsafe { taos_fetch_block(self.as_ptr(), block) }; @@ -161,7 +161,7 @@ impl RawRes { let param = Box::new((state.clone(), cx.waker().clone())); unsafe extern "C" fn async_fetch_callback( param: *mut c_void, - res: *mut TAOS_RES, + res: *mut TaosRes, num_of_rows: c_int, ) { let param = param as *mut (Arc>, Waker); @@ -214,12 +214,12 @@ impl RawRes { taos_fetch_raw_block(self.as_ptr(), &mut num as _, &mut block as _), if num > 0 { match self.tmq_message_type() { - tmq_res_t::TMQ_RES_INVALID => { + tmq_res_t::TmqResInvalid => { let mut raw = RawBlock::parse_from_ptr(block as _, self.precision()); raw.with_field_names(self.fetch_fields().iter().map(Field::name)); Some(raw) } - tmq_res_t::TMQ_RES_DATA | tmq_res_t::TMQ_RES_METADATA => { + tmq_res_t::TmqResData | tmq_res_t::TmqResMetadata => { let fields = self.fetch_fields(); let mut raw = RawBlock::parse_from_ptr(block as _, self.precision()); @@ -236,7 +236,7 @@ impl RawRes { Some(raw) } - tmq_res_t::TMQ_RES_TABLE_META => { + tmq_res_t::TmqResTableMeta => { todo!() } } @@ -320,17 +320,17 @@ impl RawRes { } // #[inline] - // pub fn fetch_row(&self) -> TAOS_ROW { + // pub fn fetch_row(&self) -> TaosRow { // unsafe { taos_fetch_row(self.as_ptr()) } // } #[inline] - pub fn fetch_rows_a(&self, fp: taos_async_fetch_cb, param: *mut c_void) { + pub fn fetch_rows_a(&self, fp: TaosAsyncFetchCb, param: *mut c_void) { unsafe { taos_fetch_rows_a(self.as_ptr(), fp, param) } } #[inline] - pub fn fetch_raw_block_a(&self, fp: taos_async_fetch_cb, param: *mut c_void) { + pub fn fetch_raw_block_a(&self, fp: TaosAsyncFetchCb, param: *mut c_void) { unsafe { taos_fetch_raw_block_a(self.as_ptr(), fp, param) } } diff --git a/taos-optin/src/raw/mod.rs b/taos-optin/src/raw/mod.rs index a8570520..17a7781a 100644 --- a/taos-optin/src/raw/mod.rs +++ b/taos-optin/src/raw/mod.rs @@ -20,9 +20,9 @@ use crate::{ err_or, into_c_str::IntoCStr, types::{ - from_raw_fields, taos_async_fetch_cb, taos_async_query_cb, tmq_commit_cb, tmq_conf_res_t, - tmq_conf_t, tmq_list_t, tmq_res_t, tmq_resp_err_t, tmq_t, TaosMultiBind, TAOS, TAOS_RES, - TAOS_ROW, TAOS_STMT, TSDB_OPTION, + from_raw_fields, TaosAsyncFetchCb, TaosAsyncQueryCb, TmqCommitCb, tmq_conf_res_t, + tmq_conf_t, tmq_list_t, tmq_res_t, TmqRespErrT, tmq_t, TaosMultiBind, TAOS, TaosRes, + TaosRow, TaosStmt, TSDB_OPTION, }, Auth, }; @@ -37,10 +37,10 @@ lazy_static::lazy_static! { #[derive(Debug)] pub struct ApiEntry { - lib: Arc, + _lib: Arc, version: String, - taos_cleanup: unsafe extern "C" fn(), - taos_get_client_info: unsafe extern "C" fn() -> *const c_char, + _taos_cleanup: unsafe extern "C" fn(), + _taos_get_client_info: unsafe extern "C" fn() -> *const c_char, taos_options: unsafe extern "C" fn(option: TSDB_OPTION, arg: *const c_void, ...) -> c_int, taos_connect: unsafe extern "C" fn( ip: *const c_char, @@ -57,19 +57,19 @@ pub struct ApiEntry { // async query taos_fetch_rows_a: - unsafe extern "C" fn(res: *mut TAOS_RES, fp: taos_async_fetch_cb, param: *mut c_void), + unsafe extern "C" fn(res: *mut TaosRes, fp: TaosAsyncFetchCb, param: *mut c_void), taos_query_a: unsafe extern "C" fn( taos: *mut TAOS, sql: *const c_char, - fp: taos_async_query_cb, + fp: TaosAsyncQueryCb, param: *mut c_void, ), - taos_result_block: Option *mut *mut c_void>, - taos_get_raw_block: Option *mut c_void>, + taos_result_block: Option *mut *mut c_void>, + taos_get_raw_block: Option *mut c_void>, taos_fetch_raw_block_a: Option< - unsafe extern "C" fn(res: *mut TAOS_RES, fp: taos_async_fetch_cb, param: *mut c_void), + unsafe extern "C" fn(res: *mut TaosRes, fp: TaosAsyncFetchCb, param: *mut c_void), >, - // taos_result_block: Option *mut c_void>, + // taos_result_block: Option *mut c_void>, tmq_write_raw: Option i32>, taos_write_raw_block: Option< unsafe extern "C" fn( @@ -91,23 +91,23 @@ pub struct ApiEntry { >, // query - taos_query: unsafe extern "C" fn(taos: *mut TAOS, sql: *const c_char) -> *mut TAOS_RES, - taos_free_result: unsafe extern "C" fn(res: *mut TAOS_RES), - taos_result_precision: unsafe extern "C" fn(res: *mut TAOS_RES) -> c_int, - taos_field_count: unsafe extern "C" fn(res: *mut TAOS_RES) -> c_int, - taos_affected_rows: unsafe extern "C" fn(res: *mut TAOS_RES) -> c_int, - taos_fetch_fields: unsafe extern "C" fn(res: *mut TAOS_RES) -> *mut c_void, - taos_fetch_lengths: unsafe extern "C" fn(res: *mut TAOS_RES) -> *mut c_int, - taos_fetch_block: unsafe extern "C" fn(res: *mut TAOS_RES, rows: *mut TAOS_ROW) -> c_int, + taos_query: unsafe extern "C" fn(taos: *mut TAOS, sql: *const c_char) -> *mut TaosRes, + taos_free_result: unsafe extern "C" fn(res: *mut TaosRes), + taos_result_precision: unsafe extern "C" fn(res: *mut TaosRes) -> c_int, + taos_field_count: unsafe extern "C" fn(res: *mut TaosRes) -> c_int, + taos_affected_rows: unsafe extern "C" fn(res: *mut TaosRes) -> c_int, + taos_fetch_fields: unsafe extern "C" fn(res: *mut TaosRes) -> *mut c_void, + taos_fetch_lengths: unsafe extern "C" fn(res: *mut TaosRes) -> *mut c_int, + taos_fetch_block: unsafe extern "C" fn(res: *mut TaosRes, rows: *mut TaosRow) -> c_int, taos_fetch_block_s: Option< unsafe extern "C" fn( - res: *mut TAOS_RES, + res: *mut TaosRes, num_of_rows: *mut c_int, - rows: *mut TAOS_ROW, + rows: *mut TaosRow, ) -> c_int, >, taos_fetch_raw_block: Option< - unsafe extern "C" fn(res: *mut TAOS_RES, num: *mut i32, data: *mut *mut c_void) -> c_int, + unsafe extern "C" fn(res: *mut TaosRes, num: *mut i32, data: *mut *mut c_void) -> c_int, >, // stmt @@ -179,8 +179,8 @@ pub(crate) struct TmqConfApi { value: *const c_char, ) -> tmq_conf_res_t, - tmq_conf_set_auto_commit_cb: - unsafe extern "C" fn(conf: *mut tmq_conf_t, cb: tmq_commit_cb, param: *mut c_void), + _tmq_conf_set_auto_commit_cb: + unsafe extern "C" fn(conf: *mut tmq_conf_t, cb: TmqCommitCb, param: *mut c_void), tmq_consumer_new: unsafe extern "C" fn( conf: *mut tmq_conf_t, @@ -207,14 +207,14 @@ impl TmqConfApi { (self.tmq_conf_set)(conf, key.as_ptr(), value.as_ptr()).ok(k, v) } - pub(crate) unsafe fn auto_commit_cb( - &self, - conf: *mut tmq_conf_t, - cb: tmq_commit_cb, - param: *mut c_void, - ) { - (self.tmq_conf_set_auto_commit_cb)(conf, cb, param) - } + // pub(crate) unsafe fn auto_commit_cb( + // &self, + // conf: *mut tmq_conf_t, + // cb: TmqCommitCb, + // param: *mut c_void, + // ) { + // (self.tmq_conf_set_auto_commit_cb)(conf, cb, param) + // } pub(crate) unsafe fn consumer(&self, conf: *mut tmq_conf_t) -> Result<*mut tmq_t, RawError> { let mut err = [0; 256]; @@ -233,28 +233,28 @@ impl TmqConfApi { #[derive(Debug, Clone, Copy)] pub(crate) struct TmqApi { - tmq_get_res_type: unsafe extern "C" fn(res: *mut TAOS_RES) -> tmq_res_t, - tmq_get_table_name: unsafe extern "C" fn(res: *mut TAOS_RES) -> *const c_char, - tmq_get_db_name: unsafe extern "C" fn(res: *mut TAOS_RES) -> *const c_char, - tmq_get_json_meta: unsafe extern "C" fn(res: *mut TAOS_RES) -> *mut c_char, - tmq_get_topic_name: unsafe extern "C" fn(res: *mut TAOS_RES) -> *const c_char, - tmq_get_vgroup_id: unsafe extern "C" fn(res: *mut TAOS_RES) -> i32, - tmq_get_raw: unsafe extern "C" fn(res: *mut TAOS_RES, raw: *mut raw_data_t) -> i32, + tmq_get_res_type: unsafe extern "C" fn(res: *mut TaosRes) -> tmq_res_t, + tmq_get_table_name: unsafe extern "C" fn(res: *mut TaosRes) -> *const c_char, + tmq_get_db_name: unsafe extern "C" fn(res: *mut TaosRes) -> *const c_char, + tmq_get_json_meta: unsafe extern "C" fn(res: *mut TaosRes) -> *mut c_char, + tmq_get_topic_name: unsafe extern "C" fn(res: *mut TaosRes) -> *const c_char, + tmq_get_vgroup_id: unsafe extern "C" fn(res: *mut TaosRes) -> i32, + tmq_get_raw: unsafe extern "C" fn(res: *mut TaosRes, raw: *mut raw_data_t) -> i32, pub(crate) tmq_subscribe: - unsafe extern "C" fn(tmq: *mut tmq_t, topics: *mut tmq_list_t) -> tmq_resp_err_t, - pub(crate) tmq_unsubscribe: unsafe extern "C" fn(tmq: *mut tmq_t) -> tmq_resp_err_t, - pub(crate) tmq_subscription: - unsafe extern "C" fn(tmq: *mut tmq_t, topic_list: *mut *mut tmq_list_t) -> tmq_resp_err_t, + unsafe extern "C" fn(tmq: *mut tmq_t, topics: *mut tmq_list_t) -> TmqRespErrT, + pub(crate) tmq_unsubscribe: unsafe extern "C" fn(tmq: *mut tmq_t) -> TmqRespErrT, + pub(crate) _tmq_subscription: + unsafe extern "C" fn(tmq: *mut tmq_t, topic_list: *mut *mut tmq_list_t) -> TmqRespErrT, pub(crate) tmq_consumer_poll: - unsafe extern "C" fn(tmq: *mut tmq_t, blocking_time: i64) -> *mut TAOS_RES, - pub(crate) tmq_consumer_close: unsafe extern "C" fn(tmq: *mut tmq_t) -> tmq_resp_err_t, + unsafe extern "C" fn(tmq: *mut tmq_t, blocking_time: i64) -> *mut TaosRes, + pub(crate) tmq_consumer_close: unsafe extern "C" fn(tmq: *mut tmq_t) -> TmqRespErrT, pub(crate) tmq_commit_sync: - unsafe extern "C" fn(tmq: *mut tmq_t, msg: *const TAOS_RES) -> tmq_resp_err_t, + unsafe extern "C" fn(tmq: *mut tmq_t, msg: *const TaosRes) -> TmqRespErrT, pub(crate) tmq_commit_async: unsafe extern "C" fn( tmq: *mut tmq_t, - msg: *const TAOS_RES, - cb: tmq_commit_cb, + msg: *const TaosRes, + cb: TmqCommitCb, param: *mut c_void, ), @@ -264,59 +264,59 @@ pub(crate) struct TmqApi { #[derive(Debug, Clone, Copy)] pub(crate) struct StmtApi { - pub(crate) taos_stmt_init: unsafe extern "C" fn(taos: *mut TAOS) -> *mut TAOS_STMT, + pub(crate) taos_stmt_init: unsafe extern "C" fn(taos: *mut TAOS) -> *mut TaosStmt, pub(crate) taos_stmt_prepare: - unsafe extern "C" fn(stmt: *mut TAOS_STMT, sql: *const c_char, length: c_ulong) -> c_int, + unsafe extern "C" fn(stmt: *mut TaosStmt, sql: *const c_char, length: c_ulong) -> c_int, pub(crate) taos_stmt_set_tbname_tags: - unsafe extern "C" fn(stmt: *mut TAOS_STMT, name: *const c_char, tags: *mut c_void) -> c_int, + unsafe extern "C" fn(stmt: *mut TaosStmt, name: *const c_char, tags: *mut c_void) -> c_int, pub(crate) taos_stmt_set_tbname: - unsafe extern "C" fn(stmt: *mut TAOS_STMT, name: *const c_char) -> c_int, + unsafe extern "C" fn(stmt: *mut TaosStmt, name: *const c_char) -> c_int, pub(crate) taos_stmt_set_tags: - Option c_int>, + Option c_int>, - pub(crate) taos_stmt_set_sub_tbname: - unsafe extern "C" fn(stmt: *mut TAOS_STMT, name: *const c_char) -> c_int, + pub(crate) _taos_stmt_set_sub_tbname: + unsafe extern "C" fn(stmt: *mut TaosStmt, name: *const c_char) -> c_int, - pub(crate) taos_stmt_is_insert: - unsafe extern "C" fn(stmt: *mut TAOS_STMT, insert: *mut c_int) -> c_int, + pub(crate) _taos_stmt_is_insert: + unsafe extern "C" fn(stmt: *mut TaosStmt, insert: *mut c_int) -> c_int, - pub(crate) taos_stmt_num_params: - unsafe extern "C" fn(stmt: *mut TAOS_STMT, nums: *mut c_int) -> c_int, + pub(crate) _taos_stmt_num_params: + unsafe extern "C" fn(stmt: *mut TaosStmt, nums: *mut c_int) -> c_int, - pub(crate) taos_stmt_get_param: unsafe extern "C" fn( - stmt: *mut TAOS_STMT, + pub(crate) _taos_stmt_get_param: unsafe extern "C" fn( + stmt: *mut TaosStmt, idx: c_int, type_: *mut c_int, bytes: *mut c_int, ) -> c_int, - pub(crate) taos_stmt_bind_param: - unsafe extern "C" fn(stmt: *mut TAOS_STMT, bind: *const c_void) -> c_int, + pub(crate) _taos_stmt_bind_param: + unsafe extern "C" fn(stmt: *mut TaosStmt, bind: *const c_void) -> c_int, pub(crate) taos_stmt_bind_param_batch: - unsafe extern "C" fn(stmt: *mut TAOS_STMT, bind: *const TaosMultiBind) -> c_int, + unsafe extern "C" fn(stmt: *mut TaosStmt, bind: *const TaosMultiBind) -> c_int, - pub(crate) taos_stmt_bind_single_param_batch: unsafe extern "C" fn( - stmt: *mut TAOS_STMT, + pub(crate) _taos_stmt_bind_single_param_batch: unsafe extern "C" fn( + stmt: *mut TaosStmt, bind: *const TaosMultiBind, colIdx: c_int, ) -> c_int, - pub(crate) taos_stmt_add_batch: unsafe extern "C" fn(stmt: *mut TAOS_STMT) -> c_int, + pub(crate) taos_stmt_add_batch: unsafe extern "C" fn(stmt: *mut TaosStmt) -> c_int, - pub(crate) taos_stmt_execute: unsafe extern "C" fn(stmt: *mut TAOS_STMT) -> c_int, + pub(crate) taos_stmt_execute: unsafe extern "C" fn(stmt: *mut TaosStmt) -> c_int, - pub(crate) taos_stmt_affected_rows: unsafe extern "C" fn(stmt: *mut TAOS_STMT) -> c_int, + pub(crate) taos_stmt_affected_rows: unsafe extern "C" fn(stmt: *mut TaosStmt) -> c_int, - pub(crate) taos_stmt_use_result: unsafe extern "C" fn(stmt: *mut TAOS_STMT) -> *mut TAOS_RES, + pub(crate) taos_stmt_use_result: unsafe extern "C" fn(stmt: *mut TaosStmt) -> *mut TaosRes, - pub(crate) taos_stmt_close: unsafe extern "C" fn(stmt: *mut TAOS_STMT) -> c_int, + pub(crate) taos_stmt_close: unsafe extern "C" fn(stmt: *mut TaosStmt) -> c_int, - pub(crate) taos_stmt_errstr: unsafe extern "C" fn(stmt: *mut TAOS_STMT) -> *const c_char, + pub(crate) taos_stmt_errstr: unsafe extern "C" fn(stmt: *mut TaosStmt) -> *const c_char, } const fn default_lib_name() -> &'static str { if cfg!(target_os = "windows") { @@ -440,13 +440,13 @@ impl ApiEntry { taos_stmt_set_tbname_tags, taos_stmt_set_tbname, taos_stmt_set_tags, - taos_stmt_set_sub_tbname, - taos_stmt_is_insert, - taos_stmt_num_params, - taos_stmt_get_param, - taos_stmt_bind_param, + _taos_stmt_set_sub_tbname: taos_stmt_set_sub_tbname, + _taos_stmt_is_insert: taos_stmt_is_insert, + _taos_stmt_num_params: taos_stmt_num_params, + _taos_stmt_get_param: taos_stmt_get_param, + _taos_stmt_bind_param: taos_stmt_bind_param, taos_stmt_bind_param_batch, - taos_stmt_bind_single_param_batch, + _taos_stmt_bind_single_param_batch: taos_stmt_bind_single_param_batch, taos_stmt_add_batch, taos_stmt_execute, taos_stmt_affected_rows, @@ -487,7 +487,7 @@ impl ApiEntry { tmq_conf_new, tmq_conf_destroy, tmq_conf_set, - tmq_conf_set_auto_commit_cb, + _tmq_conf_set_auto_commit_cb: tmq_conf_set_auto_commit_cb, tmq_consumer_new, }; @@ -508,7 +508,7 @@ impl ApiEntry { tmq_get_raw, tmq_subscribe, tmq_unsubscribe, - tmq_subscription, + _tmq_subscription: tmq_subscription, tmq_consumer_poll, tmq_consumer_close, tmq_commit_sync, @@ -522,10 +522,10 @@ impl ApiEntry { }; Ok(Self { - lib, + _lib: lib, version: version.to_string(), - taos_cleanup, - taos_get_client_info, + _taos_cleanup: taos_cleanup, + _taos_get_client_info: taos_get_client_info, taos_options, taos_connect, taos_close, @@ -586,7 +586,7 @@ impl ApiEntry { } } - pub(super) fn check(&self, ptr: *const TAOS_RES) -> Result<(), RawError> { + pub(super) fn check(&self, ptr: *const TaosRes) -> Result<(), RawError> { let code: Code = unsafe { (self.taos_errno)(ptr as _) & 0xffff }.into(); if code.success() { Ok(()) @@ -692,7 +692,7 @@ impl RawTaos { pub fn query_a<'a, S: IntoCStr<'a>>( &self, sql: S, - fp: taos_async_query_cb, + fp: TaosAsyncQueryCb, param: *mut c_void, ) { unsafe { (self.c.taos_query_a)(self.as_ptr(), sql.into_c_str().as_ptr(), fp, param) } @@ -792,7 +792,7 @@ impl RawTaos { #[derive(Debug, Clone)] pub struct RawRes { c: Arc, - ptr: *mut TAOS_RES, + ptr: *mut TaosRes, } unsafe impl Send for RawRes {} @@ -800,7 +800,7 @@ unsafe impl Sync for RawRes {} impl RawRes { #[inline] - pub fn as_ptr(&self) -> *mut TAOS_RES { + pub fn as_ptr(&self) -> *mut TaosRes { self.ptr } @@ -829,19 +829,19 @@ impl RawRes { } } #[inline] - pub fn from_ptr(c: Arc, ptr: *mut TAOS_RES) -> Result { + pub fn from_ptr(c: Arc, ptr: *mut TaosRes) -> Result { let raw = unsafe { Self::from_ptr_unchecked(c, ptr) }; let code = raw.errno(); raw.with_code(code) } #[inline] - pub unsafe fn from_ptr_unchecked(c: Arc, ptr: *mut TAOS_RES) -> RawRes { + pub unsafe fn from_ptr_unchecked(c: Arc, ptr: *mut TaosRes) -> RawRes { Self { c, ptr } } #[inline] pub fn from_ptr_with_code( c: Arc, - ptr: *mut TAOS_RES, + ptr: *mut TaosRes, code: Code, ) -> Result { unsafe { RawRes::from_ptr_unchecked(c, ptr) }.with_code(code) @@ -888,7 +888,7 @@ impl RawRes { } #[inline] - pub fn fetch_block(&self) -> Result, RawError> { + pub fn fetch_block(&self) -> Result, RawError> { let block = Box::into_raw(Box::new(std::ptr::null_mut())); // let mut num = 0; let num = unsafe { (self.c.taos_fetch_block)(self.as_ptr(), block) }; @@ -959,12 +959,12 @@ impl RawRes { (self.c.taos_fetch_raw_block.unwrap())(self.as_ptr(), &mut num as _, &mut block as _), if num > 0 { match self.tmq_message_type() { - tmq_res_t::TMQ_RES_INVALID => { + tmq_res_t::_TmqResInvalid => { let mut raw = RawBlock::parse_from_ptr(block as _, self.precision()); raw.with_field_names(fields.iter().map(Field::name)); Some(raw) } - tmq_res_t::TMQ_RES_DATA | tmq_res_t::TMQ_RES_METADATA => { + tmq_res_t::_TmqResData | tmq_res_t::_TmqResMetadata => { let fields = self.fetch_fields(); let mut raw = RawBlock::parse_from_ptr(block as _, self.precision()); @@ -981,7 +981,7 @@ impl RawRes { Some(raw) } - tmq_res_t::TMQ_RES_TABLE_META => { + tmq_res_t::_TmqResTableMeta => { todo!() } } @@ -1035,7 +1035,7 @@ impl RawRes { let param = Box::new((state.clone(), self.c.clone(), cx.waker().clone())); unsafe extern "C" fn async_fetch_callback( param: *mut c_void, - res: *mut TAOS_RES, + res: *mut TaosRes, num_of_rows: c_int, ) { let param = param as *mut (Arc>, Arc, Waker); @@ -1118,7 +1118,7 @@ impl RawRes { let param = Box::new((state.clone(), self.c.clone(), cx.waker().clone())); unsafe extern "C" fn async_fetch_callback( param: *mut c_void, - res: *mut TAOS_RES, + res: *mut TaosRes, num_of_rows: c_int, ) { let param: Box<(Arc>, Arc, Waker)> = diff --git a/taos-optin/src/raw/query_future.rs b/taos-optin/src/raw/query_future.rs index 530910df..42d6be05 100644 --- a/taos-optin/src/raw/query_future.rs +++ b/taos-optin/src/raw/query_future.rs @@ -8,7 +8,7 @@ use std::pin::Pin; use std::task::{Context, Poll, Waker}; use crate::into_c_str::IntoCStr; -use crate::types::TAOS_RES; +use crate::types::TaosRes; use crate::{RawRes, RawTaos}; use taos_query::prelude::RawError; @@ -20,7 +20,7 @@ pub struct QueryFuture<'a> { /// Shared state between the future and the waiting thread struct State { - result: *mut TAOS_RES, + result: *mut TaosRes, code: i32, done: bool, } @@ -43,7 +43,7 @@ impl<'a> Future for QueryFuture<'a> { } else { unsafe extern "C" fn async_query_callback( param: *mut c_void, - res: *mut TAOS_RES, + res: *mut TaosRes, code: c_int, ) { let param = param as *mut (&UnsafeCell, Waker); diff --git a/taos-optin/src/schemaless.rs b/taos-optin/src/schemaless.rs index ee2c7022..1c6a8904 100644 --- a/taos-optin/src/schemaless.rs +++ b/taos-optin/src/schemaless.rs @@ -1,4 +1,4 @@ -use crate::ffi::{TAOS, TAOS_RES}; +use crate::ffi::{TAOS, TaosRes}; use std::os::raw::*; /// @@ -53,7 +53,7 @@ extern "C" { numLines: c_int, protocol: SchemalessProtocol, precision: TSDB_SML_TIMESTAMP_TYPE, - ) -> *mut TAOS_RES; + ) -> *mut TaosRes; } #[test] diff --git a/taos-optin/src/stmt/bind.rs b/taos-optin/src/stmt/bind.rs index 034c65cf..d791f578 100644 --- a/taos-optin/src/stmt/bind.rs +++ b/taos-optin/src/stmt/bind.rs @@ -2,9 +2,9 @@ use taos_query::common::{itypes::IsValue, Ty}; use crate::types::{BindFrom, TaosBindV2, TaosBindV3}; -fn box_into_raw(v: T) -> *mut T { - Box::into_raw(Box::new(v)) -} +// fn box_into_raw(v: T) -> *mut T { +// Box::into_raw(Box::new(v)) +// } impl From<&T> for TaosBindV2 where @@ -143,7 +143,7 @@ mod tests_v2 { dbg!(&bind); let v1 = - unsafe { std::str::from_utf8(std::slice::from_raw_parts(bind.buffer() as _, 3)) } + unsafe { std::str::from_utf8(std::slice::from_raw_parts(bind.buffer as _, 3)) } .unwrap(); dbg!(v1); @@ -162,7 +162,7 @@ mod tests_v3 { for v in [true, false].iter() { let bind = TaosBind::from(v); dbg!(&bind); - let v1 = unsafe { (bind.buffer() as *const bool).read() }; + let v1 = unsafe { (bind.buffer as *const bool).read() }; assert_eq!(v1, *v); } } @@ -172,7 +172,7 @@ mod tests_v3 { for v in [0i8, 1i8].iter() { let bind = TaosBind::from(v); dbg!(&bind); - let v1 = unsafe { (bind.buffer() as *const i8).read() }; + let v1 = unsafe { (bind.buffer as *const i8).read() }; assert_eq!(v1, *v); } } @@ -183,7 +183,7 @@ mod tests_v3 { let bind = TaosBind::from(v); dbg!(&bind); let v1 = - unsafe { std::str::from_utf8(std::slice::from_raw_parts(bind.buffer() as _, 3)) } + unsafe { std::str::from_utf8(std::slice::from_raw_parts(bind.buffer as _, 3)) } .unwrap(); dbg!(v1); diff --git a/taos-optin/src/stmt/mod.rs b/taos-optin/src/stmt/mod.rs index f00e3a1b..3fc238fd 100644 --- a/taos-optin/src/stmt/mod.rs +++ b/taos-optin/src/stmt/mod.rs @@ -13,7 +13,8 @@ use std::{ use itertools::Itertools; // use taos_error::{Code, Error}; use taos_query::prelude::{ - sync::{Bindable, Queryable, RawError as Error, Ty}, + // sync::{Bindable, Queryable, RawError as Error, Ty}, + sync::{Bindable, Queryable, RawError as Error}, Code, }; @@ -88,7 +89,7 @@ impl Bindable for Stmt { pub(crate) struct RawStmt { c: Arc, api: StmtApi, - ptr: *mut TAOS_STMT, + ptr: *mut TaosStmt, tbname: Option, } @@ -116,14 +117,14 @@ impl RawStmt { } #[inline] - pub unsafe fn as_ptr(&self) -> *mut TAOS_STMT { + pub unsafe fn as_ptr(&self) -> *mut TaosStmt { self.ptr } - #[inline] - pub fn errstr(&self) -> &CStr { - unsafe { CStr::from_ptr((self.api.taos_stmt_errstr)(self.as_ptr())) } - } + // #[inline] + // pub fn errstr(&self) -> &CStr { + // unsafe { CStr::from_ptr((self.api.taos_stmt_errstr)(self.as_ptr())) } + // } #[inline] pub fn err_as_str(&self) -> String { @@ -157,19 +158,19 @@ impl RawStmt { }) } - pub fn set_tbname_tags_v3<'a>( - &mut self, - name: impl IntoCStr<'a>, - tags: &[TaosBindV3], - ) -> Result<(), Error> { - self.ok(unsafe { - (self.api.taos_stmt_set_tbname_tags)( - self.as_ptr(), - name.into_c_str().as_ptr(), - tags.as_ptr() as _, - ) - }) - } + // pub fn set_tbname_tags_v3<'a>( + // &mut self, + // name: impl IntoCStr<'a>, + // tags: &[TaosBindV3], + // ) -> Result<(), Error> { + // self.ok(unsafe { + // (self.api.taos_stmt_set_tbname_tags)( + // self.as_ptr(), + // name.into_c_str().as_ptr(), + // tags.as_ptr() as _, + // ) + // }) + // } #[inline] pub fn set_tbname<'c>(&mut self, name: impl IntoCStr<'c>) -> Result<(), Error> { @@ -183,12 +184,12 @@ impl RawStmt { res } - #[inline] - pub fn set_sub_tbname<'c>(&mut self, name: impl IntoCStr<'c>) -> Result<(), Error> { - self.ok(unsafe { - (self.api.taos_stmt_set_sub_tbname)(self.as_ptr(), name.into_c_str().as_ptr()) - }) - } + // #[inline] + // pub fn set_sub_tbname<'c>(&mut self, name: impl IntoCStr<'c>) -> Result<(), Error> { + // self.ok(unsafe { + // (self.api.taos_stmt_set_sub_tbname)(self.as_ptr(), name.into_c_str().as_ptr()) + // }) + // } #[inline] pub fn set_tags(&mut self, tags: *const c_void) -> Result<(), Error> { @@ -234,39 +235,39 @@ impl RawStmt { err_or!(self, (self.api.taos_stmt_add_batch)(self.as_ptr())) } - #[inline] - pub fn is_insert(&self) -> Result { - let mut is_insert = 0; - err_or!( - self, - (self.api.taos_stmt_is_insert)(self.as_ptr(), &mut is_insert as _), - is_insert != 0 - ) - } - - #[inline] - pub fn num_params(&self) -> Result { - let mut num = 0i32; - err_or!( - self, - (self.api.taos_stmt_num_params)(self.as_ptr(), &mut num as _), - num as usize - ) - } - - #[inline] - pub fn get_param(&mut self, idx: i32) -> Result<(Ty, i32), Error> { - let (mut type_, mut bytes) = (0, 0); - err_or!( - self, - (self.api.taos_stmt_get_param)(self.as_ptr(), idx, &mut type_ as _, &mut bytes as _), - ((type_ as u8).into(), bytes) - ) - } - #[inline] - pub fn bind_param(&mut self, bind: *const c_void) -> Result<(), Error> { - err_or!(self, (self.api.taos_stmt_bind_param)(self.as_ptr(), bind)) - } + // #[inline] + // pub fn is_insert(&self) -> Result { + // let mut is_insert = 0; + // err_or!( + // self, + // (self.api.taos_stmt_is_insert)(self.as_ptr(), &mut is_insert as _), + // is_insert != 0 + // ) + // } + + // #[inline] + // pub fn num_params(&self) -> Result { + // let mut num = 0i32; + // err_or!( + // self, + // (self.api.taos_stmt_num_params)(self.as_ptr(), &mut num as _), + // num as usize + // ) + // } + + // #[inline] + // pub fn get_param(&mut self, idx: i32) -> Result<(Ty, i32), Error> { + // let (mut type_, mut bytes) = (0, 0); + // err_or!( + // self, + // (self.api.taos_stmt_get_param)(self.as_ptr(), idx, &mut type_ as _, &mut bytes as _), + // ((type_ as u8).into(), bytes) + // ) + // } + // #[inline] + // pub fn bind_param(&mut self, bind: *const c_void) -> Result<(), Error> { + // err_or!(self, (self.api.taos_stmt_bind_param)(self.as_ptr(), bind)) + // } #[inline] pub fn bind_param_batch(&mut self, bind: &[TaosMultiBind]) -> Result<(), Error> { @@ -276,12 +277,12 @@ impl RawStmt { ) } - #[inline] - pub fn bind_single_param_batch(&self, bind: &TaosMultiBind, col: i32) -> Result<(), Error> { - self.ok(unsafe { - (self.api.taos_stmt_bind_single_param_batch)(self.as_ptr(), bind as *const _ as _, col) - }) - } + // #[inline] + // pub fn bind_single_param_batch(&self, bind: &TaosMultiBind, col: i32) -> Result<(), Error> { + // self.ok(unsafe { + // (self.api.taos_stmt_bind_single_param_batch)(self.as_ptr(), bind as *const _ as _, col) + // }) + // } } #[cfg(test)] diff --git a/taos-optin/src/stmt/multi.rs b/taos-optin/src/stmt/multi.rs index 612f6290..3d7594a7 100644 --- a/taos-optin/src/stmt/multi.rs +++ b/taos-optin/src/stmt/multi.rs @@ -1,6 +1,6 @@ -fn box_into_raw(v: T) -> *mut T { - Box::into_raw(Box::new(v)) -} +// fn box_into_raw(v: T) -> *mut T { +// Box::into_raw(Box::new(v)) +// } #[cfg(test)] mod tests { diff --git a/taos-optin/src/tmq/ffi.rs b/taos-optin/src/tmq/ffi.rs index 39aadaa4..fa223b3f 100644 --- a/taos-optin/src/tmq/ffi.rs +++ b/taos-optin/src/tmq/ffi.rs @@ -3,11 +3,11 @@ use std::{borrow::Cow, os::raw::*}; use taos_macros::c_cfg; use taos_query::common::raw_data_t; -use crate::ffi::{TAOS, TAOS_RES}; +use crate::ffi::{TAOS, TaosRes}; #[repr(transparent)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub struct tmq_resp_err_t(i32); +pub struct TmqRespErrT(i32); impl PartialEq for tmq_conf_res_t { fn eq(&self, other: &i32) -> bool { @@ -15,7 +15,7 @@ impl PartialEq for tmq_conf_res_t { } } -impl tmq_resp_err_t { +impl TmqRespErrT { pub fn ok_or(self, s: impl Into>) -> Result<(), taos_error::Error> { match self { Self(0) => Ok(()), @@ -65,16 +65,16 @@ impl tmq_conf_res_t { } } -pub type tmq_commit_cb = - unsafe extern "C" fn(tmq: *mut tmq_t, resp: tmq_resp_err_t, param: *mut c_void); +pub type TmqCommitCb = + unsafe extern "C" fn(tmq: *mut tmq_t, resp: TmqRespErrT, param: *mut c_void); #[repr(C)] #[derive(Debug, PartialEq, Eq, Clone, Copy)] pub enum tmq_res_t { - TMQ_RES_INVALID = -1, - TMQ_RES_DATA = 1, - TMQ_RES_TABLE_META = 2, - TMQ_RES_METADATA = 3, + TmqResInvalid = -1, + TmqResData = 1, + TmqResTableMeta = 2, + TmqResMetadata = 3, } // #[repr(C)] @@ -99,27 +99,27 @@ extern "C" { errstr_len: i32, ) -> *mut tmq_t; - pub fn tmq_err2str(err: tmq_resp_err_t) -> *const c_char; + pub fn tmq_err2str(err: TmqRespErrT) -> *const c_char; - pub fn tmq_subscribe(tmq: *mut tmq_t, topic_list: *mut tmq_list_t) -> tmq_resp_err_t; - pub fn tmq_unsubscribe(tmq: *mut tmq_t) -> tmq_resp_err_t; + pub fn tmq_subscribe(tmq: *mut tmq_t, topic_list: *mut tmq_list_t) -> TmqRespErrT; + pub fn tmq_unsubscribe(tmq: *mut tmq_t) -> TmqRespErrT; - pub fn tmq_subscription(tmq: *mut tmq_t, topic_list: *mut *mut tmq_list_t) -> tmq_resp_err_t; + pub fn tmq_subscription(tmq: *mut tmq_t, topic_list: *mut *mut tmq_list_t) -> TmqRespErrT; - pub fn tmq_consumer_poll(tmq: *mut tmq_t, blocking_time: i64) -> *mut TAOS_RES; + pub fn tmq_consumer_poll(tmq: *mut tmq_t, blocking_time: i64) -> *mut TaosRes; - pub fn tmq_consumer_close(tmq: *mut tmq_t) -> tmq_resp_err_t; + pub fn tmq_consumer_close(tmq: *mut tmq_t) -> TmqRespErrT; - pub fn tmq_commit_sync(tmq: *mut tmq_t, msg: *const TAOS_RES) -> tmq_resp_err_t; + pub fn tmq_commit_sync(tmq: *mut tmq_t, msg: *const TaosRes) -> TmqRespErrT; pub fn tmq_commit_async( tmq: *mut tmq_t, - msg: *const TAOS_RES, - cb: tmq_commit_cb, + msg: *const TaosRes, + cb: TmqCommitCb, param: *mut c_void, ); - pub fn tmq_get_raw(res: *mut TAOS_RES, meta: *mut raw_data_t) -> i32; + pub fn tmq_get_raw(res: *mut TaosRes, meta: *mut raw_data_t) -> i32; pub fn tmq_write_raw(taos: *mut TAOS, meta: raw_data_t) -> i32; pub fn taos_write_raw_block( @@ -129,21 +129,21 @@ extern "C" { tbname: *const c_char, ) -> i32; - pub fn tmq_get_json_meta(res: *mut TAOS_RES) -> *mut c_char; - pub fn tmq_get_topic_name(res: *mut TAOS_RES) -> *const c_char; - pub fn tmq_get_table_name(res: *mut TAOS_RES) -> *const c_char; - pub fn tmq_get_db_name(res: *mut TAOS_RES) -> *const c_char; - pub fn tmq_get_vgroup_id(res: *mut TAOS_RES) -> i32; + pub fn tmq_get_json_meta(res: *mut TaosRes) -> *mut c_char; + pub fn tmq_get_topic_name(res: *mut TaosRes) -> *const c_char; + pub fn tmq_get_table_name(res: *mut TaosRes) -> *const c_char; + pub fn tmq_get_db_name(res: *mut TaosRes) -> *const c_char; + pub fn tmq_get_vgroup_id(res: *mut TaosRes) -> i32; } #[cfg(taos_tmq)] extern "C" { - pub fn tmq_get_res_type(res: *mut TAOS_RES) -> tmq_res_t; + pub fn tmq_get_res_type(res: *mut TaosRes) -> tmq_res_t; } #[cfg(not(taos_tmq))] -pub unsafe fn tmq_get_res_type(res: *mut TAOS_RES) -> tmq_res_t { - tmq_res_t::TMQ_RES_INVALID +pub unsafe fn tmq_get_res_type(res: *mut TaosRes) -> tmq_res_t { + tmq_res_t::TmqResInvalid } // TMQ Conf API @@ -161,7 +161,7 @@ extern "C" { pub fn tmq_conf_set_auto_commit_cb( conf: *mut tmq_conf_t, - cb: tmq_commit_cb, + cb: TmqCommitCb, param: *mut c_void, ); } diff --git a/taos-optin/src/tmq/mod.rs b/taos-optin/src/tmq/mod.rs index f9768821..754a4504 100644 --- a/taos-optin/src/tmq/mod.rs +++ b/taos-optin/src/tmq/mod.rs @@ -225,13 +225,13 @@ impl Meta { } pub struct Data { raw: RawRes, - precision: Precision, + _precision: Precision, } impl Data { fn new(raw: RawRes) -> Self { Self { - precision: raw.precision(), + _precision: raw.precision(), raw, } } @@ -258,18 +258,18 @@ impl IsAsyncData for Data { impl From for MessageSet { fn from(raw: RawRes) -> Self { match raw.tmq_message_type() { - tmq_res_t::TMQ_RES_INVALID => unreachable!(), - tmq_res_t::TMQ_RES_DATA => Self::Data(Data::new(raw)), - tmq_res_t::TMQ_RES_TABLE_META => Self::Meta(Meta::new(raw)), - tmq_res_t::TMQ_RES_METADATA => Self::MetaData(Meta::new(raw.clone()), Data::new(raw)), + tmq_res_t::_TmqResInvalid => unreachable!(), + tmq_res_t::_TmqResData => Self::Data(Data::new(raw)), + tmq_res_t::_TmqResTableMeta => Self::Meta(Meta::new(raw)), + tmq_res_t::_TmqResMetadata => Self::MetaData(Meta::new(raw.clone()), Data::new(raw)), } } } pub struct MessageSetIter { - raw: RawRes, - msg_type: tmq_res_t, - precision: Precision, + _raw: RawRes, + _msg_type: tmq_res_t, + _precision: Precision, } impl Iterator for Data { @@ -324,12 +324,12 @@ impl AsConsumer for Consumer { ( Offset(raw.clone()), match raw.tmq_message_type() { - tmq_res_t::TMQ_RES_INVALID => unreachable!(), - tmq_res_t::TMQ_RES_DATA => taos_query::tmq::MessageSet::Data(Data::new(raw)), - tmq_res_t::TMQ_RES_TABLE_META => { + tmq_res_t::_TmqResInvalid => unreachable!(), + tmq_res_t::_TmqResData => taos_query::tmq::MessageSet::Data(Data::new(raw)), + tmq_res_t::_TmqResTableMeta => { taos_query::tmq::MessageSet::Meta(Meta::new(raw)) } - tmq_res_t::TMQ_RES_METADATA => taos_query::tmq::MessageSet::MetaData( + tmq_res_t::_TmqResMetadata => taos_query::tmq::MessageSet::MetaData( Meta::new(raw.clone()), Data::new(raw), ), @@ -378,12 +378,12 @@ impl AsAsyncConsumer for Consumer { ( Offset(raw.clone()), match raw.tmq_message_type() { - tmq_res_t::TMQ_RES_INVALID => unreachable!(), - tmq_res_t::TMQ_RES_DATA => taos_query::tmq::MessageSet::Data(Data::new(raw)), - tmq_res_t::TMQ_RES_TABLE_META => { + tmq_res_t::_TmqResInvalid => unreachable!(), + tmq_res_t::_TmqResData => taos_query::tmq::MessageSet::Data(Data::new(raw)), + tmq_res_t::_TmqResTableMeta => { taos_query::tmq::MessageSet::Meta(Meta::new(raw)) } - tmq_res_t::TMQ_RES_METADATA => todo!(), + tmq_res_t::_TmqResMetadata => todo!(), }, ) })) @@ -743,7 +743,7 @@ mod tests { let desc = taos.describe(table_name.as_str())?; dbg!(desc); } - _ => todo!(), + // _ => todo!(), }, _ => (), } diff --git a/taos-optin/src/tmq/raw.rs b/taos-optin/src/tmq/raw.rs index 6531ce1c..1877f09b 100644 --- a/taos-optin/src/tmq/raw.rs +++ b/taos-optin/src/tmq/raw.rs @@ -9,7 +9,7 @@ pub(super) mod tmq { use crate::{ raw::{ApiEntry, TmqApi}, - types::{tmq_resp_err_t, tmq_t}, + types::{TmqRespErrT, tmq_t}, RawError, RawRes, }; @@ -52,7 +52,7 @@ pub(super) mod tmq { .ok_or("commit failed") } - // pub fn commit_async(&self, msg: RawRes, cb: tmq_commit_cb, param: *mut c_void) { + // pub fn commit_async(&self, msg: RawRes, cb: TmqCommitCb, param: *mut c_void) { // unsafe { (self.tmq.tmq_commit_async)(self.as_ptr(), msg.as_ptr(), cb, param) } // } @@ -65,7 +65,7 @@ pub(super) mod tmq { // let tmq = self.tmq; // unsafe extern "C" fn tmq_commit_callback( // _tmq: *mut tmq_t, - // resp: tmq_resp_err_t, + // resp: TmqRespErrT, // param: *mut c_void, // ) { // log::trace!("commit {resp:?}"); @@ -96,7 +96,7 @@ pub(super) mod tmq { let (sender, rx) = channel::>(); unsafe extern "C" fn tmq_commit_async_cb( _tmq: *mut tmq_t, - resp: tmq_resp_err_t, + resp: TmqRespErrT, param: *mut std::os::raw::c_void, ) { let offsets = resp.ok_or("commit failed").map(|_| ()); @@ -287,7 +287,7 @@ pub(super) mod conf { unsafe { self.api.set(self.as_ptr(), key.as_ref(), value.as_ref()) }.map(|_| self) } - // pub(crate) fn with_auto_commit_cb(&mut self, cb: tmq_commit_cb, param: *mut c_void) { + // pub(crate) fn with_auto_commit_cb(&mut self, cb: TmqCommitCb, param: *mut c_void) { // unsafe { // self.api.auto_commit_cb(self.as_ptr(), cb, param); // } diff --git a/taos-optin/src/types/mod.rs b/taos-optin/src/types/mod.rs index 2468f712..428a25a3 100644 --- a/taos-optin/src/types/mod.rs +++ b/taos-optin/src/types/mod.rs @@ -12,42 +12,42 @@ pub use tmq::*; #[allow(clippy::upper_case_acronyms)] pub type TAOS = c_void; -pub type TAOS_STMT = c_void; -pub type TAOS_RES = c_void; -pub type TAOS_STREAM = c_void; -pub type TAOS_SUB = c_void; -pub type TAOS_ROW = *mut *mut c_void; +pub type TaosStmt = c_void; +pub type TaosRes = c_void; +// pub type TaosStream = c_void; +// pub type TaosSub = c_void; +pub type TaosRow = *mut *mut c_void; -pub type taos_async_fetch_cb = +pub type TaosAsyncFetchCb = unsafe extern "C" fn(param: *mut c_void, res: *mut c_void, rows: c_int); -pub type taos_async_query_cb = +pub type TaosAsyncQueryCb = unsafe extern "C" fn(param: *mut c_void, res: *mut c_void, code: c_int); -pub type taos_subscribe_cb = - unsafe extern "C" fn(sub: *mut TAOS_SUB, res: *mut TAOS_RES, param: *mut c_void, code: c_int); +// pub type TaosSubscribeCb = + // unsafe extern "C" fn(sub: *mut TaosSub, res: *mut TaosRes, param: *mut c_void, code: c_int); -pub type taos_stream_cb = - unsafe extern "C" fn(param: *mut c_void, res: *mut TAOS_RES, row: TAOS_ROW); +// pub type TaosStreamCb = + // unsafe extern "C" fn(param: *mut c_void, res: *mut TaosRes, row: TaosRow); -pub type taos_stream_close_cb = unsafe extern "C" fn(param: *mut c_void); +// pub type TaosStreamCloseCb = unsafe extern "C" fn(param: *mut c_void); #[repr(C)] #[derive(Debug, Copy, Clone)] pub enum TSDB_OPTION { - Locale = 0, - Charset, - Timezone, + _Locale = 0, + _Charset, + _Timezone, ConfigDir, ShellActivityTimer, - MaxOptions, + _MaxOptions, } -pub const TSDB_OPTION_LOCALE: TSDB_OPTION = TSDB_OPTION::Locale; -pub const TSDB_OPTION_CHARSET: TSDB_OPTION = TSDB_OPTION::Charset; -pub const TSDB_OPTION_TIMEZONE: TSDB_OPTION = TSDB_OPTION::Timezone; -pub const TSDB_OPTION_CONFIGDIR: TSDB_OPTION = TSDB_OPTION::ConfigDir; -pub const TSDB_OPTION_SHELL_ACTIVITY_TIMER: TSDB_OPTION = TSDB_OPTION::ShellActivityTimer; -pub const TSDB_MAX_OPTIONS: TSDB_OPTION = TSDB_OPTION::MaxOptions; +// pub const TSDB_OPTION_LOCALE: TSDB_OPTION = TSDB_OPTION::Locale; +// pub const TSDB_OPTION_CHARSET: TSDB_OPTION = TSDB_OPTION::Charset; +// pub const TSDB_OPTION_TIMEZONE: TSDB_OPTION = TSDB_OPTION::Timezone; +// pub const TSDB_OPTION_CONFIGDIR: TSDB_OPTION = TSDB_OPTION::ConfigDir; +// pub const TSDB_OPTION_SHELL_ACTIVITY_TIMER: TSDB_OPTION = TSDB_OPTION::ShellActivityTimer; +// pub const TSDB_MAX_OPTIONS: TSDB_OPTION = TSDB_OPTION::MaxOptions; #[repr(C)] #[derive(Clone)] @@ -270,7 +270,7 @@ impl TaosBindV2 { } } - pub(crate) fn buffer(&self) -> *const c_void { + pub(crate) fn _buffer(&self) -> *const c_void { self.buffer } @@ -431,16 +431,16 @@ pub trait ToMultiBind { } impl TaosMultiBind { - pub(crate) fn nulls(n: usize) -> Self { - TaosMultiBind { - buffer_type: Ty::Null as _, - buffer: std::ptr::null_mut(), - buffer_length: 0, - length: n as _, - is_null: std::ptr::null_mut(), - num: n as _, - } - } + // pub(crate) fn nulls(n: usize) -> Self { + // TaosMultiBind { + // buffer_type: Ty::Null as _, + // buffer: std::ptr::null_mut(), + // buffer_length: 0, + // length: n as _, + // is_null: std::ptr::null_mut(), + // num: n as _, + // } + // } pub(crate) fn from_primitives(nulls: Vec, values: &[T]) -> Self { TaosMultiBind { buffer_type: T::TY as _, @@ -523,9 +523,9 @@ impl TaosMultiBind { s } - pub(crate) fn buffer(&self) -> *const c_void { - self.buffer - } + // pub(crate) fn buffer(&self) -> *const c_void { + // self.buffer + // } } impl Drop for TaosMultiBind { diff --git a/taos-optin/src/types/tmq.rs b/taos-optin/src/types/tmq.rs index 47eaeca3..a62f64f0 100644 --- a/taos-optin/src/types/tmq.rs +++ b/taos-optin/src/types/tmq.rs @@ -4,7 +4,7 @@ use taos_query::prelude::RawError; #[repr(transparent)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub(crate) struct tmq_resp_err_t(i32); +pub(crate) struct TmqRespErrT(i32); impl PartialEq for tmq_conf_res_t { fn eq(&self, other: &i32) -> bool { @@ -12,7 +12,7 @@ impl PartialEq for tmq_conf_res_t { } } -impl tmq_resp_err_t { +impl TmqRespErrT { pub fn ok_or(self, s: impl Into>) -> Result<(), RawError> { match self { Self(0) => Ok(()), @@ -45,31 +45,31 @@ pub struct tmq_message_t { #[repr(C)] pub enum tmq_conf_res_t { - Unknown = -2, - Invalid = -1, - Ok = 0, + _Unknown = -2, + _Invalid = -1, + _Ok = 0, } impl tmq_conf_res_t { pub fn ok(self, k: &str, v: &str) -> Result<(), RawError> { match self { - Self::Ok => Ok(()), - Self::Invalid => Err(RawError::from_string(format!( + Self::_Ok => Ok(()), + Self::_Invalid => Err(RawError::from_string(format!( "Invalid key value pair ({k}, {v})" ))), - Self::Unknown => Err(RawError::from_string(format!("Unknown key {k}"))), + Self::_Unknown => Err(RawError::from_string(format!("Unknown key {k}"))), } } } -pub(crate) type tmq_commit_cb = - unsafe extern "C" fn(tmq: *mut tmq_t, resp: tmq_resp_err_t, param: *mut c_void); +pub(crate) type TmqCommitCb = + unsafe extern "C" fn(tmq: *mut tmq_t, resp: TmqRespErrT, param: *mut c_void); #[repr(C)] #[derive(Debug, PartialEq, Eq, Clone, Copy)] pub enum tmq_res_t { - TMQ_RES_INVALID = -1, - TMQ_RES_DATA = 1, - TMQ_RES_TABLE_META = 2, - TMQ_RES_METADATA = 3, + _TmqResInvalid = -1, + _TmqResData = 1, + _TmqResTableMeta = 2, + _TmqResMetadata = 3, }