package SQL::Translator::Producer::GraphViz;
# -------------------------------------------------------------------
-# $Id: GraphViz.pm,v 1.14 2007-09-26 13:20:09 schiffbruechige Exp $
+# $Id$
# -------------------------------------------------------------------
# Copyright (C) 2002-4 SQLFairy Authors
#
which columns are included in the index. this option requires
that show_fields is a true value as well
+=item * show_index_name
+
+if show_indexes is set to a true value, then the value of this
+parameter determines whether or not to print names of indexes.
+if show_index_name is false, then a list of indexed columns
+will appear below the field list. otherwise, it will be a list
+prefixed with the name of each index. it defaults to true.
+
=item * friendly_ints
if set to a true value, each integer type field will be displayed
-as a tinyint, smallint, integer or bigint depending on the field's
+as a smallint, integer or bigint depending on the field's
associated size parameter. this only applies for the 'integer'
type (and not the lowercase 'int' type, which is assumed to be a
32-bit integer).
+=item * friendly_ints_extended
+
+if set to a true value, the friendly ints displayed will take into
+account the non-standard types, 'tinyint' and 'mediumint' (which,
+as far as I am aware, is only implemented in MySQL)
+
=back
=cut
use SQL::Translator::Utils qw(debug);
use vars qw[ $VERSION $DEBUG ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.14 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/;
$DEBUG = 0 unless defined $DEBUG;
use constant VALID_LAYOUT => {
my $show_datatypes = $args->{'show_datatypes'};
my $show_sizes = $args->{'show_sizes'};
my $show_indexes = $args->{'show_indexes'};
+ my $show_index_name = $args->{'show_index_name'} || 1;
my $friendly_ints = $args->{'friendly_ints'};
+ my $friendly_ints_ex = $args->{'friendly_ints_extended'};
my $show_constraints = $args->{'show_constraints'};
my $join_pk_only = $args->{'join_pk_only'};
my $skip_fields = $args->{'skip_fields'} || '';
# requested size, if a size is given.
if ($friendly_ints && $dt eq 'integer' && $field->size) {
# Automatically translate to int2, int4, int8
- # Type (Bits) Max. Signed Length
- # tinyint (8) 128 3
- # smallint (16) 32767 5
- # int (32) 2147483647 10
- # bigint (64) 9223372036854775807 19
- if ($field->size > 10) {
+ # Type (Bits) Max. Signed/Unsigned Length
+ # tinyint* (8) 128 3
+ # 255 3
+ # smallint (16) 32767 5
+ # 65535 5
+ # mediumint* (24) 8388607 7
+ # 16777215 8
+ # int (32) 2147483647 10
+ # 4294967295 10
+ # bigint (64) 9223372036854775807 19
+ # 18446744073709551615 20
+ #
+ # * tinyint and mediumint are nonstandard extensions which are
+ # only available under MySQL (to my knowledge)
+ my $size = $field->size;
+ if ($size > 10) {
$dt = 'bigint';
}
- elsif ($field->size > 5) {
+ elsif ($size > 5) {
$dt = 'integer';
+ if ($friendly_ints_ex && $size <= 8) {
+ $dt = 'mediumint';
+ }
}
- elsif ($field->size > 3) {
+ else {
$dt = 'smallint';
- }
- else { # 8 bits
- $dt = 'tinyint';
+ if ($friendly_ints_ex && $size <= 3) {
+ $dt = 'tinyint';
+ }
}
}
foreach my $index ($table->get_indices) {
next unless $index->is_valid;
- $index_str .= '*\ ' . $index->name . ': ';
+ $index_str .= '*\ ';
+ if ($show_index_name) {
+ $index_str .= $index->name . ': ';
+ }
$index_str .= join(', ', $index->fields);
if ($index->type eq 'UNIQUE') {
$index_str .= '\ [U]';
}
$index_str .= '\l';
}
- $label .= '|' . $index_str;
+ # Only add the last box if index_str is non-null
+ if (length $index_str) {
+ $label .= '|' . $index_str;
+ }
}
$label .= '}';
# $gv->add_node( $table_name, label => $label );
Ken Y. Clark E<lt>kclark@cpan.orgE<gt>
+=head2 CONTRIBUTORS
+
+Jonathan Yu E<lt>frequency@cpan.orgE<gt>
+
=head1 SEE ALSO
SQL::Translator, GraphViz