Skip to content

Instantly share code, notes, and snippets.

@appblue
Created June 4, 2019 23:27
Show Gist options
  • Select an option

  • Save appblue/c0b551617db1f6c691f3d1b19c448049 to your computer and use it in GitHub Desktop.

Select an option

Save appblue/c0b551617db1f6c691f3d1b19c448049 to your computer and use it in GitHub Desktop.
Ocaml db access
open Sqlite3
let result = ref []
let sqls =
["select id || ' ' || name || ' ' || address from x"; "select id from x"]
let _ =
let db = db_open "t" in
sqls
|> List.iter (fun sql ->
print_endline sql ;
print_endline "----------------------" ;
let _ =
exec db sql ~cb:(fun row _ ->
match row.(0) with Some a -> result := a :: !result | _ -> () )
in
() ; print_endline " " ) ;
(* print the results *)
!result |> List.iter (fun x -> Printf.printf "%S\n" x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment