* Array walker for setPath */
| 5114 | * Array walker for setPath |
| 5115 | */ |
| 5116 | static void |
| 5117 | setPathArray(JsonbIterator **it, Datum *path_elems, bool *path_nulls, |
| 5118 | int path_len, JsonbParseState **st, int level, |
| 5119 | JsonbValue *newval, uint32 nelems, int op_type) |
| 5120 | { |
| 5121 | JsonbValue v; |
| 5122 | int idx, |
| 5123 | i; |
| 5124 | bool done = false; |
| 5125 | |
| 5126 | /* pick correct index */ |
| 5127 | if (level < path_len && !path_nulls[level]) |
| 5128 | { |
| 5129 | char *c = TextDatumGetCString(path_elems[level]); |
| 5130 | char *badp; |
| 5131 | |
| 5132 | errno = 0; |
| 5133 | idx = strtoint(c, &badp, 10); |
| 5134 | if (badp == c || *badp != '\0' || errno != 0) |
| 5135 | ereport(ERROR, |
| 5136 | (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), |
| 5137 | errmsg("path element at position %d is not an integer: \"%s\"", |
| 5138 | level + 1, c))); |
| 5139 | } |
| 5140 | else |
| 5141 | idx = nelems; |
| 5142 | |
| 5143 | if (idx < 0) |
| 5144 | { |
| 5145 | if (-idx > nelems) |
| 5146 | { |
| 5147 | /* |
| 5148 | * If asked to keep elements position consistent, it's not allowed |
| 5149 | * to prepend the array. |
| 5150 | */ |
| 5151 | if (op_type & JB_PATH_CONSISTENT_POSITION) |
| 5152 | ereport(ERROR, |
| 5153 | (errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
| 5154 | errmsg("path element at position %d is out of range: %d", |
| 5155 | level + 1, idx))); |
| 5156 | else |
| 5157 | idx = INT_MIN; |
| 5158 | } |
| 5159 | else |
| 5160 | idx = nelems + idx; |
| 5161 | } |
| 5162 | |
| 5163 | /* |
| 5164 | * Filling the gaps means there are no limits on the positive index are |
| 5165 | * imposed, we can set any element. Otherwise limit the index by nelems. |
| 5166 | */ |
| 5167 | if (!(op_type & JB_PATH_FILL_GAPS)) |
| 5168 | { |
| 5169 | if (idx > 0 && idx > nelems) |
| 5170 | idx = nelems; |
| 5171 | } |
| 5172 | |
| 5173 | /* |
no test coverage detected