pub trait LocalInfileHandler: Sync + Send {
    fn handle(
        &self,
        file_name: &[u8]
    ) -> BoxFuture<Box<dyn AsyncRead + Send + 'static>>; }
Expand description

Trait used to handle local infile requests.

Simple handler example:




struct ExampleHandler(&'static [u8]);

impl LocalInfileHandler for ExampleHandler {
    fn handle(&self, _: &[u8]) -> Box<Future<Item=Box<AsyncRead + Send>, Error=my::errors::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.kind() {
        my::errors::ErrorKind::Server(_, 1148, _) => {
            // The used command is not allowed with this MySQL version
        },
        _ => panic!("{}", err),
    });

    run(future);

Required Methods§

file_name is the file name in LOAD DATA LOCAL INFILE '<file name>' INTO TABLE ...; query.

Implementors§