PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ composite_to_json()

static void composite_to_json ( Datum  composite,
StringInfo  result,
bool  use_line_feeds 
)
static

Definition at line 482 of file lwgeom_out_geojson.c.

483 {
484  HeapTupleHeader td;
485  Oid tupType;
486  int32 tupTypmod;
487  TupleDesc tupdesc;
488  HeapTupleData tmptup,
489  *tuple;
490  int i;
491  bool needsep = false;
492  const char *sep;
493 
494  sep = use_line_feeds ? ",\n " : ",";
495 
496  td = DatumGetHeapTupleHeader(composite);
497 
498  /* Extract rowtype info and find a tupdesc */
499  tupType = HeapTupleHeaderGetTypeId(td);
500  tupTypmod = HeapTupleHeaderGetTypMod(td);
501  tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
502 
503  /* Build a temporary HeapTuple control structure */
504  tmptup.t_len = HeapTupleHeaderGetDatumLength(td);
505  tmptup.t_data = td;
506  tuple = &tmptup;
507 
508  appendStringInfoChar(result, '{');
509 
510  for (i = 0; i < tupdesc->natts; i++)
511  {
512  Datum val;
513  bool isnull;
514  char *attname;
515  JsonTypeCategory tcategory;
516  Oid outfuncoid;
517  Form_pg_attribute att = TupleDescAttr(tupdesc, i);
518 
519  if (att->attisdropped)
520  continue;
521 
522  if (needsep)
523  appendStringInfoString(result, sep);
524  needsep = true;
525 
526  attname = NameStr(att->attname);
527  escape_json(result, attname);
528  appendStringInfoChar(result, ':');
529 
530  val = heap_getattr(tuple, i + 1, tupdesc, &isnull);
531 
532  if (isnull)
533  {
534  tcategory = JSONTYPE_NULL;
535  outfuncoid = InvalidOid;
536  }
537  else
538  json_categorize_type(att->atttypid, &tcategory, &outfuncoid);
539 
540  datum_to_json(val, isnull, result, tcategory, outfuncoid, false);
541  }
542 
543  appendStringInfoChar(result, '}');
544  ReleaseTupleDesc(tupdesc);
545 }
static void json_categorize_type(Oid typoid, JsonTypeCategory *tcategory, Oid *outfuncoid)
JsonTypeCategory
@ JSONTYPE_NULL
static void datum_to_json(Datum val, bool is_null, StringInfo result, JsonTypeCategory tcategory, Oid outfuncoid, bool key_scalar)
unsigned int int32
Definition: shpopen.c:273

References datum_to_json(), json_categorize_type(), and JSONTYPE_NULL.

Referenced by datum_to_json().

Here is the call graph for this function:
Here is the caller graph for this function: