From 27ed074e83e4919e8c894a395f82c0be7ac374c1 Mon Sep 17 00:00:00 2001 From: norie balbinot <92960355+Noriebalbinot@users.noreply.github.com> Date: Wed, 21 Aug 2024 15:18:27 -0300 Subject: [PATCH] changes to allow rust 1.8 --- rsfbclient-core/src/ibase.rs | 4 +++- rsfbclient-native/src/connection.rs | 8 ++++---- rsfbclient-native/src/params.rs | 16 +++++++++++----- rsfbclient-native/src/row.rs | 10 ++++++++-- rsfbclient-native/src/varchar.rs | 4 ++-- rsfbclient-native/src/xsqlda.rs | 27 ++++++++++++++++----------- 6 files changed, 44 insertions(+), 25 deletions(-) diff --git a/rsfbclient-core/src/ibase.rs b/rsfbclient-core/src/ibase.rs index c820531..9fc1534 100644 --- a/rsfbclient-core/src/ibase.rs +++ b/rsfbclient-core/src/ibase.rs @@ -8,6 +8,8 @@ clippy::upper_case_acronyms )] +use std::{marker::PhantomData, slice::Iter}; + pub const FB_API_VER: u32 = 30; pub const ISC_TRUE: u32 = 1; pub const ISC_FALSE: u32 = 0; @@ -2491,7 +2493,7 @@ pub struct XSQLVAR { pub aliasname: [ISC_SCHAR; 32usize], } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Clone, Copy)] pub struct XSQLDA { pub version: ISC_SHORT, pub sqldaid: [ISC_SCHAR; 8usize], diff --git a/rsfbclient-native/src/connection.rs b/rsfbclient-native/src/connection.rs index 82cba90..b732f02 100644 --- a/rsfbclient-native/src/connection.rs +++ b/rsfbclient-native/src/connection.rs @@ -390,11 +390,11 @@ impl FirebirdClientSqlOps for NativeFbClient { // Create the column buffers and set the xsqlda conercions let col_buffers = (0..xsqlda.sqld) .map(|col| { - let xcol = xsqlda - .get_xsqlvar_mut(col as usize) - .ok_or_else(|| FbError::from("Error getting the xsqlvar"))?; + // let mut xcol = xsqlda + // .get_xsqlvar_mut(col as usize) + // .ok_or_else(|| FbError::from("Error getting the xsqlvar"))?; - ColumnBuffer::from_xsqlvar(xcol) + ColumnBuffer::from_xsqlvar(&mut xsqlda, col) }) .collect::>()?; diff --git a/rsfbclient-native/src/params.rs b/rsfbclient-native/src/params.rs index b606f2d..814a908 100644 --- a/rsfbclient-native/src/params.rs +++ b/rsfbclient-native/src/params.rs @@ -52,9 +52,8 @@ impl Params { for (col, info) in infos.into_iter().enumerate() { buffers.push(ParamBuffer::from_parameter( info, - xsqlda - .get_xsqlvar_mut(col) - .ok_or_else(|| FbError::from("Error getting the xsqlvar"))?, + &mut xsqlda, + col, db_handle, tr_handle, ibase, @@ -151,14 +150,20 @@ impl ParamBuffer { /// Allocate a buffer from a value to use in an input (parameter) XSQLVAR pub fn from_parameter( info: SqlType, - var: &mut ibase::XSQLVAR, + orig_var: &mut ibase::XSQLDA, + col: usize, db: &mut ibase::isc_db_handle, tr: &mut ibase::isc_tr_handle, ibase: &T, charset: &Charset, ) -> Result { let mut null = 0; - + let mut var = unsafe { + let mut sqlvar = orig_var.sqlvar.to_vec(); + sqlvar.set_len(orig_var.sqln as usize); + sqlvar.as_mut_slice(); + *sqlvar.get_mut(col).unwrap() + }; let (sqltype, sqlsubtype) = info.sql_type_and_subtype(); var.sqltype = sqltype as i16; var.sqlsubtype = sqlsubtype as i16; @@ -205,6 +210,7 @@ impl ParamBuffer { var.sqldata = buffer.as_mut_ptr(); var.sqllen = size as i16; + orig_var.sqlvar = [var]; Ok(ParamBuffer { _buffer: buffer, diff --git a/rsfbclient-native/src/row.rs b/rsfbclient-native/src/row.rs index 6e8adf9..09a5035 100644 --- a/rsfbclient-native/src/row.rs +++ b/rsfbclient-native/src/row.rs @@ -59,8 +59,14 @@ pub struct ColumnBuffer { impl ColumnBuffer { /// Allocate a buffer from an output (column) XSQLVAR, coercing the data types as necessary - pub fn from_xsqlvar(var: &mut ibase::XSQLVAR) -> Result { + pub fn from_xsqlvar(orig_var: &mut ibase::XSQLDA, col: i16) -> Result { // Remove nullable type indicator + let mut var = unsafe { + let mut sqlvar = orig_var.sqlvar.to_vec(); + sqlvar.set_len(orig_var.sqln as usize); + sqlvar.as_mut_slice(); + *sqlvar.get_mut(col as usize).unwrap() + }; let sqltype = var.sqltype & (!1); let sqlsubtype = var.sqlsubtype; @@ -149,7 +155,7 @@ impl ColumnBuffer { String::from_utf8(bname) }?; - + orig_var.sqlvar = [var]; Ok(ColumnBuffer { buffer, nullind, diff --git a/rsfbclient-native/src/varchar.rs b/rsfbclient-native/src/varchar.rs index 29435b5..db13861 100644 --- a/rsfbclient-native/src/varchar.rs +++ b/rsfbclient-native/src/varchar.rs @@ -6,7 +6,7 @@ pub struct InnerVarchar { len: u16, //changed to avoid using get_unchecked in the as_bytes() implementation //because get_unchecked was used in a UB way. - data: Vec, + data: [u8; 0], } #[derive(Debug)] @@ -37,7 +37,7 @@ impl Varchar { pub fn as_bytes(&self) -> &[u8] { let len = u16::min(self.capacity, unsafe { self.ptr.as_ref().len }) as usize; - unsafe { self.ptr.as_ref().data.get(..len).unwrap() } + unsafe { &self.ptr.as_ref().data as &[u8] } } /// Get the pointer to the inner type diff --git a/rsfbclient-native/src/xsqlda.rs b/rsfbclient-native/src/xsqlda.rs index 5aad50a..ae43d8d 100644 --- a/rsfbclient-native/src/xsqlda.rs +++ b/rsfbclient-native/src/xsqlda.rs @@ -1,9 +1,11 @@ use std::{ alloc, - ops::{Deref, DerefMut}, + ops::{Deref, DerefMut, Index}, ptr, }; +use rsfbclient_core::ibase::XSQLVAR; + use crate::ibase; pub struct XSqlDa { @@ -33,16 +35,19 @@ impl XSqlDa { xsqlda } - /// Returns a mutable reference to a XSQLVAR - pub fn get_xsqlvar_mut(&mut self, col: usize) -> Option<&mut ibase::XSQLVAR> { - if col < self.len as usize { - let xsqlvar = unsafe { self.ptr.as_mut().sqlvar.get_mut(col as usize).unwrap() }; - - Some(xsqlvar) - } else { - None - } - } + // Returns a mutable reference to a XSQLVAR + // pub fn get_xsqlvar_mut(&mut self, col: usize) -> Option { + // if col < self.len as usize { + // Some(unsafe { + // let sqlvar = &mut self.ptr.as_mut().sqlvar.to_vec(); + // sqlvar.set_len(self.len as usize); + // sqlvar.as_mut_slice(); + // *sqlvar.get_mut(col as usize) + // }) + // } else { + // None + // } + // } } impl Deref for XSqlDa {