/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/Model/transientdb.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/Model/transientdb.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1026 by frank, Mon May 26 11:46:42 2003 UTC revision 1328 by bh, Tue Jul 1 12:01:58 2003 UTC
# Line 258  class TransientTableBase(table.OldTableI Line 258  class TransientTableBase(table.OldTableI
258              return None              return None
259    
260          if type == sql_type_map[table.FIELDTYPE_DOUBLE]:          if type == sql_type_map[table.FIELDTYPE_DOUBLE]:
261              prec = self.Precision(col)              format = "%.12f"
             format = "%%.%df" % prec  
262          elif type == sql_type_map[table.FIELDTYPE_INT]:          elif type == sql_type_map[table.FIELDTYPE_INT]:
263              format = "%d"              format = "%d"
264          else:          else:
# Line 272  class TransientTableBase(table.OldTableI Line 271  class TransientTableBase(table.OldTableI
271    
272          return max          return max
273    
     def Precision(self, col):  
         """Return the precision of the column  
   
         The return value is the maximum number of numeric characters after the  
         decimal if column type is double. Else precision zero is returned.  
         The column can be represented by index or name.  
         """  
       
         type  = self.column_map[col].type  
         if type == sql_type_map[table.FIELDTYPE_DOUBLE]:  
             iname = self.column_map[col].internal_name  
             cursor = self.db.cursor()  
             cursor.execute("SELECT %s FROM %s;" % (iname, self.tablename))  
             values = [ i[0] for i in cursor.fetchall()]  
             if not values:  
                 return 0  
               
             max = 0  
             for value in values:  
                 if value is None: continue  
                 l = len(str(value % 1))  
                 if l > max:  
                     max = l  
             if max > 2:  
                 return max - 2  
             else:  
                 return 0  
         else:  
             return 0  
   
274      def SimpleQuery(self, left, comparison, right):      def SimpleQuery(self, left, comparison, right):
275          """Return the indices of all rows that matching a condition.          """Return the indices of all rows that matching a condition.
276    
# Line 441  class TransientJoinedTable(TitledObject, Line 410  class TransientJoinedTable(TitledObject,
410    
411          self.right_table.ensure_index(self.right_field)          self.right_table.ensure_index(self.right_field)
412    
413            # determine the internal column names to join on before
414            # coalescing the column information because if the external
415            # column names are the same they will be mapped to the same
416            # internal name afterwards.
417            internal_left_col = self.left_table.orig_to_internal[self.left_field]
418            internal_right_col =self.right_table.orig_to_internal[self.right_field]
419    
420          # Coalesce the column information          # Coalesce the column information
421          visited = {}          visited = {}
422          columns = []          columns = []
# Line 451  class TransientJoinedTable(TitledObject, Line 427  class TransientJoinedTable(TitledObject,
427                  # better solution.                  # better solution.
428                  continue                  continue
429              columns.append(col)              columns.append(col)
430                visited[col.name] = 1
431          TransientTableBase.create(self, columns)          TransientTableBase.create(self, columns)
432    
433          # Copy the joined data to the table.          # Copy the joined data to the table.
# Line 468  class TransientJoinedTable(TitledObject, Line 445  class TransientJoinedTable(TitledObject,
445                     self.left_table.tablename,                     self.left_table.tablename,
446                     join_operator,                     join_operator,
447                     self.right_table.tablename,                     self.right_table.tablename,
448                     self.orig_to_internal[self.left_field],                     internal_left_col,
449                     self.orig_to_internal[self.right_field]))                     internal_right_col))
450          self.db.execute(stmt)          self.db.execute(stmt)
451    
452      def Dependencies(self):      def Dependencies(self):
# Line 566  class AutoTransientTable(TitledObject, t Line 543  class AutoTransientTable(TitledObject, t
543          """Return a tuple containing the original table"""          """Return a tuple containing the original table"""
544          return (self.table,)          return (self.table,)
545    
546        def Width(self, col):
547            return self.table.Width(col)

Legend:
Removed from v.1026  
changed lines
  Added in v.1328

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26