Skip to content

Commit 0795ae7

Browse files
committed
Fix table comment of table with options.
1 parent 3dad86e commit 0795ae7

File tree

11 files changed

+33
-11
lines changed

11 files changed

+33
-11
lines changed

.gitattributes

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/.gitattributes export-ignore
2+
/.github/ export-ignore
3+
/.gitignore export-ignore
4+
/build.xml export-ignore
5+
/phpunit.xml export-ignore
6+
/README.md export-ignore
7+
/test/ export-ignore

src/MySqlFix.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,15 @@ public static function fixTableComments(string $source): string
264264
}
265265

266266
// Enhance the column definition with comment.
267-
$lines[$line_number] = mb_substr(rtrim($lines[$line_number]), 0, -1);
268-
$lines[$line_number] .= " COMMENT '".self::escapeMysqlString($comment)."';";
267+
if (mb_substr(rtrim($lines[$line_number]), -1)===';')
268+
{
269+
$lines[$line_number] = mb_substr(rtrim($lines[$line_number]), 0, -1);
270+
$lines[$line_number] .= " COMMENT '".self::escapeMysqlString($comment)."';";
271+
}
272+
else
273+
{
274+
$lines[$line_number] .= " COMMENT '".self::escapeMysqlString($comment)."'";
275+
}
269276
}
270277

271278
return implode(PHP_EOL, $lines);

test/erd/php-erd-concepts.ecm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1433,7 +1433,7 @@
14331433
</INDEXKEYS>
14341434
<BC_SCRIPT></BC_SCRIPT>
14351435
<AC_SCRIPT></AC_SCRIPT>
1436-
<STORAGE></STORAGE>
1436+
<STORAGE>engine=innodb</STORAGE>
14371437
<VARIABLES></VARIABLES>
14381438
</DATA>
14391439
<DATA>

test/source/quoted/php-erd-concepts-create.ddl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ CREATE TABLE `FOO1` (
4242
`c2` VARCHAR(40),
4343
`c3` VARCHAR(40),
4444
CONSTRAINT `PK_FOO1` PRIMARY KEY (`c1`)
45-
);
45+
)
46+
engine=innodb;
4647

4748
/*
4849
COMMENT ON TABLE `FOO1`

test/source/unquoted/php-erd-concepts-create.ddl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ CREATE TABLE FOO1 (
4242
c2 VARCHAR(40),
4343
c3 VARCHAR(40),
4444
CONSTRAINT PK_FOO1 PRIMARY KEY (c1)
45-
);
45+
)
46+
engine=innodb;
4647

4748
/*
4849
COMMENT ON TABLE FOO1

test/template/quoted/column.ddl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ CREATE TABLE `FOO1` (
4242
`c2` VARCHAR(40) COMMENT 'Column 2.',
4343
`c3` VARCHAR(40) COMMENT 'Column 3.',
4444
CONSTRAINT `PK_FOO1` PRIMARY KEY (`c1`)
45-
);
45+
)
46+
engine=innodb;
4647

4748
/*
4849
COMMENT ON TABLE `FOO1`

test/template/quoted/index.ddl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ CREATE TABLE `FOO1` (
4242
`c2` VARCHAR(40),
4343
`c3` VARCHAR(40),
4444
CONSTRAINT `PK_FOO1` PRIMARY KEY (`c1`)
45-
);
45+
)
46+
engine=innodb;
4647

4748
/*
4849
COMMENT ON TABLE `FOO1`

test/template/quoted/table.ddl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ CREATE TABLE `FOO1` (
4444
`c2` VARCHAR(40),
4545
`c3` VARCHAR(40),
4646
CONSTRAINT `PK_FOO1` PRIMARY KEY (`c1`)
47-
) COMMENT 'This is table FOO1.';
47+
) COMMENT 'This is table FOO1.'
48+
engine=innodb;
4849

4950
/*
5051
COMMENT ON TABLE `FOO1`

test/template/unquoted/column.ddl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ CREATE TABLE FOO1 (
4242
c2 VARCHAR(40) COMMENT 'Column 2.',
4343
c3 VARCHAR(40) COMMENT 'Column 3.',
4444
CONSTRAINT PK_FOO1 PRIMARY KEY (c1)
45-
);
45+
)
46+
engine=innodb;
4647

4748
/*
4849
COMMENT ON TABLE FOO1

test/template/unquoted/index.ddl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ CREATE TABLE FOO1 (
4242
c2 VARCHAR(40),
4343
c3 VARCHAR(40),
4444
CONSTRAINT PK_FOO1 PRIMARY KEY (c1)
45-
);
45+
)
46+
engine=innodb;
4647

4748
/*
4849
COMMENT ON TABLE FOO1

0 commit comments

Comments
 (0)