* Transform a list of DefElem into text array format. This is substantially * the same thing as optionListToArray(), except we recognize SET/ADD/DROP * actions for modifying an existing list of options, which is passed in * Datum form as oldOptions. Also, if fdwvalidator isn't InvalidOid * it specifies a validator function to call on the result. * * Returns the array in the form of a Datum
| 118 | * FOREIGN TABLE. |
| 119 | */ |
| 120 | Datum |
| 121 | transformGenericOptions(Oid catalogId, |
| 122 | Datum oldOptions, |
| 123 | List *options, |
| 124 | Oid fdwvalidator) |
| 125 | { |
| 126 | List *resultOptions = untransformRelOptions(oldOptions); |
| 127 | ListCell *optcell; |
| 128 | Datum result; |
| 129 | |
| 130 | foreach(optcell, options) |
| 131 | { |
| 132 | DefElem *od = lfirst(optcell); |
| 133 | ListCell *cell; |
| 134 | |
| 135 | /* |
| 136 | * Find the element in resultOptions. We need this for validation in |
| 137 | * all cases. |
| 138 | */ |
| 139 | foreach(cell, resultOptions) |
| 140 | { |
| 141 | DefElem *def = lfirst(cell); |
| 142 | |
| 143 | if (strcmp(def->defname, od->defname) == 0) |
| 144 | break; |
| 145 | } |
| 146 | |
| 147 | /* |
| 148 | * It is possible to perform multiple SET/DROP actions on the same |
| 149 | * option. The standard permits this, as long as the options to be |
| 150 | * added are unique. Note that an unspecified action is taken to be |
| 151 | * ADD. |
| 152 | */ |
| 153 | switch (od->defaction) |
| 154 | { |
| 155 | case DEFELEM_DROP: |
| 156 | if (!cell) |
| 157 | ereport(ERROR, |
| 158 | (errcode(ERRCODE_UNDEFINED_OBJECT), |
| 159 | errmsg("option \"%s\" not found", |
| 160 | od->defname))); |
| 161 | resultOptions = list_delete_cell(resultOptions, cell); |
| 162 | break; |
| 163 | |
| 164 | case DEFELEM_SET: |
| 165 | if (!cell) |
| 166 | ereport(ERROR, |
| 167 | (errcode(ERRCODE_UNDEFINED_OBJECT), |
| 168 | errmsg("option \"%s\" not found", |
| 169 | od->defname))); |
| 170 | lfirst(cell) = od; |
| 171 | break; |
| 172 | |
| 173 | case DEFELEM_ADD: |
| 174 | case DEFELEM_UNSPEC: |
| 175 | if (cell) |
| 176 | ereport(ERROR, |
| 177 | (errcode(ERRCODE_DUPLICATE_OBJECT), |
no test coverage detected