OceanBase
English日本語简体中文
Docs Home
Products
Integrations
Release Notes

Databases

OceanBase DatabaseOceanBase Cloud OceanBase Best Practices

Tools

OceanBase Cloud PlatformOceanBase Migration ServiceOceanBase Developer CenterOceanBase Migration AssessmentOceanBase Admin ToolOceanBase Loader and DumperOceanBase DeployerKubernetes operator for OceanBaseOceanBase Diagnostic Tool OceanBase Binlog Service

Connectors and Middleware

OceanBase Database Proxy OceanBase Connector/C OceanBase Connector/J OceanBase Connector/ODBC OceanBase Connector/NETOceanBase Command-Line Client

Databases

OceanBase DatabaseOceanBase Cloud OceanBase Best Practices

Connectors and Middleware

OceanBase Database Proxy OceanBase Connector/C OceanBase Connector/J OceanBase Connector/ODBC OceanBase Connector/NETOceanBase Command-Line Client

Tools

OceanBase Cloud PlatformOceanBase Migration ServiceOceanBase Developer CenterOceanBase Migration AssessmentOceanBase Admin ToolOceanBase Loader and DumperOceanBase DeployerKubernetes operator for OceanBaseOceanBase Diagnostic Tool OceanBase Binlog Service
OceanBase DatabaseOceanBase Cloud ToolsConnectors and MiddlewareLifecycle Support Policy

OceanBase Connector/C

V2.0.0
  • Overview
  • Installation guide
  • User Guide
    • Basic data structures
    • Basic operations
      • Basic API operations
      • API operations on prepared statements
  • C API functions
    • Overview
    • my_init()
    • mysql_affected_rows()
    • mysql_autocommit()
    • mysql_change_user()
    • mysql_character_set_name()
    • mysql_client_find_plugin()
    • mysql_client_register_plugin()
    • mysql_close()
    • mysql_commit()
    • mysql_connect()
    • mysql_create_db()
    • mysql_data_seek()
    • mysql_debug()
    • mysql_drop_db()
    • mysql_dump_debug_info()
    • mysql_eof()
    • mysql_errno()
    • mysql_error()
    • mysql_escape_string()
    • mysql_fetch_field()
    • mysql_fetch_field_direct()
    • mysql_fetch_fields()
    • mysql_fetch_lengths()
    • mysql_fetch_row()
    • mysql_field_count()
    • mysql_field_seek()
    • mysql_field_tell()
    • mysql_free_result()
    • mysql_get_character_set_info()
    • mysql_get_client_info()
    • mysql_get_client_version()
    • mysql_get_host_info()
    • mysql_get_proto_info()
    • mysql_get_server_info()
    • mysql_get_server_version()
    • mysql_get_ssl_cipher()
    • mysql_hex_string()
    • mysql_info()
    • mysql_init()
    • mysql_insert_id()
    • mysql_kill()
    • mysql_library_end()
    • mysql_library_init()
    • mysql_list_dbs()
    • mysql_list_fields()
    • mysql_list_processes()
    • mysql_list_tables()
    • mysql_load_plugin()
    • mysql_load_plugin_v()
    • mysql_more_results()
    • mysql_next_result()
    • mysql_num_fields()
    • mysql_num_rows()
    • mysql_options()
    • mysql_options4()
    • mysql_ping()
    • mysql_plugin_options()
    • mysql_query()
    • mysql_real_connect()
    • mysql_real_escape_string()
    • mysql_real_query()
    • mysql_refresh()
    • mysql_reload()
    • mysql_rollback()
    • mysql_row_seek()
    • mysql_row_tell()
    • mysql_select_db()
    • mysql_server_end()
    • mysql_server_init()
    • mysql_set_character_set()
    • mysql_set_local_infile_default()
    • mysql_set_local_infile_handler()
    • mysql_set_server_option()
    • mysql_shutdown()
    • mysql_sqlstate()
    • mysql_ssl_set()
    • mysql_stat()
    • mysql_stmt_affected_rows()
    • mysql_stmt_attr_get()
    • mysql_stmt_attr_set()
    • mysql_stmt_bind_param()
    • mysql_stmt_bind_result()
    • mysql_stmt_close()
    • mysql_stmt_data_seek()
    • mysql_stmt_errno()
    • mysql_stmt_error()
    • mysql_stmt_execute()
    • mysql_stmt_fetch()
    • mysql_stmt_fetch_column()
    • mysql_stmt_field_count()
    • mysql_stmt_free_result()
    • mysql_stmt_init()
    • mysql_stmt_insert_id()
    • mysql_stmt_next_result()
    • mysql_stmt_num_rows()
    • mysql_stmt_param_count()
    • mysql_stmt_param_metadata()
    • mysql_stmt_prepare()
    • mysql_stmt_reset()
    • mysql_stmt_result_metadata()
    • mysql_stmt_row_seek()
    • mysql_stmt_row_tell()
    • mysql_stmt_send_long_data()
    • mysql_stmt_sqlstate()
    • mysql_stmt_store_result()
    • mysql_store_result()
    • mysql_thread_end()
    • mysql_thread_id()
    • mysql_thread_init()
    • mysql_thread_safe()
    • mysql_use_result()
    • mysql_warning_count()

