@@ -1554,6 +1554,75 @@ pqSingleRowResult(PGconn *conn)
15541554 return pqPrepareAsyncResult (conn );
15551555}
15561556
1557+ /*
1558+ * Get raw row data from network buffer.
1559+ *
1560+ * It duplicates the flush/read logic of PQgetResult() to be able
1561+ * to work on sync connection. It does not return any error state,
1562+ * instead it leaves that to actual PQgetResult().
1563+ *
1564+ * Returns: 1 - have row data, 0 - do not have it
1565+ */
1566+ int
1567+ PQgetRowData (PGconn * conn , PGresult * * hdrp , PGdataValue * * cols )
1568+ {
1569+ if (!conn )
1570+ return 0 ;
1571+
1572+ /* Parse any available data, if our state permits. */
1573+ parseInput (conn );
1574+
1575+ /* If not ready to return something, block until we are. */
1576+ while (conn -> asyncStatus == PGASYNC_BUSY )
1577+ {
1578+ int flushResult ;
1579+
1580+ /*
1581+ * If data remains unsent, send it. Else we might be waiting for the
1582+ * result of a command the backend hasn't even got yet.
1583+ */
1584+ while ((flushResult = pqFlush (conn )) > 0 )
1585+ {
1586+ if (pqWait (FALSE, TRUE, conn ))
1587+ {
1588+ flushResult = -1 ;
1589+ break ;
1590+ }
1591+ }
1592+
1593+ /* Wait for some more data, and load it. */
1594+ if (flushResult ||
1595+ pqWait (TRUE, FALSE, conn ) ||
1596+ pqReadData (conn ) < 0 )
1597+ {
1598+ /*
1599+ * conn->errorMessage has been set by pqWait or pqReadData. We
1600+ * want to append it to any already-received error message.
1601+ */
1602+ pqSaveErrorResult (conn );
1603+
1604+ /* Make PQgetResult() return the error */
1605+ conn -> asyncStatus = PGASYNC_READY ;
1606+ break ;
1607+ }
1608+
1609+ /* Parse it. */
1610+ parseInput (conn );
1611+ }
1612+
1613+ /* should PQgetResult() be called instead? */
1614+ if (conn -> asyncStatus != PGASYNC_ROW_READY )
1615+ return 0 ;
1616+
1617+ /* allow parsing to proceed */
1618+ conn -> asyncStatus = PGASYNC_BUSY ;
1619+
1620+ /* return pointers to current row */
1621+ * hdrp = conn -> result ;
1622+ * cols = conn -> rowBuf ;
1623+ return 1 ;
1624+ }
1625+
15571626/*
15581627 * Consume any available input from the backend
15591628 * 0 return: some kind of trouble
0 commit comments