153{
154 uint16_t ci = 0;
155 size_t offset = 0;
156 Datum datum;
157 bool isnull;
158 Oid typoid;
159 uint32_t len;
160 uint32_t i;
161
162 uint8_t byte_value;
163 int16_t short_value;
164 int32_t int_value;
165 int64_t long_value;
166 float float_value;
167 double double_value;
168 char *string_value;
169
170
171
172 for (i = 0; i < (uint32_t) ctx->
tupdesc->natts; i++) {
174 continue;
175 datum = GetAttributeByNum(ctx->
row, i + 1, &isnull);
176 if (isnull)
177 continue;
179 memcpy(ctx->
ctx->properties + offset, &ci,
sizeof(ci));
180 offset += sizeof(ci);
181 typoid = getBaseType(TupleDescAttr(ctx->
tupdesc, i)->atttypid);
182 switch (typoid) {
183 case BOOLOID:
184 byte_value = DatumGetBool(datum) ? 1 : 0;
186 memcpy(ctx->
ctx->properties + offset, &byte_value,
sizeof(byte_value));
187 offset += sizeof(byte_value);
188 break;
189 case INT2OID:
190 short_value = DatumGetInt16(datum);
192 memcpy(ctx->
ctx->properties + offset, &short_value,
sizeof(short_value));
193 offset += sizeof(short_value);
194 break;
195 case INT4OID:
196 int_value = DatumGetInt32(datum);
198 memcpy(ctx->
ctx->properties + offset, &int_value,
sizeof(int_value));
199 offset += sizeof(int_value);
200 break;
201 case INT8OID:
202 long_value = DatumGetInt64(datum);
204 memcpy(ctx->
ctx->properties + offset, &long_value,
sizeof(long_value));
205 offset += sizeof(long_value);
206 break;
207 case FLOAT4OID:
208 float_value = DatumGetFloat4(datum);
210 memcpy(ctx->
ctx->properties + offset, &float_value,
sizeof(float_value));
211 offset += sizeof(float_value);
212 break;
213 case FLOAT8OID:
214 double_value = DatumGetFloat8(datum);
216 memcpy(ctx->
ctx->properties + offset, &double_value,
sizeof(double_value));
217 offset += sizeof(double_value);
218 break;
219 case TEXTOID:
220 string_value = text_to_cstring(DatumGetTextP(datum));
221 len = strlen(string_value);
223 memcpy(ctx->
ctx->properties + offset, &len,
sizeof(len));
224 offset += sizeof(len);
226 memcpy(ctx->
ctx->properties + offset, string_value, len);
227 offset += len;
228 break;
229 case TIMESTAMPTZOID: {
230 struct pg_tm tm;
231 fsec_t fsec;
232 int tz;
233 const char *tzn = NULL;
234 TimestampTz timestamp;
235 timestamp = DatumGetTimestampTz(datum);
236 timestamp2tm(timestamp, &tz, &tm, &fsec, &tzn, NULL);
237 string_value = palloc(MAXDATELEN + 1);
238 EncodeDateTime(&tm, fsec, true, tz, tzn, USE_ISO_DATES, string_value);
239 len = strlen(string_value);
241 memcpy(ctx->
ctx->properties + offset, &len,
sizeof(len));
242 offset += sizeof(len);
244 memcpy(ctx->
ctx->properties + offset, string_value, len);
245 offset += len;
246 break;
247 }
248
249
250
251
252
253
254
255
256
257
258 }
259 ci++;
260 }
261
262 if (offset > 0) {
263 POSTGIS_DEBUGF(3, "offset %ld", offset);
264 ctx->
ctx->properties_len = offset;
265 }
266}
static void ensure_properties_size(struct flatgeobuf_agg_ctx *ctx, size_t size)