* SPIReturnDatum copies first datum of the first tuple returned to SPI * by the last query that has been executed into current memory context and * returns that datum. * * Returns NULL if query returned nothing at all or if the returned datum * itself is NULL. * * Note: position is 1-based index. */
| 316 | * Note: position is 1-based index. |
| 317 | */ |
| 318 | static Datum |
| 319 | SPIReturnDatum(bool *isNull, int position) |
| 320 | { |
| 321 | *isNull = true; |
| 322 | |
| 323 | Datum retDatum = 0; |
| 324 | if (SPI_processed >= 1 && SPI_tuptable && SPI_tuptable->tupdesc->natts >= position) |
| 325 | { |
| 326 | int tupleNumber = 0; |
| 327 | AttrNumber attrNumber = position; |
| 328 | Datum resultDatum = SPI_getbinval(SPI_tuptable->vals[tupleNumber], |
| 329 | SPI_tuptable->tupdesc, attrNumber, isNull); |
| 330 | if (!*isNull) |
| 331 | { |
| 332 | /* copy datum into original memory context */ |
| 333 | Form_pg_attribute attr = TupleDescAttr(SPI_tuptable->tupdesc, attrNumber - 1); |
| 334 | retDatum = SPI_datumTransfer(resultDatum, attr->attbyval, attr->attlen); |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | return retDatum; |
| 339 | } |
| 340 | |
| 341 | |
| 342 | /* |
no outgoing calls
no test coverage detected