Skip to content

Commit 52bbf8b

Browse files
committed
Fixed broken copy_out method
1 parent 5ee63df commit 52bbf8b

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

lib/postgresql.ml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -843,19 +843,22 @@ object (self)
843843
let len = 512 in
844844
let s = String.create len in
845845
wrap_conn (fun conn ->
846-
let rec loop r =
847-
let zero = String.index s '\000' in
848-
Buffer.add_substring buf s 0 zero;
849-
match r with
850-
| 0 -> f (Buffer.contents buf); Buffer.clear buf; line ()
851-
| 1 -> loop (Stub.getline conn s 0 len)
852-
| _ -> f (Buffer.contents buf)
853-
and line () =
846+
let rec loop () =
854847
let r = Stub.getline conn s 0 len in
855-
if r < 3 || s.[0] <> '\\' || s.[1] <> '.' || s.[2] <> '\000' then
856-
loop r
848+
if r = 1 then begin (* Buffer full *)
849+
Buffer.add_substring buf s 0 len;
850+
loop ()
851+
end
852+
else if r = 0 then (* Line read *)
853+
let zero = String.index s '\000' in
854+
Buffer.add_substring buf s 0 zero;
855+
match Buffer.contents buf with
856+
| "\\." -> ()
857+
| line -> Buffer.clear buf; f line; loop ()
858+
else if r = -1 then raise End_of_file
859+
else assert false (* impossible *)
857860
in
858-
line ());
861+
loop ());
859862
self#endcopy
860863

861864
method copy_out_channel oc =

0 commit comments

Comments
 (0)