2000-01-19 00:30:24 +01:00
|
|
|
/*
|
|
|
|
* psql - the PostgreSQL interactive terminal
|
|
|
|
*
|
2017-01-03 19:48:53 +01:00
|
|
|
* Copyright (c) 2000-2017, PostgreSQL Global Development Group
|
2000-01-19 00:30:24 +01:00
|
|
|
*
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/bin/psql/settings.h
|
2000-01-19 00:30:24 +01:00
|
|
|
*/
|
1999-11-04 22:56:02 +01:00
|
|
|
#ifndef SETTINGS_H
|
|
|
|
#define SETTINGS_H
|
2000-01-19 00:30:24 +01:00
|
|
|
|
1999-11-04 22:56:02 +01:00
|
|
|
|
|
|
|
#include "variables.h"
|
2016-03-24 23:27:28 +01:00
|
|
|
#include "fe_utils/print.h"
|
1999-11-04 22:56:02 +01:00
|
|
|
|
|
|
|
#define DEFAULT_FIELD_SEP "|"
|
2000-01-19 00:30:24 +01:00
|
|
|
#define DEFAULT_RECORD_SEP "\n"
|
2004-11-17 19:32:31 +01:00
|
|
|
|
|
|
|
#if defined(WIN32) || defined(__CYGWIN__)
|
|
|
|
#define DEFAULT_EDITOR "notepad.exe"
|
2011-07-23 23:25:29 +02:00
|
|
|
/* no DEFAULT_EDITOR_LINENUMBER_ARG for Notepad */
|
2004-11-17 19:32:31 +01:00
|
|
|
#else
|
1999-12-10 04:59:30 +01:00
|
|
|
#define DEFAULT_EDITOR "vi"
|
2011-07-23 23:25:29 +02:00
|
|
|
#define DEFAULT_EDITOR_LINENUMBER_ARG "+"
|
2004-11-17 19:32:31 +01:00
|
|
|
#endif
|
1999-11-04 22:56:02 +01:00
|
|
|
|
|
|
|
#define DEFAULT_PROMPT1 "%/%R%# "
|
|
|
|
#define DEFAULT_PROMPT2 "%/%R%# "
|
|
|
|
#define DEFAULT_PROMPT3 ">> "
|
|
|
|
|
Improve consistency of parsing of psql's magic variables.
For simple boolean variables such as ON_ERROR_STOP, psql has for a long
time recognized variant spellings of "on" and "off" (such as "1"/"0"),
and it also made a point of warning you if you'd misspelled the setting.
But these conveniences did not exist for other keyword-valued variables.
In particular, though ECHO_HIDDEN and ON_ERROR_ROLLBACK include "on" and
"off" as possible values, none of the alternative spellings for those were
recognized; and to make matters worse the code would just silently assume
"on" was meant for any unrecognized spelling. Several people have reported
getting bitten by this, so let's fix it. In detail, this patch:
* Allows all spellings recognized by ParseVariableBool() for ECHO_HIDDEN
and ON_ERROR_ROLLBACK.
* Reports a warning for unrecognized values for COMP_KEYWORD_CASE, ECHO,
ECHO_HIDDEN, HISTCONTROL, ON_ERROR_ROLLBACK, and VERBOSITY.
* Recognizes all values for all these variables case-insensitively;
previously there was a mishmash of case-sensitive and case-insensitive
behaviors.
Back-patch to all supported branches. There is a small risk of breaking
existing scripts that were accidentally failing to malfunction; but the
consensus is that the chance of detecting real problems and preventing
future mistakes outweighs this.
2014-12-31 18:16:53 +01:00
|
|
|
/*
|
|
|
|
* Note: these enums should generally be chosen so that zero corresponds
|
|
|
|
* to the default behavior.
|
|
|
|
*/
|
|
|
|
|
2006-08-29 17:19:51 +02:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
PSQL_ECHO_NONE,
|
|
|
|
PSQL_ECHO_QUERIES,
|
2014-07-10 07:27:54 +02:00
|
|
|
PSQL_ECHO_ERRORS,
|
2006-08-29 17:19:51 +02:00
|
|
|
PSQL_ECHO_ALL
|
|
|
|
} PSQL_ECHO;
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
PSQL_ECHO_HIDDEN_OFF,
|
|
|
|
PSQL_ECHO_HIDDEN_ON,
|
|
|
|
PSQL_ECHO_HIDDEN_NOEXEC
|
|
|
|
} PSQL_ECHO_HIDDEN;
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
PSQL_ERROR_ROLLBACK_OFF,
|
|
|
|
PSQL_ERROR_ROLLBACK_INTERACTIVE,
|
|
|
|
PSQL_ERROR_ROLLBACK_ON
|
|
|
|
} PSQL_ERROR_ROLLBACK;
|
|
|
|
|
Improve consistency of parsing of psql's magic variables.
For simple boolean variables such as ON_ERROR_STOP, psql has for a long
time recognized variant spellings of "on" and "off" (such as "1"/"0"),
and it also made a point of warning you if you'd misspelled the setting.
But these conveniences did not exist for other keyword-valued variables.
In particular, though ECHO_HIDDEN and ON_ERROR_ROLLBACK include "on" and
"off" as possible values, none of the alternative spellings for those were
recognized; and to make matters worse the code would just silently assume
"on" was meant for any unrecognized spelling. Several people have reported
getting bitten by this, so let's fix it. In detail, this patch:
* Allows all spellings recognized by ParseVariableBool() for ECHO_HIDDEN
and ON_ERROR_ROLLBACK.
* Reports a warning for unrecognized values for COMP_KEYWORD_CASE, ECHO,
ECHO_HIDDEN, HISTCONTROL, ON_ERROR_ROLLBACK, and VERBOSITY.
* Recognizes all values for all these variables case-insensitively;
previously there was a mishmash of case-sensitive and case-insensitive
behaviors.
Back-patch to all supported branches. There is a small risk of breaking
existing scripts that were accidentally failing to malfunction; but the
consensus is that the chance of detecting real problems and preventing
future mistakes outweighs this.
2014-12-31 18:16:53 +01:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
PSQL_COMP_CASE_PRESERVE_UPPER,
|
|
|
|
PSQL_COMP_CASE_PRESERVE_LOWER,
|
|
|
|
PSQL_COMP_CASE_UPPER,
|
|
|
|
PSQL_COMP_CASE_LOWER
|
|
|
|
} PSQL_COMP_CASE;
|
|
|
|
|
2006-08-29 17:19:51 +02:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
hctl_none = 0,
|
|
|
|
hctl_ignorespace = 1,
|
|
|
|
hctl_ignoredups = 2,
|
|
|
|
hctl_ignoreboth = hctl_ignorespace | hctl_ignoredups
|
|
|
|
} HistControl;
|
|
|
|
|
2009-02-26 17:02:39 +01:00
|
|
|
enum trivalue
|
|
|
|
{
|
|
|
|
TRI_DEFAULT,
|
|
|
|
TRI_NO,
|
|
|
|
TRI_YES
|
|
|
|
};
|
1999-11-04 22:56:02 +01:00
|
|
|
|
|
|
|
typedef struct _psqlSettings
|
|
|
|
{
|
1999-11-05 00:14:30 +01:00
|
|
|
PGconn *db; /* connection to backend */
|
2006-08-29 17:19:51 +02:00
|
|
|
int encoding; /* client_encoding */
|
1999-11-05 00:14:30 +01:00
|
|
|
FILE *queryFout; /* where to send the query results */
|
|
|
|
bool queryFoutPipe; /* queryFout is from a popen() */
|
|
|
|
|
2014-03-10 20:47:06 +01:00
|
|
|
FILE *copyStream; /* Stream to read/write for \copy command */
|
|
|
|
|
2016-04-03 18:29:55 +02:00
|
|
|
PGresult *last_error_result; /* most recent error result, if any */
|
|
|
|
|
1999-11-05 00:14:30 +01:00
|
|
|
printQueryOpt popt;
|
|
|
|
|
|
|
|
char *gfname; /* one-shot file output argument for \g */
|
2013-02-02 23:06:38 +01:00
|
|
|
char *gset_prefix; /* one-shot prefix argument for \gset */
|
Add a \gexec command to psql for evaluation of computed queries.
\gexec executes the just-entered query, like \g, but instead of printing
the results it takes each field as a SQL command to send to the server.
Computing a series of queries to be executed is a fairly common thing,
but up to now you always had to resort to kluges like writing the queries
to a file and then inputting the file. Now it can be done with no
intermediate step.
The implementation is fairly straightforward except for its interaction
with FETCH_COUNT. ExecQueryUsingCursor isn't capable of being called
recursively, and even if it were, its need to create a transaction
block interferes unpleasantly with the desired behavior of \gexec after
a failure of a generated query (i.e., that it can continue). Therefore,
disable use of ExecQueryUsingCursor when doing the master \gexec query.
We can still apply it to individual generated queries, however, and there
might be some value in doing so.
While testing this feature's interaction with single-step mode, I (tgl) was
led to conclude that SendQuery needs to recognize SIGINT (cancel_pressed)
as a negative response to the single-step prompt. Perhaps that's a
back-patchable bug fix, but for now I just included it here.
Corey Huinker, reviewed by Jim Nasby, Daniel Vérité, and myself
2016-04-04 21:25:16 +02:00
|
|
|
bool gexec_flag; /* one-shot flag to execute query's results */
|
2016-04-09 01:23:18 +02:00
|
|
|
bool crosstab_flag; /* one-shot request to crosstab results */
|
2016-04-15 04:54:26 +02:00
|
|
|
char *ctv_args[4]; /* \crosstabview arguments */
|
1999-11-05 00:14:30 +01:00
|
|
|
|
2005-10-15 04:49:52 +02:00
|
|
|
bool notty; /* stdin or stdout is not a tty (as determined
|
|
|
|
* on startup) */
|
2009-02-26 17:02:39 +01:00
|
|
|
enum trivalue getPassword; /* prompt the user for a username and password */
|
1999-11-05 00:14:30 +01:00
|
|
|
FILE *cur_cmd_source; /* describe the status of the current main
|
|
|
|
* loop */
|
|
|
|
bool cur_cmd_interactive;
|
2004-08-29 07:07:03 +02:00
|
|
|
int sversion; /* backend server version */
|
2004-05-12 15:38:49 +02:00
|
|
|
const char *progname; /* in case you renamed psql */
|
2011-07-06 17:45:13 +02:00
|
|
|
char *inputfile; /* file being currently processed, if any */
|
2006-08-11 21:20:59 +02:00
|
|
|
uint64 lineno; /* also for error reporting */
|
2014-09-02 13:05:48 +02:00
|
|
|
uint64 stmt_lineno; /* line number inside the current statement */
|
2000-01-29 17:58:54 +01:00
|
|
|
|
2003-06-28 02:12:40 +02:00
|
|
|
bool timing; /* enable timing of all queries */
|
2004-03-21 23:29:11 +01:00
|
|
|
|
2005-10-15 04:49:52 +02:00
|
|
|
FILE *logfile; /* session log file handle */
|
1999-11-04 22:56:02 +01:00
|
|
|
|
2006-08-29 17:19:51 +02:00
|
|
|
VariableSpace vars; /* "shell variable" repository */
|
2000-01-14 23:18:03 +01:00
|
|
|
|
2006-08-29 17:19:51 +02:00
|
|
|
/*
|
2006-10-04 02:30:14 +02:00
|
|
|
* The remaining fields are set by assign hooks associated with entries in
|
2014-05-06 18:12:18 +02:00
|
|
|
* "vars". They should not be set directly except by those hook
|
2006-10-04 02:30:14 +02:00
|
|
|
* functions.
|
2006-08-29 17:19:51 +02:00
|
|
|
*/
|
|
|
|
bool autocommit;
|
|
|
|
bool on_error_stop;
|
|
|
|
bool quiet;
|
|
|
|
bool singleline;
|
|
|
|
bool singlestep;
|
2006-08-30 00:25:08 +02:00
|
|
|
int fetch_count;
|
2006-08-29 17:19:51 +02:00
|
|
|
PSQL_ECHO echo;
|
|
|
|
PSQL_ECHO_HIDDEN echo_hidden;
|
|
|
|
PSQL_ERROR_ROLLBACK on_error_rollback;
|
Improve consistency of parsing of psql's magic variables.
For simple boolean variables such as ON_ERROR_STOP, psql has for a long
time recognized variant spellings of "on" and "off" (such as "1"/"0"),
and it also made a point of warning you if you'd misspelled the setting.
But these conveniences did not exist for other keyword-valued variables.
In particular, though ECHO_HIDDEN and ON_ERROR_ROLLBACK include "on" and
"off" as possible values, none of the alternative spellings for those were
recognized; and to make matters worse the code would just silently assume
"on" was meant for any unrecognized spelling. Several people have reported
getting bitten by this, so let's fix it. In detail, this patch:
* Allows all spellings recognized by ParseVariableBool() for ECHO_HIDDEN
and ON_ERROR_ROLLBACK.
* Reports a warning for unrecognized values for COMP_KEYWORD_CASE, ECHO,
ECHO_HIDDEN, HISTCONTROL, ON_ERROR_ROLLBACK, and VERBOSITY.
* Recognizes all values for all these variables case-insensitively;
previously there was a mishmash of case-sensitive and case-insensitive
behaviors.
Back-patch to all supported branches. There is a small risk of breaking
existing scripts that were accidentally failing to malfunction; but the
consensus is that the chance of detecting real problems and preventing
future mistakes outweighs this.
2014-12-31 18:16:53 +01:00
|
|
|
PSQL_COMP_CASE comp_case;
|
2006-08-29 17:19:51 +02:00
|
|
|
HistControl histcontrol;
|
|
|
|
const char *prompt1;
|
|
|
|
const char *prompt2;
|
|
|
|
const char *prompt3;
|
|
|
|
PGVerbosity verbosity; /* current error verbosity level */
|
2015-09-05 17:58:20 +02:00
|
|
|
PGContextVisibility show_context; /* current context display level */
|
2006-08-29 17:19:51 +02:00
|
|
|
} PsqlSettings;
|
2000-01-14 23:18:03 +01:00
|
|
|
|
2006-08-29 17:19:51 +02:00
|
|
|
extern PsqlSettings pset;
|
1999-11-04 22:56:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef EXIT_SUCCESS
|
|
|
|
#define EXIT_SUCCESS 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef EXIT_FAILURE
|
|
|
|
#define EXIT_FAILURE 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define EXIT_BADCONN 2
|
|
|
|
|
|
|
|
#define EXIT_USER 3
|
2001-10-28 07:26:15 +01:00
|
|
|
|
1999-11-04 22:56:02 +01:00
|
|
|
#endif
|