File tree Expand file tree Collapse file tree 4 files changed +35
-22
lines changed
Expand file tree Collapse file tree 4 files changed +35
-22
lines changed Original file line number Diff line number Diff line change @@ -49,8 +49,8 @@ let rec dump_res conn =
4949
5050let rec dump_notification conn =
5151 match conn#notifies with
52- | Some ( msg , pid , extra ) ->
53- printf " Notication from backend %i: [%s] [%s]\n " pid msg extra;
52+ | Some { Notification. name; pid; extra } ->
53+ printf " Notication from backend %i: [%s] [%s]\n " pid name extra;
5454 flush stdout;
5555 dump_notification conn
5656 | None -> ()
Original file line number Diff line number Diff line change @@ -325,6 +325,9 @@ let string_of_error = function
325325
326326exception Error of error
327327
328+ module Notification = struct
329+ type t = { name : string ; pid : int ; extra : string }
330+ end (* Notification *)
328331
329332module Stub = struct
330333 (* Database Connection Functions *)
@@ -452,7 +455,7 @@ module Stub = struct
452455
453456 (* Asynchronous Notification *)
454457
455- external notifies : connection -> ( string * int * string ) option = " PQnotifies_stub"
458+ external notifies : connection -> Notification .t option = " PQnotifies_stub"
456459
457460
458461 (* Functions Associated with the COPY Command *)
Original file line number Diff line number Diff line change @@ -414,6 +414,15 @@ type conninfo_option =
414414 cio_dispsize : int ; (* * Field size in characters for dialog *)
415415 }
416416
417+ (* * Type of asynchronous notifications *)
418+ module Notification : sig
419+ type t = {
420+ name : string ; (* * name the of relation containing data *)
421+ pid : int ; (* * the process id of the backend *)
422+ extra : string ; (* * payload data (empty if not provided) *)
423+ }
424+ end (* Notification *)
425+
417426external conndefaults : unit -> conninfo_option array = " PQconndefaults_stub"
418427(* * [conndefaults ()] @return array of all records of type [conninfo_option] *)
419428
@@ -468,11 +477,8 @@ object
468477
469478 (* * Asynchronous Notification *)
470479
471- method notifies : (string * int * string ) option
472- (* * [#notifies] @return [Some (name, pid, extra)] if available ([None]
473- otherwise), where [name] is the name the of relation containing
474- data, [pid] the process id of the backend, and [extra] is any payload
475- data associated with the notification (empty it not provided).
480+ method notifies : Notification. t option
481+ (* * [#notifies] @return [Some notification] if available ([None] otherwise).
476482
477483 @raise Error if there is a connection error.
478484 *)
Original file line number Diff line number Diff line change @@ -1005,20 +1005,24 @@ CAMLprim value PQunescapeBytea_stub(value v_from)
10051005CAMLprim value PQnotifies_stub (value v_conn )
10061006{
10071007 CAMLparam1 (v_conn );
1008- CAMLlocal1 (v_str );
1009- CAMLlocal1 (v_extra );
1010- PGnotify * noti = PQnotifies (get_conn (v_conn ));
1011-
1012- if (noti ) {
1013- value v_pair ;
1014- v_str = make_string (noti -> relname );
1015- v_pair = caml_alloc_small (3 , 0 );
1016- v_extra = make_string (noti -> extra );
1017- Field (v_pair , 0 ) = v_str ;
1018- Field (v_pair , 1 ) = Val_int (noti -> be_pid );
1019- Field (v_pair , 2 ) = v_extra ;
1020- PQfreemem (noti );
1021- CAMLreturn (make_some (v_pair ));
1008+ CAMLlocal2 (v_str , v_extra );
1009+ PGnotify * notif = PQnotifies (get_conn (v_conn ));
1010+
1011+ if (notif ) {
1012+ value v_notif ;
1013+ v_str = make_string (notif -> relname );
1014+ v_extra =
1015+ #if PG_OCAML_MAJOR_VERSION >= 9
1016+ make_string (notif -> extra );
1017+ #else
1018+ v_empty_string ;
1019+ #endif
1020+ v_notif = caml_alloc_small (3 , 0 );
1021+ Field (v_notif , 0 ) = v_str ;
1022+ Field (v_notif , 1 ) = Val_int (notif -> be_pid );
1023+ Field (v_notif , 2 ) = v_extra ;
1024+ PQfreemem (notif );
1025+ CAMLreturn (make_some (v_notif ));
10221026 }
10231027 else CAMLreturn (v_None );
10241028}
You can’t perform that action at this time.
0 commit comments