listtab.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*!
  2. \file db/drivers/listtab.c
  3. \brief Low level OGR SQL driver
  4. (C) 2004-2009 by the GRASS Development Team
  5. This program is free software under the GNU General Public License
  6. (>=v2). Read the file COPYING that comes with GRASS for details.
  7. \author Radim Blazek
  8. \author Some updates by Martin Landa <landa.martin gmail.com>
  9. */
  10. #include <grass/gis.h>
  11. #include <grass/dbmi.h>
  12. #include <grass/glocale.h>
  13. #include <ogr_api.h>
  14. #include "globals.h"
  15. #include "proto.h"
  16. /*!
  17. \brief List tables
  18. \param[out] tlist list of tables
  19. \param[out] tcount number of tables
  20. \param system list also system tables (unused)
  21. \return DB_OK on success
  22. \return DB_FAILED on failure
  23. */
  24. int db__driver_list_tables(dbString ** tlist, int *tcount, int system)
  25. {
  26. int i, nlayers;
  27. dbString *list;
  28. OGRLayerH hLayer;
  29. OGRFeatureDefnH hFeatureDefn;
  30. *tlist = NULL;
  31. *tcount = 0;
  32. nlayers = OGR_DS_GetLayerCount(hDs);
  33. G_debug(3, "%d layers found", nlayers);
  34. list = db_alloc_string_array(nlayers);
  35. if (list == NULL) {
  36. db_d_append_error(_("Unable to db_alloc_string_array()"));
  37. db_d_report_error();
  38. return DB_FAILED;
  39. }
  40. for (i = 0; i < nlayers; i++) {
  41. hLayer = OGR_DS_GetLayer(hDs, i);
  42. hFeatureDefn = OGR_L_GetLayerDefn(hLayer);
  43. db_set_string(&(list[i]), (char *)OGR_FD_GetName(hFeatureDefn));
  44. }
  45. *tlist = list;
  46. *tcount = nlayers;
  47. return DB_OK;
  48. }