Skip to content

Commit 9654125

Browse files
committed
Support VARCHAR column & get current database
1 parent 141e496 commit 9654125

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

src/de.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ impl<'de> Deserializer<'de> for ValueDeserializer<'de> {
9090
Value::F32(v) => visitor.visit_f32(v),
9191
Value::F64(v) => visitor.visit_f64(v),
9292
Value::Char(v) => visitor.visit_str(v),
93+
// TODO: Deserialize Binary to Vec<u8>
94+
Value::Binary(_) => unimplemented!(),
9395
}
9496
}
9597

src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ impl Connection {
6868
Self::open(":memory:")
6969
}
7070

71+
pub fn current_database(&self) -> Result<&str> {
72+
unsafe {
73+
let ptr = xdb_curdb(self.ptr);
74+
let db = CStr::from_ptr(ptr).to_str()?;
75+
Ok(db)
76+
}
77+
}
78+
7179
pub fn query<S: AsRef<str>>(&self, sql: S) -> Result<Query> {
7280
let sql = CString::new(sql.as_ref())?;
7381
unsafe {

src/value.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub enum Value<'a> {
1010
F32(f32),
1111
F64(f64),
1212
Char(&'a str),
13+
Binary(&'a [u8]),
1314
}
1415

1516
impl Display for Value<'_> {
@@ -23,6 +24,7 @@ impl Display for Value<'_> {
2324
Value::F32(v) => write!(f, "{}", v),
2425
Value::F64(v) => write!(f, "{}", v),
2526
Value::Char(v) => write!(f, "{}", v),
27+
Value::Binary(v) => write!(f, "{:?}", v),
2628
}
2729
}
2830
}
@@ -43,10 +45,14 @@ impl<'a> Value<'a> {
4345
DataType::BigInt => Value::I64(xdb_column_int64(meta, row, col)),
4446
DataType::Float => Value::F32(xdb_column_float(meta, row, col)),
4547
DataType::Double => Value::F64(xdb_column_double(meta, row, col)),
46-
DataType::Char => {
48+
DataType::Char | DataType::VChar => {
4749
let s = CStr::from_ptr(xdb_column_str(meta, row, col));
4850
Value::Char(s.to_str().unwrap())
4951
}
52+
DataType::Binary | DataType::VBinary => {
53+
// xdb_column_blob(meta, row, col, pLen);
54+
todo!()
55+
}
5056
_ => unimplemented!(),
5157
}
5258
}

0 commit comments

Comments
 (0)