break
yield WAIT_R
- # Consume notifies
- while True:
- n = pgconn.notifies()
- if not n:
- break
- if pgconn.notify_handler:
- pgconn.notify_handler(n)
+ _consume_notifies(pgconn)
return pgconn.get_result()
if ready & READY_R:
pgconn.consume_input()
- while True:
- n = pgconn.notifies()
- if not n:
- break
- if pgconn.notify_handler:
- pgconn.notify_handler(n)
+ _consume_notifies(pgconn)
res: List[PGresult] = []
while not pgconn.is_busy():
return results
+def _consume_notifies(pgconn: PGconn) -> None:
+ # Consume notifies
+ while True:
+ n = pgconn.notifies()
+ if not n:
+ break
+ if pgconn.notify_handler:
+ pgconn.notify_handler(n)
+
+
def notifies(pgconn: PGconn) -> PQGen[List[pq.PGnotify]]:
yield WAIT_R
pgconn.consume_input()
Return a result from the database (whether success or error).
"""
cdef libpq.PGconn *pgconn_ptr = pgconn._pgconn_ptr
- cdef libpq.PGnotify *notify
cdef int cires, ibres = 0
- cdef object notify_handler = pgconn.notify_handler
cdef libpq.PGresult *pgres
if libpq.PQisBusy(pgconn_ptr):
break
yield WAIT_R
- # Consume notifies
- if notify_handler is not None:
- while True:
- pynotify = pgconn.notifies()
- if pynotify is None:
- break
- PyObject_CallFunctionObjArgs(
- notify_handler, <PyObject *>pynotify, NULL
- )
- else:
- while True:
- notify = libpq.PQnotifies(pgconn_ptr)
- if notify is NULL:
- break
- libpq.PQfreemem(notify)
+ _consume_notifies(pgconn)
pgres = libpq.PQgetResult(pgconn_ptr)
if pgres is NULL:
Return a list results, including single PIPELINE_SYNC elements.
"""
cdef libpq.PGconn *pgconn_ptr = pgconn._pgconn_ptr
- cdef object notify_handler = pgconn.notify_handler
- cdef libpq.PGnotify *notify
cdef int cires
cdef int status
cdef int ready
raise e.OperationalError(
f"consuming input failed: {error_message(pgconn)}")
- if notify_handler is not None:
- while True:
- pynotify = pgconn.notifies()
- if pynotify is None:
- break
- PyObject_CallFunctionObjArgs(
- notify_handler, <PyObject *>pynotify, NULL
- )
- else:
- while True:
- notify = libpq.PQnotifies(pgconn_ptr)
- if notify is NULL:
- break
- libpq.PQfreemem(notify)
+ _consume_notifies(pgconn)
res: List[PGresult] = []
while not libpq.PQisBusy(pgconn_ptr):
commands.popleft()()
return results
+
+
+cdef int _consume_notifies(pq.PGconn pgconn) except -1:
+ cdef object notify_handler = pgconn.notify_handler
+ cdef libpq.PGconn *pgconn_ptr
+ cdef libpq.PGnotify *notify
+
+ if notify_handler is not None:
+ while True:
+ pynotify = pgconn.notifies()
+ if pynotify is None:
+ break
+ PyObject_CallFunctionObjArgs(
+ notify_handler, <PyObject *>pynotify, NULL
+ )
+ else:
+ pgconn_ptr = pgconn._pgconn_ptr
+ while True:
+ notify = libpq.PQnotifies(pgconn_ptr)
+ if notify is NULL:
+ break
+ libpq.PQfreemem(notify)
+
+ return 0