cursor.c 957 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include <stdio.h>
  2. #include <grass/gis.h>
  3. #include <grass/dbmi.h>
  4. #include "globals.h"
  5. #include "proto.h"
  6. int db__driver_close_cursor(dbCursor * dbc)
  7. {
  8. cursor *c;
  9. init_error();
  10. /* get my cursor via the dbc token */
  11. c = (cursor *) db_find_token(db_get_cursor_token(dbc));
  12. if (c == NULL)
  13. return DB_FAILED;
  14. /* free_cursor(cursor) */
  15. free_cursor(c);
  16. return DB_OK;
  17. }
  18. cursor *alloc_cursor(void)
  19. {
  20. cursor *c;
  21. /* allocate the cursor */
  22. c = (cursor *) db_malloc(sizeof(cursor));
  23. if (c == NULL) {
  24. append_error("Cannot allocate cursor.");
  25. return NULL;
  26. }
  27. c->res = NULL;
  28. /* tokenize it */
  29. c->token = db_new_token(c);
  30. if (c->token < 0) {
  31. append_error("Cannot ad new token.");
  32. return NULL;
  33. }
  34. c->cols = NULL;
  35. c->ncols = 0;
  36. return c;
  37. }
  38. void free_cursor(cursor * c)
  39. {
  40. db_drop_token(c->token);
  41. /* TODO close results if any */
  42. G_free(c->cols);
  43. G_free(c);
  44. }