2424 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2525*)
2626
27+ open Postgresql_compat
2728open Printf
2829
2930type oid = int
@@ -447,10 +448,10 @@ module Stub = struct
447448 (* Functions Associated with the COPY Command *)
448449
449450 external getline :
450- connection -> string -> int -> int -> int = " PQgetline_stub"
451+ connection -> Bytes .t -> int -> int -> int = " PQgetline_stub"
451452
452453 external getline_async :
453- connection -> string -> int -> int -> int = " PQgetlineAsync_stub" " noalloc"
454+ connection -> Bytes .t -> int -> int -> int = " PQgetlineAsync_stub" " noalloc"
454455
455456 external putline : connection -> string -> int = " PQputline_stub"
456457
@@ -485,7 +486,7 @@ module Stub = struct
485486 external lo_unlink : connection -> oid -> oid = " lo_unlink_stub"
486487
487488 external lo_read :
488- connection -> large_object -> string -> int -> int -> int = " lo_read_stub"
489+ connection -> large_object -> Bytes .t -> int -> int -> int = " lo_read_stub"
489490
490491 external lo_read_ba :
491492 connection -> large_object ->
@@ -856,7 +857,7 @@ object (self)
856857 (* Low level *)
857858
858859 method getline ?(pos = 0 ) ?len buf =
859- let buf_len = String . length buf in
860+ let buf_len = Bytes . length buf in
860861 let len = match len with Some len -> len | None -> buf_len - pos in
861862 if len < 0 || pos < 0 || pos + len > buf_len then
862863 invalid_arg " Postgresql.connection#getline" ;
@@ -868,7 +869,7 @@ object (self)
868869 | _ -> assert false )
869870
870871 method getline_async ?(pos = 0 ) ?len buf =
871- let buf_len = String . length buf in
872+ let buf_len = Bytes . length buf in
872873 let len = match len with Some len -> len | None -> buf_len - pos in
873874 if len < 0 || pos < 0 || pos + len > buf_len then
874875 invalid_arg " Postgresql.connection#getline_async" ;
@@ -877,7 +878,7 @@ object (self)
877878 | - 1 -> if Stub. endcopy conn <> 0 then signal_error conn else EndOfData
878879 | 0 -> NoData
879880 | n when n > 0 ->
880- if buf.[ pos + n - 1 ] = '\n' then DataRead n else PartDataRead n
881+ if Bytes. get buf ( pos + n - 1 ) = '\n' then DataRead n else PartDataRead n
881882 | _ -> assert false )
882883
883884 method putline buf =
@@ -900,17 +901,17 @@ object (self)
900901 method copy_out f =
901902 let buf = Buffer. create 1024 in
902903 let len = 512 in
903- let s = String . create len in
904+ let bts = Bytes . create len in
904905 wrap_conn (fun conn ->
905906 let rec loop () =
906- let r = Stub. getline conn s 0 len in
907+ let r = Stub. getline conn bts 0 len in
907908 if r = 1 then begin (* Buffer full *)
908- Buffer. add_substring buf s 0 len;
909+ buffer_add_subbytes buf bts 0 len;
909910 loop ()
910911 end
911912 else if r = 0 then (* Line read *)
912- let zero = String . index s '\000' in
913- Buffer. add_substring buf s 0 zero;
913+ let zero = Bytes . index bts '\000' in
914+ buffer_add_subbytes buf bts 0 zero;
914915 match Buffer. contents buf with
915916 | "\\ ." -> ()
916917 | line -> Buffer. clear buf; f line; loop ()
@@ -1000,9 +1001,9 @@ object (self)
10001001 if w < len then signal_error conn)
10011002
10021003 method lo_read lo ?(pos = 0 ) ?len buf =
1003- let buf_len = String . length buf in
1004+ let buf_len = Bytes . length buf in
10041005 let len = match len with Some len -> len | None -> buf_len - pos in
1005- if len < 0 || pos < 0 || pos + len > String. length buf then
1006+ if len < 0 || pos < 0 || pos + len > buf_len then
10061007 invalid_arg " Postgresql.connection#lo_read" ;
10071008 wrap_conn (fun conn ->
10081009 let read = Stub. lo_read conn lo buf pos len in
0 commit comments