|
|
|
@ -1,5 +1,6 @@
@@ -1,5 +1,6 @@
|
|
|
|
|
package com.moparisthebest.jdbc.codegen; |
|
|
|
|
|
|
|
|
|
import java.util.regex.Matcher; |
|
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -9,6 +10,7 @@ public class SimpleSQLParser extends AbstractSQLParser {
@@ -9,6 +10,7 @@ public class SimpleSQLParser extends AbstractSQLParser {
|
|
|
|
|
|
|
|
|
|
private static final Pattern aliasPattern = Pattern.compile("^.*\\."); |
|
|
|
|
private static final Pattern parenPattern = Pattern.compile("\\([^)]+\\)"); |
|
|
|
|
private static final Pattern fromPattern = Pattern.compile("\\s+FROM\\s+"); |
|
|
|
|
|
|
|
|
|
public SimpleSQLParser() { |
|
|
|
|
super(null, false); |
|
|
|
@ -30,7 +32,9 @@ public class SimpleSQLParser extends AbstractSQLParser {
@@ -30,7 +32,9 @@ public class SimpleSQLParser extends AbstractSQLParser {
|
|
|
|
|
// (SELECT some_column from some_table where other_column = 'YAY') as tom -> () as tom
|
|
|
|
|
sql = parenPattern.matcher(sql).replaceAll("()").trim(); |
|
|
|
|
// 6 is length of "SELECT" which we already verified it starts with...
|
|
|
|
|
final String columns = sql.substring(6, sql.indexOf("FROM")); |
|
|
|
|
final Matcher fromMatcher = fromPattern.matcher(sql); |
|
|
|
|
// is a SELECT without a FROM valid? I guess maybe...
|
|
|
|
|
final String columns = sql.substring(6, fromMatcher.find() ? fromMatcher.start() : sql.length()); |
|
|
|
|
final String[] splitColumns = columns.split(","); |
|
|
|
|
columnNames = new String[splitColumns.length + 1]; |
|
|
|
|
int index = 0; |
|
|
|
|