3 # -------------------------------------------------------------------
4 # $Id: sql_translator.cgi,v 1.4 2003-08-21 02:47:22 kycl4rk Exp $
5 # -------------------------------------------------------------------
6 # Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License as
10 # published by the Free Software Foundation; version 2.
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 # -------------------------------------------------------------------
29 A CGI script for transforming SQL schemas into pictures, either GraphViz
30 graphs or ER diagrams. Basically, a simple web-form front-end for the
31 myriad options available to "auto-dia.pl" and "auto-graph.pl."
43 my $t = SQL::Translator->new(
44 from => $q->param('parser'),
46 image_type => $q->param('output_type') || 'png',
47 title => $q->param('title') || 'Schema',
48 natural_join => $q->param('natural_join') eq 'no' ? 0 : 1,
49 join_pk_only => $q->param('natural_join') eq 'pk_only' ? 1 : 0,
50 add_color => $q->param('add_color'),
51 skip_fields => $q->param('skip_fields'),
52 show_fk_only => $q->param('show_fk_only'),
53 font_size => $q->param('font_size'),
54 no_columns => $q->param('no_columns'),
55 node_shape => $q->param('node_shape'),
56 layout => $q->param('layout') || '',
57 height => $q->param('height') || 0,
58 width => $q->param('width') || 0,
59 show_fields => $q->param('show_fields') || 0,
61 ) or die SQL::Translator->error;
64 if ( $q->param('schema') ) {
65 $data = $q->param('schema');
67 elsif ( my $fh = $q->upload('schema_file') ) {
71 die "No schema provided!\n" unless $data;
73 my $producer = $q->param('producer');
74 my $image_type = $q->param('output_type') || 'png';
76 $producer =~ m/(GraphViz|Diagram)/
81 $t->producer( $producer );
82 my $output = $t->translate or die $t->error;
84 print $q->header( -type => $header_type ), $output;
91 if ( my $error = $@ ) {
92 print $q->header, $q->start_html('Error'),
93 $q->h1('Error'), $error, $q->end_html;
96 # -------------------------------------------------------------------
99 my $title = 'SQL::Translator';
102 $q->start_html( -title => $title ),
103 $q->h1( qq[<a href="http://sqlfairy.sourceforge.net">$title</a>] ),
104 $q->start_form(-enctype => 'multipart/form-data'),
105 $q->table( { -border => 1 },
108 'Paste your schema here:',
118 'Or upload your schema file:',
119 $q->filefield( -name => 'schema_file'),
127 -values => [ 'MySQL', 'PostgreSQL', 'Oracle' ],
138 -values => [ qw[ ClassDBI Diagram GraphViz HTML
139 MySQL Oracle POD PostgreSQL SQLite Sybase XML
141 -default => 'GraphViz',
149 $q->textfield('title'),
156 -name => 'output_type',
157 -values => [ 'png', 'jpeg' ],
165 'Perform Natural Joins:',
167 -name => 'natural_join',
168 -values => [ 'no', 'yes', 'pk_only' ],
171 yes => 'Yes, on all like-named fields',
172 pk_only => 'Yes, but only from primary keys'
181 'Skip These Fields in Natural Joins:',
183 -name => 'skip_fields',
193 -name => 'add_color',
206 'Show Only Foreign Keys *:',
208 -name => 'show_fk_only',
223 -name => 'font_size',
224 -values => [ qw( small medium large ) ],
225 -default => 'medium',
232 'Number of Columns *:',
233 $q->textfield('no_columns'),
241 -values => [ qw( dot neato twopi ) ],
251 -name => 'node_shape',
252 -values => [ qw( record plaintext ellipse
253 circle egg triangle box diamond trapezium
254 parallelogram house hexagon octagon
256 -default => 'record',
263 'Show Field Names **:',
265 -name => 'show_fields',
279 $q->textfield( -name => 'height', -default => 11 ),
285 $q->textfield( -name => 'width', -default => 8.5 ),
290 { -colspan => 2, -align => 'center' },
298 * -- Applies to diagram only<br>
299 ** -- Applies to graph only<br>
313 Ken Y. Clark E<lt>kclark@cpan.orgE<gt>