PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ inspect_table()

static void inspect_table ( struct flatgeobuf_agg_ctx ctx)
static

Definition at line 69 of file flatgeobuf.c.

70 {
71  flatgeobuf_column *c;
72  flatgeobuf_column **columns;
73  uint32_t columns_size = 0;
74  Oid tupType = HeapTupleHeaderGetTypeId(ctx->row);
75  int32 tupTypmod = HeapTupleHeaderGetTypMod(ctx->row);
76  TupleDesc tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
77  int natts = tupdesc->natts;
78  bool geom_found = false;
79 
80  POSTGIS_DEBUG(2, "calling inspect_table");
81 
82  columns = palloc(sizeof(flatgeobuf_column *) * natts);
83  ctx->tupdesc = tupdesc;
84 
85  // inspect columns
86  // NOTE: last element will be unused if geom attr is found
87  for (int i = 0; i < natts; i++) {
88  Oid typoid = getBaseType(TupleDescAttr(tupdesc, i)->atttypid);
89  const char *key = TupleDescAttr(tupdesc, i)->attname.data;
90  POSTGIS_DEBUGF(2, "inspecting column definition for %s with oid %d", key, typoid);
91  if (ctx->geom_name == NULL) {
92  if (!geom_found && typoid == postgis_oid(GEOMETRYOID)) {
93  ctx->geom_index = i;
94  geom_found = true;
95  continue;
96  }
97  } else {
98  if (!geom_found && strcmp(key, ctx->geom_name) == 0) {
99  ctx->geom_index = i;
100  geom_found = true;
101  continue;
102  }
103  }
104  POSTGIS_DEBUGF(2, "creating column definition for %s with oid %d", key, typoid);
105 
106  c = (flatgeobuf_column *) palloc0(sizeof(flatgeobuf_column));
107  c->name = pstrdup(key);
108  c->type = get_column_type(typoid);
109  columns[columns_size] = c;
110  columns_size++;
111  }
112 
113  if (!geom_found)
114  elog(ERROR, "no geom column found");
115 
116  if (columns_size > 0) {
117  ctx->ctx->columns = columns;
118  ctx->ctx->columns_size = columns_size;
119  }
120 }
static uint8_t get_column_type(Oid typoid)
Definition: flatgeobuf.c:37
unsigned int int32
Definition: shpopen.c:54
HeapTupleHeader row
Definition: flatgeobuf.h:52
const char * geom_name
Definition: flatgeobuf.h:49
flatgeobuf_ctx * ctx
Definition: flatgeobuf.h:48
uint32_t geom_index
Definition: flatgeobuf.h:50
TupleDesc tupdesc
Definition: flatgeobuf.h:51

References flatgeobuf_agg_ctx::ctx, flatgeobuf_agg_ctx::geom_index, flatgeobuf_agg_ctx::geom_name, get_column_type(), flatgeobuf_agg_ctx::row, and flatgeobuf_agg_ctx::tupdesc.

Referenced by flatgeobuf_agg_transfn().

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