pub struct LocalInfileHandler(_);
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.

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);

Implementations§

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.