Skip to content

Commit e02cad5

Browse files
authored
Merge pull request #138 from muzarski/update-013
cargo: update rust driver's version to 0.13.1
2 parents ca7dfa3 + b0aa444 commit e02cad5

File tree

15 files changed

+642
-264
lines changed

15 files changed

+642
-264
lines changed

scylla-rust-wrapper/Cargo.lock

Lines changed: 247 additions & 162 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scylla-rust-wrapper/Cargo.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ categories = ["database"]
1010
license = "MIT OR Apache-2.0"
1111

1212
[dependencies]
13-
scylla = { git = "https://github.com/scylladb/scylla-rust-driver.git", rev = "40aaee6", features = [
14-
"ssl",
15-
] }
13+
scylla = { version = "0.13.1", features = ["ssl"] }
1614
tokio = { version = "1.27.0", features = ["full"] }
1715
lazy_static = "1.4.0"
1816
uuid = "1.1.2"
@@ -34,7 +32,7 @@ chrono = "0.4.20"
3432
assert_matches = "1.5.0"
3533
ntest = "0.9.3"
3634
rusty-fork = "0.3.0"
37-
scylla-proxy = { git = "https://github.com/scylladb/scylla-rust-driver.git", rev = "40aaee6" }
35+
scylla-proxy = { version = "0.0.4" }
3836

3937
[lib]
4038
name = "scylla_cpp_driver"

