@@ -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 -- send a flush request to the server
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,13 @@ 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 && PQpipelineStatus (pset .db ) != PQ_PIPELINE_OFF )
1610
+ {
1611
+ pg_log_error ("\\gx not allowed in pipeline mode" );
1612
+ clean_extended_state ();
1613
+ return PSQL_CMD_ERROR ;
1614
+ }
1615
+
1553
1616
if (!fname )
1554
1617
pset .gfname = NULL ;
1555
1618
else
@@ -1703,6 +1766,42 @@ exec_command_getenv(PsqlScanState scan_state, bool active_branch,
1703
1766
return success ? PSQL_CMD_SKIP_LINE : PSQL_CMD_ERROR ;
1704
1767
}
1705
1768
1769
+ /*
1770
+ * \getresults -- read results
1771
+ */
1772
+ static backslashResult
1773
+ exec_command_getresults (PsqlScanState scan_state , bool active_branch )
1774
+ {
1775
+ backslashResult status = PSQL_CMD_SKIP_LINE ;
1776
+
1777
+ if (active_branch )
1778
+ {
1779
+ char * opt ;
1780
+ int num_results ;
1781
+
1782
+ pset .send_mode = PSQL_SEND_GET_RESULTS ;
1783
+ status = PSQL_CMD_SEND ;
1784
+ opt = psql_scan_slash_option (scan_state , OT_NORMAL , NULL , false);
1785
+
1786
+ pset .requested_results = 0 ;
1787
+ if (opt != NULL )
1788
+ {
1789
+ num_results = atoi (opt );
1790
+ if (num_results < 0 )
1791
+ {
1792
+ pg_log_error ("\\getresults: invalid number of requested results" );
1793
+ return PSQL_CMD_SKIP_LINE ;
1794
+ }
1795
+ pset .requested_results = num_results ;
1796
+ }
1797
+ }
1798
+ else
1799
+ ignore_slash_options (scan_state );
1800
+
1801
+ return status ;
1802
+ }
1803
+
1804
+
1706
1805
/*
1707
1806
* \gexec -- send query and execute each field of result
1708
1807
*/
@@ -1713,6 +1812,12 @@ exec_command_gexec(PsqlScanState scan_state, bool active_branch)
1713
1812
1714
1813
if (active_branch )
1715
1814
{
1815
+ if (PQpipelineStatus (pset .db ) != PQ_PIPELINE_OFF )
1816
+ {
1817
+ pg_log_error ("\\gexec not allowed in pipeline mode" );
1818
+ clean_extended_state ();
1819
+ return PSQL_CMD_ERROR ;
1820
+ }
1716
1821
pset .gexec_flag = true;
1717
1822
status = PSQL_CMD_SEND ;
1718
1823
}
@@ -1733,6 +1838,13 @@ exec_command_gset(PsqlScanState scan_state, bool active_branch)
1733
1838
char * prefix = psql_scan_slash_option (scan_state ,
1734
1839
OT_NORMAL , NULL , false);
1735
1840
1841
+ if (PQpipelineStatus (pset .db ) != PQ_PIPELINE_OFF )
1842
+ {
1843
+ pg_log_error ("\\gset not allowed in pipeline mode" );
1844
+ clean_extended_state ();
1845
+ return PSQL_CMD_ERROR ;
1846
+ }
1847
+
1736
1848
if (prefix )
1737
1849
pset .gset_prefix = prefix ;
1738
1850
else
@@ -2718,6 +2830,63 @@ exec_command_sf_sv(PsqlScanState scan_state, bool active_branch,
2718
2830
return status ;
2719
2831
}
2720
2832
2833
+ /*
2834
+ * \startpipeline -- enter pipeline mode
2835
+ */
2836
+ static backslashResult
2837
+ exec_command_startpipeline (PsqlScanState scan_state , bool active_branch )
2838
+ {
2839
+ backslashResult status = PSQL_CMD_SKIP_LINE ;
2840
+
2841
+ if (active_branch )
2842
+ {
2843
+ pset .send_mode = PSQL_SEND_START_PIPELINE_MODE ;
2844
+ status = PSQL_CMD_SEND ;
2845
+ }
2846
+ else
2847
+ ignore_slash_options (scan_state );
2848
+
2849
+ return status ;
2850
+ }
2851
+
2852
+ /*
2853
+ * \syncpipeline -- send a sync message to an active pipeline
2854
+ */
2855
+ static backslashResult
2856
+ exec_command_syncpipeline (PsqlScanState scan_state , bool active_branch )
2857
+ {
2858
+ backslashResult status = PSQL_CMD_SKIP_LINE ;
2859
+
2860
+ if (active_branch )
2861
+ {
2862
+ pset .send_mode = PSQL_SEND_PIPELINE_SYNC ;
2863
+ status = PSQL_CMD_SEND ;
2864
+ }
2865
+ else
2866
+ ignore_slash_options (scan_state );
2867
+
2868
+ return status ;
2869
+ }
2870
+
2871
+ /*
2872
+ * \endpipeline -- end pipeline mode
2873
+ */
2874
+ static backslashResult
2875
+ exec_command_endpipeline (PsqlScanState scan_state , bool active_branch )
2876
+ {
2877
+ backslashResult status = PSQL_CMD_SKIP_LINE ;
2878
+
2879
+ if (active_branch )
2880
+ {
2881
+ pset .send_mode = PSQL_SEND_END_PIPELINE_MODE ;
2882
+ status = PSQL_CMD_SEND ;
2883
+ }
2884
+ else
2885
+ ignore_slash_options (scan_state );
2886
+
2887
+ return status ;
2888
+ }
2889
+
2721
2890
/*
2722
2891
* \t -- turn off table headers and row count
2723
2892
*/
0 commit comments