1 (** sqlgg + ocaml + sqlite3 *)
5 type statement
= S.stmt
12 let get_column_Int stmt index
=
13 match S.column stmt index
with
15 | x
-> try Int64.of_string
(S.Data.to_string x
) with _
-> 0L (* or better fail ? *)
17 let get_column_Text stmt index
=
18 let x = S.column stmt index
in
21 let test_ok rc
= let ok = rc
= S.Rc.OK
in assert ok; ok
23 let bind_param d stmt index
=
24 let rc = S.bind stmt
(index
+1) d
in
27 let set_param_null = bind_param S.Data.NULL
28 let set_param_Text stmt index v
= bind_param (S.Data.TEXT v
) stmt index
29 let set_param_Any = set_param_Text
30 let set_param_Int stmt index v
= bind_param (S.Data.INT v
) stmt index
32 let select_exn db sql callback set_params
=
33 let stmt = S.prepare db sql
in
36 while S.Rc.ROW
= S.step
stmt do
40 test_ok (S.finalize
stmt)
42 let execute_exn db sql set_params
=
43 let stmt = S.prepare db sql
in
46 let rc = S.step
stmt in
47 assert (S.Rc.DONE
= rc);
49 test_ok (S.finalize
stmt)
51 (** may @raise exceptions other than Error *)
52 let select db sql cb p
=
54 select_exn db sql cb p
58 let execute db sql p
=