* Implementation of array_set_element() for an expanded array * * Note: as with any operation on a read/write expanded object, we must * take pains not to leave the object in a corrupt state if we fail partway * through. */
| 2513 | * through. |
| 2514 | */ |
| 2515 | static Datum |
| 2516 | array_set_element_expanded(Datum arraydatum, |
| 2517 | int nSubscripts, int *indx, |
| 2518 | Datum dataValue, bool isNull, |
| 2519 | int arraytyplen, |
| 2520 | int elmlen, bool elmbyval, char elmalign) |
| 2521 | { |
| 2522 | ExpandedArrayHeader *eah; |
| 2523 | Datum *dvalues; |
| 2524 | bool *dnulls; |
| 2525 | int i, |
| 2526 | ndim, |
| 2527 | dim[MAXDIM], |
| 2528 | lb[MAXDIM], |
| 2529 | offset; |
| 2530 | bool dimschanged, |
| 2531 | newhasnulls; |
| 2532 | int addedbefore, |
| 2533 | addedafter; |
| 2534 | char *oldValue; |
| 2535 | |
| 2536 | /* Convert to R/W object if not so already */ |
| 2537 | eah = DatumGetExpandedArray(arraydatum); |
| 2538 | |
| 2539 | /* Sanity-check caller's info against object; we don't use it otherwise */ |
| 2540 | Assert(arraytyplen == -1); |
| 2541 | Assert(elmlen == eah->typlen); |
| 2542 | Assert(elmbyval == eah->typbyval); |
| 2543 | Assert(elmalign == eah->typalign); |
| 2544 | |
| 2545 | /* |
| 2546 | * Copy dimension info into local storage. This allows us to modify the |
| 2547 | * dimensions if needed, while not messing up the expanded value if we |
| 2548 | * fail partway through. |
| 2549 | */ |
| 2550 | ndim = eah->ndims; |
| 2551 | Assert(ndim >= 0 && ndim <= MAXDIM); |
| 2552 | memcpy(dim, eah->dims, ndim * sizeof(int)); |
| 2553 | memcpy(lb, eah->lbound, ndim * sizeof(int)); |
| 2554 | dimschanged = false; |
| 2555 | |
| 2556 | /* |
| 2557 | * if number of dims is zero, i.e. an empty array, create an array with |
| 2558 | * nSubscripts dimensions, and set the lower bounds to the supplied |
| 2559 | * subscripts. |
| 2560 | */ |
| 2561 | if (ndim == 0) |
| 2562 | { |
| 2563 | /* |
| 2564 | * Allocate adequate space for new dimension info. This is harmless |
| 2565 | * if we fail later. |
| 2566 | */ |
| 2567 | Assert(nSubscripts > 0 && nSubscripts <= MAXDIM); |
| 2568 | eah->dims = (int *) MemoryContextAllocZero(eah->hdr.eoh_context, |
| 2569 | nSubscripts * sizeof(int)); |
| 2570 | eah->lbound = (int *) MemoryContextAllocZero(eah->hdr.eoh_context, |
| 2571 | nSubscripts * sizeof(int)); |
| 2572 |
no test coverage detected