Skip to content

Commit

Permalink
Add pg-consume-input
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jonathanstowe committed Mar 2, 2017
1 parent f3a7d0d commit 4ac1a53
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions lib/DBDish/Pg/Native.pm6
Expand Up @@ -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) { * }
Expand All @@ -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);
}
}

Expand All @@ -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)
Expand Down Expand Up @@ -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') {
Expand All @@ -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) { * }
Expand Down

0 comments on commit 4ac1a53

Please sign in to comment.