Skip to content

Commit

Permalink
Add row iterator implementation
Browse files Browse the repository at this point in the history
CassIterator struct modified to simulate iterator hierarchy in C++
dirver.

Added RowIterator implementation with necessary functions to get
column value and type.
  • Loading branch information
Gor027 committed Jul 28, 2022
1 parent d83e749 commit 6452ec7
Show file tree
Hide file tree
Showing 6 changed files with 232 additions and 96 deletions.
35 changes: 35 additions & 0 deletions scylla-rust-wrapper/src/cass_types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::argconv::*;
use crate::cass_error::CassError;
use crate::types::*;
use scylla::frame::response::result::CqlValue;
use std::os::raw::c_char;
use std::ptr;
use std::sync::Arc;
Expand Down Expand Up @@ -128,6 +129,40 @@ impl CassDataType {
}
}

pub fn get_type_from_value(value: &Option<CqlValue>) -> CassDataType {
match value {
Some(CqlValue::Ascii(_)) => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_ASCII),
Some(CqlValue::Boolean(_)) => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_BOOLEAN),
Some(CqlValue::Blob(_)) => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_BLOB),
Some(CqlValue::Counter(_)) => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_COUNTER),
Some(CqlValue::Decimal(_)) => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_DECIMAL),
Some(CqlValue::Date(_)) => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_DATE),
Some(CqlValue::Double(_)) => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_DOUBLE),
Some(CqlValue::Float(_)) => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_FLOAT),
Some(CqlValue::Int(_)) => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_INT),
Some(CqlValue::BigInt(_)) => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_BIGINT),
Some(CqlValue::Text(_)) => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_TEXT),
Some(CqlValue::Timestamp(_)) => {
CassDataType::Value(CassValueType::CASS_VALUE_TYPE_TIMESTAMP)
}
Some(CqlValue::Inet(_)) => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_INET),
Some(CqlValue::List(_)) => CassDataType::List(None),
Some(CqlValue::Map(_)) => CassDataType::Map(None, None),
Some(CqlValue::Set(_)) => CassDataType::Set(None),
Some(CqlValue::UserDefinedType { .. }) => CassDataType::UDT(Default::default()),
Some(CqlValue::SmallInt(_)) => {
CassDataType::Value(CassValueType::CASS_VALUE_TYPE_SMALL_INT)
}
Some(CqlValue::TinyInt(_)) => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_TINY_INT),
Some(CqlValue::Time(_)) => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_TIME),
Some(CqlValue::Timeuuid(_)) => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_TIMEUUID),
Some(CqlValue::Tuple(_)) => CassDataType::Tuple(vec![]),
Some(CqlValue::Uuid(_)) => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_UUID),
Some(CqlValue::Varint(_)) => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_VARINT),
_ => CassDataType::Value(CassValueType::CASS_VALUE_TYPE_UNKNOWN),
}
}

// Changed return type to const ptr - Arc::into_raw is const.
// It's probably not a good idea - but cppdriver doesn't guarantee
// thread safety apart from CassSession and CassFuture.
Expand Down
9 changes: 9 additions & 0 deletions scylla-rust-wrapper/src/external.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use crate::cass_error::*;
use std::os::raw::c_char;

#[no_mangle]
pub unsafe extern "C" fn cass_error_desc(_error: *const CassError) -> *const c_char {
// FIXME: add proper implementation
let error = "my_custom_error\0";
error.as_ptr() as *const c_char
}
1 change: 1 addition & 0 deletions scylla-rust-wrapper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod cass_error;
pub mod cass_types;
pub mod cluster;
pub mod collection;
mod external;
pub mod future;
pub mod inet;
pub mod prepared;
Expand Down
Loading

0 comments on commit 6452ec7

Please sign in to comment.