cursor.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. /* get my cursor via the dbc token */
  21. c = (cursor *) db_find_token(db_get_cursor_token(dbc));
  22. if (c == NULL)
  23. return DB_FAILED;
  24. /* free_cursor(cursor) */
  25. free_cursor(c);
  26. return DB_OK;
  27. }
  28. cursor *alloc_cursor()
  29. {
  30. cursor *c;
  31. /* allocate the cursor */
  32. c = (cursor *) db_malloc(sizeof(cursor));
  33. if (c == NULL) {
  34. db_d_append_error(_("Unable allocate cursor."));
  35. return NULL;
  36. }
  37. c->res = NULL;
  38. /* tokenize it */
  39. c->token = db_new_token(c);
  40. if (c->token < 0) {
  41. db_d_append_error(_("Unable to add dnew token."));
  42. return NULL;
  43. }
  44. c->cols = NULL;
  45. c->ncols = 0;
  46. return c;
  47. }
  48. void free_cursor(cursor * c)
  49. {
  50. db_drop_token(c->token);
  51. if (c->res) {
  52. mysql_free_result(c->res);
  53. }
  54. G_free(c->cols);
  55. G_free(c);
  56. }