[GRASS-SVN] r65519 - in grass/trunk/lib: python/temporal temporal/lib
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Jun 24 15:23:40 PDT 2015
Author: huhabla
Date: 2015-06-24 15:23:40 -0700 (Wed, 24 Jun 2015)
New Revision: 65519
Modified:
grass/trunk/lib/python/temporal/c_libraries_interface.py
grass/trunk/lib/python/temporal/core.py
grass/trunk/lib/temporal/lib/default_name.c
Log:
temporal library: Store the default database connection as shell variable substitude to avoid wrong temporal database path's in cases the location was renamed or the path to the grass database changed.
Modified: grass/trunk/lib/python/temporal/c_libraries_interface.py
===================================================================
--- grass/trunk/lib/python/temporal/c_libraries_interface.py 2015-06-23 16:19:25 UTC (rev 65518)
+++ grass/trunk/lib/python/temporal/c_libraries_interface.py 2015-06-24 22:23:40 UTC (rev 65519)
@@ -136,7 +136,7 @@
# This behavior is in conjunction with db.connect
dbstring = dbstring.replace("$GISDBASE", libgis.G_gisdbase())
dbstring = dbstring.replace("$LOCATION_NAME", libgis.G_location())
- dbstring = dbstring.replace("$MAPSET", libgis.G_mapset())
+ dbstring = dbstring.replace("$MAPSET", mapset)
conn.send(dbstring)
###############################################################################
Modified: grass/trunk/lib/python/temporal/core.py
===================================================================
--- grass/trunk/lib/python/temporal/core.py 2015-06-23 16:19:25 UTC (rev 65518)
+++ grass/trunk/lib/python/temporal/core.py 2015-06-24 22:23:40 UTC (rev 65519)
@@ -860,7 +860,8 @@
driver, dbstring = self.tgis_mapsets[mapset]
if dbstring not in self.unique_connections.keys():
- self.unique_connections[dbstring] = DBConnection(driver)
+ self.unique_connections[dbstring] = DBConnection(backend=driver,
+ dbstring=dbstring)
self.connections[mapset] = self.unique_connections[dbstring]
@@ -904,7 +905,7 @@
close all temporal databases that have been opened.
"""
for key in self.unique_connections.keys():
- self.unique_connections[key] .close()
+ self.unique_connections[key].close()
self.connected = False
@@ -1014,16 +1015,20 @@
class DBConnection(object):
"""This class represents the database interface connection
- and provides access to the chisen backend modules.
+ and provides access to the chosen backend modules.
The following DBMS are supported:
- sqlite via the sqlite3 standard library
- postgresql via psycopg2
-
"""
- def __init__(self, backend=None):
+ def __init__(self, backend=None, dbstring=None):
+ """ Constructor of a database connection
+
+ param backend:The database backend sqlite or pg
+ param dbstring: The database connection string
+ """
self.connected = False
if backend is None:
global tgis_backend
@@ -1037,6 +1042,10 @@
else:
self.dbmi = psycopg2
+ if dbstring is None:
+ global tgis_database_string
+ self.dbstring = tgis_database_string
+
self.msgr = get_tgis_message_interface()
self.msgr.debug(1, "SQLDatabaseInterfaceConnection constructor")
@@ -1061,13 +1070,13 @@
def connect(self, dbstring=None):
"""Connect to the DBMI to execute SQL statements
- Supported backends are sqlite3 and postgresql
+ Supported backends are sqlite3 and postgresql
+
+ param dbstring: The database connection string
"""
# Connection in the current mapset
if dbstring is None:
- global tgis_database_string
- dbstring = tgis_database_string
-
+ dbstring = self.dbstring
try:
if self.dbmi.__name__ == "sqlite3":
self.connection = self.dbmi.connect(dbstring,
Modified: grass/trunk/lib/temporal/lib/default_name.c
===================================================================
--- grass/trunk/lib/temporal/lib/default_name.c 2015-06-23 16:19:25 UTC (rev 65518)
+++ grass/trunk/lib/temporal/lib/default_name.c 2015-06-24 22:23:40 UTC (rev 65519)
@@ -40,8 +40,8 @@
{
char default_connection[2048];
- G_snprintf(default_connection, 2048, "%s/%s/%s/%s", G_gisdbase(), G_location(),
- G_mapset(), TGISDB_DEFAULT_SQLITE_PATH);
+ G_snprintf(default_connection, 2048, "$GISDBASE/$LOCATION_NAME/$MAPSET/%s",
+ TGISDB_DEFAULT_SQLITE_PATH);
return G_store(default_connection);
}
More information about the grass-commit
mailing list