Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add mysql_stmt_insert_id binding #58

Merged
merged 2 commits into from
Oct 14, 2024
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
3 changes: 3 additions & 0 deletions bindings/ffi_bindings.ml
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ module Bindings (F : Cstubs.FOREIGN) = struct
let mysql_stmt_affected_rows = foreign "mysql_stmt_affected_rows"
(stmt @-> returning ullong)

let mysql_stmt_insert_id = foreign "mysql_stmt_insert_id"
(stmt @-> returning ullong)

(* Blocking API *)

let mysql_free_result = foreign "mysql_free_result"
Expand Down
3 changes: 3 additions & 0 deletions lib/binding_wrappers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ let mysql_stmt_num_rows stmt =
let mysql_stmt_affected_rows stmt =
Unsigned.ULLong.to_int @@ B.mysql_stmt_affected_rows stmt

let mysql_stmt_insert_id stmt =
Unsigned.ULLong.to_int @@ B.mysql_stmt_insert_id stmt

(* Blocking API *)

let mysql_real_connect mysql host user pass db port socket flags =
Expand Down
3 changes: 3 additions & 0 deletions lib/blocking.ml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ module Res = struct

let affected_rows =
Common.Res.affected_rows

let insert_id =
Common.Res.insert_id
end

module Stmt = struct
Expand Down
3 changes: 3 additions & 0 deletions lib/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ module Res = struct
let affected_rows res =
B.mysql_stmt_affected_rows res.stmt

let insert_id res =
B.mysql_stmt_insert_id res.stmt

let fetch_field raw i =
coerce (ptr void) (ptr T.Field.t) (B.mysql_fetch_field_direct raw i)

Expand Down
1 change: 1 addition & 0 deletions lib/mariadb.ml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ module type S = sig

val num_rows : t -> int
val affected_rows : t -> int
val insert_id : t -> int
val fetch : (module Row.S with type t = 'r) -> t -> 'r option result
end

Expand Down
9 changes: 8 additions & 1 deletion lib/mariadb.mli
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,15 @@ module type S = sig
the execution of a [SELECT]-type query. *)

val affected_rows : t -> int
(** [num_rows res] returns the number of affected rows in result [res]
(** [affected_rows res] returns the number of affected rows in result [res]
after the execution of an [INSERT] or [UPDATE]-type query. *)

val insert_id : t -> int
(** [insert_id res] returns the ID generated by a prepared statement on a table
with a column having the [AUTO_INCREMENT] attribute. If the last query wasn't
an [INSERT] or [UPDATE] statement or if the modified table does not have a column
with the [AUTO_INCREMENT] attribute, this function will return zero. *)

val fetch : (module Row.S with type t = 'r) -> t -> 'r option result
(** [fetch (module M : Row.S) res] fetches the next available row
from [res], returning it in as the data structure specified by
Expand Down Expand Up @@ -420,6 +426,7 @@ module Nonblocking : sig

val num_rows : t -> int
val affected_rows : t -> int
val insert_id : t -> int
val fetch : (module Row.S with type t = 'r) -> t
-> 'r option result future
end
Expand Down
7 changes: 7 additions & 0 deletions lib/nonblocking.ml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ module Res = struct
let affected_rows =
Common.Res.affected_rows

let insert_id =
Common.Res.insert_id

let handle_fetch (type t) (module R : Row.S with type t = t) res = function
| 0, 0 ->
`Ok (Common.Res.build_row (module R) res)
Expand Down Expand Up @@ -428,6 +431,7 @@ module type S = sig

val num_rows : t -> int
val affected_rows : t -> int
val insert_id : t -> int
val fetch : (module Row.S with type t = 'r) -> t -> 'r option result future
end

Expand Down Expand Up @@ -618,6 +622,9 @@ module Make (W : Wait) : S with type 'a future = 'a W.IO.future = struct
let affected_rows =
Res.affected_rows

let insert_id =
Res.insert_id

let free res =
nonblocking res.Common.Res.mariadb (Res.free res)
end
Expand Down