d_closedb.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*!
  2. * \file db/dbmi_driver/d_closedb.c
  3. *
  4. * \brief DBMI Library (driver) - close database connection
  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. #include "dbstubs.h"
  17. /*!
  18. \brief Close database connection
  19. \return DB_OK on success
  20. \return DB_FAILED on failure
  21. */
  22. int db_d_close_database(void)
  23. {
  24. int stat;
  25. /* no arg(s) */
  26. /* see if a database is open */
  27. if (!db__test_database_open()) {
  28. db_error("no database is open");
  29. DB_SEND_FAILURE();
  30. return DB_OK;
  31. };
  32. /* make sure all cursors are closed */
  33. db__close_all_cursors();
  34. /* call the procedure */
  35. stat = db_driver_close_database();
  36. /* send the return code */
  37. if (stat != DB_OK) {
  38. DB_SEND_FAILURE();
  39. return DB_OK;
  40. }
  41. DB_SEND_SUCCESS();
  42. /* clear the driver state */
  43. db__mark_database_closed();
  44. db__init_driver_state();
  45. /* no results */
  46. return DB_OK;
  47. }