|
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};
|
@@ -43,13 +43,30 @@ pub struct CassStatement {
|
43 | 43 | }
|
44 | 44 |
|
45 | 45 | 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 | + |
46 | 59 | fn bind_cql_value(&mut self, index: usize, value: Option<CassCqlValue>) -> CassError {
|
47 | 60 | 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; |
52 | 66 | }
|
| 67 | + |
| 68 | + self.bound_values[index] = Set(value); |
| 69 | + CassError::CASS_OK |
53 | 70 | }
|
54 | 71 |
|
55 | 72 | fn bind_multiple_values_by_name(
|
|
0 commit comments