1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192(* Copyright (C) 2017--2025 Petter A. Urkedal <paurkedal@gmail.com>
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at your
* option) any later version, with the LGPL-3.0 Linking Exception.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* and the LGPL-3.0 Linking Exception along with this library. If not, see
* <http://www.gnu.org/licenses/> and <https://spdx.org>, respectively.
*)[@@@alert"-caqti_private"]moduleLog=(valLogs.src_log(Logs.Src.create"caqti"))typeprepare_policy=|Direct|Dynamic|Statictype('a,'b,+'m)t={id:intoption;prepare_policy:prepare_policy;query:Dialect.t->Query.t;param_type:'aRow_type.t;row_type:'bRow_type.t;row_mult:'mRow_mult.t;}constraint'm=[<`Zero|`One|`Many]letlast_id=ref(-1)letcreateprepare_policy(param_type,row_type,row_mult)query=letid=(matchprepare_policywith|Direct->None|Static|Dynamic->incrlast_id;Some!last_id)in{id;prepare_policy;query;param_type;row_type;row_mult}letprepare_policyrequest=request.prepare_policyletparam_typerequest=request.param_typeletrow_typerequest=request.row_typeletrow_multrequest=request.row_multletquery_idrequest=request.idletqueryrequest=request.queryletempty_subst_=raiseNot_foundletdefault_dialect=Dialect.create_unknown~purpose:`Printing()letmake_pp?(dialect=default_dialect)?(subst=empty_subst)()ppfreq=letquery=Query.expandsubst(req.querydialect)inFormat.fprintfppf"(%a -->%s %a) {|%a|}"Row_type.ppreq.param_type(matchRow_mult.exposereq.row_multwith|`Zero->"."|`One->""|`Zero_or_one->"?"|`Zero_or_more->"*")Row_type.ppreq.row_typeQuery.ppqueryletppppf=make_pp()ppfletpp_with_param_enabled=(matchSys.getenv"CAQTI_DEBUG_PARAM"with|"true"->true|"false"->false|s->Log.err(funf->f"Invalid value %s for CAQTI_DEBUG_PARAM, assuming false."s);false|exceptionNot_found->false)letmake_pp_with_param?dialect?subst()ppf(req,param)=letpp=make_pp?subst?dialect()inppppfreq;ifpp_with_param_enabledthenFormat.fprintfppf" %a"Row_type.pp_value(req.param_type,param)typeliveness_witness=intoptionletliveness_witnessrequest=assert(request.id<>None);request.id