Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions bindings/ffi_bindings.ml
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@ module Bindings (F : Cstubs.FOREIGN) = struct
let mysql_stmt_free_result = foreign "mysql_stmt_free_result"
(stmt @-> returning my_bool)

let mysql_real_query = foreign "mysql_real_query"
(mysql @-> ptr char @-> ulong @-> returning int)

(* Nonblocking API *)

let mysql_close_start = foreign "mysql_close_start"
Expand Down Expand Up @@ -447,4 +450,10 @@ module Bindings (F : Cstubs.FOREIGN) = struct

let mysql_stmt_next_result_cont = foreign "mysql_stmt_next_result_cont"
(ptr int @-> stmt @-> int @-> returning int)

let mysql_real_query_start = foreign "mysql_real_query_start"
(ptr int @-> mysql @-> ptr char @-> ulong @-> returning int)

let mysql_real_query_cont = foreign "mysql_real_query_cont"
(ptr int @-> mysql @-> int @-> returning int)
end
13 changes: 13 additions & 0 deletions lib/binding_wrappers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ let mysql_stmt_store_result stmt =
let mysql_stmt_free_result stmt =
B.mysql_stmt_free_result stmt = '\000'

let mysql_real_query mysql query =
let len = Unsigned.ULong.of_int (String.length query) in
let query = char_ptr_buffer_of_string query in
B.mysql_real_query mysql query len = 0

(* Nonblocking API *)

let mysql_real_connect_start mysql host user pass db port socket flags =
Expand Down Expand Up @@ -220,3 +225,11 @@ let mysql_stmt_next_result_start stmt =

let mysql_stmt_next_result_cont stmt status =
handle_int (fun err -> B.mysql_stmt_next_result_cont err stmt status)

let mysql_real_query_start mysql query =
let len = Unsigned.ULong.of_int (String.length query) in
let query = char_ptr_buffer_of_string query in
handle_int (fun err -> B.mysql_real_query_start err mysql query len)

let mysql_real_query_cont mysql status =
handle_int (fun err -> B.mysql_real_query_cont err mysql status)
3 changes: 3 additions & 0 deletions lib/blocking.ml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ let prepare mariadb query =
| Some raw -> build_stmt raw
| None -> Error (2008, "out of memory")

let start_txn mariadb =
wrap_unit mariadb (B.mysql_real_query mariadb.Common.raw "START TRANSACTION")

module Res = struct
type t = [`Blocking] Common.Res.t

Expand Down
1 change: 1 addition & 0 deletions lib/mariadb.ml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ module type S = sig
val set_server_option : t -> server_option -> unit result
val ping : t -> unit result
val autocommit : t -> bool -> unit result
val start_txn : t -> unit result
val commit : t -> unit result
val rollback : t -> unit result
val prepare : t -> string -> Stmt.t result
Expand Down
3 changes: 3 additions & 0 deletions lib/mariadb.mli
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ module type S = sig
val autocommit : t -> bool -> unit result
(** Sets autocommit mode on or off. *)

val start_txn : t -> unit result

val commit : t -> unit result
(** Commits the current transaction. *)

Expand Down Expand Up @@ -510,6 +512,7 @@ module Nonblocking : sig
val set_server_option : t -> server_option -> unit result future
val ping : t -> unit result future
val autocommit : t -> bool -> unit result future
val start_txn : t -> unit result future
val commit : t -> unit result future
val rollback : t -> unit result future
val prepare : t -> string -> Stmt.t result future
Expand Down
12 changes: 12 additions & 0 deletions lib/nonblocking.ml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ let rollback_cont mariadb status =
let rollback mariadb =
(rollback_start mariadb, rollback_cont mariadb)

let start_txn_start mariadb =
handle_int mariadb (B.mysql_real_query_start mariadb.Common.raw "START TRANSACTION")

let start_txn_cont mariadb status =
handle_int mariadb (B.mysql_real_query_cont mariadb.Common.raw status)

let start_txn mariadb =
(start_txn_start mariadb, start_txn_cont mariadb)

let build_stmt mariadb raw =
`Ok (Common.Stmt.init mariadb raw)

Expand Down Expand Up @@ -516,6 +525,7 @@ module type S = sig
val set_server_option : t -> server_option -> unit result future
val ping : t -> unit result future
val autocommit : t -> bool -> unit result future
val start_txn : t -> unit result future
val commit : t -> unit result future
val rollback : t -> unit result future
val prepare : t -> string -> Stmt.t result future
Expand Down Expand Up @@ -704,6 +714,8 @@ module Make (W : Wait) : S with type 'a future = 'a W.IO.future = struct

let autocommit m b = nonblocking m (autocommit m b)

let start_txn m = nonblocking m (start_txn m)

let commit m = nonblocking m (commit m)

let rollback m = nonblocking m (rollback m)
Expand Down