PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ composite_to_json()

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

Definition at line 498 of file lwgeom_out_geojson.c.

499 {
500  HeapTupleHeader td;
501  Oid tupType;
502  int32 tupTypmod;
503  TupleDesc tupdesc;
504  HeapTupleData tmptup,
505  *tuple;
506  int i;
507  bool needsep = false;
508  const char *sep;
509 
510  sep = use_line_feeds ? ",\n " : ",";
511 
512  td = DatumGetHeapTupleHeader(composite);
513 
514  /* Extract rowtype info and find a tupdesc */
515  tupType = HeapTupleHeaderGetTypeId(td);
516  tupTypmod = HeapTupleHeaderGetTypMod(td);
517  tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
518 
519  /* Build a temporary HeapTuple control structure */
520  tmptup.t_len = HeapTupleHeaderGetDatumLength(td);
521  tmptup.t_data = td;
522  tuple = &tmptup;
523 
524  appendStringInfoChar(result, '{');
525 
526  for (i = 0; i < tupdesc->natts; i++)
527  {
528  Datum val;
529  bool isnull;
530  char *attname;
531  JsonTypeCategory tcategory;
532  Oid outfuncoid;
533  Form_pg_attribute att = TupleDescAttr(tupdesc, i);
534 
535  if (att->attisdropped)
536  continue;
537 
538  if (needsep)
539  appendStringInfoString(result, sep);
540  needsep = true;
541 
542  attname = NameStr(att->attname);
543  escape_json(result, attname);
544  appendStringInfoChar(result, ':');
545 
546  val = heap_getattr(tuple, i + 1, tupdesc, &isnull);
547 
548  if (isnull)
549  {
550  tcategory = JSONTYPE_NULL;
551  outfuncoid = InvalidOid;
552  }
553  else
554  json_categorize_type(att->atttypid, &tcategory, &outfuncoid);
555 
556  datum_to_json(val, isnull, result, tcategory, outfuncoid, false);
557  }
558 
559  appendStringInfoChar(result, '}');
560  ReleaseTupleDesc(tupdesc);
561 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
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:54

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

Referenced by datum_to_json().

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