@@ -93,19 +93,21 @@ public static ClassInfo processTableIntoClassInfo(String tableSql) throws IOExce
9393 //修复表备注为空问题
9494 classComment = tableName ;
9595 }
96-
96+ //如果备注跟;混在一起,需要替换掉
97+ classComment =classComment .replaceAll (";" ,"" );
9798 // field List
9899 List <FieldInfo > fieldList = new ArrayList <FieldInfo >();
99100
100101 // 正常( ) 内的一定是字段相关的定义。
101102 String fieldListTmp = tableSql .substring (tableSql .indexOf ("(" )+1 , tableSql .lastIndexOf (")" ));
102103
103104 // 匹配 comment,替换备注里的小逗号, 防止不小心被当成切割符号切割
104- Matcher matcher = Pattern .compile ("\\ comment ' (.*?)\\ ' " ).matcher (fieldListTmp ); // "\\{(.*?)\\}"
105+ Matcher matcher = Pattern .compile ("\\ comment ` (.*?)\\ ` " ).matcher (fieldListTmp ); // "\\{(.*?)\\}"
105106 while (matcher .find ()){
106107
107108 String commentTmp = matcher .group ();
108- commentTmp = commentTmp .replaceAll ("\\ comment '|\\ '" , "" ); // "\\{|\\}"
109+ //2018-9-27 zhengk 不替换,只处理,支持COMMENT评论里面多种注释
110+ //commentTmp = commentTmp.replaceAll("\\ comment `|\\`", " "); // "\\{|\\}"
109111
110112 if (commentTmp .contains ("," )) {
111113 String commentTmpFinal = commentTmp .replaceAll ("," , "," );
@@ -122,7 +124,7 @@ public static ClassInfo processTableIntoClassInfo(String tableSql) throws IOExce
122124 columnLine = columnLine .replaceAll ("\n " ,"" ).replaceAll ("\t " ,"" ).trim ();
123125 // `userid` int(11) NOT NULL AUTO_INCREMENT COMMENT '用户ID',
124126 // 2018-9-18 zhengk 修改为contains,提升匹配率和匹配不按照规矩出牌的语句
125- if (!columnLine .contains ("constraint" )&&!columnLine .contains ("using" )
127+ if (!columnLine .contains ("constraint" )&&!columnLine .contains ("using" )&&! columnLine . contains ( "unique" )
126128 &&!columnLine .contains ("storage" )&&!columnLine .contains ("pctincrease" )
127129 &&!columnLine .contains ("buffer_pool" )&&!columnLine .contains ("tablespace" )
128130 &&!(columnLine .contains ("primary" )&&i >3 )){
@@ -171,6 +173,10 @@ public static ClassInfo processTableIntoClassInfo(String tableSql) throws IOExce
171173 if (commentTmp .contains ("`" ) || commentTmp .indexOf ("`" )!=commentTmp .lastIndexOf ("`" )) {
172174 commentTmp = commentTmp .substring (commentTmp .indexOf ("`" )+1 , commentTmp .lastIndexOf ("`" ));
173175 }
176+ //解决最后一句是评论,无主键且连着)的问题:album_id int(3) default '1' null comment '相册id:0 代表头像 1代表照片墙')
177+ if (commentTmp .contains (")" )){
178+ commentTmp = commentTmp .substring (0 , commentTmp .lastIndexOf (")" ));
179+ }
174180 fieldComment = commentTmp ;
175181 }else if (tableSql .contains ("comment on column" )&&tableSql .contains ("." +columnName +" is `" )){
176182 //新增对pgsql/oracle的字段备注支持
0 commit comments