* Extract a boolean value from a DefElem. */
| 108 | * Extract a boolean value from a DefElem. |
| 109 | */ |
| 110 | bool |
| 111 | defGetBoolean(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. |
no test coverage detected