PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ RASTER_getGDALDrivers()

Datum RASTER_getGDALDrivers ( PG_FUNCTION_ARGS  )

Definition at line 340 of file rtpg_gdal.c.

341 {
342  FuncCallContext *funcctx;
343  TupleDesc tupdesc;
344 
345  uint32_t drv_count;
346  rt_gdaldriver drv_set;
347  rt_gdaldriver drv_set2;
348  int call_cntr;
349  int max_calls;
350 
351  /* first call of function */
352  if (SRF_IS_FIRSTCALL()) {
353  MemoryContext oldcontext;
354 
355  /* create a function context for cross-call persistence */
356  funcctx = SRF_FIRSTCALL_INIT();
357 
358  /* switch to memory context appropriate for multiple function calls */
359  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
360 
361  drv_set = rt_raster_gdal_drivers(&drv_count, 0);
362  if (NULL == drv_set || !drv_count) {
363  elog(NOTICE, "No GDAL drivers found");
364  MemoryContextSwitchTo(oldcontext);
365  SRF_RETURN_DONE(funcctx);
366  }
367 
368  POSTGIS_RT_DEBUGF(3, "%d drivers returned", (int) drv_count);
369 
370  /* Store needed information */
371  funcctx->user_fctx = drv_set;
372 
373  /* total number of tuples to be returned */
374  funcctx->max_calls = drv_count;
375 
376  /* Build a tuple descriptor for our result type */
377  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) {
378  ereport(ERROR, (
379  errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
380  errmsg(
381  "function returning record called in context "
382  "that cannot accept type record"
383  )
384  ));
385  }
386 
387  BlessTupleDesc(tupdesc);
388  funcctx->tuple_desc = tupdesc;
389  MemoryContextSwitchTo(oldcontext);
390  }
391 
392  /* stuff done on every call of the function */
393  funcctx = SRF_PERCALL_SETUP();
394 
395  call_cntr = funcctx->call_cntr;
396  max_calls = funcctx->max_calls;
397  tupdesc = funcctx->tuple_desc;
398  drv_set2 = funcctx->user_fctx;
399 
400  /* do when there is more left to send */
401  if (call_cntr < max_calls) {
402  Datum values[VALUES_LENGTH];
403  bool nulls[VALUES_LENGTH];
404  HeapTuple tuple;
405  Datum result;
406 
407  POSTGIS_RT_DEBUGF(3, "Result %d", call_cntr);
408 
409  memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
410 
411  values[0] = Int32GetDatum(drv_set2[call_cntr].idx);
412  values[1] = CStringGetTextDatum(drv_set2[call_cntr].short_name);
413  values[2] = CStringGetTextDatum(drv_set2[call_cntr].long_name);
414  values[3] = BoolGetDatum(drv_set2[call_cntr].can_read);
415  values[4] = BoolGetDatum(drv_set2[call_cntr].can_write);
416  values[5] = CStringGetTextDatum(drv_set2[call_cntr].create_options);
417 
418  POSTGIS_RT_DEBUGF(4, "Result %d, Index %d", call_cntr, drv_set2[call_cntr].idx);
419  POSTGIS_RT_DEBUGF(4, "Result %d, Short Name %s", call_cntr, drv_set2[call_cntr].short_name);
420  POSTGIS_RT_DEBUGF(4, "Result %d, Full Name %s", call_cntr, drv_set2[call_cntr].long_name);
421  POSTGIS_RT_DEBUGF(4, "Result %d, Can Read %u", call_cntr, drv_set2[call_cntr].can_read);
422  POSTGIS_RT_DEBUGF(4, "Result %d, Can Write %u", call_cntr, drv_set2[call_cntr].can_write);
423  POSTGIS_RT_DEBUGF(5, "Result %d, Create Options %s", call_cntr, drv_set2[call_cntr].create_options);
424 
425  /* build a tuple */
426  tuple = heap_form_tuple(tupdesc, values, nulls);
427 
428  /* make the tuple into a datum */
429  result = HeapTupleGetDatum(tuple);
430 
431  /* clean up */
432  pfree(drv_set2[call_cntr].short_name);
433  pfree(drv_set2[call_cntr].long_name);
434  pfree(drv_set2[call_cntr].create_options);
435 
436  SRF_RETURN_NEXT(funcctx, result);
437  }
438  /* do when there is no more left */
439  else {
440  pfree(drv_set2);
441  SRF_RETURN_DONE(funcctx);
442  }
443 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:262
#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:1838
#define VALUES_LENGTH
Definition: rtpg_gdal.c:334
#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: