cursor.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include <stdio.h>
  2. #include <grass/dbmi.h>
  3. #include <grass/gis.h>
  4. #include <grass/glocale.h>
  5. #include "odbc.h"
  6. #include "globals.h"
  7. #include "proto.h"
  8. int db__driver_close_cursor(dbCursor * dbc)
  9. {
  10. cursor *c;
  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()
  20. {
  21. cursor *c;
  22. SQLRETURN ret;
  23. char msg[OD_MSG];
  24. SQLINTEGER err;
  25. /* allocate the cursor */
  26. c = (cursor *) db_malloc(sizeof(cursor));
  27. if (c == NULL) {
  28. db_d_append_error(_("Unable to allocate cursor"));
  29. db_d_report_error();
  30. return c;
  31. }
  32. ret = SQLAllocHandle(SQL_HANDLE_STMT, ODconn, &c->stmt);
  33. if ((ret != SQL_SUCCESS) && (ret != SQL_SUCCESS_WITH_INFO)) {
  34. SQLGetDiagRec(SQL_HANDLE_DBC, ODconn, 1, NULL, &err, msg, sizeof(msg),
  35. NULL);
  36. db_d_append_error( "AllocStatement()\n%s (%d)\n", msg, (int)err);
  37. db_d_report_error();
  38. return c;
  39. }
  40. /* tokenize it */
  41. c->token = db_new_token(c);
  42. if (c->token < 0) {
  43. free_cursor(c);
  44. c = NULL;
  45. db_d_append_error(_("Unable to add new token."));
  46. db_d_report_error();
  47. }
  48. return c;
  49. }
  50. void free_cursor(cursor * c)
  51. {
  52. db_drop_token(c->token);
  53. SQLFreeHandle(SQL_HANDLE_STMT, c->stmt);
  54. G_free(c);
  55. }