* array_set_element : * This routine sets the value of one array element (specified by * a subscript array) to a new value specified by "dataValue". * * This handles both ordinary varlena arrays and fixed-length arrays. * * Inputs: * arraydatum: the initial array object (mustn't be NULL) * nSubscripts: number of subscripts supplied * indx[]: the subscript values * dataValue: the da
| 2212 | * rather than returning a NULL as the fetch operations do. |
| 2213 | */ |
| 2214 | Datum |
| 2215 | array_set_element(Datum arraydatum, |
| 2216 | int nSubscripts, |
| 2217 | int *indx, |
| 2218 | Datum dataValue, |
| 2219 | bool isNull, |
| 2220 | int arraytyplen, |
| 2221 | int elmlen, |
| 2222 | bool elmbyval, |
| 2223 | char elmalign) |
| 2224 | { |
| 2225 | ArrayType *array; |
| 2226 | ArrayType *newarray; |
| 2227 | int i, |
| 2228 | ndim, |
| 2229 | dim[MAXDIM], |
| 2230 | lb[MAXDIM], |
| 2231 | offset; |
| 2232 | char *elt_ptr; |
| 2233 | bool newhasnulls; |
| 2234 | bits8 *oldnullbitmap; |
| 2235 | int oldnitems, |
| 2236 | newnitems, |
| 2237 | olddatasize, |
| 2238 | newsize, |
| 2239 | olditemlen, |
| 2240 | newitemlen, |
| 2241 | overheadlen, |
| 2242 | oldoverheadlen, |
| 2243 | addedbefore, |
| 2244 | addedafter, |
| 2245 | lenbefore, |
| 2246 | lenafter; |
| 2247 | |
| 2248 | if (arraytyplen > 0) |
| 2249 | { |
| 2250 | /* |
| 2251 | * fixed-length arrays -- these are assumed to be 1-d, 0-based. We |
| 2252 | * cannot extend them, either. |
| 2253 | */ |
| 2254 | char *resultarray; |
| 2255 | |
| 2256 | if (nSubscripts != 1) |
| 2257 | ereport(ERROR, |
| 2258 | (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR), |
| 2259 | errmsg("wrong number of array subscripts"))); |
| 2260 | |
| 2261 | if (indx[0] < 0 || indx[0] >= arraytyplen / elmlen) |
| 2262 | ereport(ERROR, |
| 2263 | (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR), |
| 2264 | errmsg("array subscript out of range"))); |
| 2265 | |
| 2266 | if (isNull) |
| 2267 | ereport(ERROR, |
| 2268 | (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), |
| 2269 | errmsg("cannot assign null value to an element of a fixed-length array"))); |
| 2270 | |
| 2271 | resultarray = (char *) palloc(arraytyplen); |
no test coverage detected