[GRASS-SVN] r58015 - in grass/trunk: include lib/temporal/lib
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Oct 16 05:09:44 PDT 2013
Author: huhabla
Date: 2013-10-16 05:09:44 -0700 (Wed, 16 Oct 2013)
New Revision: 58015
Modified:
grass/trunk/include/temporal.h
grass/trunk/lib/temporal/lib/connect.c
grass/trunk/lib/temporal/lib/default_name.c
Log:
Improved handling of the temporal database default connection
Modified: grass/trunk/include/temporal.h
===================================================================
--- grass/trunk/include/temporal.h 2013-10-16 09:45:16 UTC (rev 58014)
+++ grass/trunk/include/temporal.h 2013-10-16 12:09:44 UTC (rev 58015)
@@ -4,11 +4,14 @@
#include <grass/dbmi.h>
#define TGISDB_DEFAULT_DRIVER "sqlite"
+#define TGISDB_DEFAULT_SQLITE_PATH "PERMANENT/tgis/sqlite.db"
int tgis_set_connection(dbConnection * connection);
int tgis_get_connection(dbConnection * connection);
const char *tgis_get_default_driver_name(void);
-const char *tgis_get_default_database_name(void);
+char *tgis_get_default_database_name(void);
+char *tgis_get_driver_name(void);
+char *tgis_get_database_name(void);
int tgis_set_default_connection(void);
#endif
Modified: grass/trunk/lib/temporal/lib/connect.c
===================================================================
--- grass/trunk/lib/temporal/lib/connect.c 2013-10-16 09:45:16 UTC (rev 58014)
+++ grass/trunk/lib/temporal/lib/connect.c 2013-10-16 12:09:44 UTC (rev 58015)
@@ -15,6 +15,38 @@
#include <grass/temporal.h>
/*!
+ * \brief Get TGIS driver name
+ *
+ * \return pointer to TGIS driver name
+ * \return NULL if not set
+ */
+char *tgis_get_driver_name(void)
+{
+ const char *drv;
+
+ if ((drv = G__getenv2("TGISDB_DRIVER", G_VAR_MAPSET)))
+ return G_store(drv);
+
+ return NULL;
+}
+
+/*!
+ * \brief Get TGIS database name
+ *
+ * \return pointer to TGIS database name
+ * \return NULL if not set
+ */
+char *tgis_get_database_name(void)
+{
+ const char *drv;
+
+ if ((drv = G__getenv2("TGISDB_DATABASE", G_VAR_MAPSET)))
+ return G_store(drv);
+
+ return NULL;
+}
+
+/*!
\brief Set default Temporal GIS DB connection settings
This function sets environmental variables as TGISDB_DRIVER, TGISDB_DATABASE.
Modified: grass/trunk/lib/temporal/lib/default_name.c
===================================================================
--- grass/trunk/lib/temporal/lib/default_name.c 2013-10-16 09:45:16 UTC (rev 58014)
+++ grass/trunk/lib/temporal/lib/default_name.c 2013-10-16 12:09:44 UTC (rev 58015)
@@ -23,54 +23,69 @@
\brief Get default TGIS driver name
\return pointer to default TGIS driver name
- \return NULL if not set
*/
const char *tgis_get_default_driver_name(void)
{
- const char *drv;
-
- if ((drv = G__getenv2("TGISDB_DRIVER", G_VAR_MAPSET)))
- return G_store(drv);
-
- return NULL;
+ return TGISDB_DEFAULT_DRIVER;
}
/*!
- \brief Get default TGIS database name
+ \brief Get default TGIS database name for the sqlite connection
+ The default name is $GISDBASE/$LOCATION_NAME/PERMANENT/tgis/sqlite.db
+
\return pointer to default TGIS database name
- \return NULL if not set
*/
-const char *tgis_get_default_database_name(void)
+char *tgis_get_default_database_name(void)
{
- const char *drv;
+ int n;
+ const char *name = NULL, *value = NULL;
+ char *location = NULL, *gisbase = NULL;
+ char default_connection[2048];
- if ((drv = G__getenv2("TGISDB_DATABASE", G_VAR_MAPSET)))
- return G_store(drv);
+ for (n = 0; (name = G__env_name(n)); n++) {
+ value = (char *)G__getenv(name);
+ if (value) {
+ if (G_strcasecmp("GISDBASE", name) == 0)
+ gisbase = G_store(value);
+ if (G_strcasecmp("LOCATION_NAME", name) == 0)
+ location = G_store(value);
+ }
+ }
- return NULL;
+ G_snprintf(default_connection, 2048, "%s/%s/%s", gisbase, location,
+ TGISDB_DEFAULT_SQLITE_PATH);
+
+ if(location)
+ G_free(location);
+ if(gisbase)
+ G_free(gisbase);
+
+ return G_store(default_connection);
}
/*!
- \brief Sets up TGIS database connection settings using GRASS default from temporal.h
+ \brief Sets up TGIS database connection settings using GRASS default
\return returns DB_OK
*/
int tgis_set_default_connection(void)
{
dbConnection connection;
+ char db_name[2048];
+ char *tmp = tgis_get_default_database_name();
- G_verbose_message(_("Creating new default TGIS DB params"));
+ G_snprintf(db_name, 2048, "%s", tmp);
+ G_free(tmp);
if (strcmp(TGISDB_DEFAULT_DRIVER, "sqlite") == 0) {
-
connection.driverName = "sqlite";
- connection.databaseName =
- "$GISDBASE/$LOCATION_NAME/PERMANENT/tgis/sqlite.db";
+ connection.databaseName = db_name;
tgis_set_connection(&connection);
}
else
G_fatal_error(_("Programmer error - only SQLite driver is currently supported"));
+
return DB_OK;
}
More information about the grass-commit
mailing list