c_fetch.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*!
  2. * \file db/dbmi_client/c_fetch.c
  3. *
  4. * \brief DBMI Library (client) - fetch data
  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 <grass/dbmi.h>
  15. #include "macros.h"
  16. /*!
  17. \brief Fetch data from open cursor
  18. \param cursor pointer to dbCursor
  19. \param position cursor position
  20. \param[out] more get more (0 for no data to be fetched)
  21. \return DB_OK on success
  22. \return DB_FAILED on failure
  23. */
  24. int db_fetch(dbCursor * cursor, int position, int *more)
  25. {
  26. int ret_code;
  27. /* start the procedure call */
  28. db__set_protocol_fds(cursor->driver->send, cursor->driver->recv);
  29. DB_START_PROCEDURE_CALL(DB_PROC_FETCH);
  30. /* send the argument(s) to the procedure */
  31. DB_SEND_TOKEN(&cursor->token);
  32. DB_SEND_INT(position);
  33. /* get the return code for the procedure call */
  34. DB_RECV_RETURN_CODE(&ret_code);
  35. if (ret_code != DB_OK)
  36. return ret_code; /* ret_code SHOULD == DB_FAILED */
  37. /* get the results */
  38. DB_RECV_INT(more);
  39. if (*more) {
  40. DB_RECV_TABLE_DATA(cursor->table);
  41. }
  42. return DB_OK;
  43. }