cursor.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*!
  2. \file db/driver/postgres/cursor.c
  3. \brief DBMI - Low Level PostgreSQL database driver - cursor manipulation
  4. This program is free software under the GNU General Public License
  5. (>=v2). Read the file COPYING that comes with GRASS for details.
  6. \author Radim Blazek
  7. */
  8. #include <stdio.h>
  9. #include <grass/gis.h>
  10. #include <grass/dbmi.h>
  11. #include <grass/glocale.h>
  12. #include "globals.h"
  13. #include "proto.h"
  14. int db__driver_close_cursor(dbCursor * dbc)
  15. {
  16. cursor *c;
  17. /* get my cursor via the dbc token */
  18. c = (cursor *) db_find_token(db_get_cursor_token(dbc));
  19. if (c == NULL)
  20. return DB_FAILED;
  21. /* free_cursor(cursor) */
  22. free_cursor(c);
  23. return DB_OK;
  24. }
  25. cursor *alloc_cursor(void)
  26. {
  27. cursor *c;
  28. /* allocate the cursor */
  29. c = (cursor *) db_malloc(sizeof(cursor));
  30. if (c == NULL) {
  31. db_d_append_error(_("Unable allocate cursor."));
  32. return NULL;
  33. }
  34. c->res = NULL;
  35. /* tokenize it */
  36. c->token = db_new_token(c);
  37. if (c->token < 0) {
  38. db_d_append_error(_("Unable to add new token."));
  39. return NULL;
  40. }
  41. c->cols = NULL;
  42. c->ncols = 0;
  43. return c;
  44. }
  45. void free_cursor(cursor * c)
  46. {
  47. db_drop_token(c->token);
  48. /* TODO close results if any */
  49. G_free(c->cols);
  50. G_free(c);
  51. }