Skip to content

Commit

Permalink
Fix bind parameter address instability issue
Browse files Browse the repository at this point in the history
The bind parameters rely on stable addresses in memory, however the Vec
used to hold them was being allowed to re-allocate and therefore change
the addresses refered to by the OCI execute function. Now the Vec is
reserved with the right number of elements to ensure that it does not get
increases automatically.
  • Loading branch information
huwwynnjones committed Aug 21, 2018
1 parent 03c3d4f commit 82030de
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,18 @@ impl<'conn> Statement<'conn> {
/// parameters, however this is not yet available through this crate.
///
pub fn bind(&mut self, params: &[&ToSqlValue]) -> Result<(), OciError> {
// clear out previous bind parameters
self.values.clear();

// ensure that the vec is large enough to hold all the parameters
// otherwise the vec will re-size, re-allocated and the addresses will change
self.values.reserve(params.len());

for (index, param) in params.iter().enumerate() {
let sql_value = param.to_sql_value();
self.values.push(sql_value);
let binding: *mut OCIBind = ptr::null_mut();
self.bindings.push(binding);

let position = (index + 1) as c_uint;
let null_mut_ptr = ptr::null_mut();
let indp = null_mut_ptr;
Expand Down
2 changes: 1 addition & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use oci_error::OciError;

/// The types that support conversion from OCI to Rust types.
///
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub enum SqlValue {
/// Anything specified as `VARCHAR` or `VARCHAR2` will end up here.
VarChar(String),
Expand Down

0 comments on commit 82030de

Please sign in to comment.