@@ -252,6 +252,19 @@ module Res = struct
252252
253253 let fetch (type t ) (module R : Row.S with type t = t ) res =
254254 (fetch_start (module R ) res, fetch_cont (module R ) res)
255+
256+ let handle_free = function
257+ | 0 -> `Ok
258+ | s -> `Wait (Status. of_int s)
259+
260+ let free_start res =
261+ handle_free (B. mysql_free_result_start res)
262+
263+ let free_cont res status =
264+ handle_free (B. mysql_free_result_cont res status)
265+
266+ let free res =
267+ (free_start res, free_cont res)
255268end
256269
257270module Stmt = struct
@@ -635,35 +648,47 @@ module Make (W : Wait) : S with type 'a future = 'a W.IO.future = struct
635648
636649 let insert_id =
637650 Res. insert_id
651+
652+ let free = (* not public, but to avoid shadowing *)
653+ Res. free
638654 end
639655
640656 module Stmt = struct
641657 type t = Stmt .t
642658
659+ let free_meta stmt =
660+ match stmt.Common.Stmt. meta with
661+ | None -> return ()
662+ | Some { res; _ } ->
663+ stmt.Common.Stmt. meta < - None ;
664+ nonblocking' stmt.Common.Stmt. mariadb (Res. free res)
665+
666+ let free_meta_and_result stmt =
667+ match stmt.Common.Stmt. meta with
668+ | None -> return (Ok () )
669+ | Some { res; _ } ->
670+ stmt.Common.Stmt. meta < - None ;
671+ nonblocking' stmt.Common.Stmt. mariadb (Res. free res) >> = fun () ->
672+ nonblocking stmt.Common.Stmt. mariadb (Stmt. free_result stmt)
673+
643674 let handle_execute = function
644675 | Ok stmt -> nonblocking stmt.Common.Stmt. mariadb (Stmt. store_result stmt)
645676 | Error _ as e -> return e
646677
647678 let execute stmt ps =
679+ free_meta stmt >> = fun () ->
648680 match Stmt. execute stmt ps with
649681 | `Ok nb -> nonblocking stmt.Common.Stmt. mariadb nb >> = handle_execute
650682 | `Error e -> return (Error e)
651683
652- let free_res stmt =
653- if stmt.Common.Stmt. meta = None then return (Ok () ) else
654- begin
655- Common.Stmt. free_meta stmt;
656- nonblocking stmt.Common.Stmt. mariadb (Stmt. free_result stmt)
657- end
658-
659684 let reset stmt =
660- free_res stmt
685+ free_meta_and_result stmt
661686 >> = function
662687 | Ok () -> nonblocking stmt.Common.Stmt. mariadb (Stmt. reset stmt)
663688 | Error _ as e -> return e
664689
665690 let close stmt =
666- free_res stmt
691+ free_meta_and_result stmt
667692 >> = function
668693 | Ok () -> nonblocking stmt.Common.Stmt. mariadb (Stmt. close stmt)
669694 | Error _ as e -> return e
0 commit comments