Skip to content

Commit

Permalink
Support VARCHAR column & get current database
Browse files Browse the repository at this point in the history
  • Loading branch information
wyhaya committed Oct 20, 2024
1 parent 141e496 commit 9654125
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ impl<'de> Deserializer<'de> for ValueDeserializer<'de> {
Value::F32(v) => visitor.visit_f32(v),
Value::F64(v) => visitor.visit_f64(v),
Value::Char(v) => visitor.visit_str(v),
// TODO: Deserialize Binary to Vec<u8>
Value::Binary(_) => unimplemented!(),
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ impl Connection {
Self::open(":memory:")
}

pub fn current_database(&self) -> Result<&str> {
unsafe {
let ptr = xdb_curdb(self.ptr);
let db = CStr::from_ptr(ptr).to_str()?;
Ok(db)
}
}

pub fn query<S: AsRef<str>>(&self, sql: S) -> Result<Query> {
let sql = CString::new(sql.as_ref())?;
unsafe {
Expand Down
8 changes: 7 additions & 1 deletion src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub enum Value<'a> {
F32(f32),
F64(f64),
Char(&'a str),
Binary(&'a [u8]),
}

impl Display for Value<'_> {
Expand All @@ -23,6 +24,7 @@ impl Display for Value<'_> {
Value::F32(v) => write!(f, "{}", v),
Value::F64(v) => write!(f, "{}", v),
Value::Char(v) => write!(f, "{}", v),
Value::Binary(v) => write!(f, "{:?}", v),
}
}
}
Expand All @@ -43,10 +45,14 @@ impl<'a> Value<'a> {
DataType::BigInt => Value::I64(xdb_column_int64(meta, row, col)),
DataType::Float => Value::F32(xdb_column_float(meta, row, col)),
DataType::Double => Value::F64(xdb_column_double(meta, row, col)),
DataType::Char => {
DataType::Char | DataType::VChar => {
let s = CStr::from_ptr(xdb_column_str(meta, row, col));
Value::Char(s.to_str().unwrap())
}
DataType::Binary | DataType::VBinary => {
// xdb_column_blob(meta, row, col, pLen);
todo!()
}
_ => unimplemented!(),
}
}
Expand Down

0 comments on commit 9654125

Please sign in to comment.