psql: Add ignore_slash_options in bind's inactive branch
authorMichael Paquier <michael@paquier.xyz>
Fri, 19 Jan 2024 05:18:20 +0000 (14:18 +0900)
committerMichael Paquier <michael@paquier.xyz>
Fri, 19 Jan 2024 05:18:20 +0000 (14:18 +0900)
All commands accepting arguments, handling them with OT_NORMAL, OT_SQLID
or OT_SQLIDHACK, should call ignore_slash_options() in inactive branch
to scan and discard extra arguments.  All the backslash commands that
handle arguments do so, except \bind.

This commit adds the missing ignore_slash_options to \bind's inactive
branch.  This inconsistency is a logic bug, however the behavior happens
to be unchanged as any extra arguments are discarded later in
HandleSlashCmds(), so no backpatch is done.

While on it, this adds \bind to the list of backslash commands where
inactive \if branches are checked in the tests for psql.

Reported-by: Jelte Fennema-Nio
Author: Anthonin Bonnefoy
Discussion: https://postgr.es/m/CAGECzQR1+udGKz+FbHiCQ7CWDiF1fCGi2xYuvQUODdMAfJbaLA@mail.gmail.com

src/bin/psql/command.c
src/test/regress/expected/psql.out
src/test/regress/sql/psql.sql

index 9ad911e28d58d7c3895f42e9f33c6b6c3b3d40a6..5c906e480688b8135351ebb5190ac64c043ed500 100644 (file)
@@ -486,6 +486,8 @@ exec_command_bind(PsqlScanState scan_state, bool active_branch)
        pset.bind_nparams = nparams;
        pset.bind_flag = true;
    }
+   else
+       ignore_slash_options(scan_state);
 
    return status;
 }
index 4f3fd4642078d7e85f949489fc4588973c69f8b5..ad027725624b7ba1d02e5f69d12bce2d83dc20b6 100644 (file)
@@ -4506,6 +4506,7 @@ bar 'bar' "bar"
    \echo `nosuchcommand` :foo :'foo' :"foo"
    \pset fieldsep | `nosuchcommand` :foo :'foo' :"foo"
    \a
+   SELECT $1 \bind 1 \g
    \C arg1
    \c arg1 arg2 arg3 arg4
    \cd arg1
index c997106b9f3c47c1d062ea880cf143bfcb9e7185..129f8533537511edb9da59b32805033f523ac90c 100644 (file)
@@ -989,6 +989,7 @@ select \if false \\ (bogus \else \\ 42 \endif \\ forty_two;
    \echo `nosuchcommand` :foo :'foo' :"foo"
    \pset fieldsep | `nosuchcommand` :foo :'foo' :"foo"
    \a
+   SELECT $1 \bind 1 \g
    \C arg1
    \c arg1 arg2 arg3 arg4
    \cd arg1