Struct odbc_api::handles::OutputStringBuffer
source · pub struct OutputStringBuffer { /* private fields */ }Expand description
We use this as an output buffer for strings. Allows for detecting truncation.
Implementations§
source§impl OutputStringBuffer
impl OutputStringBuffer
sourcepub fn empty() -> Self
pub fn empty() -> Self
Creates an empty string buffer. Useful if you want to e.g. use a prompt to complete the connection string, but are not interessted in the actual completed connection string.
Examples found in repository?
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
pub fn connect_with_connection_string(&mut self, connection_string: &SqlText) -> SqlResult<()> {
unsafe {
let parent_window = null_mut();
let mut completed_connection_string = OutputStringBuffer::empty();
self.driver_connect(
connection_string,
parent_window,
&mut completed_connection_string,
DriverConnectOption::NoPrompt,
)
// Since we did pass NoPrompt we know the user can not abort the prompt.
.map(|_connection_string_is_complete| ())
}
}sourcepub fn with_buffer_size(max_str_len: usize) -> Self
pub fn with_buffer_size(max_str_len: usize) -> Self
Creates a new instance of an output string buffer which can hold strings up to a size of
max_str_len - 1 characters. `-1 because one place is needed for the terminating zero.
To hold a connection string the size should be at least 1024.
sourcepub fn mut_buf_ptr(&mut self) -> *mut SqlChar
pub fn mut_buf_ptr(&mut self) -> *mut SqlChar
Ptr to the internal buffer. Used by ODBC API calls to fill the buffer.
Examples found in repository?
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
pub unsafe fn driver_connect(
&mut self,
connection_string: &SqlText,
parent_window: HWnd,
completed_connection_string: &mut OutputStringBuffer,
driver_completion: DriverConnectOption,
) -> SqlResult<()> {
sql_driver_connect(
self.handle,
parent_window,
connection_string.ptr(),
connection_string.len_char().try_into().unwrap(),
completed_connection_string.mut_buf_ptr(),
completed_connection_string.buf_len(),
completed_connection_string.mut_actual_len_ptr(),
driver_completion,
)
.into_sql_result("SQLDriverConnect")
}sourcepub fn buf_len(&self) -> i16
pub fn buf_len(&self) -> i16
Length of the internal buffer in characters including the terminating zero.
Examples found in repository?
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
pub unsafe fn driver_connect(
&mut self,
connection_string: &SqlText,
parent_window: HWnd,
completed_connection_string: &mut OutputStringBuffer,
driver_completion: DriverConnectOption,
) -> SqlResult<()> {
sql_driver_connect(
self.handle,
parent_window,
connection_string.ptr(),
connection_string.len_char().try_into().unwrap(),
completed_connection_string.mut_buf_ptr(),
completed_connection_string.buf_len(),
completed_connection_string.mut_actual_len_ptr(),
driver_completion,
)
.into_sql_result("SQLDriverConnect")
}sourcepub fn mut_actual_len_ptr(&mut self) -> *mut i16
pub fn mut_actual_len_ptr(&mut self) -> *mut i16
Mutable pointer to actual output string length. Used by ODBC API calls to report truncation.
Examples found in repository?
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
pub unsafe fn driver_connect(
&mut self,
connection_string: &SqlText,
parent_window: HWnd,
completed_connection_string: &mut OutputStringBuffer,
driver_completion: DriverConnectOption,
) -> SqlResult<()> {
sql_driver_connect(
self.handle,
parent_window,
connection_string.ptr(),
connection_string.len_char().try_into().unwrap(),
completed_connection_string.mut_buf_ptr(),
completed_connection_string.buf_len(),
completed_connection_string.mut_actual_len_ptr(),
driver_completion,
)
.into_sql_result("SQLDriverConnect")
}sourcepub fn to_utf8(&self) -> String
pub fn to_utf8(&self) -> String
Call this method to extract string from buffer after ODBC has filled it.
sourcepub fn is_truncated(&self) -> bool
pub fn is_truncated(&self) -> bool
True if the buffer had not been large enough to hold the string.
Examples found in repository?
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
pub fn to_utf8(&self) -> String {
if self.buffer.is_empty() {
return String::new();
}
if self.is_truncated() {
// If the string is truncated we return the entire buffer excluding the terminating
// zero.
slice_to_utf8(&self.buffer[0..(self.buffer.len() - 1)]).unwrap()
} else {
// If the string is not truncated, we return not the entire buffer, but only the slice
// containing the actual string.
let actual_length: usize = self.actual_length.try_into().unwrap();
slice_to_utf8(&self.buffer[0..actual_length]).unwrap()
}
}