3 # -------------------------------------------------------------------
4 # $Id: sql_translator.cgi,v 1.2 2003-08-04 20:55:45 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 height => $q->param('height') || 0,
57 width => $q->param('width') || 0,
58 show_fields => $q->param('show_fields') || 0,
60 ) or die SQL::Translator->error;
63 if ( $q->param('schema') ) {
64 $data = $q->param('schema');
66 elsif ( my $fh = $q->upload('schema_file') ) {
70 die "No schema provided!\n" unless $data;
72 my $producer = $q->param('producer');
73 my $image_type = $q->param('output_type') || 'png';
75 $producer =~ m/(GraphViz|Diagram)/
80 $t->producer( $producer );
81 my $output = $t->translate or die $t->error;
83 print $q->header( -type => $header_type ), $output;
90 if ( my $error = $@ ) {
91 print $q->header, $q->start_html('Error'),
92 $q->h1('Error'), $error, $q->end_html;
95 # -------------------------------------------------------------------
98 my $title = 'SQL::Translator';
101 $q->start_html( -title => $title ),
102 $q->h1( qq[<a href="http://sqlfairy.sourceforge.net">$title</a>] ),
103 $q->start_form(-enctype => 'multipart/form-data'),
104 $q->table( { -border => 1 },
107 'Paste your schema here:',
117 'Or upload your schema file:',
118 $q->filefield( -name => 'schema_file'),
126 -values => [ 'MySQL', 'PostgreSQL', 'Oracle' ],
137 -values => [ qw[ ClassDBI Diagram GraphViz HTML
138 MySQL Oracle POD PostgreSQL SQLite Sybase XML
140 -default => 'GraphViz',
148 $q->textfield('title'),
155 -name => 'output_type',
156 -values => [ 'png', 'jpeg' ],
164 'Perform Natural Joins:',
166 -name => 'natural_join',
167 -values => [ 'no', 'yes', 'pk_only' ],
170 yes => 'Yes, on all like-named fields',
171 pk_only => 'Yes, but only from primary keys'
180 'Skip These Fields in Natural Joins:',
182 -name => 'skip_fields',
192 -name => 'add_color',
205 'Show Only Foreign Keys *:',
207 -name => 'show_fk_only',
222 -name => 'font_size',
223 -values => [ qw( small medium large ) ],
224 -default => 'medium',
231 'Number of Columns *:',
232 $q->textfield('no_columns'),
240 -values => [ qw( dot neato twopi ) ],
250 -name => 'node_shape',
251 -values => [ qw( record plaintext ellipse
252 circle egg triangle box diamond trapezium
253 parallelogram house hexagon octagon
255 -default => 'record',
262 'Show Field Names **:',
264 -name => 'show_fields',
278 $q->textfield( -name => 'height', -default => 11 ),
284 $q->textfield( -name => 'width', -default => 8.5 ),
289 { -colspan => 2, -align => 'center' },
297 * -- Applies to diagram only<br>
298 ** -- Applies to graph only<br>
312 Ken Y. Clark E<lt>kclark@cpan.orgE<gt>