PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ RASTER_getGDALDrivers()

Datum RASTER_getGDALDrivers ( PG_FUNCTION_ARGS  )

Definition at line 341 of file rtpg_gdal.c.

342{
343 FuncCallContext *funcctx;
344 TupleDesc tupdesc;
345
346 uint32_t drv_count;
347 rt_gdaldriver drv_set;
348 rt_gdaldriver drv_set2;
349 int call_cntr;
350 int max_calls;
351
352 /* first call of function */
353 if (SRF_IS_FIRSTCALL()) {
354 MemoryContext oldcontext;
355
356 /* create a function context for cross-call persistence */
357 funcctx = SRF_FIRSTCALL_INIT();
358
359 /* switch to memory context appropriate for multiple function calls */
360 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
361
362 drv_set = rt_raster_gdal_drivers(&drv_count, 0);
363 if (NULL == drv_set || !drv_count) {
364 elog(NOTICE, "No GDAL drivers found");
365 MemoryContextSwitchTo(oldcontext);
366 SRF_RETURN_DONE(funcctx);
367 }
368
369 POSTGIS_RT_DEBUGF(3, "%d drivers returned", (int) drv_count);
370
371 /* Store needed information */
372 funcctx->user_fctx = drv_set;
373
374 /* total number of tuples to be returned */
375 funcctx->max_calls = drv_count;
376
377 /* Build a tuple descriptor for our result type */
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 /* stuff done on every call of the function */
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 /* do when there is more left to send */
402 if (call_cntr < max_calls) {
403 Datum values[VALUES_LENGTH];
404 bool nulls[VALUES_LENGTH];
405 HeapTuple tuple;
406 Datum result;
407
408 POSTGIS_RT_DEBUGF(3, "Result %d", call_cntr);
409
410 memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
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
419 POSTGIS_RT_DEBUGF(4, "Result %d, Index %d", call_cntr, drv_set2[call_cntr].idx);
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 /* build a tuple */
427 tuple = heap_form_tuple(tupdesc, values, nulls);
428
429 /* make the tuple into a datum */
430 result = HeapTupleGetDatum(tuple);
431
432 /* clean up */
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 /* do when there is no more left */
440 else {
441 pfree(drv_set2);
442 SRF_RETURN_DONE(funcctx);
443 }
444}
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition cu_print.c:267
#define FALSE
Definition dbfopen.c:72
rt_gdaldriver rt_raster_gdal_drivers(uint32_t *drv_count, uint8_t cancc)
Returns a set of available GDAL drivers.
Definition rt_raster.c:1716
#define VALUES_LENGTH
Definition rtpg_gdal.c:335
#define POSTGIS_RT_DEBUGF(level, msg,...)
Definition rtpostgis.h:69

References FALSE, POSTGIS_RT_DEBUGF, result, rt_raster_gdal_drivers(), and VALUES_LENGTH.

Here is the call graph for this function: