* Add an entry to an option array. The array parameter may be NULL * to indicate the current table entry is NULL. */
| 11664 | * to indicate the current table entry is NULL. |
| 11665 | */ |
| 11666 | ArrayType * |
| 11667 | GUCArrayAdd(ArrayType *array, const char *name, const char *value) |
| 11668 | { |
| 11669 | struct config_generic *record; |
| 11670 | Datum datum; |
| 11671 | char *newval; |
| 11672 | ArrayType *a; |
| 11673 | |
| 11674 | Assert(name); |
| 11675 | Assert(value); |
| 11676 | |
| 11677 | /* test if the option is valid and we're allowed to set it */ |
| 11678 | (void) validate_option_array_item(name, value, false); |
| 11679 | |
| 11680 | /* normalize name (converts obsolete GUC names to modern spellings) */ |
| 11681 | record = find_option(name, false, true, WARNING); |
| 11682 | if (record) |
| 11683 | name = record->name; |
| 11684 | |
| 11685 | /* build new item for array */ |
| 11686 | newval = psprintf("%s=%s", name, value); |
| 11687 | datum = CStringGetTextDatum(newval); |
| 11688 | |
| 11689 | if (array) |
| 11690 | { |
| 11691 | int index; |
| 11692 | bool isnull; |
| 11693 | int i; |
| 11694 | |
| 11695 | Assert(ARR_ELEMTYPE(array) == TEXTOID); |
| 11696 | Assert(ARR_NDIM(array) == 1); |
| 11697 | Assert(ARR_LBOUND(array)[0] == 1); |
| 11698 | |
| 11699 | index = ARR_DIMS(array)[0] + 1; /* add after end */ |
| 11700 | |
| 11701 | for (i = 1; i <= ARR_DIMS(array)[0]; i++) |
| 11702 | { |
| 11703 | Datum d; |
| 11704 | char *current; |
| 11705 | |
| 11706 | d = array_ref(array, 1, &i, |
| 11707 | -1 /* varlenarray */ , |
| 11708 | -1 /* TEXT's typlen */ , |
| 11709 | false /* TEXT's typbyval */ , |
| 11710 | TYPALIGN_INT /* TEXT's typalign */ , |
| 11711 | &isnull); |
| 11712 | if (isnull) |
| 11713 | continue; |
| 11714 | current = TextDatumGetCString(d); |
| 11715 | |
| 11716 | /* check for match up through and including '=' */ |
| 11717 | if (strncmp(current, newval, strlen(name) + 1) == 0) |
| 11718 | { |
| 11719 | index = i; |
| 11720 | break; |
| 11721 | } |
| 11722 | } |
| 11723 |
no test coverage detected