3 # -------------------------------------------------------------------
4 # Copyright (C) 2002-2009 SQLFairy Authors
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation; version 2.
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 # -------------------------------------------------------------------
23 sqlt.cgi - CGI front-end for SQL::Translator
27 Place this script in your "cgi-bin" directory and point your browser
28 to it. This script is meant to be a simple graphical interface to
29 all the parsers and producers of SQL::Translator.
33 # -------------------------------------------------------------------
48 if ( $q->param('schema') ) {
49 $data = $q->param('schema');
51 elsif ( my $fh = $q->upload('schema_file') ) {
55 die "No schema provided!\n" unless $data;
57 my $producer = $q->param('producer');
58 my $output_type = $producer eq 'Diagram'
59 ? $q->param('diagram_output_type')
60 : $producer eq 'GraphViz'
61 ? $q->param('graphviz_output_type')
65 my $t = SQL::Translator->new(
66 from => $q->param('parser'),
68 add_drop_table => $q->param('add_drop_table'),
69 output_type => $output_type,
70 title => $q->param('title') || 'Schema',
71 natural_join => $q->param('natural_join') eq 'no' ? 0 : 1,
72 join_pk_only => $q->param('natural_join') eq 'pk_only'
74 add_color => $q->param('add_color'),
75 skip_fields => $q->param('skip_fields'),
76 show_fk_only => $q->param('show_fk_only'),
77 font_size => $q->param('font_size'),
78 no_columns => $q->param('no_columns'),
79 node_shape => $q->param('node_shape'),
80 layout => $q->param('layout') || '',
81 height => $q->param('height') || 0,
82 width => $q->param('width') || 0,
83 show_fields => $q->param('show_fields') || 0,
84 ttfile => $q->upload('template'),
85 validate => $q->param('validate'),
86 emit_empty_tags => $q->param('emit_empty_tags'),
87 attrib_values => $q->param('attrib_values'),
88 no_comments => !$q->param('comments'),
91 trim_fields => $q->param('trim_fields'),
92 scan_fields => $q->param('scan_fields'),
93 field_separator => $q->param('fs'),
94 record_separator => $q->param('rs'),
96 ) or die SQL::Translator->error;
99 my $text_type = 'plain';
100 if ( $output_type =~ /(gif|png|jpeg)/ ) {
101 $image_type = $output_type;
103 elsif ( $output_type eq 'svg' ) {
104 $image_type = 'svg+xml';
106 elsif ( $output_type =~ /gd/ ) {
109 elsif ( $output_type eq 'ps' ) {
110 $text_type = 'postscript';
112 elsif ( $producer eq 'HTML' ) {
116 my $header_type = $image_type ? "image/$image_type" : "text/$text_type";
119 $t->producer( $producer );
120 my $output = $t->translate or die $t->error;
122 print $q->header( -type => $header_type ), $output;
129 if ( my $error = $@ ) {
130 print $q->header, $q->start_html('Error'),
131 $q->h1('Error'), $error, $q->end_html;
134 # -------------------------------------------------------------------
137 my $title = 'SQL::Translator';
140 $q->start_html( -title => $title ),
141 $q->h1( qq[<a href="http://sqlfairy.sourceforge.net">$title</a>] ),
142 $q->start_form(-enctype => 'multipart/form-data'),
143 $q->table( { -border => 1 },
146 'Upload your schema file:',
147 $q->filefield( -name => 'schema_file'),
152 'Or paste your schema here:',
165 -values => [ qw( MySQL PostgreSQL Oracle
166 Sybase Excel XML-SQLFairy xSV
178 -values => [ qw[ ClassDBI Diagram GraphViz HTML
179 MySQL Oracle POD PostgreSQL SQLite Sybase
180 TTSchema XML-SQLFairy
182 -default => 'GraphViz',
189 { -colspan => 2, -align => 'center' },
198 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
219 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
220 'DB Producer Options:'
225 'Add "DROP TABLE" statements:',
227 -name => 'add_drop_table',
255 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
256 'HTML/POD/Diagram Producer Options:'
262 $q->textfield('title'),
267 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
268 'TTSchema Producer Options:'
274 $q->filefield( -name => 'template'),
279 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
280 'Graphical Producer Options'
285 'Perform Natural Joins:',
287 -name => 'natural_join',
288 -values => [ 'no', 'yes', 'pk_only' ],
291 yes => 'Yes, on all like-named fields',
292 pk_only => 'Yes, but only from primary keys'
301 'Skip These Fields in Natural Joins:',
303 -name => 'skip_fields',
311 'Show Only Foreign Keys:',
313 -name => 'show_fk_only',
328 -name => 'add_color',
343 -name => 'show_fields',
356 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
357 'Diagram Producer Options'
364 -name => 'diagram_output_type',
365 -values => [ 'png', 'jpeg' ],
375 -name => 'font_size',
376 -values => [ qw( small medium large ) ],
377 -default => 'medium',
384 'Number of Columns:',
385 $q->textfield('no_columns'),
390 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
391 'GraphViz Producer Options'
398 -name => 'graphviz_output_type',
399 -values => [ qw( canon text ps hpgl pcl mif pic
400 gd gd2 gif jpeg png wbmp cmap ismap imap
401 vrml vtx mp fig svg plain
413 -values => [ qw( dot neato twopi ) ],
423 -name => 'node_shape',
424 -values => [ qw( record plaintext ellipse
425 circle egg triangle box diamond trapezium
426 parallelogram house hexagon octagon
428 -default => 'record',
436 $q->textfield( -name => 'height' ),
442 $q->textfield( -name => 'width' ),
447 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
448 'XML Producer Options:'
453 'Use attributes for values:',
455 -name => 'attrib-values',
470 -name => 'emit-empty-tags',
483 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
490 $q->textfield( -name => 'fs' ),
496 $q->textfield( -name => 'rs' ),
501 'Trim Whitespace Around Fields:',
503 -name => 'trim_fields',
516 'Scan Fields for Data Type:',
518 -name => 'scan_fields',
531 { -colspan => 2, -align => 'center' },
543 # -------------------------------------------------------------------
549 Ken Youens-Clark E<lt>kclark@cpan.orgE<gt>.