Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c53d6e9

Browse files
committed
Tighten parsing of boolean options to CREATE TYPE and related functions,
so as to deliver more useful error messages for mistakes like 'PASSEDBYVALUE = f'. Per gripe from Gaetano Mendola.
1 parent 89a8e15 commit c53d6e9

File tree

6 files changed

+33
-12
lines changed

6 files changed

+33
-12
lines changed

src/backend/catalog/pg_type.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/pg_type.c,v 1.93 2004/02/12 23:41:02 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/pg_type.c,v 1.94 2004/05/14 16:11:25 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -201,7 +201,7 @@ TypeCreate(const char *typeName,
201201
(internalSize <= 0 || internalSize > (int16) sizeof(Datum)))
202202
ereport(ERROR,
203203
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
204-
errmsg("invalid type internal size %d",
204+
errmsg("internal size %d is invalid for passed-by-value type",
205205
internalSize)));
206206

207207
/* Only varlena types can be toasted */

src/backend/commands/define.c

+20-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/commands/define.c,v 1.87 2004/05/07 00:24:57 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/commands/define.c,v 1.88 2004/05/14 16:11:25 tgl Exp $
1313
*
1414
* DESCRIPTION
1515
* The "DefineFoo" routines take the parse tree and pick out the
@@ -119,6 +119,25 @@ defGetNumeric(DefElem *def)
119119
return 0; /* keep compiler quiet */
120120
}
121121

122+
/*
123+
* Extract a boolean value from a DefElem.
124+
*/
125+
bool
126+
defGetBoolean(DefElem *def)
127+
{
128+
/*
129+
* Presently, boolean flags must simply be present or absent.
130+
* Later we could allow 'flag = t', 'flag = f', etc.
131+
*/
132+
if (def->arg == NULL)
133+
return true;
134+
ereport(ERROR,
135+
(errcode(ERRCODE_SYNTAX_ERROR),
136+
errmsg("%s does not take a parameter",
137+
def->defname)));
138+
return false; /* keep compiler quiet */
139+
}
140+
122141
/*
123142
* Extract an int64 value from a DefElem.
124143
*/

src/backend/commands/functioncmds.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/commands/functioncmds.c,v 1.45 2004/05/07 00:24:57 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/commands/functioncmds.c,v 1.46 2004/05/14 16:11:25 tgl Exp $
1414
*
1515
* DESCRIPTION
1616
* These routines take the parse tree and pick out the
@@ -329,11 +329,12 @@ compute_attributes_with_style(List *parameters, bool *isStrict_p, char *volatili
329329
DefElem *param = (DefElem *) lfirst(pl);
330330

331331
if (pg_strcasecmp(param->defname, "isstrict") == 0)
332-
*isStrict_p = true;
332+
*isStrict_p = defGetBoolean(param);
333333
else if (pg_strcasecmp(param->defname, "iscachable") == 0)
334334
{
335335
/* obsolete spelling of isImmutable */
336-
*volatility_p = PROVOLATILE_IMMUTABLE;
336+
if (defGetBoolean(param))
337+
*volatility_p = PROVOLATILE_IMMUTABLE;
337338
}
338339
else
339340
ereport(WARNING,

src/backend/commands/operatorcmds.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/commands/operatorcmds.c,v 1.14 2004/05/07 00:24:57 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/commands/operatorcmds.c,v 1.15 2004/05/14 16:11:25 tgl Exp $
1313
*
1414
* DESCRIPTION
1515
* The "DefineFoo" routines take the parse tree and pick out the
@@ -124,9 +124,9 @@ DefineOperator(List *names, List *parameters)
124124
else if (pg_strcasecmp(defel->defname, "join") == 0)
125125
joinName = defGetQualifiedName(defel);
126126
else if (pg_strcasecmp(defel->defname, "hashes") == 0)
127-
canHash = TRUE;
127+
canHash = defGetBoolean(defel);
128128
else if (pg_strcasecmp(defel->defname, "merges") == 0)
129-
canMerge = TRUE;
129+
canMerge = defGetBoolean(defel);
130130
else if (pg_strcasecmp(defel->defname, "sort1") == 0)
131131
leftSortName = defGetQualifiedName(defel);
132132
else if (pg_strcasecmp(defel->defname, "sort2") == 0)

src/backend/commands/typecmds.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.55 2004/05/07 00:24:57 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.56 2004/05/14 16:11:25 tgl Exp $
1212
*
1313
* DESCRIPTION
1414
* The "DefineFoo" routines take the parse tree and pick out the
@@ -176,7 +176,7 @@ DefineType(List *names, List *parameters)
176176
else if (pg_strcasecmp(defel->defname, "default") == 0)
177177
defaultValue = defGetString(defel);
178178
else if (pg_strcasecmp(defel->defname, "passedbyvalue") == 0)
179-
byValue = true;
179+
byValue = defGetBoolean(defel);
180180
else if (pg_strcasecmp(defel->defname, "alignment") == 0)
181181
{
182182
char *a = defGetString(defel);

src/include/commands/defrem.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/commands/defrem.h,v 1.55 2004/05/05 04:48:47 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/commands/defrem.h,v 1.56 2004/05/14 16:11:25 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -69,6 +69,7 @@ extern char *case_translate_language_name(const char *input);
6969

7070
extern char *defGetString(DefElem *def);
7171
extern double defGetNumeric(DefElem *def);
72+
extern bool defGetBoolean(DefElem *def);
7273
extern int64 defGetInt64(DefElem *def);
7374
extern List *defGetQualifiedName(DefElem *def);
7475
extern TypeName *defGetTypeName(DefElem *def);

0 commit comments

Comments
 (0)