MCPcopy Create free account
hub / github.com/apache/cloudberry / defGetBoolean

Function defGetBoolean

src/backend/commands/define.c:110–160  ·  view source on GitHub ↗

* Extract a boolean value from a DefElem. */

Source from the content-addressed store, hash-verified

108 * Extract a boolean value from a DefElem.
109 */
110bool
111defGetBoolean(DefElem *def)
112{
113 /*
114 * If no parameter given, assume "true" is meant.
115 */
116 if (def->arg == NULL)
117 return true;
118
119 /*
120 * Allow 0, 1, "true", "false", "on", "off"
121 */
122 switch (nodeTag(def->arg))
123 {
124 case T_Integer:
125 switch (intVal(def->arg))
126 {
127 case 0:
128 return false;
129 case 1:
130 return true;
131 default:
132 /* otherwise, error out below */
133 break;
134 }
135 break;
136 default:
137 {
138 char *sval = defGetString(def);
139
140 /*
141 * The set of strings accepted here should match up with the
142 * grammar's opt_boolean_or_string production.
143 */
144 if (pg_strcasecmp(sval, "true") == 0)
145 return true;
146 if (pg_strcasecmp(sval, "false") == 0)
147 return false;
148 if (pg_strcasecmp(sval, "on") == 0)
149 return true;
150 if (pg_strcasecmp(sval, "off") == 0)
151 return false;
152 }
153 break;
154 }
155 ereport(ERROR,
156 (errcode(ERRCODE_SYNTAX_ERROR),
157 errmsg("%s requires a Boolean value",
158 def->defname)));
159 return false; /* keep compiler quiet */
160}
161
162/*
163 * Extract an int32 value from a DefElem.

Callers 15

make_new_connectionFunction · 0.85
postgres_fdw_validatorFunction · 0.85
apply_server_optionsFunction · 0.85
apply_table_optionsFunction · 0.85
file_fdw_validatorFunction · 0.85
dxsyn_initFunction · 0.85
dintdict_initFunction · 0.85

Calls 4

defGetStringFunction · 0.85
pg_strcasecmpFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected