cursor.c 1005 B

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