connect.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*!
  2. \file lib/db/dbmi_base/connect.c
  3. \brief DBMI Library (base) - connect to DB
  4. (C) 1999-2009, 2011 by the GRASS Development Team
  5. This program is free software under the GNU General Public License
  6. (>=v2). Read the file COPYING that comes with GRASS for details.
  7. \author Joel Jones (CERL/UIUC), Radim Blazek
  8. \author Doxygenized by Martin Landa <landa.martin gmail.com> (2011)
  9. */
  10. #include <grass/gis.h>
  11. #include <grass/dbmi.h>
  12. /*!
  13. \brief Set default DB connection settings
  14. This function sets environmental variables as DB_DRIVER, DB_DATABASE,
  15. DB_SCHEMA, DB_GROUP.
  16. \param connection pointer to dbConnection with default settings
  17. \return DB_OK
  18. */
  19. int db_set_connection(dbConnection * connection)
  20. {
  21. /* TODO: add checks and return DB_* error code if needed */
  22. if (connection->driverName)
  23. G_setenv2("DB_DRIVER", connection->driverName, G_VAR_MAPSET);
  24. if (connection->databaseName)
  25. G_setenv2("DB_DATABASE", connection->databaseName, G_VAR_MAPSET);
  26. if (connection->schemaName)
  27. G_setenv2("DB_SCHEMA", connection->schemaName, G_VAR_MAPSET);
  28. if (connection->group)
  29. G_setenv2("DB_GROUP", connection->group, G_VAR_MAPSET);
  30. /* below commented due to new mechanism:
  31. if ( connection->hostName )
  32. G_setenv("DB_HOST", connection->hostName);
  33. if ( connection->location )
  34. G_setenv("DB_LOCATION", connection->location);
  35. if ( connection->user )
  36. G_setenv("DB_USER", connection->user);
  37. if ( connection->password )
  38. G_setenv("DB_PASSWORD", connection->password);
  39. */
  40. return DB_OK;
  41. }
  42. /*!
  43. \brief Get default DB connection settings
  44. \param[out] connection pointer to dbConnection to be modified
  45. \return DB_OK
  46. */
  47. int db_get_connection(dbConnection * connection)
  48. {
  49. /* TODO: add checks and return DB_* error code if needed */
  50. G_zero(connection, sizeof(dbConnection));
  51. connection->driverName = (char *)G__getenv2("DB_DRIVER", G_VAR_MAPSET);
  52. connection->databaseName = (char *)G__getenv2("DB_DATABASE", G_VAR_MAPSET);
  53. connection->schemaName = (char *)G__getenv2("DB_SCHEMA", G_VAR_MAPSET);
  54. connection->group = (char *)G__getenv2("DB_GROUP", G_VAR_MAPSET);
  55. /* below commented due to new mechanism:
  56. connection->hostName = G__getenv("DB_HOST");
  57. connection->location = G__getenv("DB_LOCATION");
  58. connection->user = G__getenv("DB_USER");
  59. connection->password = G__getenv("DB_PASSWORD");
  60. */
  61. return DB_OK;
  62. }