From 4ac1a537b03910dbade6a7456b7669420a11f0c9 Mon Sep 17 00:00:00 2001 From: Jonathan Stowe Date: Thu, 2 Mar 2017 11:55:07 +0000 Subject: [PATCH] Add pg-consume-input If one wants to use pg-notifies "standalone" then one needs to call the PQconsumeInput before calling the PQnotifies in order to get the notifications. --- lib/DBDish/Pg/Native.pm6 | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/lib/DBDish/Pg/Native.pm6 b/lib/DBDish/Pg/Native.pm6 index 01c3e8e0..cd679f90 100644 --- a/lib/DBDish/Pg/Native.pm6 +++ b/lib/DBDish/Pg/Native.pm6 @@ -23,7 +23,7 @@ sub str-to-blob(Str $value, Mu:U :$type) is export { } else { die "Can't allocate memory!" }; } -class PGresult is export is repr('CPointer') { +class PGresult is export is repr('CPointer') { method PQclear is native(LIB) { * } method PQcmdTuples(--> Str) is native(LIB) { * } method PQfname(int32 --> Str) is native(LIB) { * } @@ -39,10 +39,10 @@ class PGresult is export is repr('CPointer') { method PQgetlength(int32, int32 --> int32) is native(LIB) { * } method PQfformat(int32 --> int32) is native(LIB) { * } method PQgetvaluePtr(int32, int32 --> Pointer) - is symbol('PQgetvalue') is native(LIB) { * } + is symbol('PQgetvalue') is native(LIB) { * } method is-ok { - self.PQresultStatus ~~ (0 .. 4); + self.PQresultStatus ~~ (0 .. 4); } } @@ -67,7 +67,7 @@ class PGconn is export is repr('CPointer') { method PQdescribePrepared(str --> PGresult) is native(LIB) { * } method PQstatus(--> int32) is native(LIB) { * } method PQprepare(str $sth_name, str $query, int32 $n_params, OidArray --> PGresult) - is native(LIB) { * } + is native(LIB) { * } method PQfinish is native(LIB) { * } method PQescapeByteaConn(Buf, size_t, size_t is rw --> Pointer) @@ -96,6 +96,11 @@ class PGconn is export is repr('CPointer') { method pg-socket(--> int32) is symbol('PQsocket') is native(LIB) { * } + method PQconsumeInput( --> int32) is native(LIB) { * } + + method pg-consume-input(--> Bool) { + ?self.PQconsumeInput(); + } method PQnotifies(--> Pointer) is native(LIB) { * } method pg-notifies(--> pg-notify) { class PGnotify is repr('CStruct') { @@ -112,26 +117,26 @@ class PGconn is export is repr('CPointer') { } method pg-parameter-status(Str --> Str) is symbol('PQparameterStatus') - is native(LIB) { * } + is native(LIB) { * } sub PQconnectdb(str --> PGconn) is native(LIB) { * }; multi method new(Str $conninfo) { # Our legacy constructor - PQconnectdb($conninfo); + PQconnectdb($conninfo); } sub PQconnectdbParams(CArray[Str], CArray[Str], int32 --> PGconn) - is native(LIB) { * }; + is native(LIB) { * }; multi method new(%connparms) { # Our named constructor - my $keys = CArray[Str].new; my $vals = CArray[Str].new; - my int $i = 0; - for %connparms.kv -> $k,$v { - next without $v; - $keys[$i] = $k.subst('-','_'); - $vals[$i] = ~$v; $i++; - } - $keys[$i] = Str; $vals[$i] = Str; - PQconnectdbParams($keys, $vals, 1); + my $keys = CArray[Str].new; my $vals = CArray[Str].new; + my int $i = 0; + for %connparms.kv -> $k,$v { + next without $v; + $keys[$i] = $k.subst('-','_'); + $vals[$i] = ~$v; $i++; + } + $keys[$i] = Str; $vals[$i] = Str; + PQconnectdbParams($keys, $vals, 1); } method pg-db(--> Str) is symbol('PQdb') is native(LIB) { * } method pg-user(--> Str) is symbol('PQuser') is native(LIB) { * }