Differences between revisions 4 and 5
Revision 4 as of 2008-11-15 09:15:59
Size: 2648
Editor: localhost
Comment: converted to 1.6 markup
Revision 5 as of 2010-01-18 07:44:08
Size: 2616
Editor: s235-200
Comment:
Deletions are marked like this. Additions are marked like this.
Line 35: Line 35:
  result = ()   result = []
Line 51: Line 51:
    result += ( row, )
  return result
    result.append( row )
  return tuple(result)
Line 58: Line 58:
  truncated = ''   truncated = False
Line 62: Line 62:
  for col in range( len( rsmd ) ) :
   
Label, Size, Type, precision, scale, TypeName = rsmd[ col ]
  for Label, Size, Type, precision, scale, TypeName in rsmd :
Line 66: Line 65:
      truncated = '*'       truncated = True
Line 69: Line 68:
  if truncated != '' : print ' * The specified field was truncated.'   if truncated : print ' * The specified field was truncated.'

Apache Derby RSMD.py

back to ApacheDerby Example page.

   1 #--------------------------------------------------------------------------
   2 # RSMD() - Routine used to gather the "interesting" ResultSet MetaData
   3 #--------------------------------------------------------------------------
   4 def RSMD( rs, NumTypes = None ) :
   5   from java.sql import Types as types
   6   #------------------------------------------------------------------------
   7   # Check for first invocation, so we can initialize NumType
   8   #------------------------------------------------------------------------
   9   if NumTypes == None :
  10     NumTypes = [ 
  11       types.BIGINT  ,
  12       types.DECIMAL ,
  13       types.DOUBLE  ,
  14       types.FLOAT   ,
  15       types.INTEGER ,
  16       types.NUMERIC ,
  17       types.REAL    ,
  18       types.SMALLINT,
  19       types.TINYINT  
  20     ]                
  21 
  22   #------------------------------------------------------------------------
  23   # Obtain MetaData for specified ResultSet
  24   #------------------------------------------------------------------------
  25   result = []
  26   rsmd   = rs.getMetaData()
  27   for col in range( 1, rsmd.getColumnCount() + 1 ) :
  28     Type = rsmd.getColumnType( col )
  29     if Type in NumTypes :                   # Only numeric values have...
  30       precision = rsmd.getPrecision( col )  # precision, and
  31       scale     = rsmd.getScale( col )      # scale
  32     else :                                  #
  33       precision = scale = None              #
  34     row =  ( rsmd.getColumnLabel( col ),
  35              rsmd.getColumnDisplaySize( col ),
  36              Type,
  37              precision,
  38              scale,
  39              rsmd.getColumnTypeName( col )
  40            )
  41     result.append( row )
  42   return tuple(result)
  43 
  44 #--------------------------------------------------------------------------
  45 # printRSMD() - Routine used to display the ResultSet MetaData of interest
  46 #--------------------------------------------------------------------------
  47 def printRSMD( rsmd, TableName ) :
  48   truncated = False
  49   print '\n Fields contained in:', TableName
  50   print '\n| Size  |  Label                 |Type |Type Name'
  51   print '+-------+------------------------+-----+--------------------'
  52   for Label, Size, Type, precision, scale, TypeName in rsmd :
  53     if len( Label ) > 24 :
  54       Label = Label[:23] + '*'
  55       truncated = True
  56     print '|%7d|%-24s|%5d|%-20s' % ( Size, Label, Type, TypeName )
  57   print
  58   if truncated : print ' * The specified field was truncated.'

back to ApacheDerby Example page.

RSMD.py (last edited 2010-01-18 07:44:08 by s235-200)