342{
343 FuncCallContext *funcctx;
344 TupleDesc tupdesc;
345
346 uint32_t drv_count;
349 int call_cntr;
350 int max_calls;
351
352
353 if (SRF_IS_FIRSTCALL()) {
354 MemoryContext oldcontext;
355
356
357 funcctx = SRF_FIRSTCALL_INIT();
358
359
360 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
361
363 if (NULL == drv_set || !drv_count) {
364 elog(NOTICE, "No GDAL drivers found");
365 MemoryContextSwitchTo(oldcontext);
366 SRF_RETURN_DONE(funcctx);
367 }
368
370
371
372 funcctx->user_fctx = drv_set;
373
374
375 funcctx->max_calls = drv_count;
376
377
378 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) {
379 ereport(ERROR, (
380 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
381 errmsg(
382 "function returning record called in context "
383 "that cannot accept type record"
384 )
385 ));
386 }
387
388 BlessTupleDesc(tupdesc);
389 funcctx->tuple_desc = tupdesc;
390 MemoryContextSwitchTo(oldcontext);
391 }
392
393
394 funcctx = SRF_PERCALL_SETUP();
395
396 call_cntr = funcctx->call_cntr;
397 max_calls = funcctx->max_calls;
398 tupdesc = funcctx->tuple_desc;
399 drv_set2 = funcctx->user_fctx;
400
401
402 if (call_cntr < max_calls) {
405 HeapTuple tuple;
407
409
411
412 values[0] = Int32GetDatum(drv_set2[call_cntr].idx);
413 values[1] = CStringGetTextDatum(drv_set2[call_cntr].short_name);
414 values[2] = CStringGetTextDatum(drv_set2[call_cntr].long_name);
415 values[3] = BoolGetDatum(drv_set2[call_cntr].can_read);
416 values[4] = BoolGetDatum(drv_set2[call_cntr].can_write);
417 values[5] = CStringGetTextDatum(drv_set2[call_cntr].create_options);
418
420 POSTGIS_RT_DEBUGF(4,
"Result %d, Short Name %s", call_cntr, drv_set2[call_cntr].short_name);
421 POSTGIS_RT_DEBUGF(4,
"Result %d, Full Name %s", call_cntr, drv_set2[call_cntr].long_name);
422 POSTGIS_RT_DEBUGF(4,
"Result %d, Can Read %u", call_cntr, drv_set2[call_cntr].can_read);
423 POSTGIS_RT_DEBUGF(4,
"Result %d, Can Write %u", call_cntr, drv_set2[call_cntr].can_write);
424 POSTGIS_RT_DEBUGF(5,
"Result %d, Create Options %s", call_cntr, drv_set2[call_cntr].create_options);
425
426
427 tuple = heap_form_tuple(tupdesc, values, nulls);
428
429
430 result = HeapTupleGetDatum(tuple);
431
432
433 pfree(drv_set2[call_cntr].short_name);
434 pfree(drv_set2[call_cntr].long_name);
435 pfree(drv_set2[call_cntr].create_options);
436
437 SRF_RETURN_NEXT(funcctx,
result);
438 }
439
440 else {
441 pfree(drv_set2);
442 SRF_RETURN_DONE(funcctx);
443 }
444}
char result[OUT_DOUBLE_BUFFER_SIZE]
rt_gdaldriver rt_raster_gdal_drivers(uint32_t *drv_count, uint8_t cancc)
Returns a set of available GDAL drivers.
#define POSTGIS_RT_DEBUGF(level, msg,...)