* Fix parsing of strings with leading whitespace for MySQL, Oracle, PostgreSQL,
SQLServer and SQLite
* Fix parsing of MySQL column comments (RT#83380)
- * Fix multi-line comments in YAML and JSON producers
+ * Fix multi-line comments in YAML, JSON and PostgreSQL producers
0.11021 2015-01-29
push @comments, "--\n-- Table: $table_name\n--\n" unless $no_comments;
- if ( $table->comments and !$no_comments ){
- my $c = "-- Comments: \n-- ";
- $c .= join "\n-- ", $table->comments;
- $c .= "\n--\n";
- push @comments, $c;
+ if ( !$no_comments and my $comments = $table->comments ) {
+ $comments =~ s/^/-- /mg;
+ push @comments, "-- Comments:\n$comments\n--\n";
}
#
$field_name_scope{$table_name} ||= {};
my $field_name = $field->name;
- my $field_comments = $field->comments
- ? "-- " . $field->comments . "\n "
- : '';
+ my $field_comments = '';
+ if (my $comments = $field->comments) {
+ $comments =~ s/(?<!\A)^/ -- /mg;
+ $field_comments = "-- $comments\n ";
+ }
my $field_def = $field_comments . $generator->quote($field_name);
my $PRODUCER = \&SQL::Translator::Producer::PostgreSQL::create_field;
{
- my $table = SQL::Translator::Schema::Table->new( name => 'foo.bar' );
+ my $table = SQL::Translator::Schema::Table->new( name => 'foo.bar',
+ comments => [ "multi\nline",'single line' ] );
my $field = SQL::Translator::Schema::Field->new( name => 'baz',
+ comments => [ "multi\nline",'single line' ],
table => $table,
data_type => 'VARCHAR',
size => 10,
my ($create, $fks) = SQL::Translator::Producer::PostgreSQL::create_table($table, { quote_table_names => q{"} });
is($table->name, 'foo.bar');
- my $expected = "--\n-- Table: foo.bar\n--\nCREATE TABLE \"foo\".\"bar\" (\n \"baz\" character varying(10) DEFAULT 'quux' NOT NULL\n)";
+ my $expected = <<EOESQL;
+--
+-- Table: foo.bar
+--
+
+-- Comments:
+-- multi
+-- line
+-- single line
+--
+CREATE TABLE "foo"."bar" (
+ -- multi
+ -- line
+ -- single line
+ "baz" character varying(10) DEFAULT 'quux' NOT NULL
+)
+EOESQL
+
+ $expected =~ s/\n\z//;
is($create, $expected);
}