mirror of
https://github.com/Wisser/Jailer.git
synced 2026-05-24 11:39:31 -05:00
Analysis of arbitrary queries for WhereConditionEditor
This commit is contained in:
@@ -928,8 +928,8 @@ public abstract class SQLConsole extends javax.swing.JPanel {
|
||||
Map<Table, Integer> tableOrd = new HashMap<Table, Integer>();
|
||||
int nextOrd = 0;
|
||||
for (int i = 0; i < metaData.getColumnCount(); ++i) {
|
||||
String columnLabel = metaData.getColumnLabel(i + 1);
|
||||
if (columnLabel == null || columnLabel.matches("\\s*|\\?column\\?")) {
|
||||
String columnLabel = metaData.getColumnLabel(i + 1).replaceAll("\\s+", " ").replaceFirst("^(.{64}).+$", "$1...");
|
||||
if (columnLabel == null || columnLabel.matches("(?is:\\s*|\\?column\\?|(^\\(*select\\b.*))")) {
|
||||
if (sqlColumnExpression.containsKey(i)) {
|
||||
columnLabel = sqlColumnExpression.get(i);
|
||||
}
|
||||
@@ -940,7 +940,7 @@ public abstract class SQLConsole extends javax.swing.JPanel {
|
||||
}
|
||||
String type = column.toSQL("").substring(column.name.length()).trim();
|
||||
if (tabPerIndex.isEmpty()) {
|
||||
columnLabels[i] = "<html><b>" + columnLabel + "</b><br><font color=\"#808080\">" + type + "</font></html>";
|
||||
columnLabels[i] = "<html><nobr><b>" + columnLabel + "</b><br><font color=\"#808080\">" + type + "</font></html>";
|
||||
} else {
|
||||
String bgColor = "0066ff";
|
||||
Table table = tabPerIndex.get(i);
|
||||
@@ -963,7 +963,7 @@ public abstract class SQLConsole extends javax.swing.JPanel {
|
||||
} else {
|
||||
columnLabel = UIUtil.toHTMLFragment(columnLabel, 128).replaceFirst("<br>$", "");
|
||||
}
|
||||
columnLabels[i] = "<html><font color=\"#" + bgColor + "\">" + titel + "</font><br><b>" + columnLabel + "</b><br><font color=\"#808080\">" + type + "</font></html>";
|
||||
columnLabels[i] = "<html><nobr><font color=\"#" + bgColor + "\">" + titel + "</font><br><b>" + columnLabel + "</b><br><font color=\"#808080\">" + type + "</font></html>";
|
||||
}
|
||||
}
|
||||
final List<Table> resultTypes = nfResultTypes;
|
||||
|
||||
@@ -163,7 +163,7 @@ public class WCTypeAnalyser {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Result [table=" + table + ", Columns=" + table.getColumns() + ", hasCondition=" + hasCondition + ", isHaving=" + isHaving
|
||||
+ ", conditionStart=" + conditionStart + ", conditionEnd=" + conditionEnd + "]";
|
||||
+ ", conditionStart=" + conditionStart + ", conditionEnd=" + conditionEnd + ", Cond=" + table.getName().substring(conditionStart, conditionEnd) + ", Length=" + table.getName().length() + "]";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,6 +275,18 @@ public class WCTypeAnalyser {
|
||||
if (pos == null) {
|
||||
pos = findFragment(sql, topLevelSql);
|
||||
}
|
||||
if (pos == null) {
|
||||
pos = findFragment((result.isHaving? "having " : "where ") + sql, topLevelSql);
|
||||
if (pos != null) {
|
||||
Pattern p = Pattern.compile("^(" + (result.isHaving? "having" : "where") + "\\s+)", Pattern.CASE_INSENSITIVE);
|
||||
Matcher matcher = p.matcher(topLevelSql.substring(pos.a, pos.b));
|
||||
if (matcher.find()) {
|
||||
pos = new Pair<Integer, Integer>(pos.a + matcher.end(), pos.b);
|
||||
} else {
|
||||
pos = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pos != null) {
|
||||
result.conditionStart = pos.a;
|
||||
@@ -431,7 +443,7 @@ public class WCTypeAnalyser {
|
||||
}
|
||||
|
||||
private static String createTopLevelSQL(String sqlSelect) {
|
||||
StringBuilder result = new StringBuilder(SqlUtil.removeCommentsAndLiterals(sqlSelect));
|
||||
StringBuilder result = new StringBuilder(SqlUtil.removeComments(sqlSelect));
|
||||
|
||||
int level = 0;
|
||||
for (int i = 0; i < result.length(); ++i) {
|
||||
|
||||
Reference in New Issue
Block a user