cursor.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**********************************************************
  2. * MODULE: mysql
  3. * AUTHOR(S): Radim Blazek (radim.blazek@gmail.com)
  4. * PURPOSE: MySQL database driver
  5. * COPYRIGHT: (C) 2001 by the GRASS Development Team
  6. * This program is free software under the
  7. * GNU General Public License (>=v2).
  8. * Read the file COPYING that comes with GRASS
  9. * for details.
  10. **********************************************************/
  11. #include <stdio.h>
  12. #include <grass/gis.h>
  13. #include <grass/dbmi.h>
  14. #include <grass/glocale.h>
  15. #include "globals.h"
  16. #include "proto.h"
  17. int db__driver_close_cursor(dbCursor * dbc)
  18. {
  19. cursor *c;
  20. init_error();
  21. /* get my cursor via the dbc token */
  22. c = (cursor *) db_find_token(db_get_cursor_token(dbc));
  23. if (c == NULL)
  24. return DB_FAILED;
  25. /* free_cursor(cursor) */
  26. free_cursor(c);
  27. return DB_OK;
  28. }
  29. cursor *alloc_cursor()
  30. {
  31. cursor *c;
  32. /* allocate the cursor */
  33. c = (cursor *) db_malloc(sizeof(cursor));
  34. if (c == NULL) {
  35. append_error(_("Cannot allocate cursor."));
  36. return NULL;
  37. }
  38. c->res = NULL;
  39. /* tokenize it */
  40. c->token = db_new_token(c);
  41. if (c->token < 0) {
  42. append_error(_("Cannot ad new token."));
  43. return NULL;
  44. }
  45. c->cols = NULL;
  46. c->ncols = 0;
  47. return c;
  48. }
  49. void free_cursor(cursor * c)
  50. {
  51. db_drop_token(c->token);
  52. if (c->res) {
  53. mysql_free_result(c->res);
  54. }
  55. G_free(c->cols);
  56. G_free(c);
  57. }