[GRASS-SVN] r51306 - in grass/trunk: lib/python/temporal temporal/t.create temporal/t.list temporal/t.rast.aggregate temporal/t.rast.aggregate.ds temporal/t.rast.extract temporal/t.rast.mapcalc temporal/t.rast.univar temporal/t.rast3d.extract temporal/t.remove temporal/t.support temporal/t.unregister temporal/t.vect.observe.strds temporal/t.vect.what.strds

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Apr 7 19:42:40 EDT 2012


Author: huhabla
Date: 2012-04-07 16:42:39 -0700 (Sat, 07 Apr 2012)
New Revision: 51306

Modified:
   grass/trunk/lib/python/temporal/abstract_dataset.py
   grass/trunk/lib/python/temporal/abstract_map_dataset.py
   grass/trunk/lib/python/temporal/abstract_space_time_dataset.py
   grass/trunk/lib/python/temporal/base.py
   grass/trunk/lib/python/temporal/core.py
   grass/trunk/lib/python/temporal/space_time_datasets.py
   grass/trunk/lib/python/temporal/space_time_datasets_tools.py
   grass/trunk/temporal/t.create/t.create.py
   grass/trunk/temporal/t.list/t.list.py
   grass/trunk/temporal/t.rast.aggregate.ds/t.rast.aggregate.ds.py
   grass/trunk/temporal/t.rast.aggregate/t.rast.aggregate.py
   grass/trunk/temporal/t.rast.extract/t.rast.extract.py
   grass/trunk/temporal/t.rast.mapcalc/t.rast.mapcalc.py
   grass/trunk/temporal/t.rast.univar/t.rast.univar.py
   grass/trunk/temporal/t.rast3d.extract/t.rast3d.extract.py
   grass/trunk/temporal/t.remove/t.remove.py
   grass/trunk/temporal/t.support/t.support.py
   grass/trunk/temporal/t.unregister/t.unregister.py
   grass/trunk/temporal/t.vect.observe.strds/t.vect.observe.strds.py
   grass/trunk/temporal/t.vect.observe.strds/test.t.vect.observe.strds.sh
   grass/trunk/temporal/t.vect.what.strds/t.vect.what.strds.py
Log:
* Using ctypes interface to libgis and libraster to read raster information to speed up map registration
* Creation and removal of timestamps in the grass file based database is now realized using ctypes and libgis to avoid the execution of timestamp modules
* Database interface connection handling changed 


Modified: grass/trunk/lib/python/temporal/abstract_dataset.py
===================================================================
--- grass/trunk/lib/python/temporal/abstract_dataset.py	2012-04-07 14:57:42 UTC (rev 51305)
+++ grass/trunk/lib/python/temporal/abstract_dataset.py	2012-04-07 23:42:39 UTC (rev 51306)
@@ -199,7 +199,10 @@
             dbif.close()
 
     def is_in_db(self, dbif=None):
-        """!Check if the temporal dataset entry is in the database"""
+        """!Check if the temporal dataset entry is in the database
+        
+           @param dbif: The database interface to be used
+        """
         return self.base.is_in_db(dbif)
 
     def delete(self):
@@ -215,6 +218,8 @@
                            If False the prepared SQL statements are returned and must be executed by the caller.
         """
 
+        dbif, connect = init_dbif(dbif)
+        
         # Build the INSERT SQL statement
         statement = self.base.get_insert_statement_mogrified(dbif)
         if self.is_time_absolute():
@@ -225,9 +230,13 @@
         statement += self.metadata.get_insert_statement_mogrified(dbif)
 
         if execute == True:
-            execute_transaction(statement, dbif)
+            dbif.execute_transaction(statement)
+	    if connect:
+		dbif.close()
             return ""
 
+        if connect:
+            dbif.close()
         return statement
 
     def update(self, dbif=None, execute=True):
@@ -239,6 +248,8 @@
                            If False the prepared SQL statements are returned and must be executed by the caller.
 	"""
 
+        dbif, connect = init_dbif(dbif)
+        
         # Build the UPDATE SQL statement
         statement = self.base.get_update_statement_mogrified(dbif)
 	if self.is_time_absolute():
@@ -249,9 +260,13 @@
         statement += self.metadata.get_update_statement_mogrified(dbif)
 
         if execute == True:
-            execute_transaction(statement, dbif)
+            dbif.execute_transaction(statement)
+	    if connect:
+		dbif.close()
             return ""
- 
+
+        if connect:
+            dbif.close()
         return statement
  
     def update_all(self, dbif=None, execute=True):
@@ -263,6 +278,8 @@
                            If False the prepared SQL statements are returned and must be executed by the caller.
 	"""
 
+        dbif, connect = init_dbif(dbif)
+        
         # Build the UPDATE SQL statement
         statement = self.base.get_update_all_statement_mogrified(dbif)
 	if self.is_time_absolute():
@@ -273,9 +290,13 @@
         statement += self.metadata.get_update_all_statement_mogrified(dbif)
 
         if execute == True:
-            execute_transaction(statement, dbif)
+            dbif.execute_transaction(statement)
+	    if connect:
+		dbif.close()
             return ""
 
+        if connect:
+            dbif.close()
         return statement
 
     def set_time_to_absolute(self):

Modified: grass/trunk/lib/python/temporal/abstract_map_dataset.py
===================================================================
--- grass/trunk/lib/python/temporal/abstract_map_dataset.py	2012-04-07 14:57:42 UTC (rev 51305)
+++ grass/trunk/lib/python/temporal/abstract_map_dataset.py	2012-04-07 23:42:39 UTC (rev 51306)
@@ -49,14 +49,6 @@
            @param ident: The name of the register table
         """
         raise IOError("This method must be implemented in the subclasses")
-      
-    def get_timestamp_module_name(self):
-        """!Return the name of the C-module to set the time stamp in the file system"""
-        raise IOError("This method must be implemented in the subclasses")
-   
-    def load(self):
-        """!Load the content of this object from map files"""
-        raise IOError("This method must be implemented in the subclasses")
  
     def check_resolution_with_current_region(self):
         """!Check if the raster or voxel resolution is finer than the current resolution
@@ -66,7 +58,64 @@
            Vector maps are alwyas finer than the current region
         """
         raise IOError("This method must be implemented in the subclasses")
+	
+    def has_grass_timestamp(self):
+        """!Check if a grass file bsased time stamp exists for this map. 
+        """
+        raise IOError("This method must be implemented in the subclasses")
+    
+    def write_timestamp_to_grass(self):
+        """!Write the timestamp of this map into the map metadata in the grass file system based spatial
+           database. 
+        """
+        raise IOError("This method must be implemented in the subclasses")
+    
+    def remove_timestamp_from_grass(self):
+        """!Remove the timestamp from the grass file system based spatial database
+        """
+        raise IOError("This method must be implemented in the subclasses")
+	
+    def map_exists(self):
+        """!Return True in case the map exists in the grass spatial database
+        
+           @return True if map exists, False otherwise
+        """        
+        raise IOError("This method must be implemented in the subclasses")
+	        
+    def read_info(self):
+        """!Read the map info from the grass file system based database and store the content 
+           into a dictionary
+        """
+        raise IOError("This method must be implemented in the subclasses")
 
