#NEWLINE# @ connected #NEWLINE# def describe( self , table ) : #NEWLINE# #INDENT# 'Print information about a table.' #NEWLINE# if ( table not in self . get_metadata ( ) . tables ) : #NEWLINE# #INDENT# print ( ( 'Table not found: %s' % table ) ) #NEWLINE# return #NEWLINE# #UNINDENT# tbl = self . get_metadata ( ) . tables [ table ] #NEWLINE# def nullstr( nullable ) : #NEWLINE# #INDENT# return ( 'NULL' if nullable else 'NOT NULL' ) #NEWLINE# #UNINDENT# def namestr( c ) : #NEWLINE# #INDENT# return ( ( '*%s' if c . primary_key else '%s' ) % c . name ) #NEWLINE# #UNINDENT# with pager ( ) as out : #NEWLINE# #INDENT# items = ( ( namestr ( c ) , c . type , nullstr ( c . nullable ) ) for c in tbl . columns ) #NEWLINE# out . write ( ( b'Columns' + b'\n' ) ) #NEWLINE# asciitable . draw ( FakedResult ( sorted ( items ) , 'Name Type Nullable' . split ( ) ) , out , paginate = True , max_fieldsize = 5000 ) #NEWLINE# out . write ( b'\n' ) #NEWLINE# out . write ( b'Primary Key (*)\n' ) #NEWLINE# out . write ( b'---------------\n' ) #NEWLINE# pk = ', ' . join ( ( c . name for c in tbl . columns if c . primary_key ) ) #NEWLINE# out . write ( b'  ' ) #NEWLINE# if ( not pk ) : #NEWLINE# #INDENT# out . write ( b'(None Found!)' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# out . write ( pk . encode ( 'utf8' ) ) #NEWLINE# #UNINDENT# out . write ( b'\n\n' ) #NEWLINE# out . write ( b'Foreign Keys\n' ) #NEWLINE# out . write ( b'------------\n' ) #NEWLINE# fks = self . get_metadata ( ) . foreign_keys ( table ) #NEWLINE# fk = None #NEWLINE# for fk in fks : #NEWLINE# #INDENT# out . write ( ( '  %s\n' % str ( fk ) ) . encode ( 'utf8' ) ) #NEWLINE# #UNINDENT# if ( fk is None ) : #NEWLINE# #INDENT# out . write ( b'  (None Found)' ) #NEWLINE# #UNINDENT# out . write ( ( '\n\nReferences to %s\n' % table ) . encode ( 'utf8' ) ) #NEWLINE# out . write ( ( ( b'--------------' + ( b'-' * len ( table ) ) ) + b'\n' ) ) #NEWLINE# fks = self . get_metadata ( ) . fields_referencing ( table ) #NEWLINE# fk = None #NEWLINE# for fk in fks : #NEWLINE# #INDENT# out . write ( ( ( b'  ' + str ( fk ) . encode ( 'utf8' ) ) + b'\n' ) ) #NEWLINE# #UNINDENT# if ( fk is None ) : #NEWLINE# #INDENT# out . write ( b'  (None found)\n' ) #NEWLINE# #UNINDENT# out . write ( b'\n\nIndexes\n' ) #NEWLINE# def items( ) : #NEWLINE# #INDENT# for idx in self . get_metadata ( ) . indexes ( table ) : #NEWLINE# #INDENT# ( yield ( idx . name , ', ' . join ( ( c . name for c in idx . columns ) ) , idx . unique ) ) #NEWLINE# #UNINDENT# #UNINDENT# asciitable . draw ( FakedResult ( sorted ( items ( ) ) , 'Name Columns Unique' . split ( ) ) , out , paginate = True , max_fieldsize = 5000 )