package SQL::Translator::Parser::XML::SQLFairy;
# -------------------------------------------------------------------
-# $Id: SQLFairy.pm,v 1.14 2005-06-28 16:39:41 mwz444 Exp $
+# $Id: SQLFairy.pm,v 1.15 2005-07-05 16:20:42 mwz444 Exp $
# -------------------------------------------------------------------
# Copyright (C) 2003 Mark Addison <mark.addison@itn.co.uk>,
#
use strict;
use vars qw[ $DEBUG $VERSION @EXPORT_OK ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.14 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.15 $ =~ /(\d+)\.(\d+)/;
$DEBUG = 0 unless defined $DEBUG;
use Data::Dumper;
$table->add_index( %data ) or die $table->error;
}
+
+ #
+ # Comments
+ #
+ @nodes = $xp->findnodes('sqlf:comments/sqlf:comment',$tblnode);
+ foreach (@nodes) {
+ my $data = $_->string_value;
+ $table->comments( $data );
+ }
+
} # tables loop
#
package SQL::Translator::Producer::PostgreSQL;
# -------------------------------------------------------------------
-# $Id: PostgreSQL.pm,v 1.22 2004-02-09 23:02:15 kycl4rk Exp $
+# $Id: PostgreSQL.pm,v 1.23 2005-07-05 16:20:43 mwz444 Exp $
# -------------------------------------------------------------------
# Copyright (C) 2002-4 SQLFairy Authors
#
use strict;
use vars qw[ $DEBUG $WARN $VERSION ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.22 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.23 $ =~ /(\d+)\.(\d+)/;
$DEBUG = 1 unless defined $DEBUG;
use SQL::Translator::Schema::Constants;
$table_name = mk_name( $table_name, '', undef, 1 );
my $table_name_ur = unreserve($table_name);
+print STDERR "$table_name table_name\n";
my ( @comments, @field_defs, @sequence_defs, @constraint_defs );
push @comments, "--\n-- Table: $table_name_ur\n--" unless $no_comments;
+ if ( $table->comments and !$no_comments ){
+ my $c = "-- Comments: \n-- ";
+ $c .= join "\n-- ", $table->comments;
+ $c .= "\n--";
+ push @comments, $c;
+ }
+
#
# Fields
#
$field->name, '', \%field_name_scope, 1
);
my $field_name_ur = unreserve( $field_name, $table_name );
- my $field_def = qq["$field_name_ur"];
+ my $field_comments = $field->comments
+ ? "-- " . $field->comments . "\n "
+ : '';
+
+ my $field_def = $field_comments.qq["$field_name_ur"];
#
# Datatype
package SQL::Translator::Producer::SQLite;
# -------------------------------------------------------------------
-# $Id: SQLite.pm,v 1.12 2005-06-13 18:23:10 mwz444 Exp $
+# $Id: SQLite.pm,v 1.13 2005-07-05 16:20:43 mwz444 Exp $
# -------------------------------------------------------------------
# Copyright (C) 2002-4 SQLFairy Authors
#
use vars qw[ $VERSION $DEBUG $WARN ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.12 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.13 $ =~ /(\d+)\.(\d+)/;
$DEBUG = 0 unless defined $DEBUG;
$WARN = 0 unless defined $WARN;
$create .= "CREATE TABLE $table_name (\n";
#
+ # Comments
+ #
+ if ( $table->comments and !$no_comments ){
+ $create .= "-- Comments: \n-- ";
+ $create .= join "\n-- ", $table->comments;
+ $create .= "\n--\n\n";
+ }
+
+ #
# How many fields in PK?
#
my $pk = $table->primary_key;
for my $field ( @fields ) {
my $field_name = $field->name;
debug("PKG: Looking at field '$field_name'\n");
- my $field_def = $field_name;
+ my $field_comments = $field->comments
+ ? "-- " . $field->comments . "\n "
+ : '';
+
+ my $field_def = $field_comments.$field_name;
# data type and size
my $size = $field->size;
package SQL::Translator::Producer::XML::SQLFairy;
# -------------------------------------------------------------------
-# $Id: SQLFairy.pm,v 1.19 2004-11-05 16:37:00 grommit Exp $
+# $Id: SQLFairy.pm,v 1.20 2005-07-05 16:20:43 mwz444 Exp $
# -------------------------------------------------------------------
# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
# darren chamberlain <darren@cpan.org>,
use strict;
use vars qw[ $VERSION @EXPORT_OK ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.19 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.20 $ =~ /(\d+)\.(\d+)/;
use Exporter;
use base qw(Exporter);
/],
);
+ #
+ # Comments
+ #
+ xml_obj_children( $xml, $table,
+ tag => 'comment',
+ collection_tag => "comments",
+ methods => [qw/
+ comments
+ /],
+ );
+
$xml->endTag( [ $Namespace => 'table' ] );
}
$xml->endTag( [ $Namespace => 'tables' ] );
my ($name,$collection_name,$methods)
= @args{qw/tag collection_tag methods/};
$collection_name ||= "${name}s";
- my $meth = "get_$collection_name";
+
+ my $meth;
+ if ( $collection_name eq 'comments' ) {
+ $meth = 'comments';
+ } else {
+ $meth = "get_$collection_name";
+ }
my @kids = $parent->$meth;
#@kids || return;
$xml->startTag( [ $Namespace => $collection_name ] );
+
for my $obj ( @kids ) {
- xml_obj($xml, $obj,
- tag => "$name",
- end_tag => 1,
- methods => $methods,
- );
+ if ( $collection_name eq 'comments' ){
+ $xml->dataElement( [ $Namespace => 'comment' ], $obj );
+ } else {
+ xml_obj($xml, $obj,
+ tag => "$name",
+ end_tag => 1,
+ methods => $methods,
+ );
+ }
}
$xml->endTag( [ $Namespace => $collection_name ] );
}