Skip to content

Commit 7109d34

Browse files
committed
SqlDocument: toSql() - doesn't print empty line on begin of file
1 parent 2da746d commit 7109d34

8 files changed

Lines changed: 10 additions & 8 deletions

src/SqlDocument.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,16 @@ public function getSqlQueries(IDriver $driver)
4949
public function toSql(IDriver $driver)
5050
{
5151
$output = '';
52+
$first = TRUE;
5253

5354
foreach ($this->statements as $statement) {
54-
$output .= "\n";
55+
if ($first) {
56+
$first = FALSE;
57+
58+
} else {
59+
$output .= "\n";
60+
}
61+
5562
$output .= $statement->toSql($driver);
5663
$output .= "\n";
5764
}

tests/SqlGenerator/SqlDocument.alterTable.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ test(function () {
5555
$contactTable->setComment('Table of contacts.');
5656

5757
Assert::same(implode("\n", array(
58-
'',
5958
'ALTER TABLE `contact`',
6059
"ADD COLUMN `active` TINYINT(1) UNSIGNED NULL DEFAULT 1 COMMENT 'Contact status' AFTER `name`,",
6160
"ADD COLUMN `id` INT NOT NULL AUTO_INCREMENT FIRST,",

tests/SqlGenerator/SqlDocument.command.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ test(function () {
1616
$sql->command('SET NAMES "utf8mb4"');
1717

1818
Assert::same(implode("\n", array(
19-
'',
2019
'SET NAMES "utf8mb4";',
2120
'',
2221
)), $sql->toSql($driver));

tests/SqlGenerator/SqlDocument.comment.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ test(function () {
1717
$sql->comment("\tblock comment #1\nblock comment #2\n\nblock comment #3\n");
1818

1919
Assert::same(implode("\n", array(
20-
'',
2120
'-- inline comment',
2221
'',
2322
'-- block comment #1',

tests/SqlGenerator/SqlDocument.createTable.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ test(function () {
3939
$contactTable->addForeignKey('fk_creator', 'creator_id', 'user', 'id');
4040

4141
Assert::same(implode("\n", array(
42-
'',
4342
'CREATE TABLE `contact` (',
4443
"\t`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,",
4544
"\t`name` VARCHAR(100) NOT NULL COMMENT 'Client name',",

tests/SqlGenerator/SqlDocument.dropTable.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ test(function () {
1414

1515
$sql->dropTable('contact');
1616

17-
Assert::same("\nDROP TABLE `contact`;\n", $sql->toSql($driver));
17+
Assert::same("DROP TABLE `contact`;\n", $sql->toSql($driver));
1818

1919
});

tests/SqlGenerator/SqlDocument.insert.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ test(function () {
2121
));
2222

2323
Assert::same(implode('', array(
24-
"\n",
2524
'INSERT INTO `contact` (',
2625
implode(', ', array(
2726
'`name`',

tests/SqlGenerator/SqlDocument.renameTable.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ test(function () {
1414

1515
$sql->renameTable('contact', 'client');
1616

17-
Assert::same("\nRENAME TABLE `contact` TO `client`;\n", $sql->toSql(new Drivers\MysqlDriver));
17+
Assert::same("RENAME TABLE `contact` TO `client`;\n", $sql->toSql(new Drivers\MysqlDriver));
1818

1919
Assert::exception(function () use ($sql) {
2020

0 commit comments

Comments
 (0)