@@ -254,6 +254,10 @@ type polling_status =
254
254
| Polling_writing
255
255
| Polling_ok
256
256
257
+ type flush_status =
258
+ | Successful
259
+ | Data_left_to_send
260
+
257
261
type conninfo_option =
258
262
{
259
263
cio_keyword : string ;
@@ -340,7 +344,7 @@ module Stub = struct
340
344
341
345
external error_message : connection -> string = " PQerrorMessage_stub"
342
346
external backend_pid : connection -> int = " PQbackendPID_stub" " noalloc"
343
-
347
+ external server_version : connection -> int = " PQserverVersion_stub " " noalloc "
344
348
345
349
(* Command Execution Functions *)
346
350
@@ -773,6 +777,20 @@ object (self)
773
777
method status = wrap_conn Stub. connection_status
774
778
method error_message = wrap_conn Stub. error_message
775
779
method backend_pid = wrap_conn Stub. backend_pid
780
+ method server_version = wrap_conn (fun conn ->
781
+ let v = Stub. server_version conn in
782
+ if v = 0 then begin
783
+ let message = if Stub. connection_status conn = Bad
784
+ then " server_version failed because the connection was bad"
785
+ else " server_version failed for an unknown reason"
786
+ in
787
+ raise (Error (Connection_failure message))
788
+ end ;
789
+ let revision = v mod 100 in
790
+ let minor = (v / 100 ) mod 100 in
791
+ let major = v / (100 * 100 ) in
792
+ major, minor, revision
793
+ )
776
794
777
795
778
796
(* Commands and Queries *)
@@ -882,18 +900,26 @@ object (self)
882
900
| _ -> assert false )
883
901
884
902
method putline buf =
885
- wrap_conn (fun conn -> if Stub. putline conn buf <> 0 then signal_error conn)
903
+ wrap_conn (fun conn ->
904
+ if (Stub. putline conn buf <> 0 ) && not (Stub. is_nonblocking conn) then
905
+ signal_error conn
906
+ )
886
907
887
908
method putnbytes ?(pos = 0 ) ?len buf =
888
909
let buf_len = String. length buf in
889
910
let len = match len with Some len -> len | None -> buf_len - pos in
890
911
if len < 0 || pos < 0 || pos + len > buf_len then
891
912
invalid_arg " Postgresql.connection#putnbytes" ;
892
913
wrap_conn (fun conn ->
893
- if Stub. putnbytes conn buf pos len <> 0 then signal_error conn)
914
+ if (Stub. putnbytes conn buf pos len <> 0 ) && not (Stub. is_nonblocking conn) then
915
+ signal_error conn
916
+ )
894
917
895
918
method endcopy =
896
- wrap_conn (fun conn -> if Stub. endcopy conn <> 0 then signal_error conn)
919
+ wrap_conn (fun conn ->
920
+ if (Stub. endcopy conn <> 0 ) && not (Stub. is_nonblocking conn) then
921
+ signal_error conn
922
+ )
897
923
898
924
899
925
(* High level *)
@@ -948,7 +974,12 @@ object (self)
948
974
method is_busy = wrap_conn Stub. is_busy
949
975
950
976
method flush =
951
- wrap_conn (fun conn -> if Stub. flush conn <> 0 then signal_error conn)
977
+ wrap_conn (fun conn ->
978
+ match Stub. flush conn with
979
+ | 0 -> Successful
980
+ | 1 -> Data_left_to_send
981
+ | _ -> signal_error conn
982
+ )
952
983
953
984
method socket =
954
985
wrap_conn (fun conn ->
0 commit comments