+    def load(self):
+        """!Load the content of this object from the grass file system based database"""
+        raise IOError("This method must be implemented in the subclasses")
+	
+    def _convert_timestamp(self):
+	"""!Convert the valid time into a grass datetime library compatible timestamp string
+	    
+	    This methods works for reltaive and absolute time
+	    
+	    @return the grass timestamp string
+	"""
+	start = ""
+        
+        if self.is_time_absolute():
+	    start_time, end_time, tz = self.get_absolute_time()
+	    start = datetime_to_grass_datetime_string(start_time)
+	    if end_time:
+		end = datetime_to_grass_datetime_string(end_time)
+		start += " / %s"%(end)
+	else:
+	    start_time, end_time, unit = self.get_relative_time()
+	    start = "%i %s"%(int(start_time), unit)
+	    if end_time != None:
+		end = "%i %s"%(int(end_time), unit)
+		start += " / %s"%(end)
+
+	return start
+		        
     def get_map_id(self):
 	"""!Return the map id. The map id is the unique map identifier in grass and must not be equal to the 
 	   primary key identifier (id) of the map in the database. Since vector maps may have layer information,
@@ -134,13 +183,14 @@
         string = ""
         if datasets:
             for ds in datasets:
+                if count > 0 and count % 3 == 0:
+                    string += "\n | ............................ "
+                    count = 0
                 if count == 0:
                     string += ds["id"]
                 else:
                     string += ",%s" % ds["id"]
                 count += 1
-                if count > 2:
-                    string += " | ............................ "
         print " | Registered datasets ........ " + string
         print " +----------------------------------------------------------------------------+"
 
@@ -164,6 +214,44 @@
             count += 1
         print "registered_datasets=" + string
 
+    def insert(self, dbif=None, execute=True):
+        """!Insert temporal dataset entry into database from the internal structure
+
+	   This functions assures that the timetsamp is written to the grass file system based database
+	    
+           @param dbif: The database interface to be used
+           @param execute: If True the SQL statements will be executed.
+                           If False the prepared SQL statements are returned and must be executed by the caller.
+        """
+        self.write_timestamp_to_grass()
+        return abstract_dataset.insert(self, dbif, execute)
+
+    def update(self, dbif=None, execute=True):
+	"""!Update temporal dataset entry of database from the internal structure
+	   excluding None variables
+	   
+	   This functions assures that the timetsamp is written to the grass file system based database
+
+           @param dbif: The database interface to be used
+           @param execute: If True the SQL statements will be executed.
+                           If False the prepared SQL statements are returned and must be executed by the caller.
+	"""
+        self.write_timestamp_to_grass()
+        return abstract_dataset.update(self, dbif, execute)
+
+    def update_all(self, dbif=None, execute=True):
+	"""!Update temporal dataset entry of database from the internal structure
+	   and include None varuables.
+	   
+	   This functions assures that the timetsamp is written to the grass file system based database
+
+           @param dbif: The database interface to be used
+           @param execute: If True the SQL statements will be executed.
+                           If False the prepared SQL statements are returned and must be executed by the caller.
+	"""
+        self.write_timestamp_to_grass()
+        return abstract_dataset.update_all(self, dbif, execute)
+        
     def set_absolute_time(self, start_time, end_time=None, timezone=None):
         """!Set the absolute time interval with start time and end time
         
@@ -204,8 +292,7 @@
     def update_absolute_time(self, start_time, end_time=None, timezone=None, dbif = None):
         """!Update the absolute time
 
-           This method should always be used to set the absolute time. Do not use insert() or update()
-           to the the time. This update functions assures that the *.timestamp commands are invoked.
+	   This functions assures that the timetsamp is written to the grass file system based database
 
            @param start_time: a datetime object specifying the start time of the map
            @param end_time: a datetime object specifying the end time of the map
@@ -220,19 +307,8 @@
         if connect == True:
             dbif.close()
 
-        self.write_absolute_time_to_file()
-
-    def write_absolute_time_to_file(self):
-        """!Start the grass timestamp module to set the time in the file system"""
-
-        start_time, end_time, unit = self.get_absolute_time()
-        start = datetime_to_grass_datetime_string(start_time)
-        if end_time:
-            end = datetime_to_grass_datetime_string(end_time)
-            start += " / %s"%(end)
-
-        core.run_command(self.get_timestamp_module_name(), map=self.get_map_id(), date=start)
-
+        self.write_timestamp_to_grass()
+        
     def set_relative_time(self, start_time, end_time, unit):
         """!Set the relative time interval 
         
@@ -278,9 +354,8 @@
     def update_relative_time(self, start_time, end_time, unit, dbif = None):
         """!Update the relative time interval
 
-           This method should always be used to set the absolute time. Do not use insert() or update()
-           to the the time. This update functions assures that the *.timestamp commands are invoked.
-
+	   This functions assures that the timetsamp is written to the grass file system based database
+	    
            @param start_time: A double value 
            @param end_time: A double value 
            @param dbif: The database interface to be used
@@ -290,23 +365,12 @@
         if self.set_relative_time(start_time, end_time, unit):
             self.relative_time.update_all(dbif)
             self.base.update(dbif)
-            dbif.connection.commit()
 
         if connect == True:
             dbif.close()
 
-        self.write_relative_time_to_file()
+        self.write_timestamp_to_grass()
 
-    def write_relative_time_to_file(self):
-        """!Start the grass timestamp module to set the time in the file system"""
-
-        start_time, end_time, unit = self.get_relative_time()
-        start = "%i %s"%(int(start_time), unit)
-        if end_time != None:
-            end = "%i %s"%(int(end_time), unit)
-            start += " / %s"%(end)
-        core.run_command(self.get_timestamp_module_name(), map=self.get_map_id(), date=start)
-
     def set_spatial_extent(self, north, south, east, west, top=0, bottom=0):
         """!Set the spatial extent of the map
 
@@ -377,17 +441,11 @@
             statement += self.base.get_delete_statement()
 
         if execute == True:
-            execute_transaction(statement, dbif)
+            dbif.execute_transaction(statement)
 
         # Remove the timestamp from the file system
-        if self.get_type() == "vect":
-	    if self.get_layer():
-		core.run_command(self.get_timestamp_module_name(), map=self.get_map_id(), layer=self.get_layer(), date="none")
-	    else:
-		core.run_command(self.get_timestamp_module_name(), map=self.get_map_id(), date="none")
-	else:
-	    core.run_command(self.get_timestamp_module_name(), map=self.get_map_id(), date="none")
-
+        self.remove_timestamp_from_grass()
+        
         self.reset(None)
 
         if connect == True:
@@ -442,7 +500,7 @@
             core.percent(1, 1, 1)
             
         if execute == True:
-            execute_transaction(statement, dbif)
+            dbif.execute_transaction(statement)
 
         if connect == True:
             dbif.close()

Modified: grass/trunk/lib/python/temporal/abstract_space_time_dataset.py
===================================================================
--- grass/trunk/lib/python/temporal/abstract_space_time_dataset.py	2012-04-07 14:57:42 UTC (rev 51305)
+++ grass/trunk/lib/python/temporal/abstract_space_time_dataset.py	2012-04-07 23:42:39 UTC (rev 51306)
@@ -777,7 +777,7 @@
         statement += self.base.get_delete_statement()
 
         if execute == True:
-            execute_transaction(statement, dbif)
+            dbif.execute_transaction(statement)
 
         self.reset(None)
 
@@ -945,7 +945,7 @@
 
         # We need to execute the statement at this time
         if statement != "":
-            execute_transaction(statement, dbif)
+            dbif.execute_transaction(statement)
 
         statement = ""
 
@@ -968,7 +968,7 @@
 	    else:
 		sql = "INSERT INTO " + map_register_table + " (id) " + "VALUES (%s);\n"
 
-            statement += dbif._mogrify_sql_statement((sql, (self.base.get_id(),)), dbif)
+            statement += dbif.mogrify_sql_statement((sql, (self.base.get_id(),)))
 
         # Now put the raster name in the stds map register table
 	if dbmi.paramstyle == "qmark":
