@@ -63,6 +63,7 @@ static backslashResult exec_command(const char *cmd,
6363 PQExpBuffer query_buf ,
6464 PQExpBuffer previous_buf );
6565static backslashResult exec_command_a (PsqlScanState scan_state , bool active_branch );
66+ static backslashResult exec_command_bind (PsqlScanState scan_state , bool active_branch );
6667static backslashResult exec_command_C (PsqlScanState scan_state , bool active_branch );
6768static backslashResult exec_command_connect (PsqlScanState scan_state , bool active_branch );
6869static backslashResult exec_command_cd (PsqlScanState scan_state , bool active_branch ,
@@ -308,6 +309,8 @@ exec_command(const char *cmd,
308309
309310 if (strcmp (cmd , "a" ) == 0 )
310311 status = exec_command_a (scan_state , active_branch );
312+ else if (strcmp (cmd , "bind" ) == 0 )
313+ status = exec_command_bind (scan_state , active_branch );
311314 else if (strcmp (cmd , "C" ) == 0 )
312315 status = exec_command_C (scan_state , active_branch );
313316 else if (strcmp (cmd , "c" ) == 0 || strcmp (cmd , "connect" ) == 0 )
@@ -453,6 +456,40 @@ exec_command_a(PsqlScanState scan_state, bool active_branch)
453456 return success ? PSQL_CMD_SKIP_LINE : PSQL_CMD_ERROR ;
454457}
455458
459+ /*
460+ * \bind -- set query parameters
461+ */
462+ static backslashResult
463+ exec_command_bind (PsqlScanState scan_state , bool active_branch )
464+ {
465+ backslashResult status = PSQL_CMD_SKIP_LINE ;
466+
467+ if (active_branch )
468+ {
469+ char * opt ;
470+ int nparams = 0 ;
471+ int nalloc = 0 ;
472+
473+ pset .bind_params = NULL ;
474+
475+ while ((opt = psql_scan_slash_option (scan_state , OT_NORMAL , NULL , false)))
476+ {
477+ nparams ++ ;
478+ if (nparams > nalloc )
479+ {
480+ nalloc = nalloc ? nalloc * 2 : 1 ;
481+ pset .bind_params = pg_realloc_array (pset .bind_params , char * , nalloc );
482+ }
483+ pset .bind_params [nparams - 1 ] = pg_strdup (opt );
484+ }
485+
486+ pset .bind_nparams = nparams ;
487+ pset .bind_flag = true;
488+ }
489+
490+ return status ;
491+ }
492+
456493/*
457494 * \C -- override table title (formerly change HTML caption)
458495 */
0 commit comments