1
1
open Postgresql
2
2
open Printf
3
3
4
- let _ =
5
- if Array. length Sys. argv <> 2 then (
4
+ let () =
5
+ if Array. length Sys. argv <> 2 then begin
6
6
Printf. printf " \
7
7
Usage: copy conninfo\n \
8
8
Connect to PostgreSQL with [conninfo] (e.g. \" host=localhost\" ),\n " ;
9
- exit 1 )
9
+ exit 1
10
+ end
10
11
11
12
let create_sql = " \
12
13
CREATE TEMPORARY TABLE pgo_copy_test (\
@@ -19,29 +20,29 @@ let populate ?error_msg (c : connection) =
19
20
let _ = c#exec ~expect: [Copy_in ] " COPY pgo_copy_test (name, x) FROM STDIN" in
20
21
for i = 0 to 9999 do
21
22
match c#put_copy_data (sprintf " c%d\t %d\n " i i) with
22
- | Put_copy_error | Put_copy_not_queued -> assert false
23
23
| Put_copy_queued -> ()
24
+ | Put_copy_error | Put_copy_not_queued -> assert false
24
25
done ;
25
26
begin match c#put_copy_end ?error_msg () with
26
- | Put_copy_error | Put_copy_not_queued -> assert false
27
27
| Put_copy_queued -> ()
28
+ | Put_copy_error | Put_copy_not_queued -> assert false
28
29
end ;
29
30
match c#get_result with
30
- | None -> assert false
31
31
| 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
37
37
38
38
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
41
42
for i = 0 to 9999 do
42
43
match c#get_copy_data () with
43
44
| Get_copy_data data ->
44
- assert (data = sprintf " %d\t c%d\t %d\n " (i + 1 ) i i)
45
+ assert (data = sprintf " %d\t c%d\t %d\n " (i + 1 ) i i)
45
46
| Get_copy_wait | Get_copy_end | Get_copy_error -> assert false
46
47
done ;
47
48
match c#get_copy_data () with
0 commit comments