[−][src]Trait mysql_async::prelude::LocalInfileHandler
Trait used to handle local infile requests.
Be aware of security issues with LOAD DATA LOCAL.
Using WhiteListFsLocalInfileHandler
is advised.
Simple handler example:
struct ExampleHandler(&'static [u8]); impl LocalInfileHandler for ExampleHandler { fn handle(&self, _: &[u8]) -> Box<Future<Item=Box<AsyncRead + Send>, Error=my::error::Error> + Send> { Box::new(futures::future::ok(Box::new(self.0) as Box<_>)) } } let mut opts = my::OptsBuilder::from_opts(&*database_url); opts.local_infile_handler(Some(ExampleHandler(b"foobar"))); let pool = my::Pool::new(opts); let future = pool.get_conn() .and_then(|conn| conn.drop_query("CREATE TEMPORARY TABLE tmp (a TEXT);")) .and_then(|conn| conn.drop_query("LOAD DATA LOCAL INFILE 'baz' INTO TABLE tmp;")) .and_then(|conn| conn.prep_exec("SELECT * FROM tmp;", ())) .and_then(|result| result.map_and_drop(|row| my::from_row::<(String,)>(row).0)) .map(|(_ /* conn */, result)| { assert_eq!(result.len(), 1); assert_eq!(result[0], "foobar"); }) .and_then(|_| pool.disconnect()) .map_err(|err| match err { my::error::Error::Server(ref err) if err.code == 1148 => { // The used command is not allowed with this MySQL version }, _ => panic!("{}", err), }); run(future);
Required methods
fn handle(
&self,
file_name: &[u8]
) -> BoxFuture<Box<dyn AsyncRead + Send + 'static>>
&self,
file_name: &[u8]
) -> BoxFuture<Box<dyn AsyncRead + Send + 'static>>
file_name
is the file name in LOAD DATA LOCAL INFILE '<file name>' INTO TABLE ...;
query.