Skip to content

Commit ad6bf71

Browse files
committed
Convert three more guc settings to enum type:
default_transaction_isolation, session_replication_role and regex_flavor.
1 parent afa2a9e commit ad6bf71

File tree

4 files changed

+67
-115
lines changed

4 files changed

+67
-115
lines changed

src/backend/utils/adt/regexp.c

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/regexp.c,v 1.79 2008/03/19 02:40:37 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/regexp.c,v 1.80 2008/04/02 14:42:56 mha Exp $
1212
*
1313
* Alistair Crooks added the code for the regex caching
1414
* agc - cached the regular expressions used - there's a good chance
@@ -40,7 +40,7 @@
4040

4141

4242
/* GUC-settable flavor parameter */
43-
static int regex_flavor = REG_ADVANCED;
43+
int regex_flavor = REG_ADVANCED;
4444

4545

4646
/* all the options of interest for regex functions */
@@ -414,33 +414,6 @@ parse_re_flags(pg_re_flags *flags, text *opts)
414414
}
415415

416416

417-
/*
418-
* assign_regex_flavor - GUC hook to validate and set REGEX_FLAVOR
419-
*/
420-
const char *
421-
assign_regex_flavor(const char *value, bool doit, GucSource source)
422-
{
423-
if (pg_strcasecmp(value, "advanced") == 0)
424-
{
425-
if (doit)
426-
regex_flavor = REG_ADVANCED;
427-
}
428-
else if (pg_strcasecmp(value, "extended") == 0)
429-
{
430-
if (doit)
431-
regex_flavor = REG_EXTENDED;
432-
}
433-
else if (pg_strcasecmp(value, "basic") == 0)
434-
{
435-
if (doit)
436-
regex_flavor = REG_BASIC;
437-
}
438-
else
439-
return NULL; /* fail */
440-
return value; /* OK */
441-
}
442-
443-
444417
/*
445418
* report whether regex_flavor is currently BASIC
446419
*/

src/backend/utils/misc/guc.c

Lines changed: 58 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Written by Peter Eisentraut <peter_e@gmx.net>.
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.440 2008/03/25 22:42:45 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.441 2008/04/02 14:42:56 mha Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -54,6 +54,7 @@
5454
#include "postmaster/postmaster.h"
5555
#include "postmaster/syslogger.h"
5656
#include "postmaster/walwriter.h"
57+
#include "regex/regex.h"
5758
#include "storage/fd.h"
5859
#include "storage/freespace.h"
5960
#include "tcop/tcopprot.h"
@@ -140,9 +141,7 @@ static const char *assign_syslog_ident(const char *ident,
140141
bool doit, GucSource source);
141142
#endif
142143

143-
static const char *assign_defaultxactisolevel(const char *newval, bool doit,
144-
GucSource source);
145-
static const char *assign_session_replication_role(const char *newval, bool doit,
144+
static bool assign_session_replication_role(int newval, bool doit,
146145
GucSource source);
147146
static const char *show_num_temp_buffers(void);
148147
static bool assign_phony_autocommit(bool newval, bool doit, GucSource source);
@@ -208,6 +207,29 @@ static const struct config_enum_entry log_statement_options[] = {
208207
{NULL, 0}
209208
};
210209

210+
static const struct config_enum_entry regex_flavor_options[] = {
211+
{"advanced", REG_ADVANCED},
212+
{"extended", REG_EXTENDED},
213+
{"basic", REG_BASIC},
214+
{NULL, 0}
215+
};
216+
217+
static const struct config_enum_entry isolation_level_options[] = {
218+
{"serializable", XACT_SERIALIZABLE},
219+
{"repeatable read", XACT_REPEATABLE_READ},
220+
{"read committed", XACT_READ_COMMITTED},
221+
{"read uncommitted", XACT_READ_UNCOMMITTED},
222+
{NULL, 0}
223+
};
224+
225+
static const struct config_enum_entry session_replication_role_options[] = {
226+
{"origin", SESSION_REPLICATION_ROLE_ORIGIN},
227+
{"replica", SESSION_REPLICATION_ROLE_REPLICA},
228+
{"local", SESSION_REPLICATION_ROLE_LOCAL},
229+
{NULL, 0}
230+
};
231+
232+
211233
/*
212234
* GUC option variables that are exported from this module
213235
*/
@@ -270,11 +292,8 @@ static double phony_random_seed;
270292
static char *backslash_quote_string;
271293
static char *client_encoding_string;
272294
static char *datestyle_string;
273-
static char *default_iso_level_string;
274-
static char *session_replication_role_string;
275295
static char *locale_collate;
276296
static char *locale_ctype;
277-
static char *regex_flavor_string;
278297
static char *server_encoding_string;
279298
static char *server_version_string;
280299
static int server_version_num;
@@ -1988,26 +2007,6 @@ static struct config_string ConfigureNamesString[] =
19882007
"", assign_temp_tablespaces, NULL
19892008
},
19902009

