PostGIS  2.1.10dev-r@@SVN_REVISION@@
Datum RASTER_getGDALDrivers ( PG_FUNCTION_ARGS  )

Definition at line 11789 of file rt_pg.c.

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

11790 {
11791  FuncCallContext *funcctx;
11792  TupleDesc tupdesc;
11793 
11794  uint32_t drv_count;
11795  rt_gdaldriver drv_set;
11796  rt_gdaldriver drv_set2;
11797  int call_cntr;
11798  int max_calls;
11799 
11800  /* first call of function */
11801  if (SRF_IS_FIRSTCALL()) {
11802  MemoryContext oldcontext;
11803 
11804  /* create a function context for cross-call persistence */
11805  funcctx = SRF_FIRSTCALL_INIT();
11806 
11807  /* switch to memory context appropriate for multiple function calls */
11808  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
11809 
11810  drv_set = rt_raster_gdal_drivers(&drv_count, 1);
11811  if (NULL == drv_set || !drv_count) {
11812  elog(NOTICE, "No GDAL drivers found");
11813  MemoryContextSwitchTo(oldcontext);
11814  SRF_RETURN_DONE(funcctx);
11815  }
11816 
11817  POSTGIS_RT_DEBUGF(3, "%d drivers returned", (int) drv_count);
11818 
11819  /* Store needed information */
11820  funcctx->user_fctx = drv_set;
11821 
11822  /* total number of tuples to be returned */
11823  funcctx->max_calls = drv_count;
11824 
11825  /* Build a tuple descriptor for our result type */
11826  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) {
11827  ereport(ERROR, (
11828  errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
11829  errmsg(
11830  "function returning record called in context "
11831  "that cannot accept type record"
11832  )
11833  ));
11834  }
11835 
11836  BlessTupleDesc(tupdesc);
11837  funcctx->tuple_desc = tupdesc;
11838  MemoryContextSwitchTo(oldcontext);
11839  }
11840 
11841  /* stuff done on every call of the function */
11842  funcctx = SRF_PERCALL_SETUP();
11843 
11844  call_cntr = funcctx->call_cntr;
11845  max_calls = funcctx->max_calls;
11846  tupdesc = funcctx->tuple_desc;
11847  drv_set2 = funcctx->user_fctx;
11848 
11849  /* do when there is more left to send */
11850  if (call_cntr < max_calls) {
11851  int values_length = 4;
11852  Datum values[values_length];
11853  bool nulls[values_length];
11854  HeapTuple tuple;
11855  Datum result;
11856 
11857  POSTGIS_RT_DEBUGF(3, "Result %d", call_cntr);
11858 
11859  memset(nulls, FALSE, sizeof(bool) * values_length);
11860 
11861  values[0] = Int32GetDatum(drv_set2[call_cntr].idx);
11862  values[1] = CStringGetTextDatum(drv_set2[call_cntr].short_name);
11863  values[2] = CStringGetTextDatum(drv_set2[call_cntr].long_name);
11864  values[3] = CStringGetTextDatum(drv_set2[call_cntr].create_options);
11865 
11866  POSTGIS_RT_DEBUGF(4, "Result %d, Index %d", call_cntr, drv_set2[call_cntr].idx);
11867  POSTGIS_RT_DEBUGF(4, "Result %d, Short Name %s", call_cntr, drv_set2[call_cntr].short_name);
11868  POSTGIS_RT_DEBUGF(4, "Result %d, Full Name %s", call_cntr, drv_set2[call_cntr].long_name);
11869  POSTGIS_RT_DEBUGF(5, "Result %d, Create Options %s", call_cntr, drv_set2[call_cntr].create_options);
11870 
11871  /* build a tuple */
11872  tuple = heap_form_tuple(tupdesc, values, nulls);
11873 
11874  /* make the tuple into a datum */
11875  result = HeapTupleGetDatum(tuple);
11876 
11877  /* clean up */
11878  pfree(drv_set2[call_cntr].short_name);
11879  pfree(drv_set2[call_cntr].long_name);
11880  pfree(drv_set2[call_cntr].create_options);
11881 
11882  SRF_RETURN_NEXT(funcctx, result);
11883  }
11884  /* do when there is no more left */
11885  else {
11886  pfree(drv_set2);
11887  SRF_RETURN_DONE(funcctx);
11888  }
11889 }
char ** result
Definition: liblwgeom.h:218
rt_gdaldriver rt_raster_gdal_drivers(uint32_t *drv_count, uint8_t cancc)
Returns a set of available GDAL drivers.
Definition: rt_api.c:8891
#define FALSE
Definition: dbfopen.c:169
#define POSTGIS_RT_DEBUGF(level, msg,...)
Definition: rt_pg.h:62

Here is the call graph for this function: