Skip to content

Commit 0011883

Browse files
committed
statement: perform typecheck on bind
1 parent c435d76 commit 0011883

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

scylla-rust-wrapper/src/statement.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use crate::argconv::*;
21
use crate::cass_error::CassError;
32
use crate::exec_profile::PerStatementExecProfile;
43
use crate::prepared::CassPrepared;
54
use crate::query_result::CassResult;
65
use crate::retry_policy::CassRetryPolicy;
76
use crate::types::*;
87
use crate::value::CassCqlValue;
8+
use crate::{argconv::*, value};
99
use scylla::frame::types::Consistency;
1010
use scylla::frame::value::MaybeUnset;
1111
use scylla::frame::value::MaybeUnset::{Set, Unset};
@@ -43,13 +43,30 @@ pub struct CassStatement {
4343
}
4444

4545
impl CassStatement {
46+
fn typecheck_on_bind(&self, index: usize, value: &Option<CassCqlValue>) -> CassError {
47+
match &self.statement {
48+
// Unprepared queries have no metadata, don't perform a typecheck.
49+
Statement::Simple(_) => CassError::CASS_OK,
50+
Statement::Prepared(p) => {
51+
if !value::is_type_compatible(value, &p.variable_col_data_types[index]) {
52+
return CassError::CASS_ERROR_LIB_INVALID_VALUE_TYPE;
53+
}
54+
CassError::CASS_OK
55+
}
56+
}
57+
}
58+
4659
fn bind_cql_value(&mut self, index: usize, value: Option<CassCqlValue>) -> CassError {
4760
if index >= self.bound_values.len() {
48-
CassError::CASS_ERROR_LIB_INDEX_OUT_OF_BOUNDS
49-
} else {
50-
self.bound_values[index] = Set(value);
51-
CassError::CASS_OK
61+
return CassError::CASS_ERROR_LIB_INDEX_OUT_OF_BOUNDS;
62+
}
63+
let err = self.typecheck_on_bind(index, &value);
64+
if err != CassError::CASS_OK {
65+
return err;
5266
}
67+
68+
self.bound_values[index] = Set(value);
69+
CassError::CASS_OK
5370
}
5471

5572
fn bind_multiple_values_by_name(

0 commit comments

Comments
 (0)