PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ composite_to_json()

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

Definition at line 503 of file lwgeom_out_geojson.c.

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