[GRASS-SVN] r62861 - in grass/branches/releasebranch_7_0: include lib/temporal/lib

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Nov 22 14:19:47 PST 2014


Author: huhabla
Date: 2014-11-22 14:19:47 -0800 (Sat, 22 Nov 2014)
New Revision: 62861

Modified:
   grass/branches/releasebranch_7_0/include/temporal.h
   grass/branches/releasebranch_7_0/lib/temporal/lib/connect.c
   grass/branches/releasebranch_7_0/lib/temporal/lib/default_name.c
Log:
temporal library: Backport of r61157, r61759, r61983 and r61997 from trunk to allow mapset specific temporal databases


Modified: grass/branches/releasebranch_7_0/include/temporal.h
===================================================================
--- grass/branches/releasebranch_7_0/include/temporal.h	2014-11-22 22:09:11 UTC (rev 62860)
+++ grass/branches/releasebranch_7_0/include/temporal.h	2014-11-22 22:19:47 UTC (rev 62861)
@@ -7,7 +7,8 @@
 
 
 #define TGISDB_DEFAULT_DRIVER "sqlite"
-#define TGISDB_DEFAULT_SQLITE_PATH "PERMANENT/tgis/sqlite.db"
+/* Default path in the current location */
+#define TGISDB_DEFAULT_SQLITE_PATH "tgis/sqlite.db"
 
 
 int tgis_set_connection(dbConnection * connection);
@@ -16,6 +17,8 @@
 char *tgis_get_default_database_name(void);
 char *tgis_get_driver_name(void);
 char *tgis_get_database_name(void);
+char *tgis_get_mapset_driver_name(const char*);
+char *tgis_get_mapset_database_name(const char*);
 int tgis_set_default_connection(void);
 
 

Modified: grass/branches/releasebranch_7_0/lib/temporal/lib/connect.c
===================================================================
--- grass/branches/releasebranch_7_0/lib/temporal/lib/connect.c	2014-11-22 22:09:11 UTC (rev 62860)
+++ grass/branches/releasebranch_7_0/lib/temporal/lib/connect.c	2014-11-22 22:19:47 UTC (rev 62861)
@@ -13,6 +13,7 @@
           Joel Jones (CERL/UIUC) and Radim Blazek
 */
 #include <grass/temporal.h>
+#include <grass/glocale.h>
 
 /*!
  * \brief Get TGIS driver name
@@ -82,3 +83,81 @@
 
     return DB_OK;
 }
+
+#define DRIVER_NAME 0
+#define DATABASE_NAME 1
+
+static char *get_mapset_connection_name(const char *mapset, int contype)
+{
+    const char *val = NULL;
+    char *ret_val = NULL;;
+    const char *gisdbase = G__getenv("GISDBASE");
+    const char *location = G__getenv("LOCATION_NAME");
+    int ret;
+
+    ret = G__mapset_permissions2(gisdbase, location, mapset);
+    switch (ret) {
+    case 0:
+        G_warning(_("You don't have permission to access the mapset <%s>"),
+                      mapset);
+        break;
+    case -1:
+        G_warning(_("Mapset <%s> does not exist."),
+	              mapset);
+        break;
+    default:
+        break;
+    }    
+
+    G_create_alt_env();
+    G__setenv("GISDBASE", gisdbase);
+    G__setenv("LOCATION_NAME", location);
+    G__setenv("MAPSET", mapset);
+    G__read_mapset_env();
+ 
+    if(contype == DATABASE_NAME) {
+        if ((val = G__getenv2("TGISDB_DATABASE", G_VAR_MAPSET)))
+            ret_val = G_store(val);
+    } else if(contype == DRIVER_NAME) {
+        if ((val = G__getenv2("TGISDB_DRIVER", G_VAR_MAPSET)))
+            ret_val = G_store(val);
+    }
+
+    G_switch_env();
+    
+    return ret_val;
+}
+
+
+/*!
+ * \brief Get TGIS driver name from a specific mapset
+ *
+ * This function give a warning in case the mapset does not exists
+ * or it is not allowed to access the mapset. NULL is returned in this case.
+ * 
+ * \param mapset The name of the mapset to receive the driver name from
+ *
+ * \return pointer to TGIS driver name
+ * \return NULL if not set 
+ */
+char *tgis_get_mapset_driver_name(const char *mapset)
+{
+    return get_mapset_connection_name(mapset, DRIVER_NAME);
+}
+
+/*!
+ * \brief Get TGIS database name
+ * 
+ * This function give a warning in case the mapset does not exists
+ * or it is not allowed to access the mapset. NULL is returned in this case..
+ * 
+ * \param mapset The name of the mapset to receive the driver name from
+ 
+ * \return pointer to TGIS database name
+ * \return NULL if not set
+ */
+char *tgis_get_mapset_database_name(const char *mapset)
+{
+    return get_mapset_connection_name(mapset, DATABASE_NAME);
+}
+

Modified: grass/branches/releasebranch_7_0/lib/temporal/lib/default_name.c
===================================================================
--- grass/branches/releasebranch_7_0/lib/temporal/lib/default_name.c	2014-11-22 22:09:11 UTC (rev 62860)
+++ grass/branches/releasebranch_7_0/lib/temporal/lib/default_name.c	2014-11-22 22:19:47 UTC (rev 62861)
@@ -40,8 +40,8 @@
 {
     char default_connection[2048];
 
-    G_snprintf(default_connection, 2048, "%s/%s/%s", G_gisdbase(), G_location(),
-               TGISDB_DEFAULT_SQLITE_PATH);
+    G_snprintf(default_connection, 2048, "%s/%s/%s/%s", G_gisdbase(), G_location(),
+               G_mapset(), TGISDB_DEFAULT_SQLITE_PATH);
 
     return G_store(default_connection);
 }



More information about the grass-commit mailing list