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 # -------------------------------------------------------------------
47 if ( $q->param('schema') ) {
48 $data = $q->param('schema');
50 elsif ( my $fh = $q->upload('schema_file') ) {
54 die "No schema provided!\n" unless $data;
56 my $producer = $q->param('producer');
57 my $output_type = $producer eq 'Diagram'
58 ? $q->param('diagram_output_type')
59 : $producer eq 'GraphViz'
60 ? $q->param('graphviz_output_type')
64 my $t = SQL::Translator->new(
65 from => $q->param('parser'),
67 add_drop_table => $q->param('add_drop_table'),
68 output_type => $output_type,
69 title => $q->param('title') || 'Schema',
70 natural_join => $q->param('natural_join') eq 'no' ? 0 : 1,
71 join_pk_only => $q->param('natural_join') eq 'pk_only'
73 add_color => $q->param('add_color'),
74 skip_fields => $q->param('skip_fields'),
75 show_fk_only => $q->param('show_fk_only'),
76 font_size => $q->param('font_size'),
77 no_columns => $q->param('no_columns'),
78 node_shape => $q->param('node_shape'),
79 layout => $q->param('layout') || '',
80 height => $q->param('height') || 0,
81 width => $q->param('width') || 0,
82 show_fields => $q->param('show_fields') || 0,
83 ttfile => $q->upload('template'),
84 validate => $q->param('validate'),
85 emit_empty_tags => $q->param('emit_empty_tags'),
86 attrib_values => $q->param('attrib_values'),
87 no_comments => !$q->param('comments'),
90 trim_fields => $q->param('trim_fields'),
91 scan_fields => $q->param('scan_fields'),
92 field_separator => $q->param('fs'),
93 record_separator => $q->param('rs'),
95 ) or die SQL::Translator->error;
98 my $text_type = 'plain';
99 if ( $output_type =~ /(gif|png|jpeg)/ ) {
100 $image_type = $output_type;
102 elsif ( $output_type eq 'svg' ) {
103 $image_type = 'svg+xml';
105 elsif ( $output_type =~ /gd/ ) {
108 elsif ( $output_type eq 'ps' ) {
109 $text_type = 'postscript';
111 elsif ( $producer eq 'HTML' ) {
115 my $header_type = $image_type ? "image/$image_type" : "text/$text_type";
118 $t->producer( $producer );
119 my $output = $t->translate or die $t->error;
121 print $q->header( -type => $header_type ), $output;
128 if ( my $error = $@ ) {
129 print $q->header, $q->start_html('Error'),
130 $q->h1('Error'), $error, $q->end_html;
133 # -------------------------------------------------------------------
136 my $title = 'SQL::Translator';
139 $q->start_html( -title => $title ),
140 $q->h1( qq[<a href="http://sqlfairy.sourceforge.net">$title</a>] ),
141 $q->start_form(-enctype => 'multipart/form-data'),
142 $q->table( { -border => 1 },
145 'Upload your schema file:',
146 $q->filefield( -name => 'schema_file'),
151 'Or paste your schema here:',
164 -values => [ qw( MySQL PostgreSQL Oracle
165 Sybase Excel XML-SQLFairy xSV
177 -values => [ qw[ ClassDBI Diagram GraphViz HTML
178 MySQL Oracle POD PostgreSQL SQLite Sybase
179 TTSchema XML-SQLFairy
181 -default => 'GraphViz',
188 { -colspan => 2, -align => 'center' },
197 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
218 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
219 'DB Producer Options:'
224 'Add "DROP TABLE" statements:',
226 -name => 'add_drop_table',
254 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
255 'HTML/POD/Diagram Producer Options:'
261 $q->textfield('title'),
266 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
267 'TTSchema Producer Options:'
273 $q->filefield( -name => 'template'),
278 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
279 'Graphical Producer Options'
284 'Perform Natural Joins:',
286 -name => 'natural_join',
287 -values => [ 'no', 'yes', 'pk_only' ],
290 yes => 'Yes, on all like-named fields',
291 pk_only => 'Yes, but only from primary keys'
300 'Skip These Fields in Natural Joins:',
302 -name => 'skip_fields',
310 'Show Only Foreign Keys:',
312 -name => 'show_fk_only',
327 -name => 'add_color',
342 -name => 'show_fields',
355 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
356 'Diagram Producer Options'
363 -name => 'diagram_output_type',
364 -values => [ 'png', 'jpeg' ],
374 -name => 'font_size',
375 -values => [ qw( small medium large ) ],
376 -default => 'medium',
383 'Number of Columns:',
384 $q->textfield('no_columns'),
389 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
390 'GraphViz Producer Options'
397 -name => 'graphviz_output_type',
398 -values => [ qw( canon text ps hpgl pcl mif pic
399 gd gd2 gif jpeg png wbmp cmap ismap imap
400 vrml vtx mp fig svg plain
412 -values => [ qw( dot neato twopi ) ],
422 -name => 'node_shape',
423 -values => [ qw( record plaintext ellipse
424 circle egg triangle box diamond trapezium
425 parallelogram house hexagon octagon
427 -default => 'record',
435 $q->textfield( -name => 'height' ),
441 $q->textfield( -name => 'width' ),
446 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
447 'XML Producer Options:'
452 'Use attributes for values:',
454 -name => 'attrib-values',
469 -name => 'emit-empty-tags',
482 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
489 $q->textfield( -name => 'fs' ),
495 $q->textfield( -name => 'rs' ),
500 'Trim Whitespace Around Fields:',
502 -name => 'trim_fields',
515 'Scan Fields for Data Type:',
517 -name => 'scan_fields',
530 { -colspan => 2, -align => 'center' },
542 # -------------------------------------------------------------------
548 Ken Y. Clark E<lt>kclark@cpan.orgE<gt>.