PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ RASTER_getGDALDrivers()

Datum RASTER_getGDALDrivers ( PG_FUNCTION_ARGS  )

Definition at line 338 of file rtpg_gdal.c.

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

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

Here is the call graph for this function: