mirror of
https://github.com/moparisthebest/JdbcMapper
synced 2024-12-22 07:18:51 -05:00
Fix case of functions in select statement in SimpleSQLParser
This commit is contained in:
parent
68c1c0482e
commit
f66c8429fb
@ -8,6 +8,7 @@ import java.util.regex.Pattern;
|
||||
public class SimpleSQLParser extends AbstractSQLParser {
|
||||
|
||||
private static final Pattern aliasPattern = Pattern.compile("^.*\\.");
|
||||
private static final Pattern parenPattern = Pattern.compile("\\([^)]+\\)");
|
||||
|
||||
public SimpleSQLParser() {
|
||||
super(null, false);
|
||||
@ -24,7 +25,7 @@ public class SimpleSQLParser extends AbstractSQLParser {
|
||||
final boolean isSelect = sql.startsWith("SELECT");
|
||||
String[] columnNames = null;
|
||||
if (isSelect) {
|
||||
final String columns = sql.substring(sql.indexOf("SELECT") + 6, sql.indexOf("FROM")).trim();
|
||||
final String columns = parenPattern.matcher(sql.substring(sql.indexOf("SELECT") + 6, sql.indexOf("FROM"))).replaceAll("").trim();
|
||||
final String[] splitColumns = columns.split(",");
|
||||
columnNames = new String[splitColumns.length + 1];
|
||||
int index = 0;
|
||||
|
@ -29,6 +29,7 @@ public class SimpleSQLParserTest {
|
||||
"select bob, tom from tom"
|
||||
, "select some_bob bob, some_tom as tom from tom"
|
||||
, "select tom.bob, some_tom as tom from tom"
|
||||
, "select tom.bob, COALESCE(some_tom, 'UNKNOWN') as tom from tom"
|
||||
}) {
|
||||
final SQLParser ret = getFactory().parse(sql);
|
||||
assertTrue(ret.isSelect());
|
||||
|
Loading…
Reference in New Issue
Block a user