Downgrade global version - highest version in 9002 on cpan is 1.58 - thus go with...
[dbsrgits/SQL-Translator.git] / bin / sqlt.cgi
index 54ebc78..513042d 100755 (executable)
@@ -1,9 +1,7 @@
 #!/usr/bin/perl
 
 # -------------------------------------------------------------------
-# $Id: sqlt.cgi,v 1.1 2003-08-26 16:25:34 kycl4rk Exp $
-# -------------------------------------------------------------------
-# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>
+# Copyright (C) 2002-2009 SQLFairy Authors
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
 
 =head1 NAME
 
-sqlt.cgi
+sqlt.cgi - CGI front-end for SQL::Translator
 
 =head1 DESCRIPTION
 
-A CGI front-end for SQL::Translator.
+Place this script in your "cgi-bin" directory and point your browser
+to it.  This script is meant to be a simple graphical interface to 
+all the parsers and producers of SQL::Translator.
 
 =cut
 
+# -------------------------------------------------------------------
+
 use strict;
 use CGI;
 use SQL::Translator;
 
 use vars '$VERSION';
-$VERSION = sprintf "%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/;
+$VERSION = '1.59';
 
 my $q = CGI->new;
 
 eval {
     if ( $q->param ) {
-        my $t                =  SQL::Translator->new( 
-            from             => $q->param('parser'),
-            producer_args    => {
-                image_type   => $q->param('output_type') || 'png',
-                title        => $q->param('title')       || 'Schema',
-                natural_join => $q->param('natural_join') eq 'no' ? 0 : 1, 
-                join_pk_only => $q->param('natural_join') eq 'pk_only' ? 1 : 0,
-                add_color    => $q->param('add_color'),
-                skip_fields  => $q->param('skip_fields'),
-                show_fk_only => $q->param('show_fk_only'),
-                font_size    => $q->param('font_size'),
-                no_columns   => $q->param('no_columns'),
-                node_shape   => $q->param('node_shape'),
-                layout       => $q->param('layout')      || '',
-                height       => $q->param('height')      || 0,
-                width        => $q->param('width')       || 0,
-                show_fields  => $q->param('show_fields') || 0,
-            },
-        ) or die SQL::Translator->error;
-
         my $data;
         if ( $q->param('schema') ) {
             $data = $q->param('schema');
@@ -72,11 +54,65 @@ eval {
         die "No schema provided!\n" unless $data;
 
         my $producer    = $q->param('producer');
-        my $image_type  = $q->param('output_type') || 'png';
-        my $header_type = 
-            $producer =~ m/(GraphViz|Diagram)/ 
-            ? "image/$image_type"
-            : 'text/plain';
+        my $output_type = $producer eq 'Diagram'
+            ? $q->param('diagram_output_type')
+            : $producer eq 'GraphViz'
+            ? $q->param('graphviz_output_type') 
+            : ''
+        ;
+
+        my $t                    =  SQL::Translator->new( 
+            from                 => $q->param('parser'),
+            producer_args        => {
+                add_drop_table   => $q->param('add_drop_table'),
+                output_type      => $output_type,
+                title            => $q->param('title')       || 'Schema',
+                natural_join     => $q->param('natural_join') eq 'no' ? 0 : 1, 
+                join_pk_only     => $q->param('natural_join') eq 'pk_only' 
+                                    ? 1 : 0,
+                add_color        => $q->param('add_color'),
+                skip_fields      => $q->param('skip_fields'),
+                show_fk_only     => $q->param('show_fk_only'),
+                font_size        => $q->param('font_size'),
+                no_columns       => $q->param('no_columns'),
+                node_shape       => $q->param('node_shape'),
+                layout           => $q->param('layout')      || '',
+                height           => $q->param('height')      || 0,
+                width            => $q->param('width')       || 0,
+                show_fields      => $q->param('show_fields') || 0,
+                ttfile           => $q->upload('template'),
+                validate         => $q->param('validate'),
+                emit_empty_tags  => $q->param('emit_empty_tags'),
+                attrib_values    => $q->param('attrib_values'),
+                no_comments      => !$q->param('comments'),
+            },
+            parser_args => {
+                trim_fields      => $q->param('trim_fields'),
+                scan_fields      => $q->param('scan_fields'),
+                field_separator  => $q->param('fs'),
+                record_separator => $q->param('rs'),
+            },
+        ) or die SQL::Translator->error;
+
+        my $image_type = '';
+        my $text_type  = 'plain';
+        if ( $output_type =~ /(gif|png|jpeg)/ ) {
+            $image_type = $output_type;
+        }
+        elsif ( $output_type eq 'svg' ) {
+            $image_type = 'svg+xml';
+        }
+        elsif ( $output_type =~ /gd/ ) {
+            $image_type = 'png';
+        }
+        elsif ( $output_type eq 'ps' ) {
+            $text_type = 'postscript';
+        }
+        elsif ( $producer eq 'HTML' ) {
+            $text_type = 'html';
+        }
+
+        my $header_type = $image_type ? "image/$image_type" : "text/$text_type";
 
         $t->data( $data );
         $t->producer( $producer );
@@ -106,18 +142,18 @@ sub show_form {
         $q->table( { -border => 1 },
             $q->Tr( 
                 $q->td( [
-                    'Paste your schema here:',
-                    $q->textarea( 
-                        -name    => 'schema', 
-                        -rows    => 10, 
-                        -columns => 60,
-                    ),
+                    'Upload your schema file:',
+                    $q->filefield( -name => 'schema_file'),
                 ] ),
             ),
             $q->Tr( 
                 $q->td( [
-                    'Or upload your schema file:',
-                    $q->filefield( -name => 'schema_file'),
+                    'Or paste your schema here:',
+                    $q->textarea( 
+                        -name    => 'schema', 
+                        -rows    => 5, 
+                        -columns => 60,
+                    ),
                 ] ),
             ),
             $q->Tr( 
@@ -125,7 +161,9 @@ sub show_form {
                     'Parser:',
                     $q->radio_group(
                         -name    => 'parser',
-                        -values  => [ 'MySQL', 'PostgreSQL', 'Oracle' ],
+                        -values  => [ qw( MySQL PostgreSQL Oracle 
+                            Sybase Excel XML-SQLFairy xSV  
+                        ) ],
                         -default => 'MySQL',
                         -rows    => 3,
                     ),
@@ -137,7 +175,8 @@ sub show_form {
                     $q->radio_group(
                         -name    => 'producer',
                         -values  => [ qw[ ClassDBI Diagram GraphViz HTML
-                            MySQL Oracle POD PostgreSQL SQLite Sybase XML
+                            MySQL Oracle POD PostgreSQL SQLite Sybase
+                            TTSchema XML-SQLFairy
                         ] ],
                         -default => 'GraphViz',
                         -rows    => 3,
@@ -145,23 +184,102 @@ sub show_form {
                 ] ),
             ),
             $q->Tr( 
+                $q->td(
+                    { -colspan => 2, -align => 'center' },
+                    $q->submit( 
+                        -name  => 'submit', 
+                        -value => 'Submit',
+                    )
+                ),
+            ),
+            $q->Tr( 
+                $q->th( 
+                    { align => 'left', bgcolor => 'lightgrey', colspan => 2 }, 
+                    'General Options:' 
+                ),
+            ),
+            $q->Tr( 
                 $q->td( [
-                    'Title:',
-                    $q->textfield('title'),
+                    'Validate Schema:',
+                    $q->radio_group(
+                        -name    => 'validate',
+                        -values  => [ 1, 0 ],
+                        -labels  => { 
+                            1    => 'Yes', 
+                            0    => 'No' 
+                        },
+                        -default => 0,
+                        -rows    => 2,
+                    ),
                 ] ),
             ),
             $q->Tr( 
+                $q->th( 
+                    { align => 'left', bgcolor => 'lightgrey', colspan => 2 }, 
+                    'DB Producer Options:' 
+                ),
+            ),
+            $q->Tr( 
                 $q->td( [
-                    'Output Type:',
+                    'Add &quot;DROP TABLE&quot; statements:',
                     $q->radio_group(
-                        -name    => 'output_type',
-                        -values  => [ 'png', 'jpeg' ],
-                        -default => 'png',
+                        -name    => 'add_drop_table',
+                        -values  => [ 1, 0 ],
+                        -labels  => { 
+                            1    => 'Yes', 
+                            0    => 'No' 
+                        },
+                        -default => 0,
+                        -rows    => 2,
+                    ),
+                ] ),
+            ),
+            $q->Tr( 
+                $q->td( [
+                    'Include comments:',
+                    $q->radio_group(
+                        -name    => 'comments',
+                        -values  => [ 1, 0 ],
+                        -labels  => { 
+                            1    => 'Yes', 
+                            0    => 'No' 
+                        },
+                        -default => 1,
                         -rows    => 2,
                     ),
                 ] ),
             ),
             $q->Tr( 
+                $q->th( 
+                    { align => 'left', bgcolor => 'lightgrey', colspan => 2 }, 
+                    'HTML/POD/Diagram Producer Options:' 
+                ),
+            ),
+            $q->Tr( 
+                $q->td( [
+                    'Title:',
+                    $q->textfield('title'),
+                ] ),
+            ),
+            $q->Tr( 
+                $q->th( 
+                    { align => 'left', bgcolor => 'lightgrey', colspan => 2 }, 
+                    'TTSchema Producer Options:' 
+                ),
+            ),
+            $q->Tr( 
+                $q->td( [
+                    'Template:',
+                    $q->filefield( -name => 'template'),
+                ] ),
+            ),
+            $q->Tr( 
+                $q->th( 
+                    { align => 'left', bgcolor => 'lightgrey', colspan => 2 }, 
+                    'Graphical Producer Options'
+                ),
+            ),
+            $q->Tr( 
                 $q->td( [
                     'Perform Natural Joins:',
                     $q->radio_group(
@@ -189,7 +307,22 @@ sub show_form {
             ),
             $q->Tr( 
                 $q->td( [
-                    'Color:',
+                    'Show Only Foreign Keys:',
+                    $q->radio_group(
+                        -name    => 'show_fk_only',
+                        -values  => [ 1, 0 ],
+                        -default => 0,
+                        -labels  => {
+                            1    => 'Yes',
+                            0    => 'No',
+                        },
+                        -rows    => 2,
+                    ),
+                ] ),
+            ),
+            $q->Tr( 
+                $q->td( [
+                    'Add Color:',
                     $q->radio_group(
                         -name    => 'add_color',
                         -values  => [ 1, 0 ],
@@ -204,11 +337,11 @@ sub show_form {
             ),
             $q->Tr( 
                 $q->td( [
-                    'Show Only Foreign Keys *:',
+                    'Show Field Names:',
                     $q->radio_group(
-                        -name    => 'show_fk_only',
+                        -name    => 'show_fields',
                         -values  => [ 1, 0 ],
-                        -default => 0,
+                        -default => 1,
                         -labels  => {
                             1    => 'Yes',
                             0    => 'No',
@@ -218,8 +351,25 @@ sub show_form {
                 ] ),
             ),
             $q->Tr( 
+                $q->th( 
+                    { align => 'left', bgcolor => 'lightgrey', colspan => 2 }, 
+                    'Diagram Producer Options'
+                ),
+            ),
+            $q->Tr( 
+                $q->td( [
+                    'Output Type:',
+                    $q->radio_group(
+                        -name    => 'diagram_output_type',
+                        -values  => [ 'png', 'jpeg' ],
+                        -default => 'png',
+                        -rows    => 2,
+                    ),
+                ] ),
+            ),
+            $q->Tr( 
                 $q->td( [
-                    'Font Size *:',
+                    'Font Size:',
                     $q->radio_group(
                         -name    => 'font_size',
                         -values  => [ qw( small medium large ) ],
@@ -230,13 +380,33 @@ sub show_form {
             ),
             $q->Tr( 
                 $q->td( [
-                    'Number of Columns *:',
+                    'Number of Columns:',
                     $q->textfield('no_columns'),
                 ] ),
             ),
             $q->Tr( 
+                $q->th( 
+                    { align => 'left', bgcolor => 'lightgrey', colspan => 2 }, 
+                    'GraphViz Producer Options'
+                ),
+            ),
+            $q->Tr( 
                 $q->td( [
-                    'Layout **:',
+                    'Output Type:',
+                    $q->radio_group(
+                        -name    => 'graphviz_output_type',
+                        -values  => [ qw( canon text ps hpgl pcl mif pic
+                            gd gd2 gif jpeg png wbmp cmap ismap imap
+                            vrml vtx mp fig svg plain
+                        ) ],
+                        -default => 'png',
+                        -rows    => 4,
+                    ),
+                ] ),
+            ),
+            $q->Tr( 
+                $q->td( [
+                    'Layout:',
                     $q->radio_group(
                         -name    => 'layout',
                         -values  => [ qw( dot neato twopi ) ],
@@ -247,7 +417,7 @@ sub show_form {
             ),
             $q->Tr( 
                 $q->td( [
-                    'Node Shape **:',
+                    'Node Shape:',
                     $q->radio_group(
                         -name    => 'node_shape',
                         -values  => [ qw( record plaintext ellipse 
@@ -255,35 +425,104 @@ sub show_form {
                             parallelogram house hexagon octagon 
                         ) ],
                         -default => 'record',
-                        -rows    => 13,
+                        -rows    => 4,
                     ),
                 ] ),
             ),
             $q->Tr( 
                 $q->td( [
-                    'Show Field Names **:',
+                    'Height:',
+                    $q->textfield( -name => 'height' ),
+                ] ),
+            ),
+            $q->Tr( 
+                $q->td( [
+                    'Width:',
+                    $q->textfield( -name => 'width' ),
+                ] ),
+            ),
+            $q->Tr( 
+                $q->th( 
+                    { align => 'left', bgcolor => 'lightgrey', colspan => 2 }, 
+                    'XML Producer Options:' 
+                ),
+            ),
+            $q->Tr( 
+                $q->td( [
+                    'Use attributes for values:',
                     $q->radio_group(
-                        -name    => 'show_fields',
+                        -name    => 'attrib-values',
                         -values  => [ 1, 0 ],
-                        -default => 1,
-                        -labels  => {
-                            1    => 'Yes',
-                            0    => 'No',
+                        -labels  => { 
+                            1    => 'Yes', 
+                            0    => 'No' 
                         },
+                        -default => 0,
                         -rows    => 2,
                     ),
                 ] ),
             ),
             $q->Tr( 
                 $q->td( [
-                    'Height **:',
-                    $q->textfield( -name => 'height', -default => 11 ),
+                    'Emit Empty Tags:',
+                    $q->radio_group(
+                        -name    => 'emit-empty-tags',
+                        -values  => [ 1, 0 ],
+                        -labels  => { 
+                            1    => 'Yes', 
+                            0    => 'No' 
+                        },
+                        -default => 0,
+                        -rows    => 2,
+                    ),
+                ] ),
+            ),
+            $q->Tr( 
+                $q->th( 
+                    { align => 'left', bgcolor => 'lightgrey', colspan => 2 }, 
+                    'xSV Parser Options'
+                ),
+            ),
+            $q->Tr( 
+                $q->td( [
+                    'Field Separator:',
+                    $q->textfield( -name => 'fs' ),
+                ] ),
+            ),
+            $q->Tr( 
+                $q->td( [
+                    'Record Separator:',
+                    $q->textfield( -name => 'rs' ),
                 ] ),
             ),
             $q->Tr( 
                 $q->td( [
-                    'Width **:',
-                    $q->textfield( -name => 'width', -default => 8.5 ),
+                    'Trim Whitespace Around Fields:',
+                    $q->radio_group(
+                        -name    => 'trim_fields',
+                        -values  => [ 1, 0 ],
+                        -default => 1,
+                        -labels  => {
+                            1    => 'Yes',
+                            0    => 'No',
+                        },
+                        -rows    => 2,
+                    ),
+                ] ),
+            ),
+            $q->Tr( 
+                $q->td( [
+                    'Scan Fields for Data Type:',
+                    $q->radio_group(
+                        -name    => 'scan_fields',
+                        -values  => [ 1, 0 ],
+                        -default => 1,
+                        -labels  => {
+                            1    => 'Yes',
+                            0    => 'No',
+                        },
+                        -rows    => 2,
+                    ),
                 ] ),
             ),
             $q->Tr( 
@@ -292,14 +531,7 @@ sub show_form {
                     $q->submit( 
                         -name  => 'submit', 
                         -value => 'Submit',
-                    ),
-                    $q->br,
-                    q[
-                        <small>
-                        * -- Applies to diagram only<br>
-                        ** -- Applies to graph only<br>
-                        </small>
-                    ],
+                    )
                 ),
             ),
         ),
@@ -313,10 +545,11 @@ sub show_form {
 
 =head1 AUTHOR
 
-Ken Y. Clark E<lt>kclark@cpan.orgE<gt>
+Ken Y. Clark E<lt>kclark@cpan.orgE<gt>.
 
 =head1 SEE ALSO
 
-perl, SQL::Translator.
+L<perl>,
+L<SQL::Translator>
 
 =cut