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

Function ParseVariableBool

src/bin/psql/variables.c:106–144  ·  view source on GitHub ↗

* Try to interpret "value" as a boolean value, and if successful, * store it in *result. Otherwise don't clobber *result. * * Valid values are: true, false, yes, no, on, off, 1, 0; as well as unique * prefixes thereof. * * "name" is the name of the variable we're assigning to, to use in error * report if any. Pass name == NULL to suppress the error report. * * Return true when "value" i

Source from the content-addressed store, hash-verified

104 * Return true when "value" is syntactically valid, false otherwise.
105 */
106bool
107ParseVariableBool(const char *value, const char *name, bool *result)
108{
109 size_t len;
110 bool valid = true;
111
112 /* Treat "unset" as an empty string, which will lead to error below */
113 if (value == NULL)
114 value = "";
115
116 len = strlen(value);
117
118 if (len > 0 && pg_strncasecmp(value, "true", len) == 0)
119 *result = true;
120 else if (len > 0 && pg_strncasecmp(value, "false", len) == 0)
121 *result = false;
122 else if (len > 0 && pg_strncasecmp(value, "yes", len) == 0)
123 *result = true;
124 else if (len > 0 && pg_strncasecmp(value, "no", len) == 0)
125 *result = false;
126 /* 'o' is not unique enough */
127 else if (pg_strncasecmp(value, "on", (len > 2 ? len : 2)) == 0)
128 *result = true;
129 else if (pg_strncasecmp(value, "off", (len > 2 ? len : 2)) == 0)
130 *result = false;
131 else if (pg_strcasecmp(value, "1") == 0)
132 *result = true;
133 else if (pg_strcasecmp(value, "0") == 0)
134 *result = false;
135 else
136 {
137 /* string is not recognized; don't clobber *result */
138 if (name)
139 pg_log_error("unrecognized value \"%s\" for \"%s\": Boolean expected",
140 value, name);
141 valid = false;
142 }
143 return valid;
144}
145
146/*
147 * Try to interpret "value" as an integer value, and if successful,

Callers 13

autocommit_hookFunction · 0.85
on_error_stop_hookFunction · 0.85
quiet_hookFunction · 0.85
singleline_hookFunction · 0.85
singlestep_hookFunction · 0.85
echo_hidden_hookFunction · 0.85
on_error_rollback_hookFunction · 0.85
hide_compression_hookFunction · 0.85
hide_tableam_hookFunction · 0.85
exec_command_connectFunction · 0.85
exec_command_timingFunction · 0.85

Calls 2

pg_strncasecmpFunction · 0.85
pg_strcasecmpFunction · 0.85

Tested by

no test coverage detected