d_opendb.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*!
  2. * \file db/dbmi_driver/d_opendb.c
  3. *
  4. * \brief DBMI Library (driver) - open 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 <stdlib.h>
  15. #include <grass/dbmi.h>
  16. #include "macros.h"
  17. #include "dbstubs.h"
  18. /*!
  19. \brief Open database connection
  20. \return DB_OK on success
  21. \return DB_FAILED on failure
  22. */
  23. int db_d_open_database(void)
  24. {
  25. dbHandle handle;
  26. int stat;
  27. /* get the arg(s) */
  28. db_init_handle(&handle);
  29. DB_RECV_HANDLE(&handle);
  30. /* see if there is a database already open */
  31. if (db__test_database_open()) {
  32. db_error("Multiple open databases not allowed");
  33. DB_SEND_FAILURE();
  34. return DB_OK;
  35. }
  36. /* call the procedure */
  37. stat = db_driver_open_database(&handle);
  38. /* send the return code */
  39. if (stat != DB_OK) {
  40. db_free_handle(&handle);
  41. DB_SEND_FAILURE();
  42. return DB_OK;
  43. }
  44. DB_SEND_SUCCESS();
  45. /* record the open in the driver state */
  46. db__mark_database_open(db_get_handle_dbname(&handle),
  47. db_get_handle_dbschema(&handle));
  48. /* DO NOT free the handle since we saved the pointers to the name,path */
  49. /* no results */
  50. return DB_OK;
  51. }