pub struct OutputStringBuffer { /* private fields */ }
Expand description

We use this as an output buffer for strings. Allows for detecting truncation.

Implementations§

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?
src/handles/connection.rs (line 114)
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| ())
        }
    }

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.

Examples found in repository?
src/handles/sql_char.rs (line 188)
187
188
189
    pub fn empty() -> Self {
        Self::with_buffer_size(0)
    }

Ptr to the internal buffer. Used by ODBC API calls to fill the buffer.

Examples found in repository?
src/handles/connection.rs (line 149)
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")
    }

Length of the internal buffer in characters including the terminating zero.

Examples found in repository?
src/handles/connection.rs (line 150)
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")
    }

Mutable pointer to actual output string length. Used by ODBC API calls to report truncation.

Examples found in repository?
src/handles/connection.rs (line 151)
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")
    }

Call this method to extract string from buffer after ODBC has filled it.

True if the buffer had not been large enough to hold the string.

Examples found in repository?
src/handles/sql_char.rs (line 224)
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()
        }
    }

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.