mirror of
https://github.com/postgres/postgres.git
synced 2025-04-24 10:47:04 +03:00
psql: Reset query buffer of \e, \ef and \ev on error
If any of these commands fail during editing or pre-processing, the command stored in the query buffer would remain around without being executed immediately as PSQL_CMD_ERROR is returned as status. The next command provided by the user would run it, likely causing failures as this could include silently some of the contents generated automatically for views or functions. The problems would be different depending on the psql meta-command used: - For \ev and \ef, some errors can happen in a predictable way while doing an object lookup or while creating an object command. A failure while editing is equally problematic, but the class of failures happening in the code path of do_edit() are unlikely. The query reset is kept in exec_command_ef_ev() as a query may be unchanged. - For \e, error can happen while editing. In both cases, the query buffer is reset on error for an incorrect file number provided, whose value check is done before filling up the query buffer. This is a slight change of behavior compared to the past for some of the predictable error patterns for \ev and \ef, so for now I have made the choice to not backpatch this commit (argument particularly available for v11 that's going to be EOL'd soon). Perhaps this could be revisited later depending on the feedback of this new behavior. Author: Ryoga Yoshida, Michael Paquier Reviewed-by: Aleksander Alekseev, Kyotaro Horiguchi Discussion: https://postgr.es/m/01419622d84ef093fd4fe585520bf03c@oss.nttdata.com
This commit is contained in:
parent
9bfd44bbde
commit
cb943054f3
@ -1127,6 +1127,14 @@ exec_command_edit(PsqlScanState scan_state, bool active_branch,
|
||||
else
|
||||
status = PSQL_CMD_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* On error while editing or if specifying an incorrect line
|
||||
* number, reset the query buffer.
|
||||
*/
|
||||
if (status == PSQL_CMD_ERROR)
|
||||
resetPQExpBuffer(query_buf);
|
||||
|
||||
free(fname);
|
||||
free(ln);
|
||||
}
|
||||
@ -1239,6 +1247,13 @@ exec_command_ef_ev(PsqlScanState scan_state, bool active_branch,
|
||||
status = PSQL_CMD_NEWEDIT;
|
||||
}
|
||||
|
||||
/*
|
||||
* On error while doing object lookup or while editing, or if
|
||||
* specifying an incorrect line number, reset the query buffer.
|
||||
*/
|
||||
if (status == PSQL_CMD_ERROR)
|
||||
resetPQExpBuffer(query_buf);
|
||||
|
||||
free(obj_desc);
|
||||
}
|
||||
else
|
||||
|
Loading…
x
Reference in New Issue
Block a user