@@ -976,10 +976,10 @@
 	else:
 	    sql = "INSERT INTO " + stds_register_table + " (id) " + "VALUES (%s);\n"
 
-        statement += dbif._mogrify_sql_statement((sql, (map_id,)), dbif)
+        statement += dbif.mogrify_sql_statement((sql, (map_id,)))
 
         # Now execute the insert transaction
-        execute_transaction(statement, dbif)
+        dbif.execute_transaction(statement)
 
         if connect == True:
             dbif.close()
@@ -1045,7 +1045,7 @@
             else:
                 sql = "DELETE FROM " + map_register_table + " WHERE id = %s;\n"
 
-            statement += dbif._mogrify_sql_statement((sql, (self.base.get_id(),)), dbif)
+            statement += dbif.mogrify_sql_statement((sql, (self.base.get_id(),)))
 
         # Remove the raster map from the space time raster dataset register
         if stds_register_table != None:
@@ -1054,10 +1054,10 @@
             else:
                 sql = "DELETE FROM " + stds_register_table + " WHERE id = %s;\n"
 
-            statement += dbif._mogrify_sql_statement((sql, (map_id,)), dbif)
+            statement += dbif.mogrify_sql_statement((sql, (map_id,)))
 
         if execute == True:
-            execute_transaction(statement, dbif)
+            dbif.execute_transaction(statement)
             
         if connect == True:
             dbif.close()
@@ -1127,7 +1127,7 @@
         sql_script += sql
         sql_script += "\n"
 
-	execute_transaction(sql_script, dbif)
+        dbif.execute_transaction(sql_script)
 	    
         # Read and validate the selected end time
         self.select()
@@ -1197,7 +1197,7 @@
                 sql = sql.replace("SPACETIME_ID", self.base.get_id())
                 sql = sql.replace("STDS", self.get_type())
 
-	    execute_transaction(sql, dbif)
+            dbif.execute_transaction(sql)
 
         # Count the temporal map types
         maps = self.get_registered_maps_as_objects(dbif=dbif)

Modified: grass/trunk/lib/python/temporal/base.py
===================================================================
--- grass/trunk/lib/python/temporal/base.py	2012-04-07 14:57:42 UTC (rev 51305)
+++ grass/trunk/lib/python/temporal/base.py	2012-04-07 23:42:39 UTC (rev 51306)
@@ -181,10 +181,7 @@
     """!This class represents the SQL database interface
 
        Functions to insert, select and update the internal structure of this class
-       in the temporal database are implemented. The following DBMS are supported:
-       * sqlite via the sqlite3 standard library
-       * postgresql via psycopg2
-
+       in the temporal database are implemented. 
        This is the base class for raster, raster3d, vector and space time datasets
        data management classes:
        * Identification information (base)
@@ -207,102 +204,25 @@
         """!Return the name of the table in which the internal data are inserted, updated or selected"""
         return self.table
 
-    def connect(self):
-        """!Connect to the DBMI to execute SQL statements
-
-           Supported backends are sqlite3 and postgresql
-        """
-        init = get_temporal_dbmi_init_string()
-        #print "Connect to",  self.database
-        if dbmi.__name__ == "sqlite3":
-	    self.connection = dbmi.connect(init, detect_types=dbmi.PARSE_DECLTYPES|dbmi.PARSE_COLNAMES)
-	    self.connection.row_factory = dbmi.Row
-            self.connection.isolation_level = None
-	    self.cursor = self.connection.cursor()
-            self.cursor.execute("PRAGMA synchronous = OFF")
-            self.cursor.execute("PRAGMA journal_mode = MEMORY")
-        elif dbmi.__name__ == "psycopg2":
-	    self.connection = dbmi.connect(init)
-	    #self.connection.set_isolation_level(dbmi.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
-	    self.cursor = self.connection.cursor(cursor_factory=dbmi.extras.DictCursor)
-
-    def close(self):
-        """!Close the DBMI connection"""
-        #print "Close connection to",  self.database
-	self.connection.commit()
-        self.cursor.close()
-
-
-    def _mogrify_sql_statement(self, content, dbif=None):
-        """!Return the SQL statement and arguments as executable SQL string
-        """
-        sql = content[0]
-        args = content[1]
-
-        if dbmi.__name__ == "psycopg2":
-            if len(args) == 0:
-                return sql
-            else:
-                if dbif:
-                    try:
-                        return dbif.cursor.mogrify(sql, args)
-                    except:
-                        print sql, args
-                        raise
-                else:
-                    self.connect()
-                    statement = self.cursor.mogrify(sql, args)
-                    self.close()
-                    return statement
-                    
-        elif dbmi.__name__ == "sqlite3":
-            if len(args) == 0:
-                return sql
-            else:
-                # Unfortunately as sqlite does not support 
-                # the transformation of sql strings and qmarked or
-                # named arguments we must make our hands dirty
-                # and do it by ourself. :(
-                # Doors are open for SQL injection because of the 
-                # limited python sqlite3 implementation!!!
-                pos = 0
-                count = 0
-                maxcount = 100
-                statement = sql
-
-                while count < maxcount:
-                    pos = statement.find("?", pos + 1)
-                    if pos == -1:
-                        break
-                    
-                    if args[count] == None:
-                        statement = "%sNULL%s"%(statement[0:pos], statement[pos+1:])
-                    elif isinstance(args[count], (int, long)):
-                        statement = "%s%d%s"%(statement[0:pos], args[count],statement[pos+1:])
-                    elif isinstance(args[count], float):
-                        statement = "%s%f%s"%(statement[0:pos], args[count],statement[pos+1:])
-                    else:
-                        # Default is a string, this works for datetime objects too
-                        statement = "%s\'%s\'%s"%(statement[0:pos], str(args[count]),statement[pos+1:])
-                    count += 1
-
-                return statement
-
     def get_delete_statement(self):
         """!Return the delete string"""
 	return "DELETE FROM " + self.get_table_name() + " WHERE id = \'" + str(self.ident) + "\';\n"
 
     def delete(self, dbif=None):
-        """!Delete the entry of this object from the temporal database"""
+        """!Delete the entry of this object from the temporal database
+
+           @param dbif: The database interface to be used, if None a temporary connection will be established
+        """
 	sql = self.get_delete_statement()
         #print sql
         
-        if dbif:
-            dbif.cursor.execute(sql)
-        else:
-            self.connect()
-            self.cursor.execute(sql)
-            self.close()
+	if dbif:
+	    dbif.cursor.execute(sql)
+	else:
+	    dbif = sql_database_interface_connection()
+	    dbif.connect()
+	    dbif.cursor.execute(sql)
+	    dbif.close()
 
     def get_is_in_db_statement(self):
         """Return the selection string"""
@@ -311,20 +231,21 @@
     def is_in_db(self, dbif=None):
         """!Check if this object is present in the temporal database
 
