use widestring::{U16Str, U16String};
use crate::{
execute::{columns, execute_with_parameters},
handles::StatementImpl,
CursorImpl, Error, ParameterCollection,
};
pub struct Preallocated<'open_connection> {
statement: StatementImpl<'open_connection>,
}
impl<'o> Preallocated<'o> {
pub(crate) fn new(statement: StatementImpl<'o>) -> Self {
Self { statement }
}
pub fn execute_utf16(
&mut self,
query: &U16Str,
params: impl ParameterCollection,
) -> Result<Option<CursorImpl<'o, &mut StatementImpl<'o>>>, Error> {
execute_with_parameters(move || Ok(&mut self.statement), Some(query), params)
}
pub fn execute(
&mut self,
query: &str,
params: impl ParameterCollection,
) -> Result<Option<CursorImpl<'o, &mut StatementImpl<'o>>>, Error> {
let query = U16String::from_str(query);
self.execute_utf16(&query, params)
}
pub fn into_statement(self) -> StatementImpl<'o> {
self.statement
}
pub fn columns(
&mut self,
catalog_name: &str,
schema_name: &str,
table_name: &str,
column_name: &str,
) -> Result<Option<CursorImpl<'o, &mut StatementImpl<'o>>>, Error> {
columns(
&mut self.statement,
&U16String::from_str(catalog_name),
&U16String::from_str(schema_name),
&U16String::from_str(table_name),
&U16String::from_str(column_name),
)
}
}