rewind_pg.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*!
  2. \file lib/vector/Vlib/rewind_pg.c
  3. \brief Vector library - rewind data (PostGIS layers)
  4. Higher level functions for reading/writing/manipulating vectors.
  5. (C) 2011-2012 by the GRASS Development Team
  6. This program is free software under the GNU General Public License
  7. (>=v2). Read the file COPYING that comes with GRASS for details.
  8. \author Martin Landa <landa.martin gmail.com>
  9. */
  10. #include <grass/vector.h>
  11. #include <grass/glocale.h>
  12. #include "local_proto.h"
  13. #ifdef HAVE_POSTGRES
  14. #include "pg_local_proto.h"
  15. #endif
  16. /*!
  17. \brief Rewind vector map (PostGIS layer) to cause reads to start
  18. at beginning (level 1)
  19. \param Map pointer to Map_info structure
  20. \return 0 on success
  21. \return -1 on error
  22. */
  23. int V1_rewind_pg(struct Map_info *Map)
  24. {
  25. G_debug(2, "V1_rewind_pg(): name = %s", Map->name);
  26. #ifdef HAVE_POSTGRES
  27. struct Format_info_pg *pg_info;
  28. pg_info = &(Map->fInfo.pg);
  29. /* reset reading */
  30. pg_info->next_line = 0;
  31. /* reset cache */
  32. if (pg_info->cache.ctype != CACHE_MAP) {
  33. pg_info->cache.lines_num = 0;
  34. pg_info->cache.fid = -1;
  35. }
  36. pg_info->cache.lines_next = 0;
  37. /* close DB cursor if necessary */
  38. return Vect__close_cursor_pg(pg_info);
  39. #else
  40. G_fatal_error(_("GRASS is not compiled with PostgreSQL support"));
  41. return -1;
  42. #endif
  43. }
  44. /*!
  45. \brief Rewind vector map (PostGIS layer) to cause reads to start
  46. at beginning on topological level (level 2)
  47. \param Map pointer to Map_info structure
  48. \return 0 on success
  49. \return -1 on error
  50. */
  51. int V2_rewind_pg(struct Map_info *Map)
  52. {
  53. G_debug(2, "V2_rewind_pg(): name = %s", Map->name);
  54. #ifdef HAVE_POSTGRES
  55. /* reset reading */
  56. Map->next_line = 1;
  57. V1_rewind_pg(Map);
  58. return 0;
  59. #else
  60. G_fatal_error(_("GRASS is not compiled with PostgreSQL support"));
  61. return -1;
  62. #endif
  63. }