[]Struct c3p0_mysql::r2d2::mysql::LocalInfileHandler

pub struct LocalInfileHandler(_);

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.

conn.query("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("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;
    },
    err => {
        err.unwrap();
    },
}

let mut row_num = 0;
for (row_idx, row) in conn.query("SELECT * FROM mysql.tbl").unwrap().enumerate() {
    row_num = row_idx + 1;
    let row: (String,) = from_row(row.unwrap());
    match row_num {
        1 => assert_eq!(row.0, "row1: file name is file_name"),
        2 => assert_eq!(row.0, "row2: foobar"),
        _ => unreachable!(),
    }
}

assert_eq!(row_num, 2);

Methods

impl LocalInfileHandler

pub fn new<F>(f: F) -> LocalInfileHandler where
    F: for<'a, 'a> FnMut(&'a [u8], &'a mut LocalInfile) -> Result<(), Error> + Send + 'static, 

Trait Implementations

impl Eq for LocalInfileHandler

impl Clone for LocalInfileHandler

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for LocalInfileHandler

impl PartialEq<LocalInfileHandler> for LocalInfileHandler

#[must_use] fn ne(&self, other: &Rhs) -> bool1.0.0[src]

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self