2000-02-15 21:49:31 +01:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* variable.c
|
|
|
|
* Routines for handling of 'SET var TO',
|
|
|
|
* 'SHOW var' and 'RESET var' statements.
|
|
|
|
*
|
|
|
|
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
1997-04-17 15:50:57 +02:00
|
|
|
*
|
2000-02-15 21:49:31 +01:00
|
|
|
* IDENTIFICATION
|
2000-12-03 21:45:40 +01:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.44 2000/12/03 20:45:33 tgl Exp $
|
1997-04-17 15:50:57 +02:00
|
|
|
*
|
2000-02-15 21:49:31 +01:00
|
|
|
*-------------------------------------------------------------------------
|
1997-04-17 15:50:57 +02:00
|
|
|
*/
|
|
|
|
|
2000-10-25 21:44:44 +02:00
|
|
|
#include "postgres.h"
|
|
|
|
|
1997-06-20 19:17:03 +02:00
|
|
|
#include <ctype.h>
|
1997-11-21 19:12:58 +01:00
|
|
|
#include <time.h>
|
1999-07-16 07:00:38 +02:00
|
|
|
|
|
|
|
#include "access/xact.h"
|
1999-09-27 22:27:32 +02:00
|
|
|
#include "catalog/pg_shadow.h"
|
1998-01-05 19:43:18 +01:00
|
|
|
#include "commands/variable.h"
|
1999-07-16 07:00:38 +02:00
|
|
|
#include "miscadmin.h"
|
2000-01-23 00:50:30 +01:00
|
|
|
#include "optimizer/cost.h"
|
|
|
|
#include "optimizer/paths.h"
|
2000-03-17 06:29:07 +01:00
|
|
|
#include "parser/parse_expr.h"
|
1999-07-16 07:00:38 +02:00
|
|
|
#include "utils/builtins.h"
|
2000-05-31 02:28:42 +02:00
|
|
|
#include "utils/guc.h"
|
1999-06-17 17:16:09 +02:00
|
|
|
#include "utils/tqual.h"
|
1999-07-16 07:00:38 +02:00
|
|
|
|
1998-07-18 20:34:34 +02:00
|
|
|
#ifdef MULTIBYTE
|
1998-07-26 06:31:41 +02:00
|
|
|
#include "mb/pg_wchar.h"
|
2000-10-25 21:44:44 +02:00
|
|
|
#else
|
|
|
|
/* Grand unified hard-coded badness */
|
|
|
|
#define pg_encoding_to_char(x) "SQL_ASCII"
|
|
|
|
#define pg_get_client_encoding() 0
|
1998-06-16 09:29:54 +02:00
|
|
|
#endif
|
1999-07-16 07:00:38 +02:00
|
|
|
|
2000-02-15 21:49:31 +01:00
|
|
|
|
1998-10-08 20:30:52 +02:00
|
|
|
static bool show_date(void);
|
|
|
|
static bool reset_date(void);
|
2000-02-19 23:10:47 +01:00
|
|
|
static bool parse_date(char *);
|
1998-10-08 20:30:52 +02:00
|
|
|
static bool show_timezone(void);
|
|
|
|
static bool reset_timezone(void);
|
2000-02-19 23:10:47 +01:00
|
|
|
static bool parse_timezone(char *);
|
2000-05-31 02:28:42 +02:00
|
|
|
|
2000-07-14 17:35:44 +02:00
|
|
|
static bool show_DefaultXactIsoLevel(void);
|
|
|
|
static bool reset_DefaultXactIsoLevel(void);
|
|
|
|
static bool parse_DefaultXactIsoLevel(char *);
|
1998-12-18 10:10:39 +01:00
|
|
|
static bool show_XactIsoLevel(void);
|
|
|
|
static bool reset_XactIsoLevel(void);
|
2000-02-19 23:10:47 +01:00
|
|
|
static bool parse_XactIsoLevel(char *);
|
2000-04-07 15:40:45 +02:00
|
|
|
static bool parse_random_seed(char *);
|
|
|
|
static bool show_random_seed(void);
|
|
|
|
static bool reset_random_seed(void);
|
1999-05-25 18:15:34 +02:00
|
|
|
|
2000-10-25 21:44:44 +02:00
|
|
|
static bool show_client_encoding(void);
|
|
|
|
static bool reset_client_encoding(void);
|
|
|
|
static bool parse_client_encoding(char *);
|
|
|
|
static bool show_server_encoding(void);
|
|
|
|
static bool reset_server_encoding(void);
|
|
|
|
static bool parse_server_encoding(char *);
|
|
|
|
|
2000-05-31 02:28:42 +02:00
|
|
|
|
1998-10-14 07:10:12 +02:00
|
|
|
/*
|
2000-02-19 23:10:47 +01:00
|
|
|
* get_token
|
|
|
|
* Obtain the next item in a comma-separated list of items,
|
|
|
|
* where each item can be either "word" or "word=word".
|
|
|
|
* The "word=word" form is only accepted if 'val' is not NULL.
|
|
|
|
* Words are any sequences not containing whitespace, ',', or '='.
|
|
|
|
* Whitespace can appear between the words and punctuation.
|
1998-10-14 07:10:12 +02:00
|
|
|
*
|
2000-02-19 23:10:47 +01:00
|
|
|
* 'tok': receives a pointer to first word of item, or NULL if none.
|
|
|
|
* 'val': if not NULL, receives a pointer to second word, or NULL if none.
|
|
|
|
* 'str': start of input string.
|
1998-10-14 07:10:12 +02:00
|
|
|
*
|
2000-02-19 23:10:47 +01:00
|
|
|
* Returns NULL if input string contained no more words, else pointer
|
|
|
|
* to just past this item, which can be used as 'str' for next call.
|
|
|
|
* (If this is the last item, returned pointer will point at a null char,
|
|
|
|
* so caller can alternatively check for that instead of calling again.)
|
|
|
|
*
|
|
|
|
* NB: input string is destructively modified by placing null characters
|
|
|
|
* at ends of words!
|
|
|
|
*
|
|
|
|
* A former version of this code avoided modifying the input string by
|
|
|
|
* returning palloc'd copies of the words. However, we want to use this
|
|
|
|
* code early in backend startup to parse the PGDATESTYLE environment var,
|
|
|
|
* and palloc/pfree aren't initialized at that point. Cleanest answer
|
|
|
|
* seems to be to palloc in SetPGVariable() so that we can treat the string
|
|
|
|
* as modifiable here.
|
1998-10-14 07:10:12 +02:00
|
|
|
*/
|
2000-02-19 23:10:47 +01:00
|
|
|
static char *
|
|
|
|
get_token(char **tok, char **val, char *str)
|
1997-06-02 13:00:57 +02:00
|
|
|
{
|
2000-02-19 23:10:47 +01:00
|
|
|
char ch;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
*tok = NULL;
|
|
|
|
if (val != NULL)
|
|
|
|
*val = NULL;
|
|
|
|
|
2000-02-19 23:10:47 +01:00
|
|
|
if (!str || *str == '\0')
|
1997-09-07 07:04:48 +02:00
|
|
|
return NULL;
|
|
|
|
|
2000-02-19 23:10:47 +01:00
|
|
|
/* skip leading white space */
|
2000-12-03 21:45:40 +01:00
|
|
|
while (isspace((unsigned char) *str))
|
1997-09-07 07:04:48 +02:00
|
|
|
str++;
|
|
|
|
|
|
|
|
/* end of string? then return NULL */
|
2000-02-19 23:10:47 +01:00
|
|
|
if (*str == '\0')
|
1997-09-07 07:04:48 +02:00
|
|
|
return NULL;
|
|
|
|
|
2000-02-19 23:10:47 +01:00
|
|
|
if (*str == ',' || *str == '=')
|
|
|
|
elog(ERROR, "Syntax error near \"%s\": empty setting", str);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-02-19 23:10:47 +01:00
|
|
|
/* OK, at beginning of non-empty item */
|
|
|
|
*tok = str;
|
|
|
|
|
|
|
|
/* Advance to end of word */
|
2000-12-03 21:45:40 +01:00
|
|
|
while (*str && !isspace((unsigned char) *str) &&
|
|
|
|
*str != ',' && *str != '=')
|
1997-09-07 07:04:48 +02:00
|
|
|
str++;
|
|
|
|
|
2000-02-19 23:10:47 +01:00
|
|
|
/* Terminate word string for caller */
|
|
|
|
ch = *str;
|
|
|
|
*str = '\0';
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-02-19 23:10:47 +01:00
|
|
|
/* Skip any whitespace */
|
2000-12-03 21:45:40 +01:00
|
|
|
while (isspace((unsigned char) ch))
|
2000-02-19 23:10:47 +01:00
|
|
|
ch = *(++str);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
/* end of string? */
|
2000-02-19 23:10:47 +01:00
|
|
|
if (ch == '\0')
|
1998-09-01 05:29:17 +02:00
|
|
|
return str;
|
2000-02-19 23:10:47 +01:00
|
|
|
/* delimiter? */
|
|
|
|
if (ch == ',')
|
1998-09-01 05:29:17 +02:00
|
|
|
return ++str;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-02-19 23:10:47 +01:00
|
|
|
/* Had better be '=', and caller must be expecting it */
|
|
|
|
if (val == NULL || ch != '=')
|
|
|
|
elog(ERROR, "Syntax error near \"%s\"", str);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-02-19 23:10:47 +01:00
|
|
|
/* '=': get the value */
|
|
|
|
str++;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-02-19 23:10:47 +01:00
|
|
|
/* skip whitespace after '=' */
|
2000-12-03 21:45:40 +01:00
|
|
|
while (isspace((unsigned char) *str))
|
1997-09-07 07:04:48 +02:00
|
|
|
str++;
|
|
|
|
|
2000-02-19 23:10:47 +01:00
|
|
|
if (*str == ',' || *str == '\0')
|
|
|
|
elog(ERROR, "Syntax error near \"=%s\"", str);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-02-19 23:10:47 +01:00
|
|
|
/* OK, at beginning of non-empty value */
|
|
|
|
*val = str;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-02-19 23:10:47 +01:00
|
|
|
/* Advance to end of word */
|
2000-12-03 21:45:40 +01:00
|
|
|
while (*str && !isspace((unsigned char) *str) && *str != ',')
|
1997-09-07 07:04:48 +02:00
|
|
|
str++;
|
|
|
|
|
2000-02-19 23:10:47 +01:00
|
|
|
/* Terminate word string for caller */
|
|
|
|
ch = *str;
|
|
|
|
*str = '\0';
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-02-19 23:10:47 +01:00
|
|
|
/* Skip any whitespace */
|
2000-12-03 21:45:40 +01:00
|
|
|
while (isspace((unsigned char) ch))
|
2000-02-19 23:10:47 +01:00
|
|
|
ch = *(++str);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-02-19 23:10:47 +01:00
|
|
|
/* end of string? */
|
|
|
|
if (ch == '\0')
|
|
|
|
return str;
|
|
|
|
/* delimiter? */
|
|
|
|
if (ch == ',')
|
1998-09-01 05:29:17 +02:00
|
|
|
return ++str;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-02-19 23:10:47 +01:00
|
|
|
elog(ERROR, "Syntax error near \"%s\"", str);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
return str;
|
1997-06-02 13:00:57 +02:00
|
|
|
}
|
1997-06-20 19:17:03 +02:00
|
|
|
|
1997-04-24 17:41:37 +02:00
|
|
|
|
1998-10-14 07:10:12 +02:00
|
|
|
/*
|
|
|
|
* DATE_STYLE
|
|
|
|
*
|
2000-02-19 23:10:47 +01:00
|
|
|
* NOTE: set_default_datestyle() is called during backend startup to check
|
2000-04-12 19:17:23 +02:00
|
|
|
* if the PGDATESTYLE environment variable is set. We want the env var
|
2000-02-19 23:10:47 +01:00
|
|
|
* to determine the value that "RESET DateStyle" will reset to!
|
1998-10-14 07:10:12 +02:00
|
|
|
*/
|
2000-02-19 23:10:47 +01:00
|
|
|
|
|
|
|
/* These get initialized from the "master" values in init/globals.c */
|
2000-04-12 19:17:23 +02:00
|
|
|
static int DefaultDateStyle;
|
2000-02-19 23:10:47 +01:00
|
|
|
static bool DefaultEuroDates;
|
|
|
|
|
1998-10-08 20:30:52 +02:00
|
|
|
static bool
|
2000-02-19 23:10:47 +01:00
|
|
|
parse_date(char *value)
|
1997-06-02 13:00:57 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
char *tok;
|
|
|
|
int dcnt = 0,
|
|
|
|
ecnt = 0;
|
1997-06-20 19:17:03 +02:00
|
|
|
|
1997-11-07 07:43:16 +01:00
|
|
|
if (value == NULL)
|
|
|
|
{
|
|
|
|
reset_date();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
while ((value = get_token(&tok, NULL, value)) != 0)
|
1997-06-02 13:00:57 +02:00
|
|
|
{
|
1997-04-17 15:50:57 +02:00
|
|
|
/* Ugh. Somebody ought to write a table driven version -- mjl */
|
1997-06-20 19:17:03 +02:00
|
|
|
|
1997-12-05 00:17:13 +01:00
|
|
|
if (!strcasecmp(tok, "ISO"))
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
To: Thomas Lockhart <Thomas.G.Lockhart@jpl.nasa.gov>
Subject: Re: [PATCHES] SET DateStyle patches
On Tue, 22 Apr 1997, Thomas Lockhart wrote:
> Some more patches! These (try to) finish implementing SET variable TO value
> for "DateStyle" (changed the name from simply "date" to be more descriptive).
> This is based on code from Martin and Bruce (?), which was easy to modify.
> The syntax is
>
> SET DateStyle TO 'iso'
> SET DateStyle TO 'postgres'
> SET DateStyle TO 'sql'
> SET DateStyle TO 'european'
> SET DateStyle TO 'noneuropean'
> SET DateStyle TO 'us' (same as "noneuropean")
> SET DateStyle TO 'default' (current same as "postgres,us")
>
> ("european" is just compared for the first 4 characters, and "noneuropean"
> is compared for the first 7 to allow less typing).
>
> Multiple arguments are allowed, so SET datestyle TO 'sql,euro' is valid.
>
> My mods also try to implement "SHOW variable" and "RESET variable", but
> that part just core dumps at the moment. I would guess that my errors
> are obvious to someone who knows what they are doing with the parser stuff,
> so if someone (Bruce and/or Martin??) could have it do the right thing
> we will have a more complete set of what we need.
>
> Also, I would like to have a floating point precision global variable to
> implement "SET precision TO 10" and perhaps "SET precision TO 10,2" for
> float8 and float4, but I don't know how to do that for integer types rather
> than strings. If someone is fixing the SHOW and RESET code, perhaps they can
> add some hooks for me to do the floats while they are at it.
>
> I've left some remnants of variable structures in the source code which
> I did not use in the interests of getting something working for v6.1.
> We'll have time to clean things up for the next release...
1997-04-23 05:18:27 +02:00
|
|
|
DateStyle = USE_ISO_DATES;
|
1997-04-17 15:50:57 +02:00
|
|
|
dcnt++;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1997-12-05 00:17:13 +01:00
|
|
|
else if (!strcasecmp(tok, "SQL"))
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
To: Thomas Lockhart <Thomas.G.Lockhart@jpl.nasa.gov>
Subject: Re: [PATCHES] SET DateStyle patches
On Tue, 22 Apr 1997, Thomas Lockhart wrote:
> Some more patches! These (try to) finish implementing SET variable TO value
> for "DateStyle" (changed the name from simply "date" to be more descriptive).
> This is based on code from Martin and Bruce (?), which was easy to modify.
> The syntax is
>
> SET DateStyle TO 'iso'
> SET DateStyle TO 'postgres'
> SET DateStyle TO 'sql'
> SET DateStyle TO 'european'
> SET DateStyle TO 'noneuropean'
> SET DateStyle TO 'us' (same as "noneuropean")
> SET DateStyle TO 'default' (current same as "postgres,us")
>
> ("european" is just compared for the first 4 characters, and "noneuropean"
> is compared for the first 7 to allow less typing).
>
> Multiple arguments are allowed, so SET datestyle TO 'sql,euro' is valid.
>
> My mods also try to implement "SHOW variable" and "RESET variable", but
> that part just core dumps at the moment. I would guess that my errors
> are obvious to someone who knows what they are doing with the parser stuff,
> so if someone (Bruce and/or Martin??) could have it do the right thing
> we will have a more complete set of what we need.
>
> Also, I would like to have a floating point precision global variable to
> implement "SET precision TO 10" and perhaps "SET precision TO 10,2" for
> float8 and float4, but I don't know how to do that for integer types rather
> than strings. If someone is fixing the SHOW and RESET code, perhaps they can
> add some hooks for me to do the floats while they are at it.
>
> I've left some remnants of variable structures in the source code which
> I did not use in the interests of getting something working for v6.1.
> We'll have time to clean things up for the next release...
1997-04-23 05:18:27 +02:00
|
|
|
DateStyle = USE_SQL_DATES;
|
1997-04-17 15:50:57 +02:00
|
|
|
dcnt++;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1997-12-05 00:17:13 +01:00
|
|
|
else if (!strcasecmp(tok, "POSTGRES"))
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
To: Thomas Lockhart <Thomas.G.Lockhart@jpl.nasa.gov>
Subject: Re: [PATCHES] SET DateStyle patches
On Tue, 22 Apr 1997, Thomas Lockhart wrote:
> Some more patches! These (try to) finish implementing SET variable TO value
> for "DateStyle" (changed the name from simply "date" to be more descriptive).
> This is based on code from Martin and Bruce (?), which was easy to modify.
> The syntax is
>
> SET DateStyle TO 'iso'
> SET DateStyle TO 'postgres'
> SET DateStyle TO 'sql'
> SET DateStyle TO 'european'
> SET DateStyle TO 'noneuropean'
> SET DateStyle TO 'us' (same as "noneuropean")
> SET DateStyle TO 'default' (current same as "postgres,us")
>
> ("european" is just compared for the first 4 characters, and "noneuropean"
> is compared for the first 7 to allow less typing).
>
> Multiple arguments are allowed, so SET datestyle TO 'sql,euro' is valid.
>
> My mods also try to implement "SHOW variable" and "RESET variable", but
> that part just core dumps at the moment. I would guess that my errors
> are obvious to someone who knows what they are doing with the parser stuff,
> so if someone (Bruce and/or Martin??) could have it do the right thing
> we will have a more complete set of what we need.
>
> Also, I would like to have a floating point precision global variable to
> implement "SET precision TO 10" and perhaps "SET precision TO 10,2" for
> float8 and float4, but I don't know how to do that for integer types rather
> than strings. If someone is fixing the SHOW and RESET code, perhaps they can
> add some hooks for me to do the floats while they are at it.
>
> I've left some remnants of variable structures in the source code which
> I did not use in the interests of getting something working for v6.1.
> We'll have time to clean things up for the next release...
1997-04-23 05:18:27 +02:00
|
|
|
DateStyle = USE_POSTGRES_DATES;
|
1997-04-17 15:50:57 +02:00
|
|
|
dcnt++;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1997-12-05 00:17:13 +01:00
|
|
|
else if (!strcasecmp(tok, "GERMAN"))
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1997-12-05 00:17:13 +01:00
|
|
|
DateStyle = USE_GERMAN_DATES;
|
|
|
|
dcnt++;
|
To: Thomas Lockhart <Thomas.G.Lockhart@jpl.nasa.gov>
Subject: Re: [PATCHES] SET DateStyle patches
On Tue, 22 Apr 1997, Thomas Lockhart wrote:
> Some more patches! These (try to) finish implementing SET variable TO value
> for "DateStyle" (changed the name from simply "date" to be more descriptive).
> This is based on code from Martin and Bruce (?), which was easy to modify.
> The syntax is
>
> SET DateStyle TO 'iso'
> SET DateStyle TO 'postgres'
> SET DateStyle TO 'sql'
> SET DateStyle TO 'european'
> SET DateStyle TO 'noneuropean'
> SET DateStyle TO 'us' (same as "noneuropean")
> SET DateStyle TO 'default' (current same as "postgres,us")
>
> ("european" is just compared for the first 4 characters, and "noneuropean"
> is compared for the first 7 to allow less typing).
>
> Multiple arguments are allowed, so SET datestyle TO 'sql,euro' is valid.
>
> My mods also try to implement "SHOW variable" and "RESET variable", but
> that part just core dumps at the moment. I would guess that my errors
> are obvious to someone who knows what they are doing with the parser stuff,
> so if someone (Bruce and/or Martin??) could have it do the right thing
> we will have a more complete set of what we need.
>
> Also, I would like to have a floating point precision global variable to
> implement "SET precision TO 10" and perhaps "SET precision TO 10,2" for
> float8 and float4, but I don't know how to do that for integer types rather
> than strings. If someone is fixing the SHOW and RESET code, perhaps they can
> add some hooks for me to do the floats while they are at it.
>
> I've left some remnants of variable structures in the source code which
> I did not use in the interests of getting something working for v6.1.
> We'll have time to clean things up for the next release...
1997-04-23 05:18:27 +02:00
|
|
|
EuroDates = TRUE;
|
1998-02-26 05:46:47 +01:00
|
|
|
if ((ecnt > 0) && (!EuroDates))
|
|
|
|
ecnt++;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1997-12-05 00:17:13 +01:00
|
|
|
else if (!strncasecmp(tok, "EURO", 4))
|
|
|
|
{
|
|
|
|
EuroDates = TRUE;
|
1998-02-26 05:46:47 +01:00
|
|
|
if ((dcnt <= 0) || (DateStyle != USE_GERMAN_DATES))
|
|
|
|
ecnt++;
|
1997-12-05 00:17:13 +01:00
|
|
|
}
|
|
|
|
else if ((!strcasecmp(tok, "US"))
|
|
|
|
|| (!strncasecmp(tok, "NONEURO", 7)))
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
To: Thomas Lockhart <Thomas.G.Lockhart@jpl.nasa.gov>
Subject: Re: [PATCHES] SET DateStyle patches
On Tue, 22 Apr 1997, Thomas Lockhart wrote:
> Some more patches! These (try to) finish implementing SET variable TO value
> for "DateStyle" (changed the name from simply "date" to be more descriptive).
> This is based on code from Martin and Bruce (?), which was easy to modify.
> The syntax is
>
> SET DateStyle TO 'iso'
> SET DateStyle TO 'postgres'
> SET DateStyle TO 'sql'
> SET DateStyle TO 'european'
> SET DateStyle TO 'noneuropean'
> SET DateStyle TO 'us' (same as "noneuropean")
> SET DateStyle TO 'default' (current same as "postgres,us")
>
> ("european" is just compared for the first 4 characters, and "noneuropean"
> is compared for the first 7 to allow less typing).
>
> Multiple arguments are allowed, so SET datestyle TO 'sql,euro' is valid.
>
> My mods also try to implement "SHOW variable" and "RESET variable", but
> that part just core dumps at the moment. I would guess that my errors
> are obvious to someone who knows what they are doing with the parser stuff,
> so if someone (Bruce and/or Martin??) could have it do the right thing
> we will have a more complete set of what we need.
>
> Also, I would like to have a floating point precision global variable to
> implement "SET precision TO 10" and perhaps "SET precision TO 10,2" for
> float8 and float4, but I don't know how to do that for integer types rather
> than strings. If someone is fixing the SHOW and RESET code, perhaps they can
> add some hooks for me to do the floats while they are at it.
>
> I've left some remnants of variable structures in the source code which
> I did not use in the interests of getting something working for v6.1.
> We'll have time to clean things up for the next release...
1997-04-23 05:18:27 +02:00
|
|
|
EuroDates = FALSE;
|
1998-02-26 05:46:47 +01:00
|
|
|
if ((dcnt <= 0) || (DateStyle == USE_GERMAN_DATES))
|
|
|
|
ecnt++;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1997-12-05 00:17:13 +01:00
|
|
|
else if (!strcasecmp(tok, "DEFAULT"))
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
2000-02-19 23:10:47 +01:00
|
|
|
DateStyle = DefaultDateStyle;
|
|
|
|
EuroDates = DefaultEuroDates;
|
1997-04-17 15:50:57 +02:00
|
|
|
ecnt++;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1997-04-17 15:50:57 +02:00
|
|
|
else
|
1998-01-05 17:40:20 +01:00
|
|
|
elog(ERROR, "Bad value for date style (%s)", tok);
|
1997-06-02 13:00:57 +02:00
|
|
|
}
|
1997-06-20 19:17:03 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
if (dcnt > 1 || ecnt > 1)
|
1997-04-17 15:50:57 +02:00
|
|
|
elog(NOTICE, "Conflicting settings for date");
|
1997-06-02 13:00:57 +02:00
|
|
|
|
1997-04-17 15:50:57 +02:00
|
|
|
return TRUE;
|
1997-06-02 13:00:57 +02:00
|
|
|
}
|
1997-06-20 19:17:03 +02:00
|
|
|
|
1998-10-08 20:30:52 +02:00
|
|
|
static bool
|
2000-10-25 21:44:44 +02:00
|
|
|
show_date(void)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
char buf[64];
|
To: Thomas Lockhart <Thomas.G.Lockhart@jpl.nasa.gov>
Subject: Re: [PATCHES] SET DateStyle patches
On Tue, 22 Apr 1997, Thomas Lockhart wrote:
> Some more patches! These (try to) finish implementing SET variable TO value
> for "DateStyle" (changed the name from simply "date" to be more descriptive).
> This is based on code from Martin and Bruce (?), which was easy to modify.
> The syntax is
>
> SET DateStyle TO 'iso'
> SET DateStyle TO 'postgres'
> SET DateStyle TO 'sql'
> SET DateStyle TO 'european'
> SET DateStyle TO 'noneuropean'
> SET DateStyle TO 'us' (same as "noneuropean")
> SET DateStyle TO 'default' (current same as "postgres,us")
>
> ("european" is just compared for the first 4 characters, and "noneuropean"
> is compared for the first 7 to allow less typing).
>
> Multiple arguments are allowed, so SET datestyle TO 'sql,euro' is valid.
>
> My mods also try to implement "SHOW variable" and "RESET variable", but
> that part just core dumps at the moment. I would guess that my errors
> are obvious to someone who knows what they are doing with the parser stuff,
> so if someone (Bruce and/or Martin??) could have it do the right thing
> we will have a more complete set of what we need.
>
> Also, I would like to have a floating point precision global variable to
> implement "SET precision TO 10" and perhaps "SET precision TO 10,2" for
> float8 and float4, but I don't know how to do that for integer types rather
> than strings. If someone is fixing the SHOW and RESET code, perhaps they can
> add some hooks for me to do the floats while they are at it.
>
> I've left some remnants of variable structures in the source code which
> I did not use in the interests of getting something working for v6.1.
> We'll have time to clean things up for the next release...
1997-04-23 05:18:27 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
strcpy(buf, "DateStyle is ");
|
|
|
|
switch (DateStyle)
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
case USE_ISO_DATES:
|
|
|
|
strcat(buf, "ISO");
|
|
|
|
break;
|
|
|
|
case USE_SQL_DATES:
|
|
|
|
strcat(buf, "SQL");
|
|
|
|
break;
|
1997-12-05 00:17:13 +01:00
|
|
|
case USE_GERMAN_DATES:
|
|
|
|
strcat(buf, "German");
|
|
|
|
break;
|
1997-09-08 04:41:22 +02:00
|
|
|
default:
|
|
|
|
strcat(buf, "Postgres");
|
|
|
|
break;
|
1997-05-16 09:24:13 +02:00
|
|
|
};
|
1997-09-07 07:04:48 +02:00
|
|
|
strcat(buf, " with ");
|
|
|
|
strcat(buf, ((EuroDates) ? "European" : "US (NonEuropean)"));
|
|
|
|
strcat(buf, " conventions");
|
To: Thomas Lockhart <Thomas.G.Lockhart@jpl.nasa.gov>
Subject: Re: [PATCHES] SET DateStyle patches
On Tue, 22 Apr 1997, Thomas Lockhart wrote:
> Some more patches! These (try to) finish implementing SET variable TO value
> for "DateStyle" (changed the name from simply "date" to be more descriptive).
> This is based on code from Martin and Bruce (?), which was easy to modify.
> The syntax is
>
> SET DateStyle TO 'iso'
> SET DateStyle TO 'postgres'
> SET DateStyle TO 'sql'
> SET DateStyle TO 'european'
> SET DateStyle TO 'noneuropean'
> SET DateStyle TO 'us' (same as "noneuropean")
> SET DateStyle TO 'default' (current same as "postgres,us")
>
> ("european" is just compared for the first 4 characters, and "noneuropean"
> is compared for the first 7 to allow less typing).
>
> Multiple arguments are allowed, so SET datestyle TO 'sql,euro' is valid.
>
> My mods also try to implement "SHOW variable" and "RESET variable", but
> that part just core dumps at the moment. I would guess that my errors
> are obvious to someone who knows what they are doing with the parser stuff,
> so if someone (Bruce and/or Martin??) could have it do the right thing
> we will have a more complete set of what we need.
>
> Also, I would like to have a floating point precision global variable to
> implement "SET precision TO 10" and perhaps "SET precision TO 10,2" for
> float8 and float4, but I don't know how to do that for integer types rather
> than strings. If someone is fixing the SHOW and RESET code, perhaps they can
> add some hooks for me to do the floats while they are at it.
>
> I've left some remnants of variable structures in the source code which
> I did not use in the interests of getting something working for v6.1.
> We'll have time to clean things up for the next release...
1997-04-23 05:18:27 +02:00
|
|
|
|
|
|
|
elog(NOTICE, buf, NULL);
|
|
|
|
|
|
|
|
return TRUE;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1997-06-20 19:17:03 +02:00
|
|
|
|
1998-10-26 02:00:13 +01:00
|
|
|
static bool
|
2000-10-25 21:44:44 +02:00
|
|
|
reset_date(void)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
2000-02-19 23:10:47 +01:00
|
|
|
DateStyle = DefaultDateStyle;
|
|
|
|
EuroDates = DefaultEuroDates;
|
To: Thomas Lockhart <Thomas.G.Lockhart@jpl.nasa.gov>
Subject: Re: [PATCHES] SET DateStyle patches
On Tue, 22 Apr 1997, Thomas Lockhart wrote:
> Some more patches! These (try to) finish implementing SET variable TO value
> for "DateStyle" (changed the name from simply "date" to be more descriptive).
> This is based on code from Martin and Bruce (?), which was easy to modify.
> The syntax is
>
> SET DateStyle TO 'iso'
> SET DateStyle TO 'postgres'
> SET DateStyle TO 'sql'
> SET DateStyle TO 'european'
> SET DateStyle TO 'noneuropean'
> SET DateStyle TO 'us' (same as "noneuropean")
> SET DateStyle TO 'default' (current same as "postgres,us")
>
> ("european" is just compared for the first 4 characters, and "noneuropean"
> is compared for the first 7 to allow less typing).
>
> Multiple arguments are allowed, so SET datestyle TO 'sql,euro' is valid.
>
> My mods also try to implement "SHOW variable" and "RESET variable", but
> that part just core dumps at the moment. I would guess that my errors
> are obvious to someone who knows what they are doing with the parser stuff,
> so if someone (Bruce and/or Martin??) could have it do the right thing
> we will have a more complete set of what we need.
>
> Also, I would like to have a floating point precision global variable to
> implement "SET precision TO 10" and perhaps "SET precision TO 10,2" for
> float8 and float4, but I don't know how to do that for integer types rather
> than strings. If someone is fixing the SHOW and RESET code, perhaps they can
> add some hooks for me to do the floats while they are at it.
>
> I've left some remnants of variable structures in the source code which
> I did not use in the interests of getting something working for v6.1.
> We'll have time to clean things up for the next release...
1997-04-23 05:18:27 +02:00
|
|
|
|
|
|
|
return TRUE;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1997-06-20 19:17:03 +02:00
|
|
|
|
2000-02-19 23:10:47 +01:00
|
|
|
void
|
|
|
|
set_default_datestyle(void)
|
|
|
|
{
|
|
|
|
char *DBDate;
|
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
/*
|
|
|
|
* Initialize from compile-time defaults in init/globals.c. NB: this
|
|
|
|
* is a necessary step; consider PGDATESTYLE="DEFAULT".
|
2000-02-19 23:10:47 +01:00
|
|
|
*/
|
|
|
|
DefaultDateStyle = DateStyle;
|
|
|
|
DefaultEuroDates = EuroDates;
|
|
|
|
|
|
|
|
/* If the environment var is set, override compiled-in values */
|
|
|
|
DBDate = getenv("PGDATESTYLE");
|
|
|
|
if (DBDate == NULL)
|
|
|
|
return;
|
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
/*
|
|
|
|
* Make a modifiable copy --- overwriting the env var doesn't seem
|
2000-02-19 23:10:47 +01:00
|
|
|
* like a good idea, even though we currently won't look at it again.
|
2000-04-12 19:17:23 +02:00
|
|
|
* Note that we cannot use palloc at this early stage of
|
|
|
|
* initialization.
|
2000-02-19 23:10:47 +01:00
|
|
|
*/
|
|
|
|
DBDate = strdup(DBDate);
|
|
|
|
|
|
|
|
/* Parse desired setting into DateStyle/EuroDates */
|
|
|
|
parse_date(DBDate);
|
|
|
|
|
|
|
|
free(DBDate);
|
|
|
|
|
|
|
|
/* And make it the default for future RESETs */
|
|
|
|
DefaultDateStyle = DateStyle;
|
|
|
|
DefaultEuroDates = EuroDates;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-10 16:24:56 +01:00
|
|
|
/* Timezone support
|
|
|
|
* Working storage for strings is allocated with an arbitrary size of 64 bytes.
|
|
|
|
*/
|
|
|
|
|
1997-11-07 07:43:16 +01:00
|
|
|
static char *defaultTZ = NULL;
|
1997-11-10 16:24:56 +01:00
|
|
|
static char TZvalue[64];
|
|
|
|
static char tzbuf[64];
|
1997-11-07 07:43:16 +01:00
|
|
|
|
1998-10-14 07:10:12 +02:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* TIMEZONE
|
|
|
|
*
|
|
|
|
*/
|
1997-11-10 16:37:15 +01:00
|
|
|
/* parse_timezone()
|
|
|
|
* Handle SET TIME ZONE...
|
|
|
|
* Try to save existing TZ environment variable for later use in RESET TIME ZONE.
|
|
|
|
* - thomas 1997-11-10
|
|
|
|
*/
|
1998-10-08 20:30:52 +02:00
|
|
|
static bool
|
2000-02-19 23:10:47 +01:00
|
|
|
parse_timezone(char *value)
|
1997-10-30 17:52:11 +01:00
|
|
|
{
|
|
|
|
char *tok;
|
|
|
|
|
1997-11-07 07:43:16 +01:00
|
|
|
if (value == NULL)
|
|
|
|
{
|
|
|
|
reset_timezone();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1997-10-30 17:52:11 +01:00
|
|
|
while ((value = get_token(&tok, NULL, value)) != 0)
|
|
|
|
{
|
1997-11-10 16:24:56 +01:00
|
|
|
/* Not yet tried to save original value from environment? */
|
|
|
|
if (defaultTZ == NULL)
|
There's a patch attached to fix gcc 2.8.x warnings, except for the
yyerror ones from bison. It also includes a few 'enhancements' to
the C programming style (which are, of course, personal).
The other patch removes the compilation of backend/lib/qsort.c, as
qsort() is a standard function in stdlib.h and can be used any
where else (and it is). It was only used in
backend/optimizer/geqo/geqo_pool.c, backend/optimizer/path/predmig.c,
and backend/storage/page/bufpage.c
> > Some or all of these changes might not be appropriate for v6.3,
since we > > are in beta testing and since they do not affect the
current functionality. > > For those cases, how about submitting
patches based on the final v6.3 > > release?
There's more to come. Please review these patches. I ran the
regression tests and they only failed where this was expected
(random, geo, etc).
Cheers,
Jeroen
1998-03-30 18:47:35 +02:00
|
|
|
{
|
1997-11-10 16:24:56 +01:00
|
|
|
/* found something? then save it for later */
|
1998-02-03 17:06:49 +01:00
|
|
|
if ((defaultTZ = getenv("TZ")) != NULL)
|
|
|
|
strcpy(TZvalue, defaultTZ);
|
|
|
|
|
There's a patch attached to fix gcc 2.8.x warnings, except for the
yyerror ones from bison. It also includes a few 'enhancements' to
the C programming style (which are, of course, personal).
The other patch removes the compilation of backend/lib/qsort.c, as
qsort() is a standard function in stdlib.h and can be used any
where else (and it is). It was only used in
backend/optimizer/geqo/geqo_pool.c, backend/optimizer/path/predmig.c,
and backend/storage/page/bufpage.c
> > Some or all of these changes might not be appropriate for v6.3,
since we > > are in beta testing and since they do not affect the
current functionality. > > For those cases, how about submitting
patches based on the final v6.3 > > release?
There's more to come. Please review these patches. I ran the
regression tests and they only failed where this was expected
(random, geo, etc).
Cheers,
Jeroen
1998-03-30 18:47:35 +02:00
|
|
|
/* found nothing so mark with an invalid pointer */
|
1997-11-07 07:43:16 +01:00
|
|
|
else
|
1997-11-10 16:24:56 +01:00
|
|
|
defaultTZ = (char *) -1;
|
There's a patch attached to fix gcc 2.8.x warnings, except for the
yyerror ones from bison. It also includes a few 'enhancements' to
the C programming style (which are, of course, personal).
The other patch removes the compilation of backend/lib/qsort.c, as
qsort() is a standard function in stdlib.h and can be used any
where else (and it is). It was only used in
backend/optimizer/geqo/geqo_pool.c, backend/optimizer/path/predmig.c,
and backend/storage/page/bufpage.c
> > Some or all of these changes might not be appropriate for v6.3,
since we > > are in beta testing and since they do not affect the
current functionality. > > For those cases, how about submitting
patches based on the final v6.3 > > release?
There's more to come. Please review these patches. I ran the
regression tests and they only failed where this was expected
(random, geo, etc).
Cheers,
Jeroen
1998-03-30 18:47:35 +02:00
|
|
|
}
|
1997-11-07 07:43:16 +01:00
|
|
|
|
1997-11-10 16:24:56 +01:00
|
|
|
strcpy(tzbuf, "TZ=");
|
|
|
|
strcat(tzbuf, tok);
|
|
|
|
if (putenv(tzbuf) != 0)
|
1998-01-05 17:40:20 +01:00
|
|
|
elog(ERROR, "Unable to set TZ environment variable to %s", tok);
|
1997-11-10 16:24:56 +01:00
|
|
|
|
1997-10-30 17:52:11 +01:00
|
|
|
tzset();
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
1998-02-26 05:46:47 +01:00
|
|
|
} /* parse_timezone() */
|
1997-10-30 17:52:11 +01:00
|
|
|
|
1998-10-08 20:30:52 +02:00
|
|
|
static bool
|
2000-10-25 21:44:44 +02:00
|
|
|
show_timezone(void)
|
1997-10-30 17:52:11 +01:00
|
|
|
{
|
|
|
|
char *tz;
|
|
|
|
|
|
|
|
tz = getenv("TZ");
|
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
elog(NOTICE, "Time zone is %s", ((tz != NULL) ? tz : "unknown"));
|
1997-10-30 17:52:11 +01:00
|
|
|
|
|
|
|
return TRUE;
|
1998-02-26 05:46:47 +01:00
|
|
|
} /* show_timezone() */
|
1997-10-30 17:52:11 +01:00
|
|
|
|
1997-11-10 16:24:56 +01:00
|
|
|
/* reset_timezone()
|
|
|
|
* Set TZ environment variable to original value.
|
|
|
|
* Note that if TZ was originally not set, TZ should be cleared.
|
|
|
|
* unsetenv() works fine, but is BSD, not POSIX, and is not available
|
|
|
|
* under Solaris, among others. Apparently putenv() called as below
|
|
|
|
* clears the process-specific environment variables.
|
|
|
|
* Other reasonable arguments to putenv() (e.g. "TZ=", "TZ", "") result
|
|
|
|
* in a core dump (under Linux anyway).
|
1998-02-03 17:06:49 +01:00
|
|
|
* - thomas 1998-01-26
|
1997-11-10 16:24:56 +01:00
|
|
|
*/
|
1998-10-26 02:00:13 +01:00
|
|
|
static bool
|
2000-10-25 21:44:44 +02:00
|
|
|
reset_timezone(void)
|
1997-10-30 17:52:11 +01:00
|
|
|
{
|
1998-02-03 17:06:49 +01:00
|
|
|
/* no time zone has been set in this session? */
|
|
|
|
if (defaultTZ == NULL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* time zone was set and original explicit time zone available? */
|
|
|
|
else if (defaultTZ != (char *) -1)
|
1997-11-07 07:43:16 +01:00
|
|
|
{
|
1997-11-10 16:24:56 +01:00
|
|
|
strcpy(tzbuf, "TZ=");
|
|
|
|
strcat(tzbuf, TZvalue);
|
|
|
|
if (putenv(tzbuf) != 0)
|
1998-01-05 17:40:20 +01:00
|
|
|
elog(ERROR, "Unable to set TZ environment variable to %s", TZvalue);
|
1998-02-03 17:06:49 +01:00
|
|
|
tzset();
|
1997-11-07 07:43:16 +01:00
|
|
|
}
|
1998-02-03 17:06:49 +01:00
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
/*
|
|
|
|
* otherwise, time zone was set but no original explicit time zone
|
|
|
|
* available
|
|
|
|
*/
|
1997-11-07 07:43:16 +01:00
|
|
|
else
|
|
|
|
{
|
1997-11-10 16:24:56 +01:00
|
|
|
strcpy(tzbuf, "=");
|
|
|
|
if (putenv(tzbuf) != 0)
|
2000-01-15 03:59:43 +01:00
|
|
|
elog(ERROR, "Unable to clear TZ environment variable");
|
1998-02-03 17:06:49 +01:00
|
|
|
tzset();
|
1997-11-07 07:43:16 +01:00
|
|
|
}
|
1997-10-30 17:52:11 +01:00
|
|
|
|
|
|
|
return TRUE;
|
1998-02-26 05:46:47 +01:00
|
|
|
} /* reset_timezone() */
|
1997-10-30 17:52:11 +01:00
|
|
|
|
2000-02-15 21:49:31 +01:00
|
|
|
|
2000-03-17 06:29:07 +01:00
|
|
|
|
2000-02-15 21:49:31 +01:00
|
|
|
/* SET TRANSACTION */
|
|
|
|
|
2000-07-14 17:35:44 +02:00
|
|
|
static bool
|
|
|
|
parse_DefaultXactIsoLevel(char *value)
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
TransactionState s = CurrentTransactionState;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (value == NULL)
|
|
|
|
{
|
|
|
|
reset_DefaultXactIsoLevel();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
if (s->state != TRANS_DEFAULT)
|
|
|
|
{
|
|
|
|
elog(ERROR, "ALTER SESSION/SET TRANSACTION ISOLATION LEVEL"
|
|
|
|
" can not be called within a transaction");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (strcasecmp(value, "SERIALIZABLE") == 0)
|
|
|
|
DefaultXactIsoLevel = XACT_SERIALIZABLE;
|
|
|
|
else if (strcasecmp(value, "COMMITTED") == 0)
|
|
|
|
DefaultXactIsoLevel = XACT_READ_COMMITTED;
|
|
|
|
else
|
|
|
|
elog(ERROR, "Bad TRANSACTION ISOLATION LEVEL (%s)", value);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2000-10-25 21:44:44 +02:00
|
|
|
show_DefaultXactIsoLevel(void)
|
2000-07-14 17:35:44 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
if (DefaultXactIsoLevel == XACT_SERIALIZABLE)
|
|
|
|
elog(NOTICE, "Default TRANSACTION ISOLATION LEVEL is SERIALIZABLE");
|
|
|
|
else
|
|
|
|
elog(NOTICE, "Default TRANSACTION ISOLATION LEVEL is READ COMMITTED");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2000-10-25 21:44:44 +02:00
|
|
|
reset_DefaultXactIsoLevel(void)
|
2000-07-14 17:35:44 +02:00
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
TransactionState s = CurrentTransactionState;
|
|
|
|
|
|
|
|
if (s->state != TRANS_DEFAULT)
|
|
|
|
{
|
|
|
|
elog(ERROR, "ALTER SESSION/SET TRANSACTION ISOLATION LEVEL"
|
|
|
|
" can not be called within a transaction");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
DefaultXactIsoLevel = XACT_READ_COMMITTED;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2000-02-15 21:49:31 +01:00
|
|
|
static bool
|
2000-02-19 23:10:47 +01:00
|
|
|
parse_XactIsoLevel(char *value)
|
2000-02-15 21:49:31 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
if (value == NULL)
|
|
|
|
{
|
|
|
|
reset_XactIsoLevel();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SerializableSnapshot != NULL)
|
|
|
|
{
|
|
|
|
elog(ERROR, "SET TRANSACTION ISOLATION LEVEL must be called before any query");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (strcasecmp(value, "SERIALIZABLE") == 0)
|
|
|
|
XactIsoLevel = XACT_SERIALIZABLE;
|
|
|
|
else if (strcasecmp(value, "COMMITTED") == 0)
|
|
|
|
XactIsoLevel = XACT_READ_COMMITTED;
|
|
|
|
else
|
|
|
|
elog(ERROR, "Bad TRANSACTION ISOLATION LEVEL (%s)", value);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2000-10-25 21:44:44 +02:00
|
|
|
show_XactIsoLevel(void)
|
2000-02-15 21:49:31 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
if (XactIsoLevel == XACT_SERIALIZABLE)
|
|
|
|
elog(NOTICE, "TRANSACTION ISOLATION LEVEL is SERIALIZABLE");
|
|
|
|
else
|
|
|
|
elog(NOTICE, "TRANSACTION ISOLATION LEVEL is READ COMMITTED");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2000-10-25 21:44:44 +02:00
|
|
|
reset_XactIsoLevel(void)
|
2000-02-15 21:49:31 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
if (SerializableSnapshot != NULL)
|
|
|
|
{
|
|
|
|
elog(ERROR, "SET TRANSACTION ISOLATION LEVEL must be called before any query");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
XactIsoLevel = DefaultXactIsoLevel;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-07 15:40:45 +02:00
|
|
|
/*
|
|
|
|
* Random number seed
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
parse_random_seed(char *value)
|
|
|
|
{
|
2000-04-12 19:17:23 +02:00
|
|
|
double seed = 0;
|
2000-04-07 15:40:45 +02:00
|
|
|
|
|
|
|
if (value == NULL)
|
|
|
|
reset_random_seed();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sscanf(value, "%lf", &seed);
|
2000-08-01 20:29:35 +02:00
|
|
|
DirectFunctionCall1(setseed, Float8GetDatum(seed));
|
2000-04-07 15:40:45 +02:00
|
|
|
}
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
show_random_seed(void)
|
|
|
|
{
|
|
|
|
elog(NOTICE, "Seed for random number generator is not known");
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
reset_random_seed(void)
|
|
|
|
{
|
2000-04-12 19:17:23 +02:00
|
|
|
double seed = 0.5;
|
2000-04-07 15:40:45 +02:00
|
|
|
|
2000-08-01 20:29:35 +02:00
|
|
|
DirectFunctionCall1(setseed, Float8GetDatum(seed));
|
2000-04-07 15:40:45 +02:00
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-25 21:44:44 +02:00
|
|
|
/*
|
|
|
|
* MULTIBYTE-related functions
|
|
|
|
*
|
|
|
|
* If MULTIBYTE support was not compiled, we still allow these variables
|
|
|
|
* to exist, but you can't set them to anything but "SQL_ASCII". This
|
|
|
|
* minimizes interoperability problems between non-MB servers and MB-enabled
|
|
|
|
* clients.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static bool
|
|
|
|
parse_client_encoding(char *value)
|
|
|
|
{
|
|
|
|
#ifdef MULTIBYTE
|
|
|
|
int encoding;
|
|
|
|
|
|
|
|
encoding = pg_valid_client_encoding(value);
|
|
|
|
if (encoding < 0)
|
|
|
|
{
|
|
|
|
if (value)
|
|
|
|
elog(ERROR, "Client encoding %s is not supported", value);
|
|
|
|
else
|
|
|
|
elog(ERROR, "No client encoding is specified");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (pg_set_client_encoding(encoding))
|
|
|
|
{
|
|
|
|
elog(ERROR, "Conversion between %s and %s is not supported",
|
|
|
|
value, pg_encoding_to_char(GetDatabaseEncoding()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (value &&
|
|
|
|
strcasecmp(value, pg_encoding_to_char(pg_get_client_encoding())) != 0)
|
|
|
|
elog(ERROR, "Client encoding %s is not supported", value);
|
|
|
|
#endif
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
show_client_encoding(void)
|
|
|
|
{
|
|
|
|
elog(NOTICE, "Current client encoding is %s",
|
|
|
|
pg_encoding_to_char(pg_get_client_encoding()));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
reset_client_encoding(void)
|
|
|
|
{
|
|
|
|
#ifdef MULTIBYTE
|
|
|
|
int encoding;
|
|
|
|
char *env = getenv("PGCLIENTENCODING");
|
|
|
|
|
|
|
|
if (env)
|
|
|
|
{
|
|
|
|
encoding = pg_char_to_encoding(env);
|
|
|
|
if (encoding < 0)
|
|
|
|
encoding = GetDatabaseEncoding();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
encoding = GetDatabaseEncoding();
|
|
|
|
pg_set_client_encoding(encoding);
|
|
|
|
#endif
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2000-10-26 19:31:35 +02:00
|
|
|
/* Called during MULTIBYTE backend startup ... */
|
|
|
|
void
|
|
|
|
set_default_client_encoding(void)
|
|
|
|
{
|
|
|
|
reset_client_encoding();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-25 21:44:44 +02:00
|
|
|
static bool
|
|
|
|
parse_server_encoding(char *value)
|
|
|
|
{
|
|
|
|
elog(NOTICE, "SET SERVER_ENCODING is not supported");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
show_server_encoding(void)
|
|
|
|
{
|
|
|
|
elog(NOTICE, "Current server encoding is %s",
|
|
|
|
pg_encoding_to_char(GetDatabaseEncoding()));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
reset_server_encoding(void)
|
|
|
|
{
|
|
|
|
elog(NOTICE, "RESET SERVER_ENCODING is not supported");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-05-31 02:28:42 +02:00
|
|
|
void
|
|
|
|
SetPGVariable(const char *name, const char *value)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
2000-09-22 17:34:31 +02:00
|
|
|
char *mvalue = value ? pstrdup(value) : ((char*) NULL);
|
|
|
|
|
2000-05-31 02:28:42 +02:00
|
|
|
/*
|
2000-06-23 00:31:24 +02:00
|
|
|
* Special cases ought to be removed and handled separately
|
2000-05-31 02:28:42 +02:00
|
|
|
* by TCOP
|
|
|
|
*/
|
|
|
|
if (strcasecmp(name, "datestyle")==0)
|
2000-09-22 17:34:31 +02:00
|
|
|
parse_date(mvalue);
|
2000-05-31 02:28:42 +02:00
|
|
|
else if (strcasecmp(name, "timezone")==0)
|
2000-09-22 17:34:31 +02:00
|
|
|
parse_timezone(mvalue);
|
2000-07-14 17:35:44 +02:00
|
|
|
else if (strcasecmp(name, "DefaultXactIsoLevel")==0)
|
2000-09-22 17:34:31 +02:00
|
|
|
parse_DefaultXactIsoLevel(mvalue);
|
2000-05-31 02:28:42 +02:00
|
|
|
else if (strcasecmp(name, "XactIsoLevel")==0)
|
2000-09-22 17:34:31 +02:00
|
|
|
parse_XactIsoLevel(mvalue);
|
2000-05-31 02:28:42 +02:00
|
|
|
else if (strcasecmp(name, "client_encoding")==0)
|
2000-09-22 17:34:31 +02:00
|
|
|
parse_client_encoding(mvalue);
|
2000-05-31 02:28:42 +02:00
|
|
|
else if (strcasecmp(name, "server_encoding")==0)
|
2000-09-22 17:34:31 +02:00
|
|
|
parse_server_encoding(mvalue);
|
2000-05-31 02:28:42 +02:00
|
|
|
else if (strcasecmp(name, "random_seed")==0)
|
2000-09-22 17:34:31 +02:00
|
|
|
parse_random_seed(mvalue);
|
2000-05-31 02:28:42 +02:00
|
|
|
else
|
|
|
|
SetConfigOption(name, value, superuser() ? PGC_SUSET : PGC_USERSET);
|
2000-09-22 17:34:31 +02:00
|
|
|
|
|
|
|
if (mvalue)
|
|
|
|
pfree(mvalue);
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1997-03-25 10:44:00 +01:00
|
|
|
|
2000-05-31 02:28:42 +02:00
|
|
|
|
|
|
|
void
|
1997-09-07 07:04:48 +02:00
|
|
|
GetPGVariable(const char *name)
|
|
|
|
{
|
2000-05-31 02:28:42 +02:00
|
|
|
if (strcasecmp(name, "datestyle")==0)
|
|
|
|
show_date();
|
|
|
|
else if (strcasecmp(name, "timezone")==0)
|
|
|
|
show_timezone();
|
2000-07-14 17:35:44 +02:00
|
|
|
else if (strcasecmp(name, "DefaultXactIsoLevel")==0)
|
|
|
|
show_DefaultXactIsoLevel();
|
2000-05-31 02:28:42 +02:00
|
|
|
else if (strcasecmp(name, "XactIsoLevel")==0)
|
|
|
|
show_XactIsoLevel();
|
|
|
|
else if (strcasecmp(name, "client_encoding")==0)
|
|
|
|
show_client_encoding();
|
|
|
|
else if (strcasecmp(name, "server_encoding")==0)
|
|
|
|
show_server_encoding();
|
|
|
|
else if (strcasecmp(name, "random_seed")==0)
|
|
|
|
show_random_seed();
|
|
|
|
else
|
|
|
|
{
|
2000-06-23 00:31:24 +02:00
|
|
|
const char * val = GetConfigOption(name);
|
|
|
|
elog(NOTICE, "%s is %s", name, val);
|
2000-05-31 02:28:42 +02:00
|
|
|
}
|
|
|
|
}
|
1997-06-20 19:17:03 +02:00
|
|
|
|
2000-05-31 02:28:42 +02:00
|
|
|
void
|
1997-09-07 07:04:48 +02:00
|
|
|
ResetPGVariable(const char *name)
|
|
|
|
{
|
2000-05-31 02:28:42 +02:00
|
|
|
if (strcasecmp(name, "datestyle")==0)
|
|
|
|
reset_date();
|
|
|
|
else if (strcasecmp(name, "timezone")==0)
|
|
|
|
reset_timezone();
|
2000-07-14 17:35:44 +02:00
|
|
|
else if (strcasecmp(name, "DefaultXactIsoLevel")==0)
|
|
|
|
reset_DefaultXactIsoLevel();
|
2000-05-31 02:28:42 +02:00
|
|
|
else if (strcasecmp(name, "XactIsoLevel")==0)
|
2000-07-14 17:35:44 +02:00
|
|
|
reset_XactIsoLevel();
|
2000-05-31 02:28:42 +02:00
|
|
|
else if (strcasecmp(name, "client_encoding")==0)
|
|
|
|
reset_client_encoding();
|
|
|
|
else if (strcasecmp(name, "server_encoding")==0)
|
|
|
|
reset_server_encoding();
|
|
|
|
else if (strcasecmp(name, "random_seed")==0)
|
|
|
|
reset_random_seed();
|
|
|
|
else
|
|
|
|
SetConfigOption(name, NULL, superuser() ? PGC_SUSET : PGC_USERSET);
|
|
|
|
}
|