Skip to content

Commit d5ca573

Browse files
committed
add comment for table and column.
1 parent 195d830 commit d5ca573

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Convertor.class.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class Convertor
1717
private $oFh;
1818

1919
private $tableFields = array();
20+
private $comment4Field = array();
21+
private $comment4Table = '';
2022
private $row = array();
2123
private $lastTable = null;
2224
private $lastRow = null;
@@ -131,6 +133,9 @@ private function start($parser, $name, $attrs)
131133
if (isset($attrs['Auto_increment'])) {
132134
$this->setSeqValue($attrs);
133135
}
136+
if (isset($attrs['Comment']) && strlen($attrs['Comment']) > 0) {
137+
$this->comment4Table = $attrs['Comment'];
138+
}
134139
break;
135140
}
136141
}
@@ -186,6 +191,23 @@ private function end($parser, $name)
186191
fwrite($this->oFh, $this->seq);
187192
$this->seq = false;
188193
}
194+
195+
if (count($this->comment4Field)) {
196+
fwrite($this->oFh, "\n");
197+
foreach ($this->comment4Field as $field => $comment) {
198+
$comment_field = sprintf("COMMENT ON COLUMN %s.%s IS '%s';\n",
199+
$this->tableFields['name'], $field, addslashes($comment));
200+
fwrite($this->oFh, $comment_field);
201+
}
202+
}
203+
if ($this->comment4Table) {
204+
fwrite($this->oFh,
205+
sprintf("COMMENT ON TABLE %s IS '%s'\n",
206+
$this->tableFields['name'], addslashes($this->comment4Table)));
207+
}
208+
209+
$this->comment4Field = array();
210+
$this->comment4Table = '';
189211
}
190212
break;
191213
case "table_data":
@@ -326,6 +348,10 @@ private function convert_field_data($attrs)
326348
if ($attrs['Key'] == "PRI") {
327349
$this->tableFields["primary"][] = $attrs['Field'];
328350
}
351+
352+
if (isset($attrs['Comment']) && strlen($attrs['Comment']) > 0) {
353+
$this->comment4Field[$attrs['Field']] = $attrs['Comment'];
354+
}
329355
}
330356
}
331357

0 commit comments

Comments
 (0)