Type Definition odbc_api::parameter::VarCharSlice
source · [−]Expand description
Binds a byte array as a VarChar input parameter.
While a byte array can provide us with a pointer to the start of the array and the length of the array itself, it can not provide us with a pointer to the length of the buffer. So to bind strings which are not zero terminated we need to store the length in a separate value.
This type is created if into_parameter
of the IntoParameter
trait is called on a &str
.
Example
use odbc_api::{Environment, IntoParameter};
let env = Environment::new()?;
let mut conn = env.connect("YourDatabase", "SA", "My@Test@Password1")?;
if let Some(cursor) = conn.execute(
"SELECT year FROM Birthdays WHERE name=?;",
&"Bernd".into_parameter())?
{
// Use cursor to process query results.
};
Implementations
sourceimpl<'a> VarCharSlice<'a>
impl<'a> VarCharSlice<'a>
sourcepub const NULL: Self = Self {
// We do not want to use the empty buffer (`&[]`) here. It would be bound as `VARCHAR(0)`
// which caused errors with Microsoft Access and older versions of the Microsoft SQL Server
// ODBC driver.
buffer: &[0],
indicator: NULL_DATA,
}
pub const NULL: Self = Self { // We do not want to use the empty buffer (`&[]`) here. It would be bound as `VARCHAR(0)` // which caused errors with Microsoft Access and older versions of the Microsoft SQL Server // ODBC driver. buffer: &[0], indicator: NULL_DATA, }
Indicates missing data
sourcepub fn new(value: &'a [u8]) -> Self
pub fn new(value: &'a [u8]) -> Self
Constructs a new VarChar containing the text in the specified buffer.
Caveat: This constructor is going to create a truncated value in case the input slice ends
with nul
. Should you want to insert an actual string those payload ends with nul
into
the database you need a buffer one byte longer than the string. You can instantiate such a
value using Self::from_buffer
.