scylla-rust-wrapper/src/batch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use crate::exec_profile::PerStatementExecProfile;
66
use crate::retry_policy::CassRetryPolicy;
77
use crate::statement::{CassStatement, Statement};
88
use crate::types::*;
9+
use crate::value::CassCqlValue;
910
use scylla::batch::Batch;
10-
use scylla::frame::response::result::CqlValue;
1111
use scylla::frame::value::MaybeUnset;
1212
use std::convert::TryInto;
1313
use std::sync::Arc;
@@ -22,7 +22,7 @@ pub struct CassBatch {
2222
#[derive(Clone)]
2323
pub struct CassBatchState {
2424
pub batch: Batch,
25-
pub bound_values: Vec<Vec<MaybeUnset<Option<CqlValue>>>>,
25+
pub bound_values: Vec<Vec<MaybeUnset<Option<CassCqlValue>>>>,
2626
}
2727

2828
#[no_mangle]

scylla-rust-wrapper/src/binding.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,9 @@
4747
//! It can be used for binding named parameter in CassStatement or field by name in CassUserType.
4848
//! * Functions from make_appender don't take any extra argument, as they are for use by CassCollection
4949
//! functions - values are appended to collection.
50-
use crate::cass_types::CassDataType;
51-
use scylla::frame::response::result::CqlValue;
50+
use crate::{cass_types::CassDataType, value::CassCqlValue};
5251

53-
pub fn is_compatible_type(_data_type: &CassDataType, _value: &Option<CqlValue>) -> bool {
52+
pub fn is_compatible_type(_data_type: &CassDataType, _value: &Option<CassCqlValue>) -> bool {
5453
// TODO: cppdriver actually checks types.
5554
true
5655
}
@@ -66,7 +65,7 @@ macro_rules! make_index_binder {
6665
) -> CassError {
6766
// For some reason detected as unused, which is not true
6867
#[allow(unused_imports)]
69-
use scylla::frame::response::result::CqlValue::*;
68+
use crate::value::CassCqlValue::*;
7069
match ($e)($($arg), *) {
7170
Ok(v) => $consume_v(ptr_to_ref_mut(this), index as usize, v),
7271
Err(e) => e,
@@ -86,7 +85,7 @@ macro_rules! make_name_binder {
8685
) -> CassError {
8786
// For some reason detected as unused, which is not true
8887
#[allow(unused_imports)]
89-
use scylla::frame::response::result::CqlValue::*;
88+
use crate::value::CassCqlValue::*;
9089
let name = ptr_to_cstr(name).unwrap();
9190
match ($e)($($arg), *) {
9291
Ok(v) => $consume_v(ptr_to_ref_mut(this), name, v),
@@ -108,7 +107,7 @@ macro_rules! make_name_n_binder {
108107
) -> CassError {
109108
// For some reason detected as unused, which is not true
110109
#[allow(unused_imports)]
111-
use scylla::frame::response::result::CqlValue::*;
110+
use crate::value::CassCqlValue::*;
112111
let name = ptr_to_cstr_n(name, name_length).unwrap();
113112
match ($e)($($arg), *) {
114113
Ok(v) => $consume_v(ptr_to_ref_mut(this), name, v),
@@ -128,7 +127,7 @@ macro_rules! make_appender {
128127
) -> CassError {
129128
// For some reason detected as unused, which is not true
130129
#[allow(unused_imports)]
131-
use scylla::frame::response::result::CqlValue::*;
130+
use crate::value::CassCqlValue::*;
132131
match ($e)($($arg), *) {
133132
Ok(v) => $consume_v(ptr_to_ref_mut(this), v),
134133
Err(e) => e,
@@ -178,7 +177,10 @@ macro_rules! invoke_binder_maker_macro_with_type {
178177
$this,
179178
$consume_v,
180179
$fn,
181-
|v| Ok(Some(Date(v))),
180+
|v| {
181+
use scylla::frame::value::CqlDate;
182+
Ok(Some(Date(CqlDate(v))))
183+
},
182184
[v @ cass_uint32_t]
183185
);
184186
};
@@ -295,7 +297,7 @@ macro_rules! invoke_binder_maker_macro_with_type {
295297
$consume_v,
296298
$fn,
297299
|p: *const crate::tuple::CassTuple| {
298-
std::convert::TryInto::try_into(ptr_to_ref(p)).map(Some)
300+
Ok(Some(ptr_to_ref(p).into()))
299301
},
300302
[p @ *const crate::tuple::CassTuple]
301303
);

scylla-rust-wrapper/src/cass_error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ impl From<&BadQuery> for CassError {
5858
BadQuery::ValuesTooLongForKey(_usize, _usize2) => CassError::CASS_ERROR_LAST_ENTRY,
5959
BadQuery::BadKeyspaceName(_bad_keyspace_name) => CassError::CASS_ERROR_LAST_ENTRY,
6060
BadQuery::Other(_other_query) => CassError::CASS_ERROR_LAST_ENTRY,
61+
BadQuery::SerializationError(_) => CassError::CASS_ERROR_LAST_ENTRY,
62+
BadQuery::TooManyQueriesInBatchStatement(_) => CassError::CASS_ERROR_LAST_ENTRY,
6163
}
6264
}
6365
}

scylla-rust-wrapper/src/collection.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use crate::argconv::*;
22
use crate::cass_error::CassError;
33
use crate::types::*;
4-
use scylla::frame::response::result::CqlValue;
5-
use scylla::frame::response::result::CqlValue::*;
4+
use crate::value::CassCqlValue;
65
use std::convert::TryFrom;
76

87
include!(concat!(env!("OUT_DIR"), "/cppdriver_data_collection.rs"));
@@ -11,24 +10,26 @@ include!(concat!(env!("OUT_DIR"), "/cppdriver_data_collection.rs"));
1110
pub struct CassCollection {
1211
pub collection_type: CassCollectionType,
1312
pub capacity: usize,
14-
pub items: Vec<CqlValue>,
13+
pub items: Vec<CassCqlValue>,
1514
}
1615

1716
impl CassCollection {
18-
pub fn append_cql_value(&mut self, value: Option<CqlValue>) -> CassError {
17+
pub fn append_cql_value(&mut self, value: Option<CassCqlValue>) -> CassError {
1918
// FIXME: Bounds check, type check
2019
// There is no API to append null, so unwrap is safe
2120
self.items.push(value.unwrap());
2221
CassError::CASS_OK
2322
}
2423
}
2524

26-
impl TryFrom<&CassCollection> for CqlValue {
25+
impl TryFrom<&CassCollection> for CassCqlValue {
2726
type Error = ();
2827
fn try_from(collection: &CassCollection) -> Result<Self, Self::Error> {
2928
// FIXME: validate that collection items are correct
3029
match collection.collection_type {
31-
CassCollectionType::CASS_COLLECTION_TYPE_LIST => Ok(List(collection.items.clone())),
30+
CassCollectionType::CASS_COLLECTION_TYPE_LIST => {
31+
Ok(CassCqlValue::List(collection.items.clone()))
32+
}
3233
CassCollectionType::CASS_COLLECTION_TYPE_MAP => {
3334
let mut grouped_items = Vec::new();
3435
// FIXME: validate even number of items
@@ -39,10 +40,10 @@ impl TryFrom<&CassCollection> for CqlValue {
3940
grouped_items.push((key, value));
4041
}
4142

42-
Ok(Map(grouped_items))
43+
Ok(CassCqlValue::Map(grouped_items))
4344
}
4445
CassCollectionType::CASS_COLLECTION_TYPE_SET => {
45-
Ok(CqlValue::Set(collection.items.clone()))
46+
Ok(CassCqlValue::Set(collection.items.clone()))
4647
}
4748
_ => Err(()),
4849
}

scylla-rust-wrapper/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub mod tuple;
3333
pub mod types;
3434
pub mod user_type;
3535
pub mod uuid;
36+
pub mod value;
3637

3738
lazy_static! {
3839
pub static ref RUNTIME: Runtime = Runtime::new().unwrap();

scylla-rust-wrapper/src/prepared.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub unsafe extern "C" fn cass_prepared_bind(
1919
prepared_raw: *const CassPrepared,
2020
) -> *mut CassStatement {
2121
let prepared: Arc<_> = clone_arced(prepared_raw);
22-
let bound_values_size = prepared.get_prepared_metadata().col_count;
22+
let bound_values_size = prepared.get_variable_col_specs().len();
2323

2424
// cloning prepared statement's arc, because creating CassStatement should not invalidate
2525
// the CassPrepared argument

scylla-rust-wrapper/src/query_error.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::argconv::*;
22
use crate::cass_error::*;
33
use crate::types::*;
4-
use scylla::frame::types::{LegacyConsistency, SerialConsistency};
54
use scylla::statement::Consistency;
65
use scylla::transport::errors::*;
76

@@ -21,6 +20,8 @@ impl From<Consistency> for CassConsistency {
2120
Consistency::LocalQuorum => CassConsistency::CASS_CONSISTENCY_LOCAL_QUORUM,
2221
Consistency::EachQuorum => CassConsistency::CASS_CONSISTENCY_EACH_QUORUM,
2322
Consistency::LocalOne => CassConsistency::CASS_CONSISTENCY_LOCAL_ONE,
23+
Consistency::Serial => CassConsistency::CASS_CONSISTENCY_SERIAL,
24+
Consistency::LocalSerial => CassConsistency::CASS_CONSISTENCY_LOCAL_SERIAL,
2425
}
2526
}
2627
}
@@ -59,34 +60,24 @@ pub unsafe extern "C" fn cass_error_result_consistency(
5960
let error_result: &CassErrorResult = ptr_to_ref(error_result);
6061
match error_result {
6162
QueryError::DbError(DbError::Unavailable { consistency, .. }, _) => {
62-
get_cass_consistency_from_legacy(consistency)
63+
CassConsistency::from(*consistency)
6364
}
6465
QueryError::DbError(DbError::ReadTimeout { consistency, .. }, _) => {
65-
get_cass_consistency_from_legacy(consistency)
66+
CassConsistency::from(*consistency)
6667
}
6768
QueryError::DbError(DbError::WriteTimeout { consistency, .. }, _) => {
68-
get_cass_consistency_from_legacy(consistency)
69+
CassConsistency::from(*consistency)
6970
}
7071
QueryError::DbError(DbError::ReadFailure { consistency, .. }, _) => {
71-
get_cass_consistency_from_legacy(consistency)
72+
CassConsistency::from(*consistency)
7273
}
7374
QueryError::DbError(DbError::WriteFailure { consistency, .. }, _) => {
74-
get_cass_consistency_from_legacy(consistency)
75+
CassConsistency::from(*consistency)
7576
}
7677
_ => CassConsistency::CASS_CONSISTENCY_UNKNOWN,
7778
}
7879
}
7980

80-
fn get_cass_consistency_from_legacy(consistency: &LegacyConsistency) -> CassConsistency {
81-
match consistency {
82-
LegacyConsistency::Regular(regular) => CassConsistency::from(*regular),
83-
LegacyConsistency::Serial(serial) => match serial {
84-
SerialConsistency::Serial => CassConsistency::CASS_CONSISTENCY_SERIAL,
85-
SerialConsistency::LocalSerial => CassConsistency::CASS_CONSISTENCY_LOCAL_SERIAL,
86-
},
87-
}
88-
}
89-
9081
#[no_mangle]
9182
pub unsafe extern "C" fn cass_error_result_responses_received(
9283
error_result: *const CassErrorResult,

scylla-rust-wrapper/src/query_result.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ pub unsafe extern "C" fn cass_value_get_uint32(
999999
) -> CassError {
10001000
let val: &CassValue = ptr_to_ref(value);
10011001
match val.value {
1002-
Some(Value::RegularValue(CqlValue::Date(u))) => std::ptr::write(output, u), // FIXME: hack
1002+
Some(Value::RegularValue(CqlValue::Date(u))) => std::ptr::write(output, u.0), // FIXME: hack
10031003
Some(_) => return CassError::CASS_ERROR_LIB_INVALID_VALUE_TYPE,
10041004
None => return CassError::CASS_ERROR_LIB_NULL_VALUE,
10051005
};
@@ -1033,12 +1033,9 @@ pub unsafe extern "C" fn cass_value_get_int64(
10331033
Some(Value::RegularValue(CqlValue::Counter(i))) => {
10341034
std::ptr::write(output, i.0 as cass_int64_t)
10351035
}
1036-
Some(Value::RegularValue(CqlValue::Time(d))) => match d.num_nanoseconds() {
1037-
Some(nanos) => std::ptr::write(output, nanos as cass_int64_t),
1038-
None => return CassError::CASS_ERROR_LIB_NULL_VALUE,
1039-
},
1036+
Some(Value::RegularValue(CqlValue::Time(d))) => std::ptr::write(output, d.0),
10401037
Some(Value::RegularValue(CqlValue::Timestamp(d))) => {
1041-
std::ptr::write(output, d.num_milliseconds() as cass_int64_t)
1038+
std::ptr::write(output, d.0 as cass_int64_t)
10421039
}
10431040
Some(_) => return CassError::CASS_ERROR_LIB_INVALID_VALUE_TYPE,
10441041
None => return CassError::CASS_ERROR_LIB_NULL_VALUE,
@@ -1055,7 +1052,9 @@ pub unsafe extern "C" fn cass_value_get_uuid(
10551052
let val: &CassValue = ptr_to_ref(value);
10561053
match val.value {
10571054
Some(Value::RegularValue(CqlValue::Uuid(uuid))) => std::ptr::write(output, uuid.into()),
1058-
Some(Value::RegularValue(CqlValue::Timeuuid(uuid))) => std::ptr::write(output, uuid.into()),
1055+
Some(Value::RegularValue(CqlValue::Timeuuid(uuid))) => {
1056+
std::ptr::write(output, Into::<Uuid>::into(uuid).into())
1057+
}
10591058
Some(_) => return CassError::CASS_ERROR_LIB_INVALID_VALUE_TYPE,
10601059
None => return CassError::CASS_ERROR_LIB_NULL_VALUE,
10611060
};

0 commit comments

Comments
 (0)