LibPQ.jl icon indicating copy to clipboard operation
LibPQ.jl copied to clipboard

Fix PQnotifies to return Ptr{pgNotify}

Open deyandyankov opened this issue 3 years ago • 1 comments
trafficstars

This is related to https://github.com/invenia/LibPQ.jl/issues/242

The fix allows one to use LISTEN and NOTIFY.

See the following minimum working example:

using LibPQ

lpqc = LibPQ.libpq_c

function onenotify()
    conn = lpqc.PQconnectdb("host=localhost port=5432 dbname=db user=user password=pass")
    res = lpqc.PQexec(conn, "LISTEN virtual")
    lpqc.PQclear(res)
    relname = ""
    payload = ""

    @info "Listeing to channel..."
    while true
        notify = lpqc.PQnotifies(conn)
        if notify != C_NULL
            n = unsafe_load(notify)
            relname = unsafe_string(n.relname)
            payload = unsafe_string(n.extra)
            break
        end
        lpqc.PQfreeNotify(notify)
        lpqc.PQconsumeInput(conn)
        sleep(1)
    end
    lpqc.PQfinish(conn)
    (relname, payload)
end

channel, payload = onenotify()
@info "Received message from channel \"$channel\" with payload: $payload"

When one runs the above in a julia session, and in a separate psql session the following is issued:

db=> notify virtual, 'payload';
NOTIFY

Then the julia session receives the message:

[ Info: Received message from channel "virtual" with payload: payload

deyandyankov avatar Jan 29 '22 13:01 deyandyankov

I checked out what the current version of Clang.jl generates and it seems like this is the change that would be more in line with potential future versions of this file:

-const PGnotify = Cvoid
+const PGnotify = pgNotify

iamed2 avatar Jan 31 '22 21:01 iamed2