* PQpipelineSync * Send a Sync message as part of a pipeline, and flush to server * * It's legal to start submitting more commands in the pipeline immediately, * without waiting for the results of the current pipeline. There's no need to * end pipeline mode and start it again. * * If a command in a pipeline fails, every subsequent command up to and including * the result to the Sync messa
| 3113 | * are processed by the client. |
| 3114 | */ |
| 3115 | int |
| 3116 | PQpipelineSync(PGconn *conn) |
| 3117 | { |
| 3118 | PGcmdQueueEntry *entry; |
| 3119 | |
| 3120 | if (!conn) |
| 3121 | return 0; |
| 3122 | |
| 3123 | if (conn->pipelineStatus == PQ_PIPELINE_OFF) |
| 3124 | { |
| 3125 | appendPQExpBufferStr(&conn->errorMessage, |
| 3126 | libpq_gettext("cannot send pipeline when not in pipeline mode\n")); |
| 3127 | return 0; |
| 3128 | } |
| 3129 | |
| 3130 | switch (conn->asyncStatus) |
| 3131 | { |
| 3132 | case PGASYNC_COPY_IN: |
| 3133 | case PGASYNC_COPY_OUT: |
| 3134 | case PGASYNC_COPY_BOTH: |
| 3135 | /* should be unreachable */ |
| 3136 | appendPQExpBufferStr(&conn->errorMessage, |
| 3137 | "internal error: cannot send pipeline while in COPY\n"); |
| 3138 | return 0; |
| 3139 | case PGASYNC_READY: |
| 3140 | case PGASYNC_READY_MORE: |
| 3141 | case PGASYNC_BUSY: |
| 3142 | case PGASYNC_IDLE: |
| 3143 | /* OK to send sync */ |
| 3144 | break; |
| 3145 | } |
| 3146 | |
| 3147 | entry = pqAllocCmdQueueEntry(conn); |
| 3148 | if (entry == NULL) |
| 3149 | return 0; /* error msg already set */ |
| 3150 | |
| 3151 | entry->queryclass = PGQUERY_SYNC; |
| 3152 | entry->query = NULL; |
| 3153 | |
| 3154 | /* construct the Sync message */ |
| 3155 | if (pqPutMsgStart('S', conn) < 0 || |
| 3156 | pqPutMsgEnd(conn) < 0) |
| 3157 | goto sendFailed; |
| 3158 | |
| 3159 | /* |
| 3160 | * Give the data a push. In nonblock mode, don't complain if we're unable |
| 3161 | * to send it all; PQgetResult() will do any additional flushing needed. |
| 3162 | */ |
| 3163 | if (PQflush(conn) < 0) |
| 3164 | goto sendFailed; |
| 3165 | |
| 3166 | /* OK, it's launched! */ |
| 3167 | pqAppendCmdQueueEntry(conn, entry); |
| 3168 | |
| 3169 | return 1; |
| 3170 | |
| 3171 | sendFailed: |
| 3172 | pqRecycleCmdQueueEntry(conn, entry); |