*** pgsql/src/backend/commands/define.c 2009/01/01 17:23:37 1.102 --- pgsql/src/backend/commands/define.c 2009/02/02 19:31:38 1.103 *************** *** 9,15 **** * * * IDENTIFICATION ! * $PostgreSQL: pgsql/src/backend/commands/define.c,v 1.101 2008/01/01 19:45:48 momjian Exp $ * * DESCRIPTION * The "DefineFoo" routines take the parse tree and pick out the --- 9,15 ---- * * * IDENTIFICATION ! * $PostgreSQL: pgsql/src/backend/commands/define.c,v 1.102 2009/01/01 17:23:37 momjian Exp $ * * DESCRIPTION * The "DefineFoo" routines take the parse tree and pick out the *************** case_translate_language_name(const char *** 55,78 **** } ! /* ! * Extract a string value (otherwise uninterpreted) from a DefElem. ! */ ! char * ! defGetString(DefElem *def) { ! if (def->arg == NULL) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), ! errmsg("%s requires a parameter", ! def->defname))); ! switch (nodeTag(def->arg)) { case T_Integer: { char *str = palloc(32); ! snprintf(str, 32, "%ld", (long) intVal(def->arg)); return str; } case T_Float: --- 55,74 ---- } ! static char * ! nodeGetString(Node *value, char *name) { ! if (value == NULL) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), ! errmsg("%s requires a parameter", name))); ! switch (nodeTag(value)) { case T_Integer: { char *str = palloc(32); ! snprintf(str, 32, "%ld", (long) intVal(value)); return str; } case T_Float: *************** defGetString(DefElem *def) *** 81,100 **** * T_Float values are kept in string form, so this type cheat * works (and doesn't risk losing precision) */ ! return strVal(def->arg); case T_String: ! return strVal(def->arg); case T_TypeName: ! return TypeNameToString((TypeName *) def->arg); case T_List: ! return NameListToString((List *) def->arg); default: ! elog(ERROR, "unrecognized node type: %d", (int) nodeTag(def->arg)); } return NULL; /* keep compiler quiet */ } /* * Extract a numeric value (actually double) from a DefElem. */ double --- 77,105 ---- * T_Float values are kept in string form, so this type cheat * works (and doesn't risk losing precision) */ ! return strVal(value); case T_String: ! return strVal(value); case T_TypeName: ! return TypeNameToString((TypeName *) value); case T_List: ! return NameListToString((List *) value); default: ! elog(ERROR, "unrecognized node type: %d", (int) nodeTag(value)); } return NULL; /* keep compiler quiet */ } /* + * Extract a string value (otherwise uninterpreted) from a DefElem. + */ + char * + defGetString(DefElem *def) + { + return nodeGetString(def->arg, def->defname); + } + + /* * Extract a numeric value (actually double) from a DefElem. */ double *************** defGetNumeric(DefElem *def) *** 120,144 **** return 0; /* keep compiler quiet */ } ! /* ! * Extract a boolean value from a DefElem. ! */ ! bool ! defGetBoolean(DefElem *def) { /* * If no parameter given, assume "true" is meant. */ ! if (def->arg == NULL) return true; /* * Allow 0, 1, "true", "false" */ ! switch (nodeTag(def->arg)) { case T_Integer: ! switch (intVal(def->arg)) { case 0: return false; --- 125,146 ---- return 0; /* keep compiler quiet */ } ! static bool ! nodeGetBoolean(Node *value, char *name) { /* * If no parameter given, assume "true" is meant. */ ! if (value == NULL) return true; /* * Allow 0, 1, "true", "false" */ ! switch (nodeTag(value)) { case T_Integer: ! switch (intVal(value)) { case 0: return false; *************** defGetBoolean(DefElem *def) *** 151,157 **** break; default: { ! char *sval = defGetString(def); if (pg_strcasecmp(sval, "true") == 0) return true; --- 153,159 ---- break; default: { ! char *sval = nodeGetString(value, name); if (pg_strcasecmp(sval, "true") == 0) return true; *************** defGetBoolean(DefElem *def) *** 163,174 **** } ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), ! errmsg("%s requires a Boolean value", ! def->defname))); return false; /* keep compiler quiet */ } /* * Extract an int64 value from a DefElem. */ int64 --- 165,184 ---- } ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), ! errmsg("%s requires a Boolean value", name))); return false; /* keep compiler quiet */ } /* + * Extract a boolean value from a DefElem. + */ + bool + defGetBoolean(DefElem *def) + { + return nodeGetBoolean(def->arg, def->defname); + } + + /* * Extract an int64 value from a DefElem. */ int64 *************** defGetTypeLength(DefElem *def) *** 305,319 **** return 0; /* keep compiler quiet */ } /* ! * Create a DefElem setting "oids" to the specified value. */ ! DefElem * ! defWithOids(bool value) { ! DefElem *f = makeNode(DefElem); ! f->defname = "oids"; f->arg = (Node *) makeInteger(value); return f; } --- 315,349 ---- return 0; /* keep compiler quiet */ } + + /* + * Extract a string value (otherwise uninterpreted) from a ReloptElem. + */ + char * + reloptGetString(ReloptElem *relopt) + { + return nodeGetString(relopt->arg, relopt->optname); + } + + /* + * Extract a boolean value from a ReloptElem. + */ + bool + reloptGetBoolean(ReloptElem *relopt) + { + return nodeGetBoolean(relopt->arg, relopt->optname); + } + /* ! * Create a ReloptElem setting "oids" to the specified value. */ ! ReloptElem * ! reloptWithOids(bool value) { ! ReloptElem *f = makeNode(ReloptElem); ! f->optname = "oids"; ! f->nmspc = NULL; f->arg = (Node *) makeInteger(value); return f; }