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