File: populate.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 (19 lines) | stat: -rw-r--r-- 546 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
if (Array.length Sys.argv <> 3) then (Printf.printf "\
   Usage:  populate conninfo table
   Connect to Postgres with [conninfo] (e.g. \"host=glouglou\"),
   and copy stdin to [table]
"; exit 1);;


let main() =
  let c = new Postgres.connection Sys.argv.(1) in
  let _ = c#exec_expect ("copy "^(Sys.argv.(2))^" from stdin") 
	    [Postgres.Result.Copy_in] in
  c#copy_in_channel stdin;
  c#close

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