Skip to content

Commit

Permalink
show FK columns in table details view, don't count comments in SQL cons.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wisser committed Aug 18, 2023
1 parent 7e09160 commit 8b1573a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;

import javax.swing.DefaultComboBoxModel;
Expand Down Expand Up @@ -89,9 +91,25 @@ public TableDetailsView(final Table table, final MDTable mdTable, final MetaData
commentLabel.setVisible(false);
}

Set<Column> fks = new HashSet<>();

table.associations.forEach(a -> {
a.createSourceToDestinationKeyMapping().keySet().forEach(c -> fks.add(c));
});

renderConsumer = new HashMap<String, Consumer<JLabel>>();
table.getColumns().forEach(c -> { if (c.name != null) { renderConsumer.put(Quoting.staticUnquote(c.name), label -> label.setIcon(emptyIcon)); }});
if (table.primaryKey != null) {
fks.forEach(c -> {
if (c.name != null) {
renderConsumer.put(c.name,
label -> {
label.setForeground(Color.blue);
label.setIcon(emptyIcon);
}
);
}
});
if (table.primaryKey != null) {
table.primaryKey.getColumns().forEach(c -> {
if (c.name != null) {
renderConsumer.put(c.name,
Expand Down Expand Up @@ -301,6 +319,8 @@ public int compare(Column o1, Column o2) {

if (isPk) {
label.setForeground(Color.red);
} else if (fks.contains(column)) {
label.setForeground(Color.blue);
}

label.setText(Quoting.staticUnquote(column.name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1081,10 +1081,7 @@ private void executeSQL(final String sql, final Status status, int statementStar
resetAutoCommitConnection = connection;
}
}
status.numStatements++;
localStatus.numStatements++;
UISettings.s3++;
status.updateView(false);
status.updateView(false);
statement = connection.createStatement();
if (session.dbms != null) {
Object limit = limitComboBox.getSelectedItem();
Expand All @@ -1105,6 +1102,11 @@ private void executeSQL(final String sql, final Status status, int statementStar
.replaceAll("((?:\\n(?: |\\t|\\r)*?)) ?\\\\([ \\t\\r]*)(?=\\n)", "$1");
sqlStatement = sqlPlusSupport.replaceVariables(sqlStatement, positionOffsets);
status.statement = sqlStatement;
if (!isCommentOnly(sqlStatement)) {
status.numStatements++;
localStatus.numStatements++;
UISettings.s3++;
}
boolean loadButtonIsVisible = true;
boolean hasResultSet;
boolean hasUpdateCount = true;
Expand Down Expand Up @@ -1915,7 +1917,6 @@ public void run() {
}
status.failed = true;
status.error = error;
status.numStatements--;
}
if (error instanceof CancellationException) {
status.cancelled = true;
Expand Down

0 comments on commit 8b1573a

Please sign in to comment.