5 sqlt.cgi - CGI front-end for SQL::Translator
9 Place this script in your "cgi-bin" directory and point your browser
10 to it. This script is meant to be a simple graphical interface to
11 all the parsers and producers of SQL::Translator.
15 # -------------------------------------------------------------------
30 if ( $q->param('schema') ) {
31 $data = $q->param('schema');
33 elsif ( my $fh = $q->upload('schema_file') ) {
37 die "No schema provided!\n" unless $data;
39 my $producer = $q->param('producer');
40 my $output_type = $producer eq 'Diagram'
41 ? $q->param('diagram_output_type')
42 : $producer eq 'GraphViz'
43 ? $q->param('graphviz_output_type')
47 my $t = SQL::Translator->new(
48 from => $q->param('parser'),
50 add_drop_table => $q->param('add_drop_table'),
51 output_type => $output_type,
52 title => $q->param('title') || 'Schema',
53 natural_join => $q->param('natural_join') eq 'no' ? 0 : 1,
54 join_pk_only => $q->param('natural_join') eq 'pk_only'
56 add_color => $q->param('add_color'),
57 skip_fields => $q->param('skip_fields'),
58 show_fk_only => $q->param('show_fk_only'),
59 font_size => $q->param('font_size'),
60 no_columns => $q->param('no_columns'),
61 node_shape => $q->param('node_shape'),
62 layout => $q->param('layout') || '',
63 height => $q->param('height') || 0,
64 width => $q->param('width') || 0,
65 show_fields => $q->param('show_fields') || 0,
66 ttfile => $q->upload('template'),
67 validate => $q->param('validate'),
68 emit_empty_tags => $q->param('emit_empty_tags'),
69 attrib_values => $q->param('attrib_values'),
70 no_comments => !$q->param('comments'),
73 trim_fields => $q->param('trim_fields'),
74 scan_fields => $q->param('scan_fields'),
75 field_separator => $q->param('fs'),
76 record_separator => $q->param('rs'),
78 ) or die SQL::Translator->error;
81 my $text_type = 'plain';
82 if ( $output_type =~ /(gif|png|jpeg)/ ) {
83 $image_type = $output_type;
85 elsif ( $output_type eq 'svg' ) {
86 $image_type = 'svg+xml';
88 elsif ( $output_type =~ /gd/ ) {
91 elsif ( $output_type eq 'ps' ) {
92 $text_type = 'postscript';
94 elsif ( $producer eq 'HTML' ) {
98 my $header_type = $image_type ? "image/$image_type" : "text/$text_type";
101 $t->producer( $producer );
102 my $output = $t->translate or die $t->error;
104 print $q->header( -type => $header_type ), $output;
111 if ( my $error = $@ ) {
112 print $q->header, $q->start_html('Error'),
113 $q->h1('Error'), $error, $q->end_html;
116 # -------------------------------------------------------------------
119 my $title = 'SQL::Translator';
122 $q->start_html( -title => $title ),
123 $q->h1( qq[<a href="http://sqlfairy.sourceforge.net">$title</a>] ),
124 $q->start_form(-enctype => 'multipart/form-data'),
125 $q->table( { -border => 1 },
128 'Upload your schema file:',
129 $q->filefield( -name => 'schema_file'),
134 'Or paste your schema here:',
147 -values => [ qw( MySQL PostgreSQL Oracle
148 Sybase Excel XML-SQLFairy xSV
160 -values => [ qw[ ClassDBI Diagram GraphViz HTML
161 MySQL Oracle POD PostgreSQL SQLite Sybase
162 TTSchema XML-SQLFairy
164 -default => 'GraphViz',
171 { -colspan => 2, -align => 'center' },
180 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
201 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
202 'DB Producer Options:'
207 'Add "DROP TABLE" statements:',
209 -name => 'add_drop_table',
237 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
238 'HTML/POD/Diagram Producer Options:'
244 $q->textfield('title'),
249 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
250 'TTSchema Producer Options:'
256 $q->filefield( -name => 'template'),
261 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
262 'Graphical Producer Options'
267 'Perform Natural Joins:',
269 -name => 'natural_join',
270 -values => [ 'no', 'yes', 'pk_only' ],
273 yes => 'Yes, on all like-named fields',
274 pk_only => 'Yes, but only from primary keys'
283 'Skip These Fields in Natural Joins:',
285 -name => 'skip_fields',
293 'Show Only Foreign Keys:',
295 -name => 'show_fk_only',
310 -name => 'add_color',
325 -name => 'show_fields',
338 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
339 'Diagram Producer Options'
346 -name => 'diagram_output_type',
347 -values => [ 'png', 'jpeg' ],
357 -name => 'font_size',
358 -values => [ qw( small medium large ) ],
359 -default => 'medium',
366 'Number of Columns:',
367 $q->textfield('no_columns'),
372 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
373 'GraphViz Producer Options'
380 -name => 'graphviz_output_type',
381 -values => [ qw( canon text ps hpgl pcl mif pic
382 gd gd2 gif jpeg png wbmp cmap ismap imap
383 vrml vtx mp fig svg plain
395 -values => [ qw( dot neato twopi ) ],
405 -name => 'node_shape',
406 -values => [ qw( record plaintext ellipse
407 circle egg triangle box diamond trapezium
408 parallelogram house hexagon octagon
410 -default => 'record',
418 $q->textfield( -name => 'height' ),
424 $q->textfield( -name => 'width' ),
429 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
430 'XML Producer Options:'
435 'Use attributes for values:',
437 -name => 'attrib-values',
452 -name => 'emit-empty-tags',
465 { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
472 $q->textfield( -name => 'fs' ),
478 $q->textfield( -name => 'rs' ),
483 'Trim Whitespace Around Fields:',
485 -name => 'trim_fields',
498 'Scan Fields for Data Type:',
500 -name => 'scan_fields',
513 { -colspan => 2, -align => 'center' },
525 # -------------------------------------------------------------------
531 Ken Youens-Clark E<lt>kclark@cpan.orgE<gt>.