c_openselect.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*!
  2. \file db/dbmi_client/c_openselect.c
  3. \brief DBMI Library (client) - open select cursor
  4. (C) 1999-2008, 2012 by the GRASS Development Team
  5. This program is free software under the GNU General Public
  6. License (>=v2). Read the file COPYING that comes with GRASS
  7. for details.
  8. \author Joel Jones (CERL/UIUC)
  9. \author Radim Blazek
  10. */
  11. #include <grass/dbmi.h>
  12. #include "macros.h"
  13. /*!
  14. \brief Open select cursor
  15. Open modes:
  16. - DB_SEQUENTIAL
  17. Data can be fetched by db_fetch().
  18. Cursor should be closed by db_close_cursor().
  19. \param driver pointer to dbDriver
  20. \param select SQL select statement (pointer to dbString)
  21. \param cursor pointer to dbCursor to be opened
  22. \param mode open mode
  23. \return DB_OK on success
  24. \return DB_FAILED on failure
  25. */
  26. int db_open_select_cursor(dbDriver * driver, dbString * select, dbCursor * cursor,
  27. int mode)
  28. {
  29. int ret_code;
  30. db_init_cursor(cursor);
  31. cursor->driver = driver;
  32. /* start the procedure call */
  33. db__set_protocol_fds(driver->send, driver->recv);
  34. DB_START_PROCEDURE_CALL(DB_PROC_OPEN_SELECT_CURSOR);
  35. /* send the argument(s) to the procedure */
  36. DB_SEND_STRING(select);
  37. DB_SEND_INT(mode);
  38. /* get the return code for the procedure call */
  39. DB_RECV_RETURN_CODE(&ret_code);
  40. if (ret_code != DB_OK)
  41. return ret_code; /* ret_code SHOULD == DB_FAILED */
  42. /* get the results */
  43. DB_RECV_TOKEN(&cursor->token);
  44. DB_RECV_INT(&cursor->type);
  45. DB_RECV_INT(&cursor->mode);
  46. DB_RECV_TABLE_DEFINITION(&cursor->table);
  47. return DB_OK;
  48. }