|
1 |
| -use crate::argconv::*; |
2 | 1 | use crate::cass_error::CassError;
|
3 | 2 | use crate::exec_profile::PerStatementExecProfile;
|
4 | 3 | use crate::prepared::CassPrepared;
|
5 | 4 | use crate::query_result::CassResult;
|
6 | 5 | use crate::retry_policy::CassRetryPolicy;
|
7 | 6 | use crate::types::*;
|
8 | 7 | use crate::value::CassCqlValue;
|
| 8 | +use crate::{argconv::*, value}; |
9 | 9 | use scylla::frame::types::Consistency;
|
10 | 10 | use scylla::frame::value::MaybeUnset;
|
11 | 11 | use scylla::frame::value::MaybeUnset::{Set, Unset};
|
@@ -45,12 +45,35 @@ pub struct CassStatement {
|
45 | 45 |
|
46 | 46 | impl CassStatement {
|
47 | 47 | fn bind_cql_value(&mut self, index: usize, value: Option<CassCqlValue>) -> CassError {
|
48 |
| - if index >= self.bound_values.len() { |
49 |
| - CassError::CASS_ERROR_LIB_INDEX_OUT_OF_BOUNDS |
50 |
| - } else { |
51 |
| - self.bound_values[index] = Set(value); |
52 |
| - CassError::CASS_OK |
| 48 | + let (bound_value, maybe_data_type) = match &self.statement { |
| 49 | + Statement::Simple(_) => match self.bound_values.get_mut(index) { |
| 50 | + Some(v) => (v, None), |
| 51 | + None => return CassError::CASS_ERROR_LIB_INDEX_OUT_OF_BOUNDS, |
| 52 | + }, |
| 53 | + Statement::Prepared(p) => match ( |
| 54 | + self.bound_values.get_mut(index), |
| 55 | + p.variable_col_data_types.get(index), |
| 56 | + ) { |
| 57 | + (Some(v), Some(dt)) => (v, Some(dt)), |
| 58 | + (None, None) => return CassError::CASS_ERROR_LIB_INDEX_OUT_OF_BOUNDS, |
| 59 | + // This indicates a length mismtach between col specs table and self.bound_values. |
| 60 | + // |
| 61 | + // It can only occur when user provides bad `count` value in `cass_statement_reset_parameters`. |
| 62 | + // Cpp-driver does not verify that both of these values are equal. |
| 63 | + // I believe returning CASS_ERROR_LIB_INDEX_OUT_OF_BOUNDS is best we can do here. |
| 64 | + _ => return CassError::CASS_ERROR_LIB_INDEX_OUT_OF_BOUNDS, |
| 65 | + }, |
| 66 | + }; |
| 67 | + |
| 68 | + // Perform the typecheck. |
| 69 | + if let Some(dt) = maybe_data_type { |
| 70 | + if !value::is_type_compatible(&value, dt) { |
| 71 | + return CassError::CASS_ERROR_LIB_INVALID_VALUE_TYPE; |
| 72 | + } |
53 | 73 | }
|
| 74 | + |
| 75 | + *bound_value = Set(value); |
| 76 | + CassError::CASS_OK |
54 | 77 | }
|
55 | 78 |
|
56 | 79 | fn bind_multiple_values_by_name(
|
|
0 commit comments