Article Figure 1 Figure 2 Figure 3 Listing 1
Listing 2 Listing 3 Table 1 Table 2 jul2005.tar

Listing 2 convert.pl

#!/usr/bin/perl -w

# $Id: convert.pl,v 1.5 2005/03/07 21:48:50 mtsouk Exp mtsouk $
#
use strict;

my $tablespace_found = 0;
my $line="";

# The following two hashes will hold the
# names of the tables and the tablespaces.
my %TABLE = ();
my %TABLESPACE = ();

my $firsttable = 1;

die <<Thanatos unless @ARGV;
usage:
         $0 inputfile.log outputfilename
         inputfile.log: The input filename
         outputfilename: The filename of the output
Thanatos

if ( @ARGV != 2 )
{
         die <<Thanatos
         usage info:
                  Please use exactly 2 arguments!
Thanatos
}

my $input = $ARGV[0];
open(INPUT, "< $input " ) ||
         die "Cannot read $input: $!\n";

my $output = $ARGV[1].".dot";
open(OUTPUT, "> $output " ) ||
         die "Cannot write $output: $!\n";

print OUTPUT "digraph G\n";
print OUTPUT "{\n";
print OUTPUT "\tgraph [rankdir = \"LR\" ]\;\n";
print OUTPUT "\tnode[fontsize = \"14\" style=bold]\;";
print OUTPUT "\n\n";
print OUTPUT "\# Table-field connection part.\n";

# Read the input file
while ($line = <INPUT>)
{
         chomp $line;
         # Drop empty lines.
         if ( $line =~ /^$/ )
         {
                  next;
         }
         if ( $line =~ /^TABLESPACE/ )
         {
                  # Close the previous table node.
                  print OUTPUT " \"\n\tshape = \"record\"\n\t]\;\n\n";
                  print OUTPUT "\n\# TABLESPACE-table connection part.\n";
                  $tablespace_found = 1;
                  next;
         }
         if ( $tablespace_found )
         {
                  my $tablespace = (split " ", $line)[1];
                  my $table = (split " ", $line)[0];
                  # Connect tables with their Tablespaces                  
                  print OUTPUT "\t$table:tb -> TB_$tablespace:tb\;\n";
                  if ( !defined $TABLESPACE{$tablespace} )
                  {
                           $TABLESPACE{$tablespace} = 1;
                  }
         }
         else
         {
                  my $table = (split " ", $line)[0];
                  my $column = (split " ", $line)[1];
                  if ( defined $TABLE{$table} )
                  {
                           print OUTPUT " | ".lc($column);
                  }
                  else
                  {
                           # The very first table has to be treated differently.
                           if ( $firsttable )
                           {
                                    $firsttable = 0;
                           }
                           else
                           {
                                    print OUTPUT " \"\n\tshape = \"record\"\n\t]\;\n\n";
                           }
                           $TABLE{$table} = 1;
                           print OUTPUT "\t$table [label = \"<tb> $table";
                           print OUTPUT " | ".lc($column);
                  }
         }
}

print OUTPUT "\n\# Tablespace decoration part.\n";
my $tablespace = "";
foreach $tablespace ( keys %TABLESPACE )
{
         print OUTPUT "\tTB_".$tablespace;
         print OUTPUT '[label="<tb> '.$tablespace.'"';
         print OUTPUT ' shape = "record" style=filled color="red"];';
         print OUTPUT "\n";
}

my $first = 1;
my $tb_first = "";
foreach $tablespace ( keys %TABLESPACE )
{
         print OUTPUT "\tTB_$tablespace ->";
         if ( $first )
         {
                  $tb_first = $tablespace;
                  $first = 0;
         }
}
         print OUTPUT "TB_$tb_first;\n";

print OUTPUT "}\n";

# Close INPUT and OUTPUT
close(INPUT) ||
         die "Cannot close $input: $!\n";
close(OUTPUT) ||
         die "Cannot close $output: $!\n";

exit 0;