How can I get a list of all the table.field entities in a schema?

From BRTT

Jump to: navigation, search


Question
Question:

How can I get a list of all the table.field entities in a schema?


Answer:

Try the following perl program. Type the program name followed by the schema of interest, e.g.

 % cat dbquery_allfields
 : # use perl
 eval 'exec perl -S $0 "$@"'
 if 0;
 use lib "$ENV{ANTELOPE}/data/perl" ;
 use Datascope ;
 
 sub dbquery_allfields {
    my( $schema ) = @_;
    my( @fieldlist ) = ();
    @db = dbtmp( $schema );
    @schema_tables = dbquery( @db, "dbSCHEMA_TABLES" );
    foreach $table ( sort( @schema_tables ) ) {
	@dbtable = dblookup( @db, "", "$table", "", "" );
	@attributes = dbquery( @dbtable, "dbTABLE_FIELDS" );
	foreach $field ( sort( @attributes ) ) {
	    push( @fieldlist, "$table.$field" );
	}
    }
    dbclose( @db );
    return @fieldlist;
 }
 
 if ( @ARGV != 1 ) { 
    my $pgm = $0 ; 
    $pgm =~ s".*/"" ;
    die ( "Usage: $pgm schema\n" ) ; 
 }
 
 @mylist = dbquery_allfields( $ARGV[0] );
 print join( "\n", @mylist );

Running the program should show something like this:

% dbquery_allfields css3.0
achanaux.aux
achanaux.chan
achanaux.fchan
achanaux.lddate
achanaux.sta
affiliation.lddate
affiliation.net
affiliation.sta
anetsta.anet
anetsta.fsta  
  .
  .
  .