3 # -------------------------------------------------------------------
4 # $Id: auto-viv.cgi,v 1.2 2003-06-05 01:43:35 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('database'),
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') ) {
71 die "No schema provided!\n" unless $data;
73 $t->producer( $q->param('do_graph') ? 'GraphViz' : 'Diagram' );
74 my $output = $t->translate or die $t->error;
76 my $image_type = $q->param('output_type') || 'png';
77 print $q->header( -type => "image/$image_type" ), $output;
84 if ( my $error = $@ ) {
85 print $q->header, $q->start_html('Error'),
86 $q->h1('Error'), $error, $q->end_html;
89 # -------------------------------------------------------------------
92 my $title = 'SQL::Translator';
95 $q->start_html( -title => $title ),
96 $q->h1( qq[<a href="http://sqlfairy.sourceforge.net">$title</a>] ),
97 $q->start_form(-enctype => 'multipart/form-data'),
98 $q->table( { -border => 1 },
101 'Paste your schema here:',
111 'Or upload your schema file:',
112 $q->filefield( -name => 'schema_file'),
120 -values => [ 'MySQL', 'PostgreSQL', 'Oracle' ],
129 $q->textfield('title'),
136 -name => 'output_type',
137 -values => [ 'png', 'jpeg' ],
145 'Perform Natural Joins:',
147 -name => 'natural_join',
148 -values => [ 'no', 'yes', 'pk_only' ],
151 yes => 'Yes, on all like-named fields',
152 pk_only => 'Yes, but only from primary keys'
161 'Skip These Fields in Natural Joins:',
163 -name => 'skip_fields',
173 -name => 'add_color',
186 'Show Only Foreign Keys *:',
188 -name => 'show_fk_only',
203 -name => 'font_size',
204 -values => [ qw( small medium large ) ],
205 -default => 'medium',
212 'Number of Columns *:',
213 $q->textfield('no_columns'),
221 -values => [ qw( dot neato twopi ) ],
231 -name => 'node_shape',
232 -values => [ qw( record plaintext ellipse
233 circle egg triangle box diamond trapezium
234 parallelogram house hexagon octagon
236 -default => 'record',
243 'Show Field Names **:',
245 -name => 'show_fields',
259 $q->textfield( -name => 'height', -default => 11 ),
265 $q->textfield( -name => 'width', -default => 8.5 ),
270 { -colspan => 2, -align => 'center' },
272 -name => 'do_diagram',
273 -value => 'Create ER Diagram'
277 -value => 'Create Graph'
282 * -- Applies to diagram only<br>
283 ** -- Applies to graph only<br>
297 Ken Y. Clark E<lt>kclark@cpan.orgE<gt>