pub struct LocalInfileHandler(/* private fields */);
Expand description
Callback to handle requests for local files. Consult Mysql documentation for the format of local infile data.
§Support
Note that older versions of Mysql server may not support this functionality.
use mysql::*;
use mysql::prelude::*;
use std::io::Write;
let pool = Pool::new(get_opts())?;
let mut conn = pool.get_conn().unwrap();
conn.query_drop("CREATE TEMPORARY TABLE mysql.tbl(a TEXT)").unwrap();
conn.set_local_infile_handler(Some(
LocalInfileHandler::new(|file_name, writer| {
writer.write_all(b"row1: file name is ")?;
writer.write_all(file_name)?;
writer.write_all(b"\n")?;
writer.write_all(b"row2: foobar\n")
})
));
match conn.query_drop("LOAD DATA LOCAL INFILE 'file_name' INTO TABLE mysql.tbl") {
Ok(_) => (),
Err(Error::MySqlError(ref e)) if e.code == 1148 => {
// functionality is not supported by the server
return Ok(());
}
err => {
err.unwrap();
}
}
let mut row_num = 0;
let result: Vec<String> = conn.query("SELECT * FROM mysql.tbl").unwrap();
assert_eq!(
result,
vec!["row1: file name is file_name".to_string(), "row2: foobar".to_string()],
);
Implementations§
Trait Implementations§
Source§impl Clone for LocalInfileHandler
impl Clone for LocalInfileHandler
Source§fn clone(&self) -> LocalInfileHandler
fn clone(&self) -> LocalInfileHandler
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for LocalInfileHandler
impl Debug for LocalInfileHandler
Source§impl PartialEq for LocalInfileHandler
impl PartialEq for LocalInfileHandler
impl Eq for LocalInfileHandler
Auto Trait Implementations§
impl Freeze for LocalInfileHandler
impl RefUnwindSafe for LocalInfileHandler
impl Send for LocalInfileHandler
impl Sync for LocalInfileHandler
impl Unpin for LocalInfileHandler
impl UnwindSafe for LocalInfileHandler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more