/[papo]/papo/xot/zot2xot
ViewVC logotype

Diff of /papo/xot/zot2xot

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by jlenton, Mon May 19 19:06:08 2003 UTC revision 1.2 by jlenton, Mon Jun 30 03:42:06 2003 UTC
# Line 11  die "Usage: $0 ER.zot" Line 11  die "Usage: $0 ER.zot"
11  my $zot = Zot->new($zotfile)->parse;  my $zot = Zot->new($zotfile)->parse;
12    
13    
14  print "<database>\n  <tables>\n";  print <<EOF;
15    <?xml version="1.0" encoding="iso-8859-1"?>
16    <!DOCTYPE database SYSTEM "xot.dtd">
17    <database>
18      <tables>
19    EOF
20  foreach my $table ($zot->tables)  foreach my $table ($zot->tables)
21  {  {
22      printf "    <table name=\"%s\">\n", $table->name;      printf "    <table name=\"%s\">\n", $table->name;
# Line 20  foreach my $table ($zot->tables) Line 25  foreach my $table ($zot->tables)
25      {      {
26          my $attr = $_;          my $attr = $_;
27          $attr =~ s/^_/$table->name . '_'/e;          $attr =~ s/^_/$table->name . '_'/e;
28          printf "        <field name=\"%s\" type=\"%s\"", $attr, $table->attr($_);          printf "        <field name=\"%s\" type=\"%s\"/>\n", $attr, $table->attr($_);
         print " primary_key=\"yes\""  
             if ($_ eq 'id');  
         print "/>\n";  
29      }      }
30      foreach ($table->rels)      foreach ($table->rels)
31      {      {
# Line 31  foreach my $table ($zot->tables) Line 33  foreach my $table ($zot->tables)
33          $rel =~ s/^_/$table->name . '_'/e;          $rel =~ s/^_/$table->name . '_'/e;
34          printf "        <field name=\"%s\" references=\"%s\"/>\n", $rel, $table->rel($_);          printf "        <field name=\"%s\" references=\"%s\"/>\n", $rel, $table->rel($_);
35      }      }
36      printf "      </fields>\n";      print("      </fields>\n",
37              "      <indexes>\n",
38              "        <index type=\"primary_key\">\n",
39              "          <index_field name=\"id\"/>\n",
40              "        </index>\n",
41              "      </indexes>\n");
42      if ($table->styles)      if ($table->styles)
43      {      {
44          printf "      <styles>\n";          printf "      <styles>\n";
# Line 45  print "  </tables>\n"; Line 52  print "  </tables>\n";
52  if ($zot->styles)  if ($zot->styles)
53  {  {
54      print "  <style_definitions>\n";      print "  <style_definitions>\n";
55      printf "    <style_definition name=\"%s\" definition=\"%s\"/>\n", $_, $zot->style($_)      foreach ($zot->styles)
56          foreach ($zot->styles);      {
57            print "    <style_definition name=\"$_\">\n";
58            printf("      <style_implementation target=\"dot\"><![CDATA[%s]]></style_implementation>\n",
59                   $zot->style($_));
60            printf("      <style_implementation target=\"sql\"><![CDATA[%s]]></style_implementation>\n",
61                   sql_style($_));
62            print "    </style_definition>\n";
63        }
64      print "  </style_definitions>\n";      print "  </style_definitions>\n";
65  }  }
66  print "</database>\n";  print "</database>\n";
67    
68    
69    sub sql_style
70    {
71        my $name = shift;
72        my $style = '';
73        if ($name eq 'history')
74        {
75            $style = "\$self->add_history;";
76        }
77        elsif ($name eq 'account')
78        {
79            $style = "\$self->add_reference_to('account_plan');";
80        }
81        else
82        {
83            $style = "\$self->add_reference_to('$name');";
84        }
85    
86        return $style;
87    }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26