/[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 1025 by jan, Fri May 23 13:03:07 2003 UTC revision 1026 by frank, Mon May 26 11:46:42 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                prec = self.Precision(col)
262                format = "%%.%df" % prec
263            elif type == sql_type_map[table.FIELDTYPE_INT]:
264                format = "%d"
265            else:
266                format = "%s"
267            for value in values:
268                if value is None: continue
269                l = len(format % value)
270                if l > max:
271                    max = l
272    
273            return max
274    
275        def Precision(self, col):
276            """Return the precision of the column
277    
278            The return value is the maximum number of numeric characters after the
279            decimal if column type is double. Else precision zero is returned.
280            The column can be represented by index or name.
281            """
282        
283            type  = self.column_map[col].type
284            if type == sql_type_map[table.FIELDTYPE_DOUBLE]:
285                iname = self.column_map[col].internal_name
286                cursor = self.db.cursor()
287                cursor.execute("SELECT %s FROM %s;" % (iname, self.tablename))
288                values = [ i[0] for i in cursor.fetchall()]
289                if not values:
290                    return 0
291                
292                max = 0
293                for value in values:
294                    if value is None: continue
295                    l = len(str(value % 1))
296                    if l > max:
297                        max = l
298                if max > 2:
299                    return max - 2
300                else:
301                    return 0
302            else:
303                return 0
304    
305      def SimpleQuery(self, left, comparison, right):      def SimpleQuery(self, left, comparison, right):
306          """Return the indices of all rows that matching a condition.          """Return the indices of all rows that matching a condition.
307    
# Line 505  class AutoTransientTable(TitledObject, t Line 565  class AutoTransientTable(TitledObject, t
565      def Dependencies(self):      def Dependencies(self):
566          """Return a tuple containing the original table"""          """Return a tuple containing the original table"""
567          return (self.table,)          return (self.table,)
568    

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26