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 =
49
49
50
50
let rec dump_notification conn =
51
51
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;
54
54
flush stdout;
55
55
dump_notification conn
56
56
| None -> ()
Original file line number Diff line number Diff line change @@ -325,6 +325,9 @@ let string_of_error = function
325
325
326
326
exception Error of error
327
327
328
+ module Notification = struct
329
+ type t = { name : string ; pid : int ; extra : string }
330
+ end (* Notification *)
328
331
329
332
module Stub = struct
330
333
(* Database Connection Functions *)
@@ -452,7 +455,7 @@ module Stub = struct
452
455
453
456
(* Asynchronous Notification *)
454
457
455
- external notifies : connection -> ( string * int * string ) option = " PQnotifies_stub"
458
+ external notifies : connection -> Notification .t option = " PQnotifies_stub"
456
459
457
460
458
461
(* Functions Associated with the COPY Command *)
Original file line number Diff line number Diff line change @@ -414,6 +414,15 @@ type conninfo_option =
414
414
cio_dispsize : int ; (* * Field size in characters for dialog *)
415
415
}
416
416
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
+
417
426
external conndefaults : unit -> conninfo_option array = " PQconndefaults_stub"
418
427
(* * [conndefaults ()] @return array of all records of type [conninfo_option] *)
419
428
@@ -468,11 +477,8 @@ object
468
477
469
478
(* * Asynchronous Notification *)
470
479
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).
476
482
477
483
@raise Error if there is a connection error.
478
484
*)
Original file line number Diff line number Diff line change @@ -1005,20 +1005,24 @@ CAMLprim value PQunescapeBytea_stub(value v_from)
1005
1005
CAMLprim value PQnotifies_stub (value v_conn )
1006
1006
{
1007
1007
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 ));
1022
1026
}
1023
1027
else CAMLreturn (v_None );
1024
1028
}
You can’t perform that action at this time.
0 commit comments