Mysql_protocol.Mp_clientMySQL Protocol natively implements the MySQL client protocol (ie without any binding to C library).
License:
External dependencies:
Tested configurations:
The following functionalities are not implemented:
Known limitations:
Usage examples:
type client_error = {client_error_errno : int; | (* error number *) |
client_error_sqlstate : string; | (* state *) |
client_error_message : string; | (* error message *) |
}MySQL error.
exception Error of client_errorRaise if the MySQL server returns an error.
type configuration = {sockaddr : Unix.sockaddr; | (* socket *) |
capabilities : Mp_capabilities.capabilities list; | (* capabilities *) |
max_packet_size : Stdlib.Int64.t; | (* max packet size *) |
charset_number : int; | (* charset *) |
user : string; | (* login *) |
password : string; | (* password *) |
databasename : string; | (* database name (can be empty) *) |
}Client configuration.
type connection = {configuration : configuration; | (* configuration *) |
mutable channel : (Stdlib.in_channel * Stdlib.out_channel) option; | (* channel between client and server *) |
mutable handshake : Mp_handshake.handshake option; | (* handshake answer from the server *) |
}Client connection.
type dml_dcl_result = {}DML (Data Manipulation Language) and DCL (Data Control Language) result. Result of INSERT, UPDATE, GRANT... statements.
insert_id can be negative in two cases:
Unfortunately, the protocol gives no way to differentiate these two cases (see this bug report). So we return two values:
type prepare_result = {prepare_handler : Stdlib.Int64.t; |
prepare_nb_columns : int; |
prepare_nb_parameters : int; |
prepare_warning_count : int; |
prepare_parameters_fields : Mp_field_packet.field_packet list; |
prepare_parameters_names : Mp_field.field_name list; |
prepare_columns_fields : Mp_field_packet.field_packet list; |
prepare_columns_names : Mp_field.field_name list; |
}Result for a prepare command.
val error_exception_to_string : client_error -> stringConvert MySQL exception to string.
val dml_dcl_result_to_string : dml_dcl_result -> stringConvert DML (Data Manipulation Language) and DCL (Data Control Language) result to string.
val configuration :
user:string ->
password:string ->
sockaddr:Unix.sockaddr ->
?databasename:string ->
?max_packet_size:Stdlib.Int64.t ->
?charset:(Mp_charset.charset_name * Mp_charset.collation_name) ->
?capabilities:Mp_capabilities.capabilities list ->
unit ->
configurationBuild client configuration.
val connect : configuration:configuration -> ?force:bool -> unit -> connectionConnection to the server.
val change_user :
connection:connection ->
user:string ->
password:string ->
?databasename:string ->
?charset:(Mp_charset.charset_name * Mp_charset.collation_name) ->
unit ->
configurationChange user / databasename / charset
val reset_session : connection:connection -> unitReset the session : equivalent to a disconnect/reconnect with the same configuration.
val reset_connection : connection:connection -> unitReset the connection without re-authentication. From documentation), this will:
Database will NOT be reset to initial value.
val use_database : connection:connection -> databasename:string -> unitChange current database.
val ping : connection:connection -> unitSend a PING to the server.
val create_statement_from_string : string -> executable_statementCreate a new statement from a SQL string.
val prepare :
connection:connection ->
statement:executable_statement ->
executable_statementPrepare a statement.
val get_created_statement : executable_statement -> stringExtract the statement from an executable statement.
val get_prepared_statement : executable_statement -> string * prepare_resultExtract the prepared statement from an executable statement.
val execute :
connection:connection ->
statement:executable_statement ->
?filter:( (string * int) list -> Mp_data.t list -> bool ) option ->
?iter:( (string * int) list -> Mp_data.t list -> unit ) option ->
?return_all_raw_mysql_data:bool ->
?params:Mp_data.t list ->
?bind:Mp_execute.bind ->
?flag:Mp_execute.flag ->
unit ->
execute_resultExecute a statement (prepared or not prepared) and return the result.
val get_result : execute_result -> resultExtract the result part from an executed result.
val get_result_multiple : execute_result -> result listExtract the multiple part from an executed result (for CALL result).
val get_result_set : result -> Mp_result_set_packet.result_selectExtract the set part from a result (for SELECT result).
val get_result_ok : result -> dml_dcl_resultExtract the ok part from a result (for INSERT, UPDATE, GRANT... result).
val fetch :
connection:connection ->
statement:execute_result ->
?nb_rows:int64 ->
?filter:( (string * int) list -> Mp_data.t list -> bool ) option ->
?iter:( (string * int) list -> Mp_data.t list -> unit ) option ->
?return_all_raw_mysql_data:bool ->
unit ->
resultFetch row(s) from an executed result. It must be a prepared statement executed with a cursor.
val get_fetch_result_set : result -> Mp_result_set_packet.result_selectExtract the set part from a fetch.
val close_statement :
connection:connection ->
statement:executable_statement ->
unitClose and destroy the prepared statement. It will be unusable.
val disconnect : connection:connection -> unitClose the connection to the server.