3 # -------------------------------------------------------------------
4 # $Id: sqlt.cgi,v 1.3 2003-09-18 19:11: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 # -------------------------------------------------------------------
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.3 $ =~ /(\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';
113 elsif ( $producer eq 'HTML' ) {
117 my $header_type = $image_type ? "image/$image_type" : "text/$text_type";
120 $t->producer( $producer );
121 my $output = $t->translate or die $t->error;
123 print $q->header( -type => $header_type ), $output;
130 if ( my $error = $@ ) {
131 print $q->header, $q->start_html('Error'),
132 $q->h1('Error'), $error, $q->end_html;
135 # -------------------------------------------------------------------
138 my $title = 'SQL::Translator';
141 $q->start_html( -title => $title ),
142 $q->h1( qq[<a href="http://sqlfairy.sourceforge.net">$title</a>] ),
143 $q->start_form(-enctype => 'multipart/form-data'),
144 $q->table( { -border => 1 },
147 'Upload your schema file:',
148 $q->filefield( -name => 'schema_file'),
153 'Or paste your schema here:',
166 -values => [ qw( MySQL PostgreSQL Oracle
167 Sybase Excel XML-SQLFairy xSV
179 -values => [ qw[ ClassDBI Diagram GraphViz HTML
180 MySQL Oracle POD PostgreSQL SQLite Sybase
181 TTSchema XML-SQLFairy
183 -default => 'GraphViz',
190 { -colspan => 2, -align => 'center' },
199 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
220 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
221 'DB Producer Options:'
226 'Add "DROP TABLE" statements:',
228 -name => 'add_drop_table',
256 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
257 'HTML/POD/Diagram Producer Options:'
263 $q->textfield('title'),
268 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
269 'TTSchema Producer Options:'
275 $q->filefield( -name => 'template'),
280 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
281 'Graphical Producer Options'
286 'Perform Natural Joins:',
288 -name => 'natural_join',
289 -values => [ 'no', 'yes', 'pk_only' ],
292 yes => 'Yes, on all like-named fields',
293 pk_only => 'Yes, but only from primary keys'
302 'Skip These Fields in Natural Joins:',
304 -name => 'skip_fields',
312 'Show Only Foreign Keys:',
314 -name => 'show_fk_only',
329 -name => 'add_color',
344 -name => 'show_fields',
357 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
358 'Diagram Producer Options'
365 -name => 'diagram_output_type',
366 -values => [ 'png', 'jpeg' ],
376 -name => 'font_size',
377 -values => [ qw( small medium large ) ],
378 -default => 'medium',
385 'Number of Columns:',
386 $q->textfield('no_columns'),
391 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
392 'GraphViz Producer Options'
399 -name => 'graphviz_output_type',
400 -values => [ qw( canon text ps hpgl pcl mif pic
401 gd gd2 gif jpeg png wbmp cmap ismap imap
402 vrml vtx mp fig svg plain
414 -values => [ qw( dot neato twopi ) ],
424 -name => 'node_shape',
425 -values => [ qw( record plaintext ellipse
426 circle egg triangle box diamond trapezium
427 parallelogram house hexagon octagon
429 -default => 'record',
437 $q->textfield( -name => 'height' ),
443 $q->textfield( -name => 'width' ),
448 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
449 'XML Producer Options:'
454 'Use attributes for values:',
456 -name => 'attrib-values',
471 -name => 'emit-empty-tags',
484 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
491 $q->textfield( -name => 'fs' ),
497 $q->textfield( -name => 'rs' ),
502 'Trim Whitespace Around Fields:',
504 -name => 'trim_fields',
517 'Scan Fields for Data Type:',
519 -name => 'scan_fields',
532 { -colspan => 2, -align => 'center' },
544 # -------------------------------------------------------------------
550 Ken Y. Clark E<lt>kclark@cpan.orgE<gt>
554 perl, SQL::Translator.