Download PDF

Document Feedback
  1. Documentation Center
  2. OceanBase Connector/C
  3. V2.0.0

mysql_set_local_infile_handler()

Last Updated:2026-09-04 08:24:09

Syntax
Return values
Errors
Notes

You can call the mysql_set_local_infile_handler() function to install callbacks to be used during the execution of LOAD DATA LOCAL statements.

Syntax

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

Return values

None.

Errors

None.

Notes

mysql_set_local_infile_handler() enables application programs to control 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.

To use mysql_set_local_infile_handler(), you must write the following callback functions:

  • Initialization function: It is called once to perform necessary settings, open the data file, allocate data structures, and so on.

    int
    local_infile_init(void **ptr, const char *filename, void *userdata);
    

    The first void** argument is a pointer to a pointer. You can set the pointer (that is, *ptr) to a value to be passed to other callbacks (as a void*). The callbacks can use this pointed-to value to maintain status information. The value of the userdata argument is the same as that passed to mysql_set_local_infile_handler(). The initialization function returns 0 for an operation success, a non-zero value if an error occurred.

  • Data reading function: It is called repeatedly to read the data file.

    int
    local_infile_read(void *ptr, char *buf, unsigned int buf_len);
    

    buf points to the buffer that stores the read data, and buf_len indicates the maximum number of bytes that can be read during a callback and are stored in the buffer. The return value is the number of bytes that have been read, or 0 when no more data could be read (indicating EOF). If an error occurs, a value smaller than 0 is returned.

  • Termination function: It is called once after local_infile_read() returns 0 (EOF) or an error.

    void
    local_infile_end(void *ptr)
    

    Within this function, the memory allocated by local_infile_init() is freed and necessary cleanup is performed. It is called even if the initialization function returns an error.

  • Error handling function: It is called to obtain a textual error message and return the error message to the user when any of other functions returns an error.

    int
    local_infile_error(void *ptr,
                       char *error_msg,
                       unsigned int error_msg_len);
    

    error_msg points to the buffer into which the message is written, and error_msg_len indicates the length of the buffer. The message is written as a null-terminated string, with a maximum length of error_msg_len−1 bytes. The return value is an error number.

    Generally, other callbacks store an error message in the data structure that ptr points to, so that local_infile_error() can copy the message to error_msg.

After calling mysql_set_local_infile_handler() in C code and passing pointers to the callback functions, you can issue a LOAD DATA LOCAL statement by using mysql_real_query() or mysql_query(). The client library automatically calls the callbacks. The file name specified in LOAD DATA LOCAL will be passed as the second argument to the local_infile_init() callback.

Previous topic

mysql_set_local_infile_default()
Last

Next topic

mysql_set_server_option()
Next
on this page
Syntax
Return values
Errors
Notes