]> granicus.if.org Git - postgresql/commitdiff
Tighten parsing of boolean options to CREATE TYPE and related functions,
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 14 May 2004 16:11:25 +0000 (16:11 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 14 May 2004 16:11:25 +0000 (16:11 +0000)
so as to deliver more useful error messages for mistakes like
'PASSEDBYVALUE = f'.  Per gripe from Gaetano Mendola.

src/backend/catalog/pg_type.c
src/backend/commands/define.c
src/backend/commands/functioncmds.c
src/backend/commands/operatorcmds.c
src/backend/commands/typecmds.c
src/include/commands/defrem.h

index efd2f61747c720711ca42719bec2c9e067ccd88f..b5b6eaf9aa4f037cdf82f2c308952e32390588ee 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/catalog/pg_type.c,v 1.93 2004/02/12 23:41:02 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/catalog/pg_type.c,v 1.94 2004/05/14 16:11:25 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -201,7 +201,7 @@ TypeCreate(const char *typeName,
                (internalSize <= 0 || internalSize > (int16) sizeof(Datum)))
                ereport(ERROR,
                                (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
-                                errmsg("invalid type internal size %d",
+                                errmsg("internal size %d is invalid for passed-by-value type",
                                                internalSize)));
 
        /* Only varlena types can be toasted */
index 19f14879a0e83440f97120e4c3d2b9fd977c02bb..e4a62b77308ffe6289cad333bfa5c81e3fc0b961 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/commands/define.c,v 1.87 2004/05/07 00:24:57 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/commands/define.c,v 1.88 2004/05/14 16:11:25 tgl Exp $
  *
  * DESCRIPTION
  *       The "DefineFoo" routines take the parse tree and pick out the
@@ -119,6 +119,25 @@ defGetNumeric(DefElem *def)
        return 0;                                       /* keep compiler quiet */
 }
 
+/*
+ * Extract a boolean value from a DefElem.
+ */
+bool
+defGetBoolean(DefElem *def)
+{
+       /*
+        * Presently, boolean flags must simply be present or absent.
+        * Later we could allow 'flag = t', 'flag = f', etc.
+        */
+       if (def->arg == NULL)
+               return true;
+       ereport(ERROR,
+                       (errcode(ERRCODE_SYNTAX_ERROR),
+                        errmsg("%s does not take a parameter",
+                                       def->defname)));
+       return false;                           /* keep compiler quiet */
+}
+
 /*
  * Extract an int64 value from a DefElem.
  */
index a0a9c5824095850628c64189f6ebca7658b79a2a..c118e8e3b5e7a615e7d64e445c5962a5d8f0a779 100644 (file)
@@ -10,7 +10,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/commands/functioncmds.c,v 1.45 2004/05/07 00:24:57 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/commands/functioncmds.c,v 1.46 2004/05/14 16:11:25 tgl Exp $
  *
  * DESCRIPTION
  *       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
                DefElem    *param = (DefElem *) lfirst(pl);
 
                if (pg_strcasecmp(param->defname, "isstrict") == 0)
-                       *isStrict_p = true;
+                       *isStrict_p = defGetBoolean(param);
                else if (pg_strcasecmp(param->defname, "iscachable") == 0)
                {
                        /* obsolete spelling of isImmutable */
-                       *volatility_p = PROVOLATILE_IMMUTABLE;
+                       if (defGetBoolean(param))
+                               *volatility_p = PROVOLATILE_IMMUTABLE;
                }
                else
                        ereport(WARNING,
index 2736a31f3c094a9613f5e72d347c163812282e8c..a198f51eeebe09d34825a83dad62e88437bae9f5 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/commands/operatorcmds.c,v 1.14 2004/05/07 00:24:57 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/commands/operatorcmds.c,v 1.15 2004/05/14 16:11:25 tgl Exp $
  *
  * DESCRIPTION
  *       The "DefineFoo" routines take the parse tree and pick out the
@@ -124,9 +124,9 @@ DefineOperator(List *names, List *parameters)
                else if (pg_strcasecmp(defel->defname, "join") == 0)
                        joinName = defGetQualifiedName(defel);
                else if (pg_strcasecmp(defel->defname, "hashes") == 0)
-                       canHash = TRUE;
+                       canHash = defGetBoolean(defel);
                else if (pg_strcasecmp(defel->defname, "merges") == 0)
-                       canMerge = TRUE;
+                       canMerge = defGetBoolean(defel);
                else if (pg_strcasecmp(defel->defname, "sort1") == 0)
                        leftSortName = defGetQualifiedName(defel);
                else if (pg_strcasecmp(defel->defname, "sort2") == 0)
index 411ad725bc8fd83110fa526c9b89a7c22e20109a..03428369ff485feb00b508b03d2b96e5288ed3e6 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.55 2004/05/07 00:24:57 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.56 2004/05/14 16:11:25 tgl Exp $
  *
  * DESCRIPTION
  *       The "DefineFoo" routines take the parse tree and pick out the
@@ -176,7 +176,7 @@ DefineType(List *names, List *parameters)
                else if (pg_strcasecmp(defel->defname, "default") == 0)
                        defaultValue = defGetString(defel);
                else if (pg_strcasecmp(defel->defname, "passedbyvalue") == 0)
-                       byValue = true;
+                       byValue = defGetBoolean(defel);
                else if (pg_strcasecmp(defel->defname, "alignment") == 0)
                {
                        char       *a = defGetString(defel);
index 78fe4ab9071a0da97a6ee919286b7d31c4389001..892aee34aedabbab568df5ea04f567980e5895a6 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/commands/defrem.h,v 1.55 2004/05/05 04:48:47 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/commands/defrem.h,v 1.56 2004/05/14 16:11:25 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -69,6 +69,7 @@ extern char *case_translate_language_name(const char *input);
 
 extern char *defGetString(DefElem *def);
 extern double defGetNumeric(DefElem *def);
+extern bool defGetBoolean(DefElem *def);
 extern int64 defGetInt64(DefElem *def);
 extern List *defGetQualifiedName(DefElem *def);
 extern TypeName *defGetTypeName(DefElem *def);