3 # -------------------------------------------------------------------
4 # $Id: sqlt.cgi,v 1.2 2003-08-27 04:01:14 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 # -------------------------------------------------------------------
25 sqlt.cgi - CGI front-end for SQL::Translator
29 Place this script in your "cgi-bin" directory and point your browser
30 to it. This script is meant to be a simple graphical interface to
31 all the parsers and producers of SQL::Translator.
35 # -------------------------------------------------------------------
42 $VERSION = sprintf "%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/;
49 if ( $q->param('schema') ) {
50 $data = $q->param('schema');
52 elsif ( my $fh = $q->upload('schema_file') ) {
56 die "No schema provided!\n" unless $data;
58 my $producer = $q->param('producer');
59 my $output_type = $producer eq 'Diagram'
60 ? $q->param('diagram_output_type')
61 : $producer eq 'GraphViz'
62 ? $q->param('graphviz_output_type')
66 my $t = SQL::Translator->new(
67 from => $q->param('parser'),
69 add_drop_table => $q->param('add_drop_table'),
70 output_type => $output_type,
71 title => $q->param('title') || 'Schema',
72 natural_join => $q->param('natural_join') eq 'no' ? 0 : 1,
73 join_pk_only => $q->param('natural_join') eq 'pk_only'
75 add_color => $q->param('add_color'),
76 skip_fields => $q->param('skip_fields'),
77 show_fk_only => $q->param('show_fk_only'),
78 font_size => $q->param('font_size'),
79 no_columns => $q->param('no_columns'),
80 node_shape => $q->param('node_shape'),
81 layout => $q->param('layout') || '',
82 height => $q->param('height') || 0,
83 width => $q->param('width') || 0,
84 show_fields => $q->param('show_fields') || 0,
85 ttfile => $q->upload('template'),
86 validate => $q->param('validate'),
87 emit_empty_tags => $q->param('emit_empty_tags'),
88 attrib_values => $q->param('attrib_values'),
89 no_comments => !$q->param('comments'),
92 trim_fields => $q->param('trim_fields'),
93 scan_fields => $q->param('scan_fields'),
94 field_separator => $q->param('fs'),
95 record_separator => $q->param('rs'),
97 ) or die SQL::Translator->error;
100 my $text_type = 'plain';
101 if ( $output_type =~ /(gif|png|jpeg)/ ) {
102 $image_type = $output_type;
104 elsif ( $output_type eq 'svg' ) {
105 $image_type = 'svg+xml';
107 elsif ( $output_type =~ /gd/ ) {
110 elsif ( $output_type eq 'ps' ) {
111 $text_type = 'postscript';
114 my $header_type = $image_type ? "image/$image_type" : "text/$text_type";
117 $t->producer( $producer );
118 my $output = $t->translate or die $t->error;
120 print $q->header( -type => $header_type ), $output;
127 if ( my $error = $@ ) {
128 print $q->header, $q->start_html('Error'),
129 $q->h1('Error'), $error, $q->end_html;
132 # -------------------------------------------------------------------
135 my $title = 'SQL::Translator';
138 $q->start_html( -title => $title ),
139 $q->h1( qq[<a href="http://sqlfairy.sourceforge.net">$title</a>] ),
140 $q->start_form(-enctype => 'multipart/form-data'),
141 $q->table( { -border => 1 },
144 'Upload your schema file:',
145 $q->filefield( -name => 'schema_file'),
150 'Or paste your schema here:',
163 -values => [ qw( MySQL PostgreSQL Oracle
164 Sybase Excel XML-SQLFairy xSV
176 -values => [ qw[ ClassDBI Diagram GraphViz HTML
177 MySQL Oracle POD PostgreSQL SQLite Sybase
178 TTSchema XML-SQLFairy
180 -default => 'GraphViz',
187 { -colspan => 2, -align => 'center' },
196 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
217 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
218 'DB Producer Options:'
223 'Add "DROP TABLE" statements:',
225 -name => 'add_drop_table',
253 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
254 'HTML/POD/Diagram Producer Options:'
260 $q->textfield('title'),
265 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
266 'TTSchema Producer Options:'
272 $q->filefield( -name => 'template'),
277 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
278 'Graphical Producer Options'
283 'Perform Natural Joins:',
285 -name => 'natural_join',
286 -values => [ 'no', 'yes', 'pk_only' ],
289 yes => 'Yes, on all like-named fields',
290 pk_only => 'Yes, but only from primary keys'
299 'Skip These Fields in Natural Joins:',
301 -name => 'skip_fields',
309 'Show Only Foreign Keys:',
311 -name => 'show_fk_only',
326 -name => 'add_color',
341 -name => 'show_fields',
354 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
355 'Diagram Producer Options'
362 -name => 'diagram_output_type',
363 -values => [ 'png', 'jpeg' ],
373 -name => 'font_size',
374 -values => [ qw( small medium large ) ],
375 -default => 'medium',
382 'Number of Columns:',
383 $q->textfield('no_columns'),
388 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
389 'GraphViz Producer Options'
396 -name => 'graphviz_output_type',
397 -values => [ qw( canon text ps hpgl pcl mif pic
398 gd gd2 gif jpeg png wbmp cmap ismap imap
399 vrml vtx mp fig svg plain
411 -values => [ qw( dot neato twopi ) ],
421 -name => 'node_shape',
422 -values => [ qw( record plaintext ellipse
423 circle egg triangle box diamond trapezium
424 parallelogram house hexagon octagon
426 -default => 'record',
434 $q->textfield( -name => 'height' ),
440 $q->textfield( -name => 'width' ),
445 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
446 'XML Producer Options:'
451 'Use attributes for values:',
453 -name => 'attrib-values',
468 -name => 'emit-empty-tags',
481 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
488 $q->textfield( -name => 'fs' ),
494 $q->textfield( -name => 'rs' ),
499 'Trim Whitespace Around Fields:',
501 -name => 'trim_fields',
514 'Scan Fields for Data Type:',
516 -name => 'scan_fields',
529 { -colspan => 2, -align => 'center' },
541 # -------------------------------------------------------------------
547 Ken Y. Clark E<lt>kclark@cpan.orgE<gt>
551 perl, SQL::Translator.