default_name.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*!
  2. \file lib/db/dbmi_base/default_name.c
  3. \brief Temporal GIS Library (base) - default settings
  4. (C) 2012 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 Soeren Gebbert
  8. Code is based on the dbmi library written by
  9. Joel Jones (CERL/UIUC) and Radim Blazek
  10. */
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <grass/gis.h>
  14. #include <grass/temporal.h>
  15. #include <grass/glocale.h>
  16. /*!
  17. \brief Get default TGIS driver name
  18. \return pointer to default TGIS driver name
  19. */
  20. const char *tgis_get_default_driver_name(void)
  21. {
  22. return TGISDB_DEFAULT_DRIVER;
  23. }
  24. /*!
  25. \brief Get default TGIS database name for the sqlite connection
  26. The default name is $GISDBASE/$LOCATION_NAME/PERMANENT/tgis/sqlite.db
  27. \return pointer to default TGIS database name
  28. */
  29. char *tgis_get_default_database_name(void)
  30. {
  31. char default_connection[2048];
  32. G_snprintf(default_connection, 2048, "%s/%s/%s", G_gisdbase(), G_location(),
  33. TGISDB_DEFAULT_SQLITE_PATH);
  34. return G_store(default_connection);
  35. }
  36. /*!
  37. \brief Sets up TGIS database connection settings using GRASS default
  38. \return returns DB_OK
  39. */
  40. int tgis_set_default_connection(void)
  41. {
  42. dbConnection connection;
  43. char db_name[2048];
  44. char *tmp = tgis_get_default_database_name();
  45. G_snprintf(db_name, 2048, "%s", tmp);
  46. G_free(tmp);
  47. if (strcmp(TGISDB_DEFAULT_DRIVER, "sqlite") == 0) {
  48. connection.driverName = "sqlite";
  49. connection.databaseName = db_name;
  50. tgis_set_connection(&connection);
  51. }
  52. else
  53. G_fatal_error(_("Programmer error - only SQLite driver is currently supported"));
  54. return DB_OK;
  55. }