d_openselect.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*!
  2. * \file db/dbmi_driver/d_openselect.c
  3. *
  4. * \brief DBMI Library (driver) - open select cursor
  5. *
  6. * (C) 1999-2008 by the GRASS Development Team
  7. *
  8. * This program is free software under the GNU General Public
  9. * License (>=v2). Read the file COPYING that comes with GRASS
  10. * for details.
  11. *
  12. * \author Joel Jones (CERL/UIUC), Radim Blazek
  13. */
  14. #include <stdlib.h>
  15. #include <grass/dbmi.h>
  16. #include "macros.h"
  17. #include "dbstubs.h"
  18. /*!
  19. \brief Open select cursor
  20. \return DB_OK on success
  21. \return DB_FAILED on failure
  22. */
  23. int db_d_open_select_cursor(void)
  24. {
  25. dbCursor *cursor;
  26. int stat;
  27. dbToken token;
  28. dbString select;
  29. int mode;
  30. /* get the arg(s) */
  31. db_init_string(&select);
  32. DB_RECV_STRING(&select);
  33. DB_RECV_INT(&mode);
  34. /* create a cursor */
  35. cursor = (dbCursor *) db_malloc(sizeof(dbCursor));
  36. if (cursor == NULL)
  37. return db_get_error_code();
  38. token = db_new_token((dbAddress) cursor);
  39. if (token < 0)
  40. return db_get_error_code();
  41. db_init_cursor(cursor);
  42. /* call the procedure */
  43. stat = db_driver_open_select_cursor(&select, cursor, mode);
  44. db_free_string(&select);
  45. /* send the return code */
  46. if (stat != DB_OK) {
  47. DB_SEND_FAILURE();
  48. return DB_OK;
  49. }
  50. DB_SEND_SUCCESS();
  51. /* mark this as a readonly cursor */
  52. db_set_cursor_type_readonly(cursor);
  53. /* add this cursor to the cursors managed by the driver state */
  54. db__add_cursor_to_driver_state(cursor);
  55. /* results */
  56. DB_SEND_TOKEN(&token);
  57. DB_SEND_INT(cursor->type);
  58. DB_SEND_INT(cursor->mode);
  59. DB_SEND_TABLE_DEFINITION(cursor->table);
  60. return DB_OK;
  61. }