Mysql_protocol.Mp_client
MySQL 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_error
Raise 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 -> string
Convert MySQL exception to string.
val dml_dcl_result_to_string : dml_dcl_result -> string
Convert 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 ->
configuration
Build client configuration.
val connect : configuration:configuration -> ?force:bool -> unit -> connection
Connection to the server.
val change_user :
connection:connection ->
user:string ->
password:string ->
?databasename:string ->
?charset:(Mp_charset.charset_name * Mp_charset.collation_name) ->
unit ->
configuration
Change user / databasename / charset
val reset_session : connection:connection -> unit
Reset the session : equivalent to a disconnect/reconnect with the same configuration.
val reset_connection : connection:connection -> unit
Reset the connection without re-authentication. From documentation), this will:
Database will NOT be reset to initial value.
val use_database : connection:connection -> databasename:string -> unit
Change current database.
val ping : connection:connection -> unit
Send a PING to the server.
val create_statement_from_string : string -> executable_statement
Create a new statement from a SQL string.
val prepare :
connection:connection ->
statement:executable_statement ->
executable_statement
Prepare a statement.
val get_created_statement : executable_statement -> string
Extract the statement from an executable statement.
val get_prepared_statement : executable_statement -> string * prepare_result
Extract 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_result
Execute a statement (prepared or not prepared) and return the result.
val get_result : execute_result -> result
Extract the result part from an executed result.
val get_result_multiple : execute_result -> result list
Extract the multiple part from an executed result (for CALL result).
val get_result_set : result -> Mp_result_set_packet.result_select
Extract the set part from a result (for SELECT result).
val get_result_ok : result -> dml_dcl_result
Extract 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 ->
result
Fetch 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_select
Extract the set part from a fetch.
val close_statement :
connection:connection ->
statement:executable_statement ->
unit
Close and destroy the prepared statement. It will be unusable.
val disconnect : connection:connection -> unit
Close the connection to the server.