@@ -64,10 +64,14 @@ static backslashResult exec_command(const char *cmd,
64
64
PQExpBuffer previous_buf );
65
65
static backslashResult exec_command_a (PsqlScanState scan_state , bool active_branch );
66
66
static backslashResult exec_command_bind (PsqlScanState scan_state , bool active_branch );
67
+ static backslashResult exec_command_bind_named (PsqlScanState scan_state , bool active_branch ,
68
+ const char * cmd );
67
69
static backslashResult exec_command_C (PsqlScanState scan_state , bool active_branch );
68
70
static backslashResult exec_command_connect (PsqlScanState scan_state , bool active_branch );
69
71
static backslashResult exec_command_cd (PsqlScanState scan_state , bool active_branch ,
70
72
const char * cmd );
73
+ static backslashResult exec_command_close (PsqlScanState scan_state , bool active_branch ,
74
+ const char * cmd );
71
75
static backslashResult exec_command_conninfo (PsqlScanState scan_state , bool active_branch );
72
76
static backslashResult exec_command_copy (PsqlScanState scan_state , bool active_branch );
73
77
static backslashResult exec_command_copyright (PsqlScanState scan_state , bool active_branch );
@@ -116,6 +120,8 @@ static backslashResult exec_command_lo(PsqlScanState scan_state, bool active_bra
116
120
static backslashResult exec_command_out (PsqlScanState scan_state , bool active_branch );
117
121
static backslashResult exec_command_print (PsqlScanState scan_state , bool active_branch ,
118
122
PQExpBuffer query_buf , PQExpBuffer previous_buf );
123
+ static backslashResult exec_command_parse (PsqlScanState scan_state , bool active_branch ,
124
+ const char * cmd );
119
125
static backslashResult exec_command_password (PsqlScanState scan_state , bool active_branch );
120
126
static backslashResult exec_command_prompt (PsqlScanState scan_state , bool active_branch ,
121
127
const char * cmd );
@@ -312,12 +318,16 @@ exec_command(const char *cmd,
312
318
status = exec_command_a (scan_state , active_branch );
313
319
else if (strcmp (cmd , "bind" ) == 0 )
314
320
status = exec_command_bind (scan_state , active_branch );
321
+ else if (strcmp (cmd , "bind_named" ) == 0 )
322
+ status = exec_command_bind_named (scan_state , active_branch , cmd );
315
323
else if (strcmp (cmd , "C" ) == 0 )
316
324
status = exec_command_C (scan_state , active_branch );
317
325
else if (strcmp (cmd , "c" ) == 0 || strcmp (cmd , "connect" ) == 0 )
318
326
status = exec_command_connect (scan_state , active_branch );
319
327
else if (strcmp (cmd , "cd" ) == 0 )
320
328
status = exec_command_cd (scan_state , active_branch , cmd );
329
+ else if (strcmp (cmd , "close" ) == 0 )
330
+ status = exec_command_close (scan_state , active_branch , cmd );
321
331
else if (strcmp (cmd , "conninfo" ) == 0 )
322
332
status = exec_command_conninfo (scan_state , active_branch );
323
333
else if (pg_strcasecmp (cmd , "copy" ) == 0 )
@@ -379,6 +389,8 @@ exec_command(const char *cmd,
379
389
else if (strcmp (cmd , "p" ) == 0 || strcmp (cmd , "print" ) == 0 )
380
390
status = exec_command_print (scan_state , active_branch ,
381
391
query_buf , previous_buf );
392
+ else if (strcmp (cmd , "parse" ) == 0 )
393
+ status = exec_command_parse (scan_state , active_branch , cmd );
382
394
else if (strcmp (cmd , "password" ) == 0 )
383
395
status = exec_command_password (scan_state , active_branch );
384
396
else if (strcmp (cmd , "prompt" ) == 0 )
@@ -472,6 +484,7 @@ exec_command_bind(PsqlScanState scan_state, bool active_branch)
472
484
int nalloc = 0 ;
473
485
474
486
pset .bind_params = NULL ;
487
+ pset .stmtName = NULL ;
475
488
476
489
while ((opt = psql_scan_slash_option (scan_state , OT_NORMAL , NULL , false)))
477
490
{
@@ -485,7 +498,57 @@ exec_command_bind(PsqlScanState scan_state, bool active_branch)
485
498
}
486
499
487
500
pset .bind_nparams = nparams ;
488
- pset .bind_flag = true;
501
+ pset .send_mode = PSQL_SEND_EXTENDED_QUERY_PARAMS ;
502
+ }
503
+ else
504
+ ignore_slash_options (scan_state );
505
+
506
+ return status ;
507
+ }
508
+
509
+ /*
510
+ * \bind_named -- set query parameters for an existing prepared statement
511
+ */
512
+ static backslashResult
513
+ exec_command_bind_named (PsqlScanState scan_state , bool active_branch ,
514
+ const char * cmd )
515
+ {
516
+ backslashResult status = PSQL_CMD_SKIP_LINE ;
517
+
518
+ if (active_branch )
519
+ {
520
+ char * opt ;
521
+ int nparams = 0 ;
522
+ int nalloc = 0 ;
523
+
524
+ pset .bind_params = NULL ;
525
+ pset .stmtName = NULL ;
526
+
527
+ /* get the mandatory prepared statement name */
528
+ opt = psql_scan_slash_option (scan_state , OT_NORMAL , NULL , false);
529
+ if (!opt )
530
+ {
531
+ pg_log_error ("\\%s: missing required argument" , cmd );
532
+ status = PSQL_CMD_ERROR ;
533
+ }
534
+ else
535
+ {
536
+ pset .stmtName = opt ;
537
+ pset .send_mode = PSQL_SEND_EXTENDED_QUERY_PREPARED ;
538
+
539
+ /* set of parameters */
540
+ while ((opt = psql_scan_slash_option (scan_state , OT_NORMAL , NULL , false)))
541
+ {
542
+ nparams ++ ;
543
+ if (nparams > nalloc )
544
+ {
545
+ nalloc = nalloc ? nalloc * 2 : 1 ;
546
+ pset .bind_params = pg_realloc_array (pset .bind_params , char * , nalloc );
547
+ }
548
+ pset .bind_params [nparams - 1 ] = opt ;
549
+ }
550
+ pset .bind_nparams = nparams ;
551
+ }
489
552
}
490
553
else
491
554
ignore_slash_options (scan_state );
@@ -643,6 +706,38 @@ exec_command_cd(PsqlScanState scan_state, bool active_branch, const char *cmd)
643
706
return success ? PSQL_CMD_SKIP_LINE : PSQL_CMD_ERROR ;
644
707
}
645
708
709
+ /*
710
+ * \close -- close a previously prepared statement
711
+ */
712
+ static backslashResult
713
+ exec_command_close (PsqlScanState scan_state , bool active_branch , const char * cmd )
714
+ {
715
+ backslashResult status = PSQL_CMD_SKIP_LINE ;
716
+
717
+ if (active_branch )
718
+ {
719
+ char * opt = psql_scan_slash_option (scan_state ,
720
+ OT_NORMAL , NULL , false);
721
+
722
+ pset .stmtName = NULL ;
723
+ if (!opt )
724
+ {
725
+ pg_log_error ("\\%s: missing required argument" , cmd );
726
+ status = PSQL_CMD_ERROR ;
727
+ }
728
+ else
729
+ {
730
+ pset .stmtName = opt ;
731
+ pset .send_mode = PSQL_SEND_EXTENDED_CLOSE ;
732
+ status = PSQL_CMD_SEND ;
733
+ }
734
+ }
735
+ else
736
+ ignore_slash_options (scan_state );
737
+
738
+ return status ;
739
+ }
740
+
646
741
/*
647
742
* \conninfo -- display information about the current connection
648
743
*/
@@ -2096,6 +2191,39 @@ exec_command_print(PsqlScanState scan_state, bool active_branch,
2096
2191
return PSQL_CMD_SKIP_LINE ;
2097
2192
}
2098
2193
2194
+ /*
2195
+ * \parse -- parse query
2196
+ */
2197
+ static backslashResult
2198
+ exec_command_parse (PsqlScanState scan_state , bool active_branch ,
2199
+ const char * cmd )
2200
+ {
2201
+ backslashResult status = PSQL_CMD_SKIP_LINE ;
2202
+
2203
+ if (active_branch )
2204
+ {
2205
+ char * opt = psql_scan_slash_option (scan_state ,
2206
+ OT_NORMAL , NULL , false);
2207
+
2208
+ pset .stmtName = NULL ;
2209
+ if (!opt )
2210
+ {
2211
+ pg_log_error ("\\%s: missing required argument" , cmd );
2212
+ status = PSQL_CMD_ERROR ;
2213
+ }
2214
+ else
2215
+ {
2216
+ pset .stmtName = opt ;
2217
+ pset .send_mode = PSQL_SEND_EXTENDED_PARSE ;
2218
+ status = PSQL_CMD_SEND ;
2219
+ }
2220
+ }
2221
+ else
2222
+ ignore_slash_options (scan_state );
2223
+
2224
+ return status ;
2225
+ }
2226
+
2099
2227
/*
2100
2228
* \password -- set user password
2101
2229
*/
0 commit comments