File: test_lo.ml

package info (click to toggle)
postgresql-ocaml 1.5.4-2%2Betch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 320 kB
  • ctags: 536
  • sloc: ml: 1,143; ansic: 524; sh: 118; makefile: 99
file content (26 lines) | stat: -rw-r--r-- 647 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
(* A simple demonstration of Large Objects manipulation *)

open Postgresql

let _ =
  if Array.length Sys.argv <> 2 then (
    Printf.eprintf "Usage:  %s conninfo\n" Sys.argv.(0);
    exit 1)

let conninfo = Sys.argv.(1)

let main () =
  let c = new connection ~conninfo () in
  let _ = c#exec ~expect:[Command_ok] "begin" in
  let oid = c#lo_creat in
  let lo = c#lo_open oid in
  c#lo_write "Hello world !\n" lo;
  c#lo_close lo;
  c#lo_export oid "/dev/stdout";
  let _ = c#exec ~expect:[Command_ok] "end" in
  c#finish

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