[−][src]Struct mysql::Stmt
Mysql prepared statement.
Methods
impl<'a> Stmt<'a>
[src]
pub fn params_ref(&self) -> Option<&[Column]>
[src]
Returns a slice of a Column
s which represents
Stmt
's params if any.
pub fn columns_ref(&self) -> Option<&[Column]>
[src]
Returns a slice of a Column
s which represents
Stmt
's columns if any.
pub fn column_index<T: AsRef<str>>(&self, name: T) -> Option<usize>
[src]
Returns index of a Stmt
's column by name.
pub fn execute<T: Into<Params>>(&mut self, params: T) -> Result<QueryResult>
[src]
Executes prepared statement with parameters passed as a [Into<Params>
] implementor.
let mut stmt0 = pool.prepare("SELECT 42").unwrap(); let mut stmt1 = pool.prepare("SELECT ?").unwrap(); let mut stmt2 = pool.prepare("SELECT ?, ?").unwrap(); let mut stmt13 = pool.prepare("SELECT ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?").unwrap(); // It is better to pass params as a tuple when executing statements of arity <= 12 for row in stmt0.execute(()).unwrap() { let cell = from_row::<u8>(row.unwrap()); assert_eq!(cell, 42u8); } // just do not forget about trailing comma in case of arity = 1 for row in stmt1.execute((42,)).unwrap() { let cell = from_row::<u8>(row.unwrap()); assert_eq!(cell, 42u8); } // If you don't want to lose ownership of param, then you should pass it by reference let word = "hello".to_string(); for row in stmt2.execute((&word, &word)).unwrap() { let (cell1, cell2) = from_row::<(String, String)>(row.unwrap()); assert_eq!(cell1, "hello"); assert_eq!(cell2, "hello"); } // If you want to execute statement of arity > 12, then you can pass params as &[&ToValue]. let params: &[&dyn ToValue] = &[&1, &2, &3, &4, &5, &6, &7, &8, &9, &10, &11, &12, &13]; for row in stmt13.execute(params).unwrap() { let row: Vec<u8> = row.unwrap().unwrap().into_iter().map(from_value::<u8>).collect(); assert_eq!(row, vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]); } // but be aware of implicit copying, so if you have huge params and do not care // about ownership, then better to use plain Vec<Value>. let mut params: Vec<Value> = Vec::with_capacity(13); for i in 1..14 { params.push(repeat('A').take(i * 1000).collect::<String>().into()); } for row in stmt13.execute(params).unwrap() { let row = row.unwrap(); let row: Vec<String> = row.unwrap().into_iter().map(from_value::<String>).collect(); for i in 1..14 { assert_eq!(row[i-1], repeat('A').take(i * 1000).collect::<String>()); } }
pub fn first_exec<P, T>(&mut self, params: P) -> Result<Option<T>> where
P: Into<Params>,
T: FromRow,
[src]
P: Into<Params>,
T: FromRow,
See Conn::first_exec
.
Trait Implementations
Auto Trait Implementations
impl<'a> Send for Stmt<'a>
impl<'a> Sync for Stmt<'a>
impl<'a> Unpin for Stmt<'a>
impl<'a> !UnwindSafe for Stmt<'a>
impl<'a> !RefUnwindSafe for Stmt<'a>
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,
fn vzip(self) -> V
impl<T> Same<T> for T
type Output = T
Should always be Self