@@ -90,9 +90,12 @@ static backslashResult exec_command_else(PsqlScanState scan_state, ConditionalSt
90
90
PQExpBuffer query_buf );
91
91
static backslashResult exec_command_endif (PsqlScanState scan_state , ConditionalStack cstack ,
92
92
PQExpBuffer query_buf );
93
+ static backslashResult exec_command_endpipeline (PsqlScanState scan_state , bool active_branch );
93
94
static backslashResult exec_command_encoding (PsqlScanState scan_state , bool active_branch );
94
95
static backslashResult exec_command_errverbose (PsqlScanState scan_state , bool active_branch );
95
96
static backslashResult exec_command_f (PsqlScanState scan_state , bool active_branch );
97
+ static backslashResult exec_command_flush (PsqlScanState scan_state , bool active_branch );
98
+ static backslashResult exec_command_flushrequest (PsqlScanState scan_state , bool active_branch );
96
99
static backslashResult exec_command_g (PsqlScanState scan_state , bool active_branch ,
97
100
const char * cmd );
98
101
static backslashResult process_command_g_options (char * first_option ,
@@ -103,6 +106,7 @@ static backslashResult exec_command_gdesc(PsqlScanState scan_state, bool active_
103
106
static backslashResult exec_command_getenv (PsqlScanState scan_state , bool active_branch ,
104
107
const char * cmd );
105
108
static backslashResult exec_command_gexec (PsqlScanState scan_state , bool active_branch );
109
+ static backslashResult exec_command_getresults (PsqlScanState scan_state , bool active_branch );
106
110
static backslashResult exec_command_gset (PsqlScanState scan_state , bool active_branch );
107
111
static backslashResult exec_command_help (PsqlScanState scan_state , bool active_branch );
108
112
static backslashResult exec_command_html (PsqlScanState scan_state , bool active_branch );
@@ -132,6 +136,8 @@ static backslashResult exec_command_setenv(PsqlScanState scan_state, bool active
132
136
const char * cmd );
133
137
static backslashResult exec_command_sf_sv (PsqlScanState scan_state , bool active_branch ,
134
138
const char * cmd , bool is_func );
139
+ static backslashResult exec_command_startpipeline (PsqlScanState scan_state , bool active_branch );
140
+ static backslashResult exec_command_syncpipeline (PsqlScanState scan_state , bool active_branch );
135
141
static backslashResult exec_command_t (PsqlScanState scan_state , bool active_branch );
136
142
static backslashResult exec_command_T (PsqlScanState scan_state , bool active_branch );
137
143
static backslashResult exec_command_timing (PsqlScanState scan_state , bool active_branch );
@@ -351,18 +357,26 @@ exec_command(const char *cmd,
351
357
status = exec_command_else (scan_state , cstack , query_buf );
352
358
else if (strcmp (cmd , "endif" ) == 0 )
353
359
status = exec_command_endif (scan_state , cstack , query_buf );
360
+ else if (strcmp (cmd , "endpipeline" ) == 0 )
361
+ status = exec_command_endpipeline (scan_state , active_branch );
354
362
else if (strcmp (cmd , "encoding" ) == 0 )
355
363
status = exec_command_encoding (scan_state , active_branch );
356
364
else if (strcmp (cmd , "errverbose" ) == 0 )
357
365
status = exec_command_errverbose (scan_state , active_branch );
358
366
else if (strcmp (cmd , "f" ) == 0 )
359
367
status = exec_command_f (scan_state , active_branch );
368
+ else if (strcmp (cmd , "flush" ) == 0 )
369
+ status = exec_command_flush (scan_state , active_branch );
370
+ else if (strcmp (cmd , "flushrequest" ) == 0 )
371
+ status = exec_command_flushrequest (scan_state , active_branch );
360
372
else if (strcmp (cmd , "g" ) == 0 || strcmp (cmd , "gx" ) == 0 )
361
373
status = exec_command_g (scan_state , active_branch , cmd );
362
374
else if (strcmp (cmd , "gdesc" ) == 0 )
363
375
status = exec_command_gdesc (scan_state , active_branch );
364
376
else if (strcmp (cmd , "getenv" ) == 0 )
365
377
status = exec_command_getenv (scan_state , active_branch , cmd );
378
+ else if (strcmp (cmd , "getresults" ) == 0 )
379
+ status = exec_command_getresults (scan_state , active_branch );
366
380
else if (strcmp (cmd , "gexec" ) == 0 )
367
381
status = exec_command_gexec (scan_state , active_branch );
368
382
else if (strcmp (cmd , "gset" ) == 0 )
@@ -411,6 +425,10 @@ exec_command(const char *cmd,
411
425
status = exec_command_sf_sv (scan_state , active_branch , cmd , true);
412
426
else if (strcmp (cmd , "sv" ) == 0 || strcmp (cmd , "sv+" ) == 0 )
413
427
status = exec_command_sf_sv (scan_state , active_branch , cmd , false);
428
+ else if (strcmp (cmd , "startpipeline" ) == 0 )
429
+ status = exec_command_startpipeline (scan_state , active_branch );
430
+ else if (strcmp (cmd , "syncpipeline" ) == 0 )
431
+ status = exec_command_syncpipeline (scan_state , active_branch );
414
432
else if (strcmp (cmd , "t" ) == 0 )
415
433
status = exec_command_t (scan_state , active_branch );
416
434
else if (strcmp (cmd , "T" ) == 0 )
@@ -1515,6 +1533,44 @@ exec_command_f(PsqlScanState scan_state, bool active_branch)
1515
1533
return success ? PSQL_CMD_SKIP_LINE : PSQL_CMD_ERROR ;
1516
1534
}
1517
1535
1536
+ /*
1537
+ * \flush -- call PQflush() on the connection
1538
+ */
1539
+ static backslashResult
1540
+ exec_command_flush (PsqlScanState scan_state , bool active_branch )
1541
+ {
1542
+ backslashResult status = PSQL_CMD_SKIP_LINE ;
1543
+
1544
+ if (active_branch )
1545
+ {
1546
+ pset .send_mode = PSQL_SEND_FLUSH ;
1547
+ status = PSQL_CMD_SEND ;
1548
+ }
1549
+ else
1550
+ ignore_slash_options (scan_state );
1551
+
1552
+ return status ;
1553
+ }
1554
+
1555
+ /*
1556
+ * \flushrequest -- call PQsendFlushRequest() on the connection
1557
+ */
1558
+ static backslashResult
1559
+ exec_command_flushrequest (PsqlScanState scan_state , bool active_branch )
1560
+ {
1561
+ backslashResult status = PSQL_CMD_SKIP_LINE ;
1562
+
1563
+ if (active_branch )
1564
+ {
1565
+ pset .send_mode = PSQL_SEND_FLUSH_REQUEST ;
1566
+ status = PSQL_CMD_SEND ;
1567
+ }
1568
+ else
1569
+ ignore_slash_options (scan_state );
1570
+
1571
+ return status ;
1572
+ }
1573
+
1518
1574
/*
1519
1575
* \g [(pset-option[=pset-value] ...)] [filename/shell-command]
1520
1576
* \gx [(pset-option[=pset-value] ...)] [filename/shell-command]
@@ -1550,6 +1606,14 @@ exec_command_g(PsqlScanState scan_state, bool active_branch, const char *cmd)
1550
1606
1551
1607
if (status == PSQL_CMD_SKIP_LINE && active_branch )
1552
1608
{
1609
+ if (strcmp (cmd , "gx" ) == 0 &&
1610
+ PQpipelineStatus (pset .db ) != PQ_PIPELINE_OFF )
1611
+ {
1612
+ pg_log_error ("\\gx not allowed in pipeline mode" );
1613
+ clean_extended_state ();
1614
+ return PSQL_CMD_ERROR ;
1615
+ }
1616
+
1553
1617
if (!fname )
1554
1618
pset .gfname = NULL ;
1555
1619
else
@@ -1703,6 +1767,42 @@ exec_command_getenv(PsqlScanState scan_state, bool active_branch,
1703
1767
return success ? PSQL_CMD_SKIP_LINE : PSQL_CMD_ERROR ;
1704
1768
}
1705
1769
1770
+ /*
1771
+ * \getresults -- read results
1772
+ */
1773
+ static backslashResult
1774
+ exec_command_getresults (PsqlScanState scan_state , bool active_branch )
1775
+ {
1776
+ backslashResult status = PSQL_CMD_SKIP_LINE ;
1777
+
1778
+ if (active_branch )
1779
+ {
1780
+ char * opt ;
1781
+ int num_results ;
1782
+
1783
+ pset .send_mode = PSQL_SEND_GET_RESULTS ;
1784
+ status = PSQL_CMD_SEND ;
1785
+ opt = psql_scan_slash_option (scan_state , OT_NORMAL , NULL , false);
1786
+
1787
+ pset .requested_results = 0 ;
1788
+ if (opt != NULL )
1789
+ {
1790
+ num_results = atoi (opt );
1791
+ if (num_results < 0 )
1792
+ {
1793
+ pg_log_error ("\\getresults: invalid number of requested results" );
1794
+ return PSQL_CMD_SKIP_LINE ;
1795
+ }
1796
+ pset .requested_results = num_results ;
1797
+ }
1798
+ }
1799
+ else
1800
+ ignore_slash_options (scan_state );
1801
+
1802
+ return status ;
1803
+ }
1804
+
1805
+
1706
1806
/*
1707
1807
* \gexec -- send query and execute each field of result
1708
1808
*/
@@ -1713,6 +1813,12 @@ exec_command_gexec(PsqlScanState scan_state, bool active_branch)
1713
1813
1714
1814
if (active_branch )
1715
1815
{
1816
+ if (PQpipelineStatus (pset .db ) != PQ_PIPELINE_OFF )
1817
+ {
1818
+ pg_log_error ("\\gexec not allowed in pipeline mode" );
1819
+ clean_extended_state ();
1820
+ return PSQL_CMD_ERROR ;
1821
+ }
1716
1822
pset .gexec_flag = true;
1717
1823
status = PSQL_CMD_SEND ;
1718
1824
}
@@ -1733,6 +1839,13 @@ exec_command_gset(PsqlScanState scan_state, bool active_branch)
1733
1839
char * prefix = psql_scan_slash_option (scan_state ,
1734
1840
OT_NORMAL , NULL , false);
1735
1841
1842
+ if (PQpipelineStatus (pset .db ) != PQ_PIPELINE_OFF )
1843
+ {
1844
+ pg_log_error ("\\gset not allowed in pipeline mode" );
1845
+ clean_extended_state ();
1846
+ return PSQL_CMD_ERROR ;
1847
+ }
1848
+
1736
1849
if (prefix )
1737
1850
pset .gset_prefix = prefix ;
1738
1851
else
@@ -2718,6 +2831,63 @@ exec_command_sf_sv(PsqlScanState scan_state, bool active_branch,
2718
2831
return status ;
2719
2832
}
2720
2833
2834
+ /*
2835
+ * \startpipeline -- enter pipeline mode
2836
+ */
2837
+ static backslashResult
2838
+ exec_command_startpipeline (PsqlScanState scan_state , bool active_branch )
2839
+ {
2840
+ backslashResult status = PSQL_CMD_SKIP_LINE ;
2841
+
2842
+ if (active_branch )
2843
+ {
2844
+ pset .send_mode = PSQL_SEND_START_PIPELINE_MODE ;
2845
+ status = PSQL_CMD_SEND ;
2846
+ }
2847
+ else
2848
+ ignore_slash_options (scan_state );
2849
+
2850
+ return status ;
2851
+ }
2852
+
2853
+ /*
2854
+ * \syncpipeline -- send a sync message to an active pipeline
2855
+ */
2856
+ static backslashResult
2857
+ exec_command_syncpipeline (PsqlScanState scan_state , bool active_branch )
2858
+ {
2859
+ backslashResult status = PSQL_CMD_SKIP_LINE ;
2860
+
2861
+ if (active_branch )
2862
+ {
2863
+ pset .send_mode = PSQL_SEND_PIPELINE_SYNC ;
2864
+ status = PSQL_CMD_SEND ;
2865
+ }
2866
+ else
2867
+ ignore_slash_options (scan_state );
2868
+
2869
+ return status ;
2870
+ }
2871
+
2872
+ /*
2873
+ * \endpipeline -- end pipeline mode
2874
+ */
2875
+ static backslashResult
2876
+ exec_command_endpipeline (PsqlScanState scan_state , bool active_branch )
2877
+ {
2878
+ backslashResult status = PSQL_CMD_SKIP_LINE ;
2879
+
2880
+ if (active_branch )
2881
+ {
2882
+ pset .send_mode = PSQL_SEND_END_PIPELINE_MODE ;
2883
+ status = PSQL_CMD_SEND ;
2884
+ }
2885
+ else
2886
+ ignore_slash_options (scan_state );
2887
+
2888
+ return status ;
2889
+ }
2890
+
2721
2891
/*
2722
2892
* \t -- turn off table headers and row count
2723
2893
*/
0 commit comments