1991-
{
1992-
{"default_transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
1993-
gettext_noop("Sets the transaction isolation level of each new transaction."),
1994-
gettext_noop("Each SQL transaction has an isolation level, which "
1995-
"can be either \"read uncommitted\", \"read committed\", \"repeatable read\", or \"serializable\".")
1996-
},
1997-
&default_iso_level_string,
1998-
"read committed", assign_defaultxactisolevel, NULL
1999-
},
2000-
2001-
{
2002-
{"session_replication_role", PGC_SUSET, CLIENT_CONN_STATEMENT,
2003-
gettext_noop("Sets the session's behavior for triggers and rewrite rules."),
2004-
gettext_noop("Each session can be either"
2005-
" \"origin\", \"replica\", or \"local\".")
2006-
},
2007-
&session_replication_role_string,
2008-
"origin", assign_session_replication_role, NULL
2009-
},
2010-
20112010
{
20122011
{"dynamic_library_path", PGC_SUSET, CLIENT_CONN_OTHER,
20132012
gettext_noop("Sets the path for dynamically loadable modules."),
@@ -2146,15 +2145,6 @@ static struct config_string ConfigureNamesString[] =
21462145
"", NULL, NULL
21472146
},
21482147

2149-
{
2150-
{"regex_flavor", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
2151-
gettext_noop("Sets the regular expression \"flavor\"."),
2152-
gettext_noop("This can be set to advanced, extended, or basic.")
2153-
},
2154-
&regex_flavor_string,
2155-
"advanced", assign_regex_flavor, NULL
2156-
},
2157-
21582148
{
21592149
{"search_path", PGC_USERSET, CLIENT_CONN_STATEMENT,
21602150
gettext_noop("Sets the schema search order for names that are not schema-qualified."),
@@ -2449,6 +2439,16 @@ static struct config_enum ConfigureNamesEnum[] =
24492439
NOTICE, message_level_options,NULL, NULL
24502440
},
24512441

2442+
{
2443+
{"default_transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
2444+
gettext_noop("Sets the transaction isolation level of each new transaction."),
2445+
gettext_noop("Each SQL transaction has an isolation level, which "
2446+
"can be either \"read uncommitted\", \"read committed\", \"repeatable read\", or \"serializable\".")
2447+
},
2448+
&DefaultXactIsoLevel,
2449+
XACT_READ_COMMITTED, isolation_level_options, NULL, NULL
2450+
},
2451+
24522452
{
24532453
{"log_error_verbosity", PGC_SUSET, LOGGING_WHEN,
24542454
gettext_noop("Sets the verbosity of logged messages."),
@@ -2488,7 +2488,25 @@ static struct config_enum ConfigureNamesEnum[] =
24882488
LOGSTMT_NONE, log_statement_options, NULL, NULL
24892489
},
24902490

2491+
{
2492+
{"regex_flavor", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
2493+
gettext_noop("Sets the regular expression \"flavor\"."),
2494+
gettext_noop("This can be set to advanced, extended, or basic.")
2495+
},
2496+
&regex_flavor,
2497+
REG_ADVANCED, regex_flavor_options, NULL, NULL
2498+
},
24912499

2500+
{
2501+
{"session_replication_role", PGC_SUSET, CLIENT_CONN_STATEMENT,
2502+
gettext_noop("Sets the session's behavior for triggers and rewrite rules."),
2503+
gettext_noop("Each session can be either"
2504+
" \"origin\", \"replica\", or \"local\".")
2505+
},
2506+
&SessionReplicationRole,
2507+
SESSION_REPLICATION_ROLE_ORIGIN, session_replication_role_options,
2508+
assign_session_replication_role, NULL
2509+
},
24922510

24932511

24942512
/* End-of-list marker */
@@ -6887,59 +6905,19 @@ assign_syslog_ident(const char *ident, bool doit, GucSource source)
68876905
#endif /* HAVE_SYSLOG */
68886906

68896907

6890-
static const char *
6891-
assign_defaultxactisolevel(const char *newval, bool doit, GucSource source)
6892-
{
6893-
if (pg_strcasecmp(newval, "serializable") == 0)
6894-
{
6895-
if (doit)
6896-
DefaultXactIsoLevel = XACT_SERIALIZABLE;
6897-
}
6898-
else if (pg_strcasecmp(newval, "repeatable read") == 0)
6899-
{
6900-
if (doit)
6901-
DefaultXactIsoLevel = XACT_REPEATABLE_READ;
6902-
}
6903-
else if (pg_strcasecmp(newval, "read committed") == 0)
6904-
{
6905-
if (doit)
6906-
DefaultXactIsoLevel = XACT_READ_COMMITTED;
6907-
}
6908-
else if (pg_strcasecmp(newval, "read uncommitted") == 0)
6909-
{
6910-
if (doit)
6911-
DefaultXactIsoLevel = XACT_READ_UNCOMMITTED;
6912-
}
6913-
else
6914-
return NULL;
6915-
return newval;
6916-
}
6917-
6918-
static const char *
6919-
assign_session_replication_role(const char *newval, bool doit, GucSource source)
6908+
static bool
6909+
assign_session_replication_role(int newval, bool doit, GucSource source)
69206910
{
6921-
int newrole;
6922-
6923-
if (pg_strcasecmp(newval, "origin") == 0)
6924-
newrole = SESSION_REPLICATION_ROLE_ORIGIN;
6925-
else if (pg_strcasecmp(newval, "replica") == 0)
6926-
newrole = SESSION_REPLICATION_ROLE_REPLICA;
6927-
else if (pg_strcasecmp(newval, "local") == 0)
6928-
newrole = SESSION_REPLICATION_ROLE_LOCAL;
6929-
else
6930-
return NULL;
6931-
69326911
/*
69336912
* Must flush the plan cache when changing replication role; but don't
69346913
* flush unnecessarily.
69356914
*/
6936-
if (doit && SessionReplicationRole != newrole)
6915+
if (doit && SessionReplicationRole != newval)
69376916
{
69386917
ResetPlanCache();
6939-
SessionReplicationRole = newrole;
69406918
}
69416919

6942-
return newval;
6920+
return true;
69436921
}
69446922

69456923
static const char *

src/include/regex/regex.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
3030
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3131
*
32-
* $PostgreSQL: pgsql/src/include/regex/regex.h,v 1.29 2008/01/03 20:47:55 tgl Exp $
32+
* $PostgreSQL: pgsql/src/include/regex/regex.h,v 1.30 2008/04/02 14:42:56 mha Exp $
3333
*/
3434

3535
/*
@@ -166,4 +166,9 @@ extern int pg_regexec(regex_t *, const pg_wchar *, size_t, size_t, rm_detail_t *
166166
extern void pg_regfree(regex_t *);
167167
extern size_t pg_regerror(int, const regex_t *, char *, size_t);
168168

169+
/*
170+
* guc configuration variables
171+
*/
172+
extern int regex_flavor;
173+
169174
#endif /* _REGEX_H_ */

src/include/utils/guc.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Copyright (c) 2000-2008, PostgreSQL Global Development Group
88
* Written by Peter Eisentraut <peter_e@gmx.net>.
99
*
10-
* $PostgreSQL: pgsql/src/include/utils/guc.h,v 1.92 2008/03/16 16:42:44 mha Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/guc.h,v 1.93 2008/04/02 14:42:56 mha Exp $
1111
*--------------------------------------------------------------------
1212
*/
1313
#ifndef GUC_H
@@ -263,10 +263,6 @@ extern const char *assign_default_tablespace(const char *newval,
263263
extern const char *assign_temp_tablespaces(const char *newval,
264264
bool doit, GucSource source);
265265

266-
/* in utils/adt/regexp.c */
267-
extern const char *assign_regex_flavor(const char *value,
268-
bool doit, GucSource source);
269-
270266
/* in catalog/namespace.c */
271267
extern const char *assign_search_path(const char *newval,
272268
bool doit, GucSource source);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy