From: Peter Rabbitson Date: Sat, 6 Mar 2010 23:44:37 +0000 (+0000) Subject: Get SQLite to produce saner output X-Git-Tag: v0.11008~52 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b6b0696fc9a3c5184dad2710e346e1f7233fe8ff;p=dbsrgits%2FSQL-Translator.git Get SQLite to produce saner output --- diff --git a/lib/SQL/Translator/Producer/SQLite.pm b/lib/SQL/Translator/Producer/SQLite.pm index f85b360..40acc57 100644 --- a/lib/SQL/Translator/Producer/SQLite.pm +++ b/lib/SQL/Translator/Producer/SQLite.pm @@ -65,9 +65,12 @@ sub produce { %global_names = (); #reset + + my $head = (header_comment() . "\n") unless $no_comments; + my @create = (); - push @create, header_comment unless ($no_comments); - $create[0] .= "\n\nBEGIN TRANSACTION" unless $no_txn; + + push @create, "BEGIN TRANSACTION" unless $no_txn; for my $table ( $schema->get_tables ) { push @create, create_table($table, { no_comments => $no_comments, @@ -89,12 +92,16 @@ sub produce { }); } + push @create, "COMMIT" unless $no_txn; + if (wantarray) { - push @create, "COMMIT" unless $no_txn; - return @create; + return ($head||(), @create); } else { - push @create, "COMMIT;\n" unless $no_txn; - return join(";\n\n", @create ); + return join ('', + $head||(), + join(";\n\n", @create ), + ";\n", + ); } } diff --git a/t/48xml-to-sqlite.t b/t/48xml-to-sqlite.t index 60a607a..f1029eb 100644 --- a/t/48xml-to-sqlite.t +++ b/t/48xml-to-sqlite.t @@ -34,8 +34,6 @@ my $sql = $sqlt->translate( ) or die $sqlt->error; eq_or_diff($sql, << "SQL"); - - BEGIN TRANSACTION; DROP TABLE Basic; @@ -92,7 +90,7 @@ my @sql = $sqlt->translate( eq_or_diff(\@sql, [ - "\n\nBEGIN TRANSACTION", + 'BEGIN TRANSACTION', 'DROP TABLE Basic', 'CREATE TABLE Basic ( id INTEGER PRIMARY KEY NOT NULL,