@@ -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 ();
@@ -305,18 +305,20 @@ public ClassInfo processTableIntoClassInfo(ParamInfo paramInfo) throws Exception
305305 // 2019-2-22 zhengkai 要在条件中使用复杂的表达式
306306 // 2019-4-29 zhengkai 优化对普通和特殊storage关键字的判断(感谢@AhHeadFloating的反馈 )
307307 // 2020-10-20 zhengkai 优化对fulltext/index关键字的处理(感谢@WEGFan的反馈)
308+ // 2025-12-07 zhengkai 修复对primary key的处理
308309 boolean notSpecialFlag = (
309310 !columnLine .contains ("key " )
310- && !columnLine .contains ("constraint" )
311- && !columnLine .contains (" using " )
312- && !columnLine .contains ("unique " )
313- && !columnLine .contains ("fulltext " )
314- && !columnLine .contains ("index " )
315- && !columnLine .contains ("pctincrease" )
316- && !columnLine .contains ("buffer_pool" )
317- && !columnLine .contains ("tablespace" )
318- && !(columnLine .contains ("primary " ) && columnLine .indexOf ("storage" ) + 3 > columnLine .indexOf ("(" ))
319- && !(columnLine .contains ("primary " ) && i > 3 )
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 ("(" ))
320+ && !(columnLine .toLowerCase ().contains ("primary " ) && i > 3 )
321+ && !columnLine .toLowerCase ().contains ("primary key" )
320322 );
321323
322324 if (notSpecialFlag ) {
@@ -349,7 +351,10 @@ public ClassInfo processTableIntoClassInfo(ParamInfo paramInfo) throws Exception
349351 } else {
350352 fieldName = columnName ;
351353 }
352- columnLine = columnLine .substring (columnLine .indexOf ("`" ) + 1 ).trim ();
354+ // 修复Oracle字段名不带引号的情况
355+ if (columnLine .contains ("`" )) {
356+ columnLine = columnLine .substring (columnLine .indexOf ("`" ) + 1 ).trim ();
357+ }
353358 //2025-03-16 修复由于类型大写导致无法转换的问题
354359 String mysqlType = columnLine .split ("\\ s+" )[1 ].toLowerCase ();
355360 if (mysqlType .contains ("(" )){
@@ -372,23 +377,23 @@ public ClassInfo processTableIntoClassInfo(ParamInfo paramInfo) throws Exception
372377 }
373378 // field comment,MySQL的一般位于field行,而pgsql和oralce多位于后面。
374379 String fieldComment = null ;
375- if (tableSql .contains ("comment on column" ) && (tableSql .contains ("." + columnName + " is " ) || tableSql .contains (".`" + columnName + "` is" ))) {
380+ if (tableSql .toLowerCase (). contains ("comment on column" ) && (tableSql .toLowerCase (). contains ("." + columnName + " is " ) || tableSql . toLowerCase () .contains (".`" + columnName + "` is" ))) {
376381 //新增对pgsql/oracle的字段备注支持
377382 //COMMENT ON COLUMN public.check_info.check_name IS '检查者名称';
378383 //2018-11-22 lshz0088 正则表达式的点号前面应该加上两个反斜杠,否则会认为是任意字符
379384 //2019-4-29 zhengkai 优化对oracle注释comment on column的支持(@liukex)
380- tableSql = tableSql .replaceAll (".`" + columnName + "` is" , "." + columnName + " is" );
381- Matcher columnCommentMatcher = Pattern .compile ("\\ ." + columnName + " is `" ).matcher (tableSql );
385+ tableSql = tableSql .toLowerCase (). replaceAll (".`" + columnName + "` is" , "." + columnName + " is" );
386+ Matcher columnCommentMatcher = Pattern .compile ("\\ ." + columnName + " is `" ).matcher (tableSql . toLowerCase () );
382387 fieldComment = columnName ;
383388 while (columnCommentMatcher .find ()) {
384389 String columnCommentTmp = columnCommentMatcher .group ();
385390 //System.out.println(columnCommentTmp);
386391 fieldComment = tableSql .substring (tableSql .indexOf (columnCommentTmp ) + columnCommentTmp .length ()).trim ();
387392 fieldComment = fieldComment .substring (0 , fieldComment .indexOf ("`" )).trim ();
388393 }
389- } else if (columnLine .contains (" comment" )) {
394+ } else if (columnLine .toLowerCase (). contains (" comment" )) {
390395 //20200518 zhengkai 修复包含comment关键字的问题
391- String commentTmp = columnLine .substring (columnLine .lastIndexOf ("comment" ) + 7 ).trim ();
396+ String commentTmp = columnLine .toLowerCase (). substring (columnLine . toLowerCase () .lastIndexOf ("comment" ) + 7 ).trim ();
392397 // '用户ID',
393398 if (commentTmp .contains ("`" ) || commentTmp .indexOf ("`" ) != commentTmp .lastIndexOf ("`" )) {
394399 commentTmp = commentTmp .substring (commentTmp .indexOf ("`" ) + 1 , commentTmp .lastIndexOf ("`" ));
@@ -398,6 +403,9 @@ public ClassInfo processTableIntoClassInfo(ParamInfo paramInfo) throws Exception
398403 commentTmp = commentTmp .substring (0 , commentTmp .lastIndexOf (")" ) + 1 );
399404 }
400405 fieldComment = commentTmp ;
406+ } else if (columnLine .contains ("--" )) {
407+ // 支持Oracle风格的注释(--)
408+ fieldComment = columnLine .substring (columnLine .indexOf ("--" ) + 2 ).trim ();
401409 } else {
402410 //修复comment不存在导致报错的问题
403411 fieldComment = columnName ;
@@ -416,10 +424,10 @@ public ClassInfo processTableIntoClassInfo(ParamInfo paramInfo) throws Exception
416424 }
417425 }
418426
419- if (fieldList .size () < 1 ) {
427+ if (fieldList .isEmpty () ) {
420428 throw new Exception ("表结构分析失败,请检查语句或者提交issue给我" );
421429 }
422-
430+ //build Class Info
423431 ClassInfo codeJavaInfo = new ClassInfo ();
424432 codeJavaInfo .setTableName (tableName );
425433 codeJavaInfo .setClassName (className );
0 commit comments