void mysql_set_local_infile_handler(MYSQL *mysql, int
(*local_infile_init)(void **, const char *, void *), int
(*local_infile_read)(void *, char *, unsigned int), void
(*local_infile_end)(void *), int (*local_infile_error)(void *,
char*, unsigned int), void *userdata);
This function installs callbacks to be used during the execution
LOAD DATA LOCAL
INFILE statements. It enables application programs to
exert control over local (client-side) data file reading. The
arguments are the connection handler, a set of pointers to
callback functions, and a pointer to a data area that the
callbacks can use to share information.
you must write the following callback functions:
int local_infile_init(void **ptr, const char *filename, void *userdata);
The initialization function. This is called once to do any setup
necessary, open the data file, allocate data structures, and so
forth. The first
void** argument is a pointer
to a pointer. You can set the pointer (that is,
*ptr) to a value that will be passed to each
of the other callbacks (as a
callbacks can use this pointed-to value to maintain state
userdata argument is the
same value that is passed to
The initialization function should return zero for success, nonzero for an error.
int local_infile_read(void *ptr, char *buf, unsigned int buf_len);
The data-reading function. This is called repeatedly to read the
buf points to the buffer where the
read data should be stored, and
the maximum number of bytes that the callback can read and store
in the buffer. (It can read fewer bytes, but should not read
The return value is the number of bytes read, or zero when no more data could be read (this indicates EOF). Return a value less than zero if an error occurs.
void local_infile_end(void *ptr)
The termination function. This is called once after
local_infile_read() has returned zero (EOF)
or an error. This function should deallocate any memory
local_infile_init() and perform
any other cleanup necessary. It is invoked even if the
initalization function returns an error.
int local_infile_error(void *ptr, char *error_msg, unsigned int error_msg_len);
The error-handling function. This is called to get a textual
error message to return to the user in case any of your other
functions returns an error.
to the buffer into which the message should be written, and
error_msg_len is the length of the buffer.
The message should be written as a null-terminated string, so
the message can be at most
error_msg_len–1 bytes long.
The return value is the error number.
Typically, the other callbacks store the error message in the
data structure pointed to by
ptr, so that
local_infile_error() can copy the message
from there into
in your C code and passing pointers to your callback functions,
you can then issue a
LOAD DATA LOCAL
INFILE statement (for example, by using
mysql_query()). The client
library automatically invokes your callbacks. The file name
DATA LOCAL INFILE will be passed as the second
parameter to the
function was added in MySQL 4.1.2.