mirror of
https://github.com/postgres/postgres.git
synced 2025-11-19 13:42:17 +03:00
Replace libpq's "row processor" API with a "single row" mode.
After taking awhile to digest the row-processor feature that was added to
libpq in commit 92785dac2e, we've concluded
it is over-complicated and too hard to use. Leave the core infrastructure
changes in place (that is, there's still a row processor function inside
libpq), but remove the exposed API pieces, and instead provide a "single
row" mode switch that causes PQgetResult to return one row at a time in
separate PGresult objects.
This approach incurs more overhead than proper use of a row processor
callback would, since construction of a PGresult per row adds extra cycles.
However, it is far easier to use and harder to break. The single-row mode
still affords applications the primary benefit that the row processor API
was meant to provide, namely not having to accumulate large result sets in
memory before processing them. Preliminary testing suggests that we can
probably buy back most of the extra cycles by micro-optimizing construction
of the extra results, but that task will be left for another day.
Marko Kreen
This commit is contained in:
@@ -90,7 +90,8 @@ typedef enum
|
||||
* backend */
|
||||
PGRES_NONFATAL_ERROR, /* notice or warning message */
|
||||
PGRES_FATAL_ERROR, /* query failed */
|
||||
PGRES_COPY_BOTH /* Copy In/Out data transfer in progress */
|
||||
PGRES_COPY_BOTH, /* Copy In/Out data transfer in progress */
|
||||
PGRES_SINGLE_TUPLE /* single tuple from larger resultset */
|
||||
} ExecStatusType;
|
||||
|
||||
typedef enum
|
||||
@@ -129,17 +130,6 @@ typedef struct pg_conn PGconn;
|
||||
*/
|
||||
typedef struct pg_result PGresult;
|
||||
|
||||
/* PGdataValue represents a data field value being passed to a row processor.
|
||||
* It could be either text or binary data; text data is not zero-terminated.
|
||||
* A SQL NULL is represented by len < 0; then value is still valid but there
|
||||
* are no data bytes there.
|
||||
*/
|
||||
typedef struct pgDataValue
|
||||
{
|
||||
int len; /* data length in bytes, or <0 if NULL */
|
||||
const char *value; /* data value, without zero-termination */
|
||||
} PGdataValue;
|
||||
|
||||
/* PGcancel encapsulates the information needed to cancel a running
|
||||
* query on an existing connection.
|
||||
* The contents of this struct are not supposed to be known to applications.
|
||||
@@ -161,10 +151,6 @@ typedef struct pgNotify
|
||||
struct pgNotify *next; /* list link */
|
||||
} PGnotify;
|
||||
|
||||
/* Function type for row-processor callback */
|
||||
typedef int (*PQrowProcessor) (PGresult *res, const PGdataValue *columns,
|
||||
const char **errmsgp, void *param);
|
||||
|
||||
/* Function types for notice-handling callbacks */
|
||||
typedef void (*PQnoticeReceiver) (void *arg, const PGresult *res);
|
||||
typedef void (*PQnoticeProcessor) (void *arg, const char *message);
|
||||
@@ -403,17 +389,13 @@ extern int PQsendQueryPrepared(PGconn *conn,
|
||||
const int *paramLengths,
|
||||
const int *paramFormats,
|
||||
int resultFormat);
|
||||
extern int PQsetSingleRowMode(PGconn *conn);
|
||||
extern PGresult *PQgetResult(PGconn *conn);
|
||||
extern PGresult *PQskipResult(PGconn *conn);
|
||||
|
||||
/* Routines for managing an asynchronous query */
|
||||
extern int PQisBusy(PGconn *conn);
|
||||
extern int PQconsumeInput(PGconn *conn);
|
||||
|
||||
/* Override default per-row processing */
|
||||
extern void PQsetRowProcessor(PGconn *conn, PQrowProcessor func, void *param);
|
||||
extern PQrowProcessor PQgetRowProcessor(const PGconn *conn, void **param);
|
||||
|
||||
/* LISTEN/NOTIFY support */
|
||||
extern PGnotify *PQnotifies(PGconn *conn);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user