[−][src]Trait mysql_async::prelude::LocalInfileHandler
Trait used to handle local infile requests.
Be aware of security issues with LOAD DATA LOCAL.
Using crate::WhiteListFsLocalInfileHandler
is advised.
Simple handler example:
struct ExampleHandler(&'static [u8]); impl LocalInfileHandler for ExampleHandler { fn handle(&self, _: &[u8]) -> mysql_async::InfileHandlerFuture { let handler = Box::new(self.0) as Box<_>; Box::pin(async move { Ok(handler) }) } } let mut opts = mysql_async::OptsBuilder::from_opts(&*database_url); opts.local_infile_handler(Some(ExampleHandler(b"foobar"))); let pool = mysql_async::Pool::new(opts); let conn = pool.get_conn().await?; let conn = conn.drop_query("CREATE TEMPORARY TABLE tmp (a TEXT);").await?; let conn = match conn.drop_query("LOAD DATA LOCAL INFILE 'baz' INTO TABLE tmp;").await { Ok(conn) => conn, Err(mysql_async::error::Error::Server(ref err)) if err.code == 1148 => { // The used command is not allowed with this MySQL version return Ok(()); }, Err(mysql_async::error::Error::Server(ref err)) if err.code == 3948 => { // Loading local data is disabled; // this must be enabled on both the client and server sides return Ok(()); } e@Err(_) => e.unwrap(), }; let result = conn.prep_exec("SELECT * FROM tmp;", ()).await?; let (_ /* conn */, result) = result.map_and_drop(|row| { mysql_async::from_row::<(String,)>(row).0 }).await?; assert_eq!(result.len(), 1); assert_eq!(result[0], "foobar"); pool.disconnect().await?;
Required methods
fn handle(&self, file_name: &[u8]) -> InfileHandlerFuture
file_name
is the file name in LOAD DATA LOCAL INFILE '<file name>' INTO TABLE ...;
query.