Created
June 4, 2019 23:27
-
-
Save appblue/c0b551617db1f6c691f3d1b19c448049 to your computer and use it in GitHub Desktop.
Ocaml db access
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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