-           @param dbif: The database interface to be used
+           @param dbif: The database interface to be used, if None a temporary connection will be established
         """
 
 	sql = self.get_is_in_db_statement()
         #print sql
 
-        if dbif:
-            dbif.cursor.execute(sql)
-            row = dbif.cursor.fetchone()
-        else:
-            self.connect()
-            self.cursor.execute(sql)
-            row = self.cursor.fetchone()
-            self.close()
+	if dbif:
+	    dbif.cursor.execute(sql)
+	    row = dbif.cursor.fetchone()
+	else:
+	    dbif = sql_database_interface_connection()
+	    dbif.connect()
+	    dbif.cursor.execute(sql)
+	    row = dbif.cursor.fetchone()
+	    dbif.close()
 
 	# Nothing found
 	if row == None:
@@ -337,14 +258,20 @@
 	return self.serialize("SELECT", self.get_table_name(), "WHERE id = \'" + str(self.ident) + "\'")
     
     def get_select_statement_mogrified(self, dbif=None):
-        """!Return the select statement as mogrified string"""
-        return self._mogrify_sql_statement(self.get_select_statement(), dbif)
+        """!Return the select statement as mogrified string
+
+           @param dbif: The database interface to be used, if None a temporary connection will be established
+        """
+        if not dbif:
+	    dbif = sql_database_interface_connection()
+	    
+        return dbif.mogrify_sql_statement(self.get_select_statement())
                 
     def select(self, dbif=None):
         """!Select the content from the temporal database and store it
            in the internal dictionary structure
 
-           @param dbif: The database interface to be used
+           @param dbif: The database interface to be used, if None a temporary connection will be established
         """
 	sql, args = self.get_select_statement()
 	#print sql
@@ -357,13 +284,14 @@
                 dbif.cursor.execute(sql, args)
             row = dbif.cursor.fetchone()
         else:
-            self.connect()
-            if len(args) == 0:
-                self.cursor.execute(sql)
-            else:
-                self.cursor.execute(sql, args)
-            row = self.cursor.fetchone()
-            self.close()
+	    dbif = sql_database_interface_connection()
+	    dbif.connect()
+	    if len(args) == 0:
+		dbif.cursor.execute(sql)
+	    else:
+		dbif.cursor.execute(sql, args)
+	    row = dbif.cursor.fetchone()
+	    dbif.close()
 
 	# Nothing found
 	if row == None:
@@ -381,41 +309,54 @@
 	return self.serialize("INSERT", self.get_table_name())
     
     def get_insert_statement_mogrified(self, dbif=None):
-        """!Return the insert statement as mogrified string"""
-        return self._mogrify_sql_statement(self.get_insert_statement(), dbif)
+        """!Return the insert statement as mogrified string
 
+           @param dbif: The database interface to be used, if None a temporary connection will be established
+        """
+        if not dbif:
+	    dbif = sql_database_interface_connection()
+	    
+        return dbif.mogrify_sql_statement(self.get_insert_statement())
+
     def insert(self, dbif=None):
         """!Serialize the content of this object and store it in the temporal
            database using the internal identifier
 
-           @param dbif: The database interface to be used
+           @param dbif: The database interface to be used, if None a temporary connection will be established
         """
 	sql, args = self.get_insert_statement()
 	#print sql
 	#print args
 
-        if dbif:
-            dbif.cursor.execute(sql, args)
-        else:
-            self.connect()
-            self.cursor.execute(sql, args)
-            self.close()
+	if dbif:
+	    dbif.cursor.execute(sql, args)
+	else:
+	    dbif = sql_database_interface_connection()
+	    dbif.connect()
+	    dbif.cursor.execute(sql, args)
+	    dbif.close()
 
     def get_update_statement(self):
         """!Return the sql statement and the argument list in database specific style"""
 	return self.serialize("UPDATE", self.get_table_name(), "WHERE id = \'" + str(self.ident) + "\'")
 
     def get_update_statement_mogrified(self,dbif=None):
-        """!Return the update statement as mogrified string"""
-        return self._mogrify_sql_statement(self.get_update_statement(), dbif)
+        """!Return the update statement as mogrified string
 
+           @param dbif: The database interface to be used, if None a temporary connection will be established
+        """
+        if not dbif:
+	    dbif = sql_database_interface_connection()
+	    
+        return dbif.mogrify_sql_statement(self.get_update_statement())
+
     def update(self, dbif=None):
         """!Serialize the content of this object and update it in the temporal
            database using the internal identifier
 
            Only object entries which are exists (not None) are updated
 
-           @param dbif: The database interface to be used
+           @param dbif: The database interface to be used, if None a temporary connection will be established
         """
 	if self.ident == None:
 	    raise IOError("Missing identifer");
@@ -424,26 +365,33 @@
 	#print sql
 	#print args
 
-        if dbif:
-            dbif.cursor.execute(sql, args)
-        else:
-            self.connect()
-            self.cursor.execute(sql, args)
-            self.close()
+	if dbif:
+	    dbif.cursor.execute(sql, args)
+	else:
+	    dbif = sql_database_interface_connection()
+	    dbif.connect()
+	    dbif.cursor.execute(sql, args)
+	    dbif.close()
 
     def get_update_all_statement(self):
         """!Return the sql statement and the argument list in database specific style"""
 	return self.serialize("UPDATE ALL", self.get_table_name(), "WHERE id = \'" + str(self.ident) + "\'")
 
     def get_update_all_statement_mogrified(self, dbif=None):
-        """!Return the update all statement as mogrified string"""
-        return self._mogrify_sql_statement(self.get_update_all_statement(), dbif)
+        """!Return the update all statement as mogrified string
 
+           @param dbif: The database interface to be used, if None a temporary connection will be established
+        """
+        if not dbif:
+	    dbif = sql_database_interface_connection()
+	    
+        return dbif.mogrify_sql_statement(self.get_update_all_statement())
+
     def update_all(self, dbif=None):
         """!Serialize the content of this object, including None objects, and update it in the temporal
            database using the internal identifier
 
