* array_get_element : * This routine takes an array datum and a subscript array and returns * the referenced item as a Datum. Note that for a pass-by-reference * datatype, the returned Datum is a pointer into the array object. * * This handles both ordinary varlena arrays and fixed-length arrays. * * Inputs: * arraydatum: the array object (mustn't be NULL) * nSubscripts: number of
| 1831 | * *isNull is set to indicate whether the element is NULL. |
| 1832 | */ |
| 1833 | Datum |
| 1834 | array_get_element(Datum arraydatum, |
| 1835 | int nSubscripts, |
| 1836 | int *indx, |
| 1837 | int arraytyplen, |
| 1838 | int elmlen, |
| 1839 | bool elmbyval, |
| 1840 | char elmalign, |
| 1841 | bool *isNull) |
| 1842 | { |
| 1843 | int i, |
| 1844 | ndim, |
| 1845 | *dim, |
| 1846 | *lb, |
| 1847 | offset, |
| 1848 | fixedDim[1], |
| 1849 | fixedLb[1]; |
| 1850 | char *arraydataptr, |
| 1851 | *retptr; |
| 1852 | bits8 *arraynullsptr; |
| 1853 | |
| 1854 | if (arraytyplen > 0) |
| 1855 | { |
| 1856 | /* |
| 1857 | * fixed-length arrays -- these are assumed to be 1-d, 0-based |
| 1858 | */ |
| 1859 | ndim = 1; |
| 1860 | fixedDim[0] = arraytyplen / elmlen; |
| 1861 | fixedLb[0] = 0; |
| 1862 | dim = fixedDim; |
| 1863 | lb = fixedLb; |
| 1864 | arraydataptr = (char *) DatumGetPointer(arraydatum); |
| 1865 | arraynullsptr = NULL; |
| 1866 | } |
| 1867 | else if (VARATT_IS_EXTERNAL_EXPANDED(DatumGetPointer(arraydatum))) |
| 1868 | { |
| 1869 | /* expanded array: let's do this in a separate function */ |
| 1870 | return array_get_element_expanded(arraydatum, |
| 1871 | nSubscripts, |
| 1872 | indx, |
| 1873 | arraytyplen, |
| 1874 | elmlen, |
| 1875 | elmbyval, |
| 1876 | elmalign, |
| 1877 | isNull); |
| 1878 | } |
| 1879 | else |
| 1880 | { |
| 1881 | /* detoast array if necessary, producing normal varlena input */ |
| 1882 | ArrayType *array = DatumGetArrayTypeP(arraydatum); |
| 1883 | |
| 1884 | ndim = ARR_NDIM(array); |
| 1885 | dim = ARR_DIMS(array); |
| 1886 | lb = ARR_LBOUND(array); |
| 1887 | arraydataptr = ARR_DATA_PTR(array); |
| 1888 | arraynullsptr = ARR_NULLBITMAP(array); |
| 1889 | } |
| 1890 |
no test coverage detected