#format wiki #language en #pragma section-numbers off = Apache Derby RSMD.py = back to ApacheDerby Example page. {{{#!python #-------------------------------------------------------------------------- # RSMD() - Routine used to gather the "interesting" ResultSet MetaData #-------------------------------------------------------------------------- def RSMD( rs, NumTypes = None ) : from java.sql import Types as types #------------------------------------------------------------------------ # Check for first invocation, so we can initialize NumType #------------------------------------------------------------------------ if NumTypes == None : NumTypes = [ types.BIGINT , types.DECIMAL , types.DOUBLE , types.FLOAT , types.INTEGER , types.NUMERIC , types.REAL , types.SMALLINT, types.TINYINT ] #------------------------------------------------------------------------ # Obtain MetaData for specified ResultSet #------------------------------------------------------------------------ result = [] rsmd = rs.getMetaData() for col in range( 1, rsmd.getColumnCount() + 1 ) : Type = rsmd.getColumnType( col ) if Type in NumTypes : # Only numeric values have... precision = rsmd.getPrecision( col ) # precision, and scale = rsmd.getScale( col ) # scale else : # precision = scale = None # row = ( rsmd.getColumnLabel( col ), rsmd.getColumnDisplaySize( col ), Type, precision, scale, rsmd.getColumnTypeName( col ) ) result.append( row ) return tuple(result) #-------------------------------------------------------------------------- # printRSMD() - Routine used to display the ResultSet MetaData of interest #-------------------------------------------------------------------------- def printRSMD( rsmd, TableName ) : truncated = False print '\n Fields contained in:', TableName print '\n| Size | Label |Type |Type Name' print '+-------+------------------------+-----+--------------------' for Label, Size, Type, precision, scale, TypeName in rsmd : if len( Label ) > 24 : Label = Label[:23] + '*' truncated = True print '|%7d|%-24s|%5d|%-20s' % ( Size, Label, Type, TypeName ) print if truncated : print ' * The specified field was truncated.' }}} back to ApacheDerby Example page.