MCPcopy Create free account
hub / github.com/documentdb/documentdb / SPIReturnDatum

Function SPIReturnDatum

pg_documentdb/src/utils/query_utils.c:318–339  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

316 * Note: position is 1-based index.
317 */
318static Datum
319SPIReturnDatum(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/*

Calls

no outgoing calls

Tested by

no test coverage detected