Skip to content

Commit 1998225

Browse files
committed
2025-12-07 zhengkai 修复COMMENT、COMMENT ON的处理
1 parent fc44cd8 commit 1998225

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/main/java/com/softdev/system/generator/service/impl/parser/SqlParserServiceImpl.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,11 @@ public ClassInfo processTableIntoClassInfo(ParamInfo paramInfo) throws Exception
233233
String classComment = null;
234234
//mysql是comment=,pgsql/oracle是comment on table,
235235
//2020-05-25 优化表备注的获取逻辑
236-
if (tableSql.contains("comment=") || tableSql.contains("comment on table")) {
237-
int ix = tableSql.lastIndexOf("comment=");
236+
if (tableSql.toLowerCase().contains("comment=") || tableSql.toLowerCase().contains("comment on table")) {
237+
int ix = tableSql.toLowerCase().lastIndexOf("comment=");
238238
String classCommentTmp = (ix > -1) ?
239239
tableSql.substring(ix + 8).trim() :
240-
tableSql.substring(tableSql.lastIndexOf("comment on table") + 17).trim();
240+
tableSql.substring(tableSql.toLowerCase().lastIndexOf("comment on table") + 17).trim();
241241
if (classCommentTmp.contains("`")) {
242242
classCommentTmp = classCommentTmp.substring(classCommentTmp.indexOf("`") + 1);
243243
classCommentTmp = classCommentTmp.substring(0, classCommentTmp.indexOf("`"));
@@ -256,11 +256,11 @@ public ClassInfo processTableIntoClassInfo(ParamInfo paramInfo) throws Exception
256256
List<FieldInfo> fieldList = new ArrayList<FieldInfo>();
257257

258258
// 正常( ) 内的一定是字段相关的定义。
259-
String fieldListTmp = tableSql.substring(tableSql.indexOf("(") + 1, tableSql.lastIndexOf(")"));
259+
String fieldListTmp = tableSql.substring(tableSql.indexOf("(") + 1, tableSql.lastIndexOf(")")).trim();
260260

261261
// 匹配 comment,替换备注里的小逗号, 防止不小心被当成切割符号切割
262262
String commentPattenStr1 = "comment `(.*?)\\`";
263-
Matcher matcher1 = Pattern.compile(commentPattenStr1).matcher(fieldListTmp);
263+
Matcher matcher1 = Pattern.compile(commentPattenStr1).matcher(fieldListTmp.toLowerCase());
264264
while (matcher1.find()) {
265265

266266
String commentTmp = matcher1.group();
@@ -308,15 +308,15 @@ public ClassInfo processTableIntoClassInfo(ParamInfo paramInfo) throws Exception
308308
// 2025-12-07 zhengkai 修复对primary key的处理
309309
boolean notSpecialFlag = (
310310
!columnLine.contains("key ")
311-
&& !columnLine.contains("constraint")
312-
&& !columnLine.contains(" using ")
313-
&& !columnLine.contains("unique ")
314-
&& !columnLine.contains("fulltext ")
315-
&& !columnLine.contains("index ")
316-
&& !columnLine.contains("pctincrease")
317-
&& !columnLine.contains("buffer_pool")
318-
&& !columnLine.contains("tablespace")
319-
&& !(columnLine.contains("primary ") && columnLine.indexOf("storage") + 3 > columnLine.indexOf("("))
311+
&& !columnLine.toLowerCase().contains("constraint")
312+
&& !columnLine.toLowerCase().contains(" using ")
313+
&& !columnLine.toLowerCase().contains("unique ")
314+
&& !columnLine.toLowerCase().contains("fulltext ")
315+
&& !columnLine.toLowerCase().contains("index ")
316+
&& !columnLine.toLowerCase().contains("pctincrease")
317+
&& !columnLine.toLowerCase().contains("buffer_pool")
318+
&& !columnLine.toLowerCase().contains("tablespace")
319+
&& !(columnLine.toLowerCase().contains("primary ") && columnLine.indexOf("storage") + 3 > columnLine.indexOf("("))
320320
&& !(columnLine.toLowerCase().contains("primary ") && i > 3)
321321
&& !columnLine.toLowerCase().contains("primary key")
322322
);
@@ -374,23 +374,23 @@ public ClassInfo processTableIntoClassInfo(ParamInfo paramInfo) throws Exception
374374
}
375375
// field comment,MySQL的一般位于field行,而pgsql和oralce多位于后面。
376376
String fieldComment = null;
377-
if (tableSql.contains("comment on column") && (tableSql.contains("." + columnName + " is ") || tableSql.contains(".`" + columnName + "` is"))) {
377+
if (tableSql.toLowerCase().contains("comment on column") && (tableSql.toLowerCase().contains("." + columnName + " is ") || tableSql.toLowerCase().contains(".`" + columnName + "` is"))) {
378378
//新增对pgsql/oracle的字段备注支持
379379
//COMMENT ON COLUMN public.check_info.check_name IS '检查者名称';
380380
//2018-11-22 lshz0088 正则表达式的点号前面应该加上两个反斜杠,否则会认为是任意字符
381381
//2019-4-29 zhengkai 优化对oracle注释comment on column的支持(@liukex)
382-
tableSql = tableSql.replaceAll(".`" + columnName + "` is", "." + columnName + " is");
383-
Matcher columnCommentMatcher = Pattern.compile("\\." + columnName + " is `").matcher(tableSql);
382+
tableSql = tableSql.toLowerCase().replaceAll(".`" + columnName + "` is", "." + columnName + " is");
383+
Matcher columnCommentMatcher = Pattern.compile("\\." + columnName + " is `").matcher(tableSql.toLowerCase());
384384
fieldComment = columnName;
385385
while (columnCommentMatcher.find()) {
386386
String columnCommentTmp = columnCommentMatcher.group();
387387
//System.out.println(columnCommentTmp);
388388
fieldComment = tableSql.substring(tableSql.indexOf(columnCommentTmp) + columnCommentTmp.length()).trim();
389389
fieldComment = fieldComment.substring(0, fieldComment.indexOf("`")).trim();
390390
}
391-
} else if (columnLine.contains(" comment")) {
391+
} else if (columnLine.toLowerCase().contains(" comment")) {
392392
//20200518 zhengkai 修复包含comment关键字的问题
393-
String commentTmp = columnLine.substring(columnLine.lastIndexOf("comment") + 7).trim();
393+
String commentTmp = columnLine.toLowerCase().substring(columnLine.toLowerCase().lastIndexOf("comment") + 7).trim();
394394
// '用户ID',
395395
if (commentTmp.contains("`") || commentTmp.indexOf("`") != commentTmp.lastIndexOf("`")) {
396396
commentTmp = commentTmp.substring(commentTmp.indexOf("`") + 1, commentTmp.lastIndexOf("`"));

0 commit comments

Comments
 (0)