9
9
*
10
10
*
11
11
* IDENTIFICATION
12
- * $PostgreSQL: pgsql/src/backend/commands/define.c,v 1.103 2009/02/02 19:31:38 alvherre Exp $
12
+ * $PostgreSQL: pgsql/src/backend/commands/define.c,v 1.104 2009/04/04 21:12:31 tgl Exp $
13
13
*
14
14
* DESCRIPTION
15
15
* The "DefineFoo" routines take the parse tree and pick out the
@@ -55,20 +55,24 @@ case_translate_language_name(const char *input)
55
55
}
56
56
57
57
58
- static char *
59
- nodeGetString (Node * value , char * name )
58
+ /*
59
+ * Extract a string value (otherwise uninterpreted) from a DefElem.
60
+ */
61
+ char *
62
+ defGetString (DefElem * def )
60
63
{
61
- if (value == NULL )
64
+ if (def -> arg == NULL )
62
65
ereport (ERROR ,
63
66
(errcode (ERRCODE_SYNTAX_ERROR ),
64
- errmsg ("%s requires a parameter" , name )));
65
- switch (nodeTag (value ))
67
+ errmsg ("%s requires a parameter" ,
68
+ def -> defname )));
69
+ switch (nodeTag (def -> arg ))
66
70
{
67
71
case T_Integer :
68
72
{
69
73
char * str = palloc (32 );
70
74
71
- snprintf (str , 32 , "%ld" , (long ) intVal (value ));
75
+ snprintf (str , 32 , "%ld" , (long ) intVal (def -> arg ));
72
76
return str ;
73
77
}
74
78
case T_Float :
@@ -77,28 +81,19 @@ nodeGetString(Node *value, char *name)
77
81
* T_Float values are kept in string form, so this type cheat
78
82
* works (and doesn't risk losing precision)
79
83
*/
80
- return strVal (value );
84
+ return strVal (def -> arg );
81
85
case T_String :
82
- return strVal (value );
86
+ return strVal (def -> arg );
83
87
case T_TypeName :
84
- return TypeNameToString ((TypeName * ) value );
88
+ return TypeNameToString ((TypeName * ) def -> arg );
85
89
case T_List :
86
- return NameListToString ((List * ) value );
90
+ return NameListToString ((List * ) def -> arg );
87
91
default :
88
- elog (ERROR , "unrecognized node type: %d" , (int ) nodeTag (value ));
92
+ elog (ERROR , "unrecognized node type: %d" , (int ) nodeTag (def -> arg ));
89
93
}
90
94
return NULL ; /* keep compiler quiet */
91
95
}
92
96
93
- /*
94
- * Extract a string value (otherwise uninterpreted) from a DefElem.
95
- */
96
- char *
97
- defGetString (DefElem * def )
98
- {
99
- return nodeGetString (def -> arg , def -> defname );
100
- }
101
-
102
97
/*
103
98
* Extract a numeric value (actually double) from a DefElem.
104
99
*/
@@ -125,22 +120,25 @@ defGetNumeric(DefElem *def)
125
120
return 0 ; /* keep compiler quiet */
126
121
}
127
122
128
- static bool
129
- nodeGetBoolean (Node * value , char * name )
123
+ /*
124
+ * Extract a boolean value from a DefElem.
125
+ */
126
+ bool
127
+ defGetBoolean (DefElem * def )
130
128
{
131
129
/*
132
130
* If no parameter given, assume "true" is meant.
133
131
*/
134
- if (value == NULL )
132
+ if (def -> arg == NULL )
135
133
return true;
136
134
137
135
/*
138
136
* Allow 0, 1, "true", "false"
139
137
*/
140
- switch (nodeTag (value ))
138
+ switch (nodeTag (def -> arg ))
141
139
{
142
140
case T_Integer :
143
- switch (intVal (value ))
141
+ switch (intVal (def -> arg ))
144
142
{
145
143
case 0 :
146
144
return false;
@@ -153,7 +151,7 @@ nodeGetBoolean(Node *value, char *name)
153
151
break ;
154
152
default :
155
153
{
156
- char * sval = nodeGetString ( value , name );
154
+ char * sval = defGetString ( def );
157
155
158
156
if (pg_strcasecmp (sval , "true" ) == 0 )
159
157
return true;
@@ -165,19 +163,11 @@ nodeGetBoolean(Node *value, char *name)
165
163
}
166
164
ereport (ERROR ,
167
165
(errcode (ERRCODE_SYNTAX_ERROR ),
168
- errmsg ("%s requires a Boolean value" , name )));
166
+ errmsg ("%s requires a Boolean value" ,
167
+ def -> defname )));
169
168
return false; /* keep compiler quiet */
170
169
}
171
170
172
- /*
173
- * Extract a boolean value from a DefElem.
174
- */
175
- bool
176
- defGetBoolean (DefElem * def )
177
- {
178
- return nodeGetBoolean (def -> arg , def -> defname );
179
- }
180
-
181
171
/*
182
172
* Extract an int64 value from a DefElem.
183
173
*/
@@ -315,35 +305,11 @@ defGetTypeLength(DefElem *def)
315
305
return 0 ; /* keep compiler quiet */
316
306
}
317
307
318
-
319
308
/*
320
- * Extract a string value (otherwise uninterpreted) from a ReloptElem .
309
+ * Create a DefElem setting "oids" to the specified value .
321
310
*/
322
- char *
323
- reloptGetString ( ReloptElem * relopt )
311
+ DefElem *
312
+ defWithOids ( bool value )
324
313
{
325
- return nodeGetString (relopt -> arg , relopt -> optname );
326
- }
327
-
328
- /*
329
- * Extract a boolean value from a ReloptElem.
330
- */
331
- bool
332
- reloptGetBoolean (ReloptElem * relopt )
333
- {
334
- return nodeGetBoolean (relopt -> arg , relopt -> optname );
335
- }
336
-
337
- /*
338
- * Create a ReloptElem setting "oids" to the specified value.
339
- */
340
- ReloptElem *
341
- reloptWithOids (bool value )
342
- {
343
- ReloptElem * f = makeNode (ReloptElem );
344
-
345
- f -> optname = "oids" ;
346
- f -> nmspc = NULL ;
347
- f -> arg = (Node * ) makeInteger (value );
348
- return f ;
314
+ return makeDefElem ("oids" , (Node * ) makeInteger (value ));
349
315
}
0 commit comments