|
| 1 | +diff --git src/interfaces/libpq/fe-exec.c src/interfaces/libpq/fe-exec.c |
| 2 | +index b833e76..51ad8d8 100644 |
| 3 | +--- src/interfaces/libpq/fe-exec.c |
| 4 | ++++ src/interfaces/libpq/fe-exec.c |
| 5 | +@@ -4558,3 +4558,65 @@ int PShandleRowData(PGconn *conn, bool is_first_packet, PSresult* result) { |
| 6 | + return psHandleRowData(conn, is_first_packet, result); |
| 7 | + } |
| 8 | + |
| 9 | ++int |
| 10 | ++PQsendPipelineSync(PGconn *conn) |
| 11 | ++{ |
| 12 | ++ PGcmdQueueEntry *entry; |
| 13 | ++ |
| 14 | ++ if (!conn) |
| 15 | ++ return 0; |
| 16 | ++ |
| 17 | ++ if (conn->pipelineStatus == PQ_PIPELINE_OFF) |
| 18 | ++ { |
| 19 | ++ libpq_append_conn_error(conn, "cannot send pipeline when not in pipeline mode"); |
| 20 | ++ return 0; |
| 21 | ++ } |
| 22 | ++ |
| 23 | ++ switch (conn->asyncStatus) |
| 24 | ++ { |
| 25 | ++ case PGASYNC_COPY_IN: |
| 26 | ++ case PGASYNC_COPY_OUT: |
| 27 | ++ case PGASYNC_COPY_BOTH: |
| 28 | ++ /* should be unreachable */ |
| 29 | ++ appendPQExpBufferStr(&conn->errorMessage, |
| 30 | ++ "internal error: cannot send pipeline while in COPY\n"); |
| 31 | ++ return 0; |
| 32 | ++ case PGASYNC_READY: |
| 33 | ++ case PGASYNC_READY_MORE: |
| 34 | ++ case PGASYNC_BUSY: |
| 35 | ++ case PGASYNC_IDLE: |
| 36 | ++ case PGASYNC_PIPELINE_IDLE: |
| 37 | ++ /* OK to send sync */ |
| 38 | ++ break; |
| 39 | ++ } |
| 40 | ++ |
| 41 | ++ entry = pqAllocCmdQueueEntry(conn); |
| 42 | ++ if (entry == NULL) |
| 43 | ++ return 0; /* error msg already set */ |
| 44 | ++ |
| 45 | ++ entry->queryclass = PGQUERY_SYNC; |
| 46 | ++ entry->query = NULL; |
| 47 | ++ |
| 48 | ++ /* construct the Sync message */ |
| 49 | ++ if (pqPutMsgStart('S', conn) < 0 || |
| 50 | ++ pqPutMsgEnd(conn) < 0) |
| 51 | ++ goto sendFailed; |
| 52 | ++ |
| 53 | ++ /* |
| 54 | ++ * Give the data a push (in pipeline mode, only if we're past the size |
| 55 | ++ * threshold). In nonblock mode, don't complain if we're unable to send |
| 56 | ++ * it all; PQgetResult() will do any additional flushing needed. |
| 57 | ++ */ |
| 58 | ++ if (pqPipelineFlush(conn) < 0) |
| 59 | ++ goto sendFailed; |
| 60 | ++ |
| 61 | ++ /* OK, it's launched! */ |
| 62 | ++ pqAppendCmdQueueEntry(conn, entry); |
| 63 | ++ |
| 64 | ++ return 1; |
| 65 | ++ |
| 66 | ++sendFailed: |
| 67 | ++ pqRecycleCmdQueueEntry(conn, entry); |
| 68 | ++ /* error message should be set up already */ |
| 69 | ++ return 0; |
| 70 | ++} |
| 71 | +diff --git src/interfaces/libpq/libpq-fe.h src/interfaces/libpq/libpq-fe.h |
| 72 | +index 47f25e0..b769b64 100644 |
| 73 | +--- src/interfaces/libpq/libpq-fe.h |
| 74 | ++++ src/interfaces/libpq/libpq-fe.h |
| 75 | +@@ -688,6 +688,9 @@ extern const PGresult *PQgetResultFromPGconn(PGconn *conn); |
| 76 | + /* ProxySQL special handler function */ |
| 77 | + extern int PShandleRowData(PGconn *conn, bool is_first_packet, PSresult* result); |
| 78 | + |
| 79 | ++/* Send a pipeline sync message without flushing the send buffer */ |
| 80 | ++extern int PQsendPipelineSync(PGconn *conn); |
| 81 | ++ |
| 82 | + #ifdef __cplusplus |
| 83 | + } |
| 84 | + #endif |
0 commit comments