-           @param dbif: The database interface to be used
+           @param dbif: The database interface to be used, if None a temporary connection will be established
         """
 	if self.ident == None:
 	    raise IOError("Missing identifer");
@@ -452,12 +400,13 @@
 	#print sql
 	#print args
 
-        if dbif:
-            dbif.cursor.execute(sql, args)
-        else:
-            self.connect()
-            self.cursor.execute(sql, args)
-            self.close()
+	if dbif:
+	    dbif.cursor.execute(sql, args)
+	else:
+	    dbif = sql_database_interface_connection()
+	    dbif.connect()
+	    dbif.cursor.execute(sql, args)
+	    dbif.close()
 
 ###############################################################################
 
@@ -754,52 +703,4 @@
         stds_base.__init__(self, "stvds_base", ident, name, mapset, semantic_type, creator, creation_time,\
 	            modification_time, temporal_type, revision)
 
-###############################################################################
 
-def init_dbif(dbif):
-    """!This method checks if the database interface exists, if not a new one 
-        will be created and True will be returned
-
-        Usage code sample:
-        dbif, connect = self._init_dbif(dbif)
-        if connect:
-            dbif.close()
-    """
-    if dbif == None:
-        dbif = sql_database_interface()
-        dbif.connect()
-        return dbif, True
-
-    return dbif, False
-
-###############################################################################
-
-def execute_transaction(statement, dbif=None):
-    """!Execute a transactional SQL statement
-
-        The BEGIN and END TRANSACTION statements will be added automatically
-        to the sql statement
-
-        @param statement The executable SQL statement or SQL script
-        @param dbif The database interface, if None a new db interface will be created temporary
-    """
-    dbif, connect = init_dbif(dbif)
-
-    sql_script = ""
-    sql_script += "BEGIN TRANSACTION;\n"
-    sql_script += statement
-    sql_script += "END TRANSACTION;"
-    try:
-        if dbmi.__name__ == "sqlite3":
-            dbif.cursor.executescript(statement)
-        else:
-            dbif.cursor.execute(statement)
-        dbif.connection.commit()
-    except:
-        if connect == True:
-            dbif.close()
-        core.error(_("Unable to execute transaction:\n %s") % (statement))
-        raise
-
-    if connect:
-        dbif.close()

Modified: grass/trunk/lib/python/temporal/core.py
===================================================================
--- grass/trunk/lib/python/temporal/core.py	2012-04-07 14:57:42 UTC (rev 51305)
+++ grass/trunk/lib/python/temporal/core.py	2012-04-07 23:42:39 UTC (rev 51306)
@@ -167,3 +167,148 @@
 
     connection.commit()
     cursor.close()
+
+###############################################################################
+
+class sql_database_interface_connection():
+    """!This class represents the database interface connection
+    
+       The following DBMS are supported:
+       * sqlite via the sqlite3 standard library
+       * postgresql via psycopg2
+
+    """
+    def __init__(self):
+	self.connected = False
+	
+    def connect(self):
+        """!Connect to the DBMI to execute SQL statements
+
+           Supported backends are sqlite3 and postgresql
+        """
+        init = get_temporal_dbmi_init_string()
+        #print "Connect to",  self.database
+        if dbmi.__name__ == "sqlite3":
+	    self.connection = dbmi.connect(init, detect_types=dbmi.PARSE_DECLTYPES|dbmi.PARSE_COLNAMES)
+	    self.connection.row_factory = dbmi.Row
+            self.connection.isolation_level = None
+	    self.cursor = self.connection.cursor()
+            self.cursor.execute("PRAGMA synchronous = OFF")
+            self.cursor.execute("PRAGMA journal_mode = MEMORY")
+        elif dbmi.__name__ == "psycopg2":
+	    self.connection = dbmi.connect(init)
+	    #self.connection.set_isolation_level(dbmi.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
+	    self.cursor = self.connection.cursor(cursor_factory=dbmi.extras.DictCursor)
+	self.connected = True
+	
+    def close(self):
+        """!Close the DBMI connection"""
+        #print "Close connection to",  self.database
+	self.connection.commit()
+        self.cursor.close()
+	self.connected = False
+
+    def mogrify_sql_statement(self, content):
+        """!Return the SQL statement and arguments as executable SQL string
+        """
+        sql = content[0]
+        args = content[1]
+
+        if dbmi.__name__ == "psycopg2":
+            if len(args) == 0:
+                return sql
+            else:
+                if self.connected:
+                    try:
+                        return self.cursor.mogrify(sql, args)
+                    except:
+                        print sql, args
+                        raise
+                else:
+                    self.connect()
+                    statement = self.cursor.mogrify(sql, args)
+                    self.close()
+                    return statement
+                    
+        elif dbmi.__name__ == "sqlite3":
+            if len(args) == 0:
+                return sql
+            else:
+                # Unfortunately as sqlite does not support 
+                # the transformation of sql strings and qmarked or
+                # named arguments we must make our hands dirty
+                # and do it by ourself. :(
+                # Doors are open for SQL injection because of the 
+                # limited python sqlite3 implementation!!!
+                pos = 0
+                count = 0
+                maxcount = 100
+                statement = sql
+
+                while count < maxcount:
+                    pos = statement.find("?", pos + 1)
+                    if pos == -1:
+                        break
+                    
+                    if args[count] == None:
+                        statement = "%sNULL%s"%(statement[0:pos], statement[pos+1:])
+                    elif isinstance(args[count], (int, long)):
+                        statement = "%s%d%s"%(statement[0:pos], args[count],statement[pos+1:])
+                    elif isinstance(args[count], float):
+                        statement = "%s%f%s"%(statement[0:pos], args[count],statement[pos+1:])
+                    else:
+                        # Default is a string, this works for datetime objects too
+                        statement = "%s\'%s\'%s"%(statement[0:pos], str(args[count]),statement[pos+1:])
+                    count += 1
+
+                return statement
+                
+    def execute_transaction(self, statement):
+	"""!Execute a transactional SQL statement
+
+	    The BEGIN and END TRANSACTION statements will be added automatically
+	    to the sql statement
+
+	    @param statement The executable SQL statement or SQL script
+	"""
+	connect = False
+	if self.connected == False:
+	    self.connect()
+	    connect = True
+
+	sql_script = ""
+	sql_script += "BEGIN TRANSACTION;\n"
+	sql_script += statement
+	sql_script += "END TRANSACTION;"
+	try:
+	    if dbmi.__name__ == "sqlite3":
+		self.cursor.executescript(statement)
+	    else:
+		self.cursor.execute(statement)
+	    self.connection.commit()
+	except:
+	    if connect == True:
+		self.close()
+	    core.error(_("Unable to execute transaction:\n %s") % (statement))
+	    raise
+
+	if connect:
+	    self.close()
+	    
+###############################################################################
+
+def init_dbif(dbif):
+    """!This method checks if the database interface connection exists, if not a new one 
+        will be created, connected and True will be returned
+
+        Usage code sample:
+        dbif, connect = tgis.init_dbif(dbif)
+        if connect:
+            dbif.close()
+    """
+    if dbif == None:
+        dbif = sql_database_interface_connection()
+        dbif.connect()
+        return dbif, True
+
+    return dbif, False

Modified: grass/trunk/lib/python/temporal/space_time_datasets.py
===================================================================
--- grass/trunk/lib/python/temporal/space_time_datasets.py	2012-04-07 14:57:42 UTC (rev 51305)
+++ grass/trunk/lib/python/temporal/space_time_datasets.py	2012-04-07 23:42:39 UTC (rev 51306)
@@ -25,6 +25,11 @@
 import grass.script.raster as raster
 import grass.script.vector as vector
 import grass.script.raster3d as raster3d
+
+from ctypes import *
+import grass.lib.gis as libgis
+import grass.lib.raster as libraster
+
 from datetime_math import *
 from abstract_map_dataset import *
 from abstract_space_time_dataset import *
@@ -59,10 +64,6 @@
     def set_stds_register(self, name):
         """!Set the space time dataset register table name in which stds are listed in which this map is registered"""
         self.metadata.set_strds_register(name)
- 
-    def get_timestamp_module_name(self):
-        """!Return the name of the C-module to set the time stamp in the file system"""
-        return "r.timestamp"
 
     def spatial_overlapping(self, dataset):
         """!Return True if the spatial extents 2d overlap"""
@@ -83,12 +84,119 @@
 	self.relative_time = raster_relative_time(ident=ident)
 	self.spatial_extent = raster_spatial_extent(ident=ident)
 	self.metadata = raster_metadata(ident=ident)
+		
+    def has_grass_timestamp(self):
+        """!Check if a grass file bsased time stamp exists for this map. 
+        """
+        if G_has_raster_timestamp(self.get_name(), self.get_mapset()):
+	    return True
+	else:
+	    return False
+ 
+    def write_timestamp_to_grass(self):
+        """!Write the timestamp of this map into the map metadata in the grass file system based spatial
+           database. 
+           
+           Internally the libgis API functions are used for writing
+        """
+        
+	ts = libgis.TimeStamp()
 
+	libgis.G_scan_timestamp(byref(ts), self._convert_timestamp())
+	check = libgis.G_write_raster_timestamp(self.get_name(), byref(ts))
+	
+	if check == -1:
+		core.error(_("Unable to create timestamp file for raster map <%s>"%(self.get_map_id())))
+		
+	if check == -2:
+		core.error(_("Invalid datetime in timestamp for raster map <%s>"%(self.get_map_id())))
+			
+    
+    def remove_timestamp_from_grass(self):
+        """!Remove the timestamp from the grass file system based spatial database
+        
+           Internally the libgis API functions are used for removal
+        """
+        check = libgis.G_remove_raster_timestamp(self.get_name())
+        
+        if check == -1:
+            core.error(_("Unable to remove timestamp for raster map <%s>"%(self.get_name())))
+	
+    def map_exists(self):
+        """!Return True in case the map exists in the grass spatial database
+        
+           @return True if map exists, False otherwise
+        """        
+        mapset = libgis.G_find_raster(self.get_name(), self.get_mapset())
+        
+        if not mapset:
+            return False
+	
+	return True
+        
+    def read_info(self):
+        """!Read the raster map info from the file system and store the content 
+           into a dictionary
+           
+           This method uses the ctypes interface to the gis and raster libraries
+           to read the map metadata information
+        """
+        
+        kvp = {}
+        
+        name = self.get_name()
+        mapset = self.get_mapset()
+        
+        if not self.map_exists():
+	  core.fatal(_("Raster map <%s> not found" % name))
+        
+        # Read the region information
+        region = libgis.Cell_head()
+	libraster.Rast_get_cellhd(name, mapset, byref(region))
+	
+	kvp["north"] = region.north
+	kvp["south"] = region.south
+	kvp["east"] = region.east
+	kvp["west"] = region.west
+	kvp["nsres"] = region.ns_res
+	kvp["ewres"] = region.ew_res
+	kvp["rows"] = region.cols
+	kvp["cols"] = region.rows
+	
+	maptype = libraster.Rast_map_type(name, mapset)
+  
+	if maptype == libraster.DCELL_TYPE:
+	    kvp["datatype"] = "DCELL"
+        elif maptype == libraster.FCELL_TYPE:
+	    kvp["datatype"] = "FCELL"
+        elif maptype == libraster.CELL_TYPE:
+	    kvp["datatype"] = "CELL"
+	    
+	# Read range
+	if libraster.Rast_map_is_fp(name, mapset):
+	    range = libraster.FPRange()
+	    libraster.Rast_init_fp_range (byref(range))
+	    libraster.Rast_read_fp_range(name, mapset, byref(range))
+	    min = libgis.DCELL()
+	    max = libgis.DCELL()
+	    libraster.Rast_get_fp_range_min_max(byref(range), byref(min), byref(max))
+	    kvp["min"] = float(min.value)
+	    kvp["max"] = float(max.value)
+	else:
+	    range = libraster.Range()
+	    libraster.Rast_init_range (byref(range))
+	    libraster.Rast_read_range(name, mapset, byref(range))
+	    min = libgis.CELL()
+	    max = libgis.CELL()
+	    libraster.Rast_get_fp_range_min_max(byref(range), byref(min), byref(max))
+	    kvp["min"] = int(min.value)
+	    kvp["max"] = int(max.value)
+	
+	return kvp
+
     def load(self):
         """!Load all info from an existing raster map into the internal structure"""
 
-        # Get the data from an existing raster map
-        kvp = raster.raster_info(self.get_map_id())
 
         # Fill base information
 
@@ -96,6 +204,9 @@
         self.base.set_mapset(self.ident.split("@")[1])
         self.base.set_creator(str(getpass.getuser()))
 
+        # Get the data from an existing raster map
+        kvp = self.read_info()
+        
         # Fill spatial extent
 
         self.set_spatial_extent(north=kvp["north"], south=kvp["south"], \
@@ -109,8 +220,8 @@
         self.metadata.set_min(kvp["min"])
         self.metadata.set_max(kvp["max"])
 
-        rows = int((kvp["north"] - kvp["south"])/kvp["nsres"] + 0.5)
-        cols = int((kvp["east"] - kvp["west"])/kvp["ewres"] + 0.5)
+        rows = kvp["rows"]
+        cols = kvp["cols"]
 
         ncells = cols * rows
 
@@ -147,10 +258,6 @@
     def set_stds_register(self, name):
         """!Set the space time dataset register table name in which stds are listed in which this map is registered"""
         self.metadata.set_str3ds_register(name)
- 
-    def get_timestamp_module_name(self):
-        """!Return the name of the C-module to set the time stamp in the file system"""
-        return "r3.timestamp"
 
     def spatial_overlapping(self, dataset):
         """!Return True if the spatial extents overlap"""
@@ -178,6 +285,55 @@
 	self.spatial_extent = raster3d_spatial_extent(ident=ident)
 	self.metadata = raster3d_metadata(ident=ident)
 
+    def has_grass_timestamp(self):
+        """!Check if a grass file bsased time stamp exists for this map. 
+        """
+        if G_has_raster3d_timestamp(self.get_name(), self.get_mapset()):
+	    return True
+	else:
+	    return False
+ 
+    def write_timestamp_to_grass(self):
+        """!Write the timestamp of this map into the map metadata in the grass file system based spatial
+           database. 
+           
+           Internally the libgis API functions are used for writing
+        """
+        
+	ts = libgis.TimeStamp()
+
+	libgis.G_scan_timestamp(byref(ts), self._convert_timestamp())
+	check = libgis.G_write_raster3d_timestamp(self.get_name(), byref(ts))
+	
+	if check == -1:
+		core.error(_("Unable to create timestamp file for raster3d map <%s>"%(self.get_map_id())))
+		
+	if check == -2:
+		core.error(_("Invalid datetime in timestamp for raster3d map <%s>"%(self.get_map_id())))
+			
+    
+    def remove_timestamp_from_grass(self):
+        """!Remove the timestamp from the grass file system based spatial database
+        
+           Internally the libgis API functions are used for removal
+        """
+        check = libgis.G_remove_raster3d_timestamp(self.get_name())
+        
+        if check == -1:
+            core.error(_("Unable to remove timestamp for raster3d map <%s>"%(self.get_name())))
+	
+    def map_exists(self):
+        """!Return True in case the map exists in the grass spatial database
+        
+           @return True if map exists, False otherwise
+        """        
+        mapset = libgis.G_find_raster3d(self.get_name(), self.get_mapset())
+        
+        if not mapset:
+            return False
+	
+	return True
+        
     def load(self):
         """!Load all info from an existing raster3d map into the internal structure"""
 
@@ -245,10 +401,6 @@
     def set_stds_register(self, name):
         """!Set the space time dataset register table name in which stds are listed in which this map is registered"""
         self.metadata.set_stvds_register(name)
- 
-    def get_timestamp_module_name(self):
-        """!Return the name of the C-module to set the time stamp in the file system"""
-        return "v.timestamp"
 
     def get_layer(self):
         """!Return the layer"""
@@ -264,7 +416,6 @@
         
         return self.spatial_extent.spatial_relation_2d(dataset.spatial_extent)
 	
-
     def reset(self, ident):
 	"""!Reset the internal structure and set the identifier"""
 	self.ident = ident
@@ -275,6 +426,55 @@
 	self.spatial_extent = vector_spatial_extent(ident=ident)
 	self.metadata = vector_metadata(ident=ident)
 
+    def has_grass_timestamp(self):
+        """!Check if a grass file bsased time stamp exists for this map. 
+        """
+        if G_has_raster_timestamp(self.get_name(), self.get_layer(), self.get_mapset()):
+	    return True
+	else:
+	    return False
+ 
+    def write_timestamp_to_grass(self):
+        """!Write the timestamp of this map into the map metadata in the grass file system based spatial
+           database. 
+           
+           Internally the libgis API functions are used for writing
+        """
+        
+	ts = libgis.TimeStamp()
+
+	libgis.G_scan_timestamp(byref(ts), self._convert_timestamp())
+	check = libgis.G_write_vector_timestamp(self.get_name(), self.get_layer(), byref(ts))
+	
+	if check == -1:
+		core.error(_("Unable to create timestamp file for vector map <%s>"%(self.get_map_id())))
+		
+	if check == -2:
+		core.error(_("Invalid datetime in timestamp for vector map <%s>"%(self.get_map_id())))
+			
+    
+    def remove_timestamp_from_grass(self):
+        """!Remove the timestamp from the grass file system based spatial database
+        
+           Internally the libgis API functions are used for removal
+        """
+        check = libgis.G_remove_vector_timestamp(self.get_name(), self.get_layer())
+        
+        if check == -1:
+            core.error(_("Unable to remove timestamp for vector map <%s>"%(self.get_name())))
+	
+    def map_exists(self):
+        """!Return True in case the map exists in the grass spatial database
+        
+           @return True if map exists, False otherwise
+        """        
+        mapset = libgis.G_find_vector(self.get_name(), self.get_mapset())
+        
+        if not mapset:
+            return False
+	
+	return True
+        
     def load(self):
         """!Load all info from an existing vector map into the internal structure"""
 

Modified: grass/trunk/lib/python/temporal/space_time_datasets_tools.py
===================================================================
--- grass/trunk/lib/python/temporal/space_time_datasets_tools.py	2012-04-07 14:57:42 UTC (rev 51305)
+++ grass/trunk/lib/python/temporal/space_time_datasets_tools.py	2012-04-07 23:42:39 UTC (rev 51306)
@@ -218,7 +218,7 @@
 
         if is_in_db:
            #  Gather the SQL update statement
-           statement += map.update_all(dbif=dbif, execute=True)
+           statement += map.update_all(dbif=dbif, execute=False)
         else:
            #  Gather the SQL insert statement
            statement += map.insert(dbif=dbif, execute=False)
@@ -227,8 +227,8 @@
         if dbmi.__name__ == "sqlite3":
             if count % 100 == 0:
                 if statement != None and statement != "":
-                    core.message(_("Registering 100 maps in the temporal database"))
-                    execute_transaction(statement, dbif)
+                    core.message(_("Registering maps in the temporal database"))
+		    dbif.execute_transaction(statement)
                     statement = ""
 
         # Store the maps in a list to register in a space time dataset
@@ -239,7 +239,7 @@
 
     if statement != None and statement != "":
         core.message(_("Register maps in the temporal database"))
-        execute_transaction(statement, dbif)
+        dbif.execute_transaction(statement)
 
     # Finally Register the maps in the space time dataset
     if name:
@@ -534,7 +534,7 @@
 
     sst = dataset_factory(sampletype, sid)
 
-    dbif = sql_database_interface()
+    dbif = sql_database_interface_connection()
     dbif.connect()
 
     for st in sts:

Modified: grass/trunk/temporal/t.create/t.create.py
===================================================================
--- grass/trunk/temporal/t.create/t.create.py	2012-04-07 14:57:42 UTC (rev 51305)
+++ grass/trunk/temporal/t.create/t.create.py	2012-04-07 23:42:39 UTC (rev 51306)
@@ -80,7 +80,7 @@
 
     sp = tgis.dataset_factory(type, id)
 
-    dbif = tgis.sql_database_interface()
+    dbif = tgis.sql_database_interface_connection()
     dbif.connect()
 
     if sp.is_in_db(dbif) and grass.overwrite() == False:

Modified: grass/trunk/temporal/t.list/t.list.py
===================================================================
--- grass/trunk/temporal/t.list/t.list.py	2012-04-07 14:57:42 UTC (rev 51305)
+++ grass/trunk/temporal/t.list/t.list.py	2012-04-07 23:42:39 UTC (rev 51306)
@@ -89,7 +89,7 @@
     id = None
     sp = tgis.dataset_factory(type, id)
 
-    dbif = tgis.sql_database_interface()
+    dbif = tgis.sql_database_interface_connection()
     dbif.connect()
 
     # Create the sql selection statement

Modified: grass/trunk/temporal/t.rast.aggregate/t.rast.aggregate.py
===================================================================
--- grass/trunk/temporal/t.rast.aggregate/t.rast.aggregate.py	2012-04-07 14:57:42 UTC (rev 51305)
+++ grass/trunk/temporal/t.rast.aggregate/t.rast.aggregate.py	2012-04-07 23:42:39 UTC (rev 51306)
@@ -94,7 +94,7 @@
     # Make sure the temporal database exists
     tgis.create_temporal_database()
     # We need a database interface
-    dbif = tgis.sql_database_interface()
+    dbif = tgis.sql_database_interface_connection()
     dbif.connect()
    
     mapset =  grass.gisenv()["MAPSET"]

Modified: grass/trunk/temporal/t.rast.aggregate.ds/t.rast.aggregate.ds.py
===================================================================
--- grass/trunk/temporal/t.rast.aggregate.ds/t.rast.aggregate.ds.py	2012-04-07 14:57:42 UTC (rev 51305)
+++ grass/trunk/temporal/t.rast.aggregate.ds/t.rast.aggregate.ds.py	2012-04-07 23:42:39 UTC (rev 51306)
@@ -81,7 +81,7 @@
     # Make sure the temporal database exists
     tgis.create_temporal_database()
     # We need a database interface
-    dbif = tgis.sql_database_interface()
+    dbif = tgis.sql_database_interface_connection()
     dbif.connect()
    
     mapset =  grass.gisenv()["MAPSET"]

Modified: grass/trunk/temporal/t.rast.extract/t.rast.extract.py
===================================================================
--- grass/trunk/temporal/t.rast.extract/t.rast.extract.py	2012-04-07 14:57:42 UTC (rev 51305)
+++ grass/trunk/temporal/t.rast.extract/t.rast.extract.py	2012-04-07 23:42:39 UTC (rev 51306)
@@ -83,15 +83,17 @@
 
     sp = tgis.space_time_raster_dataset(id)
     
-    if sp.is_in_db() == False:
+    dbif = tgis.sql_database_interface_connection()
+    dbif.connect()
+    
+    if sp.is_in_db(dbif) == False:
+	dbif.close()
         grass.fatal(_("Space time %s dataset <%s> not found") % (sp.get_new_map_instance(None).get_type(), id))
 
     if expression and not base:
+	dbif.close()
         grass.fatal(_("Please specify base="))
 
-    dbif = tgis.sql_database_interface()
-    dbif.connect()
-
     sp.select(dbif)
 
     if output.find("@") >= 0:
@@ -103,6 +105,7 @@
     new_sp = tgis.space_time_raster_dataset(out_id)
     if new_sp.is_in_db():
         if grass.overwrite() == False:
+	    dbif.close()
             grass.fatal(_("Space time raster dataset <%s> is already in database, use overwrite flag to overwrite") % out_id)
             
     rows = sp.get_registered_maps("id", where, "start_time", dbif)
@@ -156,6 +159,7 @@
 			exitcodes += proc.exitcode
 			
 		    if exitcodes != 0:
+			dbif.close()
 			grass.fatal(_("Error while r.mapcalc computation"))
 			
 		    # Empty proc list

Modified: grass/trunk/temporal/t.rast.mapcalc/t.rast.mapcalc.py
===================================================================
--- grass/trunk/temporal/t.rast.mapcalc/t.rast.mapcalc.py	2012-04-07 14:57:42 UTC (rev 51305)
+++ grass/trunk/temporal/t.rast.mapcalc/t.rast.mapcalc.py	2012-04-07 23:42:39 UTC (rev 51306)
@@ -88,7 +88,7 @@
     tgis.create_temporal_database()
     
     # We need a database interface for fast computation
-    dbif = tgis.sql_database_interface()
+    dbif = tgis.sql_database_interface_connection()
     dbif.connect()
 
     mapset =  grass.gisenv()["MAPSET"]

Modified: grass/trunk/temporal/t.rast.univar/t.rast.univar.py
===================================================================
--- grass/trunk/temporal/t.rast.univar/t.rast.univar.py	2012-04-07 14:57:42 UTC (rev 51305)
+++ grass/trunk/temporal/t.rast.univar/t.rast.univar.py	2012-04-07 23:42:39 UTC (rev 51306)
@@ -62,7 +62,7 @@
     # Make sure the temporal database exists
     tgis.create_temporal_database()
     # We need a database interface
-    dbif = tgis.sql_database_interface()
+    dbif = tgis.sql_database_interface_connection()
     dbif.connect()
    
     mapset =  grass.gisenv()["MAPSET"]

Modified: grass/trunk/temporal/t.rast3d.extract/t.rast3d.extract.py
===================================================================
--- grass/trunk/temporal/t.rast3d.extract/t.rast3d.extract.py	2012-04-07 14:57:42 UTC (rev 51305)
+++ grass/trunk/temporal/t.rast3d.extract/t.rast3d.extract.py	2012-04-07 23:42:39 UTC (rev 51306)
@@ -83,7 +83,7 @@
     if sp.is_in_db() == False:
         grass.fatal(_("Space time %s dataset <%s> not found") % (sp.get_new_map_instance(None).get_type(), id))
 
-    dbif = tgis.sql_database_interface()
+    dbif = tgis.sql_database_interface_connection()
     dbif.connect()
 
     sp.select(dbif)

Modified: grass/trunk/temporal/t.remove/t.remove.py
===================================================================
--- grass/trunk/temporal/t.remove/t.remove.py	2012-04-07 14:57:42 UTC (rev 51305)
+++ grass/trunk/temporal/t.remove/t.remove.py	2012-04-07 23:42:39 UTC (rev 51306)
@@ -46,10 +46,6 @@
 
 ############################################################################
 
-#
-# TODO: Add recursive and physical removement of maps and datasets
-#
-
 def main():
     
     # Get the options
@@ -63,7 +59,7 @@
     # Make sure the temporal database exists
     tgis.create_temporal_database()
 
-    dbif = tgis.sql_database_interface()
+    dbif = tgis.sql_database_interface_connection()
     dbif.connect()
 
     dataset_list = []
@@ -110,7 +106,7 @@
         statement += sp.delete(dbif=dbif, execute=False)
 
     # Execute the collected SQL statenents
-    tgis.execute_transaction(statement, dbif)
+    dbif.execute_transaction(statement)
 
     dbif.close()
 

Modified: grass/trunk/temporal/t.support/t.support.py
===================================================================
--- grass/trunk/temporal/t.support/t.support.py	2012-04-07 14:57:42 UTC (rev 51305)
+++ grass/trunk/temporal/t.support/t.support.py	2012-04-07 23:42:39 UTC (rev 51306)
@@ -89,7 +89,7 @@
     else:
         id = name + "@" + mapset
         
-    dbif = tgis.sql_database_interface()
+    dbif = tgis.sql_database_interface_connection()
     dbif.connect()
 
     sp = tgis.dataset_factory(type, id)

Modified: grass/trunk/temporal/t.unregister/t.unregister.py
===================================================================
--- grass/trunk/temporal/t.unregister/t.unregister.py	2012-04-07 14:57:42 UTC (rev 51305)
+++ grass/trunk/temporal/t.unregister/t.unregister.py	2012-04-07 23:42:39 UTC (rev 51306)
@@ -63,7 +63,7 @@
 
     mapset =  grass.gisenv()["MAPSET"]
 
-    dbif = tgis.sql_database_interface()
+    dbif = tgis.sql_database_interface_connection()
     dbif.connect()
 
     # In case a space time dataset is specified
@@ -152,7 +152,7 @@
 	count += 1
 
     # Execute the collected SQL statenents
-    tgis.execute_transaction(statement, dbif)
+    dbif.execute_transaction(statement)
 	
     grass.percent(num_maps, num_maps, 1)
 

Modified: grass/trunk/temporal/t.vect.observe.strds/t.vect.observe.strds.py
===================================================================
--- grass/trunk/temporal/t.vect.observe.strds/t.vect.observe.strds.py	2012-04-07 14:57:42 UTC (rev 51305)
+++ grass/trunk/temporal/t.vect.observe.strds/t.vect.observe.strds.py	2012-04-07 23:42:39 UTC (rev 51306)
@@ -76,7 +76,7 @@
     # Make sure the temporal database exists
     tgis.create_temporal_database()
     # We need a database interface
-    dbif = tgis.sql_database_interface()
+    dbif = tgis.sql_database_interface_connection()
     dbif.connect()
    
     mapset =  grass.gisenv()["MAPSET"]
@@ -107,8 +107,8 @@
 
     # Overwrite existing stvds
     if out_sp.is_in_db(dbif) == True and grass.overwrite() == True:
-        out_sp.select()
-        out_sp.delete()
+        out_sp.select(dbif)
+        out_sp.delete(dbif)
         out_sp = tgis.space_time_vector_dataset(id)
 
     # Select the raster maps
@@ -122,8 +122,8 @@
 
     out_sp.set_initial_values(strds_sp.get_temporal_type(), \
                               strds_sp.get_semantic_type(),\
-                              _("Observation of space time raster dataset <%s>")%(strds_id),\
-                              _("Observattion of space time raster dataset <%s> with vector map <%s>")%(strds_id, input))
+                              _("Observaion of space time raster dataset <%s>")%(strds_id),\
+                              _("Observation of space time raster dataset <%s> with vector map <%s>")%(strds_id, input))
 
     out_sp.insert(dbif)
 
@@ -192,7 +192,7 @@
         else:
             vect.set_relative_time(start, end, strds_ds.get_relative_time_unit())
        
-        if vect.is_in_db():
+        if vect.is_in_db(dbif):
             vect.update(dbif)
         else:
             vect.insert(dbif)

Modified: grass/trunk/temporal/t.vect.observe.strds/test.t.vect.observe.strds.sh
===================================================================
--- grass/trunk/temporal/t.vect.observe.strds/test.t.vect.observe.strds.sh	2012-04-07 14:57:42 UTC (rev 51305)
+++ grass/trunk/temporal/t.vect.observe.strds/test.t.vect.observe.strds.sh	2012-04-07 23:42:39 UTC (rev 51306)
@@ -17,7 +17,7 @@
 t.register -i input=precip_abs1 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-03-01 00:00:00" increment="1 months"
 
 # The @test
-tv.observe.strds input=prec strds=precip_abs1 output=prec_observer 
+t.vect.observe.strds input=prec strds=precip_abs1 output=prec_observer 
 v.info prec_observer
 t.info type=stvds input=prec_observer
 

Modified: grass/trunk/temporal/t.vect.what.strds/t.vect.what.strds.py
===================================================================
--- grass/trunk/temporal/t.vect.what.strds/t.vect.what.strds.py	2012-04-07 14:57:42 UTC (rev 51305)
+++ grass/trunk/temporal/t.vect.what.strds/t.vect.what.strds.py	2012-04-07 23:42:39 UTC (rev 51306)
@@ -68,7 +68,7 @@
     # Make sure the temporal database exists
     tgis.create_temporal_database()
     # We need a database interface
-    dbif = tgis.sql_database_interface()
+    dbif = tgis.sql_database_interface_connection()
     dbif.connect()
    
     mapset =  grass.gisenv()["MAPSET"]



More information about the grass-commit mailing list