聂秋秋 2020-04-18 21:14:28 +08:00
parent 723514f4cc
commit 2702ad909f
2 changed files with 8 additions and 4 deletions

View File

@ -89,11 +89,9 @@ public final class TableNameParser {
if (isFromToken(currentToken)) {
processFromToken(tokens, index);
} else if (shouldProcess(currentToken)) {
String nextToken = tokens[index++];
considerInclusion(nextToken);
if (moreTokens(tokens, index)) {
nextToken = tokens[index++];
String nextToken = tokens[index++];
considerInclusion(nextToken);
}
}
}

View File

@ -476,6 +476,12 @@ public class TableNameParserTest {
String sql = "select * -- I like stars \n from foo f -- I like foo \n join bar b -- I also like bar \n on f.id = b.id -- comment ending with update";
assertThat(new TableNameParser(sql).tables()).isEqualTo(asSet("foo","bar"));
}
@Test
void testSelectForUpdate() {
//TODO 暂时解决不能使用的问题,当碰到for update nowait这样的,后面的nowait会被当做成表但也不是很影响苗老板的动态表过滤.
assertThat(new TableNameParser("select * from mp where id = 1 for update").tables()).isEqualTo(asSet("mp"));
}
private static Collection<String> asSet(String... a) {
Set<String> result = new HashSet<String>();