Skip to content

Commit 9a8cebc

Browse files
committed
Minor copy example cleanups
1 parent cb0deed commit 9a8cebc

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

examples/copy.ml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
open Postgresql
22
open Printf
33

4-
let _ =
5-
if Array.length Sys.argv <> 2 then (
4+
let () =
5+
if Array.length Sys.argv <> 2 then begin
66
Printf.printf "\
77
Usage: copy conninfo\n\
88
Connect to PostgreSQL with [conninfo] (e.g. \"host=localhost\"),\n";
9-
exit 1)
9+
exit 1
10+
end
1011

1112
let create_sql = "\
1213
CREATE TEMPORARY TABLE pgo_copy_test (\
@@ -19,29 +20,29 @@ let populate ?error_msg (c : connection) =
1920
let _ = c#exec ~expect:[Copy_in] "COPY pgo_copy_test (name, x) FROM STDIN" in
2021
for i = 0 to 9999 do
2122
match c#put_copy_data (sprintf "c%d\t%d\n" i i) with
22-
| Put_copy_error | Put_copy_not_queued -> assert false
2323
| Put_copy_queued -> ()
24+
| Put_copy_error | Put_copy_not_queued -> assert false
2425
done;
2526
begin match c#put_copy_end ?error_msg () with
26-
| Put_copy_error | Put_copy_not_queued -> assert false
2727
| Put_copy_queued -> ()
28+
| Put_copy_error | Put_copy_not_queued -> assert false
2829
end;
2930
match c#get_result with
30-
| None -> assert false
3131
| Some result ->
32-
begin match error_msg, result#status with
33-
| None, Command_ok -> ()
34-
| Some _msg, Fatal_error -> ()
35-
| _ -> assert false
36-
end
32+
begin match error_msg, result#status with
33+
| None, Command_ok -> ()
34+
| Some _msg, Fatal_error -> ()
35+
| _ -> assert false end
36+
| None -> assert false
3737

3838
let verify (c : connection) =
39-
let _ =
40-
c#exec ~expect:[Copy_out] "COPY pgo_copy_test (id, name, x) TO STDOUT" in
39+
let _res =
40+
c#exec ~expect:[Copy_out] "COPY pgo_copy_test (id, name, x) TO STDOUT"
41+
in
4142
for i = 0 to 9999 do
4243
match c#get_copy_data () with
4344
| Get_copy_data data ->
44-
assert (data = sprintf "%d\tc%d\t%d\n" (i + 1) i i)
45+
assert (data = sprintf "%d\tc%d\t%d\n" (i + 1) i i)
4546
| Get_copy_wait | Get_copy_end | Get_copy_error -> assert false
4647
done;
4748
match c#get_copy_data () with

0 commit comments

Comments
 (0)