c_finddb.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*!
  2. * \file db/dbmi_client/c_finddb.c
  3. *
  4. * \brief DBMI Library (client) - find database
  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. /*!
  18. \brief Find database
  19. \param driver db driver
  20. \param handle handle info
  21. \param[out] found if non-zero database found
  22. \return DB_OK on success
  23. \return DB_FAILED on failure
  24. */
  25. int db_find_database(dbDriver * driver, dbHandle * handle, int *found)
  26. {
  27. int ret_code;
  28. int stat;
  29. dbHandle temp;
  30. /* start the procedure call */
  31. db__set_protocol_fds(driver->send, driver->recv);
  32. DB_START_PROCEDURE_CALL(DB_PROC_FIND_DATABASE);
  33. /* send the arguments to the procedure */
  34. DB_SEND_HANDLE(handle);
  35. /* get the return code for the procedure call */
  36. DB_RECV_RETURN_CODE(&ret_code);
  37. if (ret_code != DB_OK)
  38. return ret_code; /* ret_code SHOULD == DB_FAILED */
  39. /* get results */
  40. DB_RECV_INT(found);
  41. stat = DB_OK;
  42. if (*found) {
  43. DB_RECV_HANDLE(&temp);
  44. stat = db_set_handle(handle,
  45. db_get_handle_dbname(&temp),
  46. db_get_handle_dbschema(&temp)
  47. );
  48. db_free_handle(&temp);
  49. }
  50. return stat;
  51. }