cursor.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*****************************************************************************
  2. *
  3. * MODULE: DBF driver
  4. *
  5. * AUTHOR(S): Radim Blazek
  6. *
  7. * PURPOSE: Simple driver for reading and writing dbf files
  8. *
  9. * COPYRIGHT: (C) 2000 by the GRASS Development Team
  10. *
  11. * This program is free software under the GNU General Public
  12. * License (>=v2). Read the file COPYING that comes with GRASS
  13. * for details.
  14. *
  15. *****************************************************************************/
  16. #include <stdlib.h>
  17. #include <grass/dbmi.h>
  18. #include <grass/gis.h>
  19. #include <grass/glocale.h>
  20. #include "globals.h"
  21. #include "proto.h"
  22. int db__driver_close_cursor(dbCursor * dbc)
  23. {
  24. cursor *c;
  25. /* get my cursor via the dbc token */
  26. c = (cursor *) db_find_token(db_get_cursor_token(dbc));
  27. if (c == NULL)
  28. return DB_FAILED;
  29. /* free_cursor(cursor) */
  30. free_cursor(c);
  31. return DB_OK;
  32. }
  33. cursor *alloc_cursor()
  34. {
  35. cursor *c;
  36. /* allocate the cursor */
  37. c = (cursor *) db_malloc(sizeof(cursor));
  38. if (c == NULL) {
  39. db_d_append_error(_("Unable to allocate new cursor"));
  40. db_d_report_error();
  41. return c;
  42. }
  43. c->st = NULL;
  44. c->cols = NULL;
  45. /* tokenize it */
  46. c->token = db_new_token(c);
  47. if (c->token < 0) {
  48. free_cursor(c);
  49. c = NULL;
  50. db_d_append_error(_("Unable to tokenize new cursor"));
  51. db_d_report_error();
  52. }
  53. return c;
  54. }
  55. void free_cursor(cursor * c)
  56. {
  57. db_drop_token(c->token);
  58. sqpFreeStmt(c->st);
  59. if (c->cols)
  60. G_free(c->cols);
  61. G_free(c);
  62. }