/[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 1020 by jan, Fri May 23 13:03:07 2003 UTC revision 1328 by bh, Tue Jul 1 12:01:58 2003 UTC
# Line 242  class TransientTableBase(table.OldTableI Line 242  class TransientTableBase(table.OldTableI
242              result.append(row[0])              result.append(row[0])
243          return result          return result
244    
245        def Width(self, col):
246            """Return the maximum width of values in the column
247    
248            The return value is the the maximum length of string representation
249            of the values in the column (represented by index or name)."""
250            max = 0
251            
252            type  = self.column_map[col].type
253            iname = self.column_map[col].internal_name
254            cursor = self.db.cursor()
255            cursor.execute("SELECT %s FROM %s;" % (iname, self.tablename))
256            values = [ i[0] for i in cursor.fetchall()]
257            if not values:
258                return None
259    
260            if type == sql_type_map[table.FIELDTYPE_DOUBLE]:
261                format = "%.12f"
262            elif type == sql_type_map[table.FIELDTYPE_INT]:
263                format = "%d"
264            else:
265                format = "%s"
266            for value in values:
267                if value is None: continue
268                l = len(format % value)
269                if l > max:
270                    max = l
271    
272            return max
273    
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 381  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 391  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 408  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 505  class AutoTransientTable(TitledObject, t Line 542  class AutoTransientTable(TitledObject, t
542      def Dependencies(self):      def Dependencies(self):
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.1020  
changed lines
  Added in v.1328

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26