3434
3535#include <libpq-int.h>
3636
37- /* Glue to simplify working with differing interfaces between versions */
38- #if PG_VERSION_NUM >= 140000
3937#define updatePQXExpBufferStr appendPQExpBufferStr
4038#define pqxPutMsgStart3 pqPutMsgStart
4139
4240#include "pq_pipeline_funcs.i"
43- #else
44- #define updatePQXExpBufferStr printfPQExpBuffer
45-
46- static int pqxPutMsgStart3 (char msg_type , PGconn * conn ) {
47- return pqPutMsgStart (msg_type , false, conn );
48- }
49- #endif
5041
5142/*
5243 * Common startup code for PQsendQuery and sibling routines
@@ -76,18 +67,14 @@ static bool PQXsendQueryStart(PGconn* conn) {
7667 }
7768
7869 /* Can't send while already busy, either, unless enqueuing for later */
79- if (conn -> asyncStatus != PGASYNC_IDLE
80- #if PG_VERSION_NUM >= 140000
81- && conn -> pipelineStatus == PQ_PIPELINE_OFF
82- #endif
83- ) {
70+ if (conn -> asyncStatus != PGASYNC_IDLE &&
71+ conn -> pipelineStatus == PQ_PIPELINE_OFF ) {
8472 updatePQXExpBufferStr (
8573 & conn -> errorMessage ,
8674 libpq_gettext ("another command is already in progress\n" ));
8775 return false;
8876 }
8977
90- #if PG_VERSION_NUM >= 140000
9178 if (conn -> pipelineStatus != PQ_PIPELINE_OFF ) {
9279 /*
9380 * When enqueuing commands we don't change much of the connection
@@ -119,9 +106,6 @@ static bool PQXsendQueryStart(PGconn* conn) {
119106 return false;
120107 }
121108 } else {
122- #else
123- {
124- #endif
125109 /*
126110 * This command's results will come in immediately. Initialize async
127111 * result-accumulation state
@@ -169,23 +153,18 @@ int PQXSendPortalBind(PGconn* conn, const char* stmt_name,
169153 * used in transaction blocks. If that is not the case, the portal will not be
170154 * created and the exception will be thrown on an attempt to fetch data.
171155 */
172- if (conn -> xactStatus != PQTRANS_INTRANS
173- #if PG_VERSION_NUM >= 140000
174- && (conn -> pipelineStatus == PQ_PIPELINE_OFF ||
175- conn -> asyncStatus == PGASYNC_IDLE )
176- #endif
177- ) {
156+ if (conn -> xactStatus != PQTRANS_INTRANS &&
157+ (conn -> pipelineStatus == PQ_PIPELINE_OFF ||
158+ conn -> asyncStatus == PGASYNC_IDLE )) {
178159 updatePQXExpBufferStr (& conn -> errorMessage ,
179160 "a transaction is needed for a portal to work\n" );
180161 return 0 ;
181162 }
182163
183- #if PG_VERSION_NUM >= 140000
184164 PGcmdQueueEntry * entry ;
185165
186166 entry = pqAllocCmdQueueEntry (conn );
187167 if (entry == NULL ) return 0 ; /* error msg already set */
188- #endif
189168
190169 /* Construct the Bind message */
191170 if (pqxPutMsgStart3 ('B' , conn ) < 0 || pqPuts (portal_name , conn ) < 0 ||
@@ -236,50 +215,28 @@ int PQXSendPortalBind(PGconn* conn, const char* stmt_name,
236215 goto sendFailed ;
237216 if (pqPutMsgEnd (conn ) < 0 ) goto sendFailed ;
238217
239- /* construct the Sync message if not in pipeline mode */
240- #if PG_VERSION_NUM >= 140000
241- if (conn -> pipelineStatus == PQ_PIPELINE_OFF )
242- #endif
243- {
218+ /* construct the Sync message if not in pipeline mode */
219+ if (conn -> pipelineStatus == PQ_PIPELINE_OFF ) {
244220 if (pqxPutMsgStart3 ('S' , conn ) < 0 || pqPutMsgEnd (conn ) < 0 )
245221 goto sendFailed ;
246222 }
247223
248- #if PG_VERSION_NUM >= 140000
249224 /* this query has non-standard flow, using custom class */
250225 entry -> queryclass = PGXQUERY_BIND ;
251- #else
252- /* this query has non-standard flow, using custom class */
253- conn -> queryclass = PGXQUERY_BIND ;
254- /* we don't have a statement, so we just need to clear it */
255- if (conn -> last_query ) free (conn -> last_query );
256- conn -> last_query = NULL ;
257- #endif
258226
259227 /*
260228 * Give the data a push (in pipeline mode, only if we're past the size
261229 * threshold). In nonblock mode, don't complain if we're unable to send
262230 * it all; PQgetResult() will do any additional flushing needed.
263231 */
264- #if PG_VERSION_NUM >= 140000
265- if (pqPipelineFlush (conn ) < 0 )
266- #else
267- if (pqFlush (conn ) < 0 )
268- #endif
269- goto sendFailed ;
232+ if (pqPipelineFlush (conn ) < 0 ) goto sendFailed ;
270233
271- /* OK, it's launched! */
272- #if PG_VERSION_NUM >= 140000
234+ /* OK, it's launched! */
273235 pqAppendCmdQueueEntry (conn , entry );
274- #else
275- conn -> asyncStatus = PGASYNC_BUSY ;
276- #endif
277236 return 1 ;
278237
279238sendFailed :
280- #if PG_VERSION_NUM >= 140000
281239 pqRecycleCmdQueueEntry (conn , entry );
282- #endif
283240 /* error message should be set up already */
284241 return 0 ;
285242}
@@ -303,12 +260,10 @@ int PQXSendPortalExecute(PGconn* conn, const char* portal_name, int n_rows) {
303260 return 0 ;
304261 }
305262
306- #if PG_VERSION_NUM >= 140000
307263 PGcmdQueueEntry * entry ;
308264
309265 entry = pqAllocCmdQueueEntry (conn );
310266 if (entry == NULL ) return 0 ; /* error msg already set */
311- #endif
312267
313268 /* construct the Describe Portal message */
314269 if (pqxPutMsgStart3 ('D' , conn ) < 0 || pqPutc ('P' , conn ) < 0 ||
@@ -320,50 +275,28 @@ int PQXSendPortalExecute(PGconn* conn, const char* portal_name, int n_rows) {
320275 pqPutInt (n_rows , 4 , conn ) < 0 || pqPutMsgEnd (conn ) < 0 )
321276 goto sendFailed ;
322277
323- /* construct the Sync message if not in pipeline mode */
324- #if PG_VERSION_NUM >= 140000
325- if (conn -> pipelineStatus == PQ_PIPELINE_OFF )
326- #endif
327- {
278+ /* construct the Sync message if not in pipeline mode */
279+ if (conn -> pipelineStatus == PQ_PIPELINE_OFF ) {
328280 if (pqxPutMsgStart3 ('S' , conn ) < 0 || pqPutMsgEnd (conn ) < 0 )
329281 goto sendFailed ;
330282 }
331283
332- #if PG_VERSION_NUM >= 140000
333284 /* remember we are using extended query protocol */
334285 entry -> queryclass = PGQUERY_EXTENDED ;
335- #else
336- /* remember we are using extended query protocol */
337- conn -> queryclass = PGQUERY_EXTENDED ;
338- /* we don't have a statement, so we just need to clear it */
339- if (conn -> last_query ) free (conn -> last_query );
340- conn -> last_query = NULL ;
341- #endif
342286
343287 /*
344288 * Give the data a push (in pipeline mode, only if we're past the size
345289 * threshold). In nonblock mode, don't complain if we're unable to send
346290 * it all; PQgetResult() will do any additional flushing needed.
347291 */
348- #if PG_VERSION_NUM >= 140000
349- if (pqPipelineFlush (conn ) < 0 )
350- #else
351- if (pqFlush (conn ) < 0 )
352- #endif
353- goto sendFailed ;
292+ if (pqPipelineFlush (conn ) < 0 ) goto sendFailed ;
354293
355- /* OK, it's launched! */
356- #if PG_VERSION_NUM >= 140000
294+ /* OK, it's launched! */
357295 pqAppendCmdQueueEntry (conn , entry );
358- #else
359- conn -> asyncStatus = PGASYNC_BUSY ;
360- #endif
361296 return 1 ;
362297
363298sendFailed :
364- #if PG_VERSION_NUM >= 140000
365299 pqRecycleCmdQueueEntry (conn , entry );
366- #endif
367300 /* error message should be set up already */
368301 return 0 ;
369302}
0 commit comments