Skip to content

Commit eaac2de

Browse files
committed
Upgrade crossdb to v0.12.0
1 parent 4bc8219 commit eaac2de

File tree

6 files changed

+33
-30
lines changed

6 files changed

+33
-30
lines changed

Cargo.toml

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ homepage = "hhttps://github.com/crossdb-org/crossdb-rust"
99
repository = "https://github.com/crossdb-org/crossdb-rust.git"
1010

1111
[dependencies]
12-
lru = "0.12"
12+
lru = "0.14"
1313
serde = "1.0"
14-
thiserror = "1.0"
15-
strum = { version = "0.26", features = ["derive"] }
16-
cidr = "0.3.0"
17-
mac_address = "1.1.7"
14+
thiserror = "2.0"
15+
strum = { version = "0.27", features = ["derive"] }
16+
cidr = "0.3"
17+
mac_address = "1.1"
1818

1919
[build-dependencies]
20-
bindgen = "0.70"
21-
cc = "1.1"
20+
bindgen = "0.71"
21+
cc = "1.2"

crossdb

src/column.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,15 @@ pub enum DataType {
4545
Inet = xdb_type_t_XDB_TYPE_INET,
4646
#[strum(serialize = "MAC")]
4747
Mac = xdb_type_t_XDB_TYPE_MAC,
48+
#[strum(serialize = "ARRAY")]
49+
Array = xdb_type_t_XDB_TYPE_ARRAY,
4850
#[strum(serialize = "MAX")]
4951
Max = xdb_type_t_XDB_TYPE_MAX,
5052
}
5153

5254
impl DataType {
53-
unsafe fn from_meta(meta: u64, col: u16) -> Self {
54-
let t = xdb_column_type(meta, col);
55+
unsafe fn from_meta(ptr: *mut xdb_res_t, col: u16) -> Self {
56+
let t = xdb_column_type(ptr, col);
5557
match Self::from_repr(t) {
5658
Some(t) => t,
5759
None => unreachable!(),
@@ -66,15 +68,15 @@ pub struct Columns {
6668

6769
impl Columns {
6870
pub(crate) unsafe fn from_res(ptr: *mut xdb_res_t) -> Self {
69-
let res = *ptr;
70-
let mut columns = Vec::with_capacity(res.col_count as usize);
71-
for i in 0..res.col_count {
71+
let count = xdb_column_count(ptr);
72+
let mut columns = Vec::with_capacity(count as usize);
73+
for i in 0..(count as u16) {
7274
unsafe {
73-
let name = CStr::from_ptr(xdb_column_name(res.col_meta, i))
75+
let name = CStr::from_ptr(xdb_column_name(ptr, i))
7476
.to_str()
7577
.unwrap()
7678
.to_string();
77-
let datatype = DataType::from_meta(res.col_meta, i);
79+
let datatype = DataType::from_meta(ptr, i);
7880
columns.push(Column::new(name, datatype));
7981
}
8082
}
@@ -83,6 +85,7 @@ impl Columns {
8385
}
8486
}
8587

88+
#[allow(clippy::len_without_is_empty)]
8689
pub fn len(&self) -> usize {
8790
self.inner.len()
8891
}

src/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub enum Error {
99
#[error("UTF8 error: {0}")]
1010
Utf8(#[from] std::str::Utf8Error),
1111
#[error("Query error: {0}, {1}")]
12-
Query(u16, String),
12+
Query(u32, String),
1313
#[error("Clear bindings error")]
1414
ClearBindings,
1515
#[error("Bind params error")]

src/lib.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ impl Connection {
123123

124124
#[derive(Debug)]
125125
pub struct Query {
126-
res: xdb_res_t,
127126
ptr: *mut xdb_res_t,
128127
columns: Columns,
129128
}
@@ -141,28 +140,27 @@ unsafe impl Sync for Query {}
141140

142141
impl Query {
143142
pub(crate) unsafe fn from_res(ptr: *mut xdb_res_t) -> Result<Self> {
144-
let res = *ptr;
145-
if res.errcode != xdb_errno_e_XDB_OK as u16 {
143+
let code = xdb_errcode(ptr);
144+
if code != xdb_errno_e_XDB_OK {
146145
let msg = CStr::from_ptr(xdb_errmsg(ptr)).to_str()?.to_string();
147-
return Err(Error::Query(res.errcode, msg));
146+
return Err(Error::Query(code, msg));
148147
}
149148
Ok(Self {
150-
res,
151149
ptr,
152150
columns: Columns::from_res(ptr),
153151
})
154152
}
155153

156154
pub fn column_count(&self) -> usize {
157-
self.res.col_count as usize
155+
unsafe { xdb_column_count(self.ptr) as usize }
158156
}
159157

160158
pub fn row_count(&self) -> usize {
161-
self.res.row_count as usize
159+
unsafe { xdb_row_count(self.ptr) as usize }
162160
}
163161

164162
pub fn affected_rows(&self) -> u64 {
165-
self.res.affected_rows
163+
unsafe { xdb_affected_rows(self.ptr) as u64 }
166164
}
167165

168166
pub fn columns(&self) -> &Columns {
@@ -179,7 +177,7 @@ impl Query {
179177
self.fetch_row().map(|row| row.deserialize())
180178
}
181179

182-
pub fn fetch_rows_as<'a, T: DeserializeOwned>(&mut self) -> Result<Vec<T>, DeError> {
180+
pub fn fetch_rows_as<T: DeserializeOwned>(&mut self) -> Result<Vec<T>, DeError> {
183181
let mut rows = Vec::with_capacity(self.row_count());
184182
while let Some(row) = self.fetch_row() {
185183
rows.push(row.deserialize()?);
@@ -189,14 +187,14 @@ impl Query {
189187

190188
fn inner_fetch_row_values(&mut self) -> Option<Vec<Value<'_>>> {
191189
unsafe {
192-
let row = xdb_fetch_row(self.ptr);
190+
let row: *mut c_void = xdb_fetch_row(self.ptr);
193191
if row.is_null() {
194192
return None;
195193
}
196-
let mut values = Vec::with_capacity(self.column_count());
197-
let iter = from_raw_parts(row, self.column_count()).iter().enumerate();
194+
let count = self.columns.len();
195+
let mut values = Vec::with_capacity(count);
196+
let iter = from_raw_parts(row, count).iter().enumerate();
198197
for (i, ptr) in iter {
199-
let ptr = *ptr as *const c_void;
200198
values.push(Value::from_ptr(ptr, self.columns.datatype(i)));
201199
}
202200
Some(values)

src/value.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub enum Value<'a> {
2020
Bool(bool),
2121
Inet(IpInet),
2222
Mac(MacAddress),
23+
// TODO: Array
2324
}
2425

2526
impl Display for Value<'_> {
@@ -42,7 +43,7 @@ impl Display for Value<'_> {
4243
}
4344
}
4445

45-
impl<'a> Value<'a> {
46+
impl Value<'_> {
4647
pub(crate) unsafe fn from_ptr(ptr: *const c_void, t: DataType) -> Self {
4748
if ptr.is_null() {
4849
return Self::Null;
@@ -96,6 +97,7 @@ impl<'a> Value<'a> {
9697
MacAddress::new([bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5]]);
9798
Self::Mac(address)
9899
}
100+
DataType::Array => todo!(),
99101
DataType::Max => todo!(),
100102
}
101103
}

0 commit comments

Comments
 (0)