File: test_lo.ml

package info (click to toggle)
libpgsql-ocaml 20040120-6
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 164 kB
  • ctags: 304
  • sloc: ml: 911; ansic: 312; makefile: 138
file content (20 lines) | stat: -rw-r--r-- 630 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
if (Array.length Sys.argv <> 2) then 
  (Printf.eprintf "\n Usage:  %s conninfo\n" Sys.argv.(0); exit 1);;
let conninfo = Sys.argv.(1);;

let main() =
  let c = new Postgres.connection conninfo in
  let _ = c#exec_expect "begin" [Postgres.Result.Command_ok] in
  let oid = c#lo_create in
  let lo  = c#lo_open oid in
  c#lo_write_string lo "Hello world !\n";
  c#lo_close lo;
  c#lo_export oid "/dev/stdout";
  let _ = c#exec_expect "end" [Postgres.Result.Command_ok] in
  c#close

let _ = 
  try main ()
  with 
    | Postgres.Error e -> prerr_endline (Postgres.string_of_error e)
    | e -> prerr_endline (Printexc.to_string e)