コミットメタ情報

リビジョン8dd566916e71760f4d5ca727c40d3aa245d475ab (tree)
日時2013-05-25 09:07:14
作者argius <argius.net@gmai...>
コミッターargius

ログメッセージ

refactoring: separate addCommas from generateUpdateOrInsertPhrase (and apply to where phrase)

変更サマリ

差分

--- a/src/net/argius/stew/ui/window/DatabaseInfoTree.java
+++ b/src/net/argius/stew/ui/window/DatabaseInfoTree.java
@@ -96,7 +96,7 @@ final class DatabaseInfoTree extends JTree implements AnyActionListener, TextSea
9696 }
9797 final String phrase = generateEquivalentJoinClause(columnNodes);
9898 if (phrase.length() > 0) {
99- insertTextIntoTextArea(phrase);
99+ insertTextIntoTextArea(addCommas(phrase));
100100 }
101101 } else if (ev.isAnyOf(generateSelectPhrase)) {
102102 final String phrase = generateSelectPhrase(getSelectionNodes());
@@ -109,7 +109,7 @@ final class DatabaseInfoTree extends JTree implements AnyActionListener, TextSea
109109 final String phrase = generateUpdateOrInsertPhrase(getSelectionNodes(), isInsert);
110110 if (phrase.length() > 0) {
111111 if (isInsert) {
112- insertTextIntoTextArea(phrase);
112+ insertTextIntoTextArea(addCommas(phrase));
113113 } else {
114114 insertTextIntoTextArea(phrase + " WHERE ");
115115 }
@@ -208,6 +208,19 @@ final class DatabaseInfoTree extends JTree implements AnyActionListener, TextSea
208208 }
209209 }
210210
211+ private static String addCommas(String phrase) {
212+ int c = 0;
213+ for (final char ch : phrase.toCharArray()) {
214+ if (ch == '?') {
215+ ++c;
216+ }
217+ }
218+ if (c >= 2) {
219+ return String.format("%s;%s", phrase, join(",", nCopies(c, "")));
220+ }
221+ return phrase;
222+ }
223+
211224 static String generateEquivalentJoinClause(List<ColumnNode> nodes) {
212225 if (nodes.isEmpty()) {
213226 return "";
@@ -243,7 +256,7 @@ final class DatabaseInfoTree extends JTree implements AnyActionListener, TextSea
243256 }
244257 expressions.addAll(expressions2);
245258 }
246- return String.format("%s;", join(" AND ", expressions));
259+ return String.format("%s", join(" AND ", expressions));
247260 }
248261
249262 static String generateSelectPhrase(List<TreeNode> nodes) {
@@ -338,11 +351,10 @@ final class DatabaseInfoTree extends JTree implements AnyActionListener, TextSea
338351 final String phrase;
339352 if (isInsert) {
340353 final int columnCount = columnsInTable.size();
341- phrase = String.format("INSERT INTO %s (%s) VALUES (%s);%s",
354+ phrase = String.format("INSERT INTO %s (%s) VALUES (%s)",
342355 tableName,
343356 join(",", columnsInTable),
344- join(",", nCopies(columnCount, "?")),
345- join(",", nCopies(columnCount, "")));
357+ join(",", nCopies(columnCount, "?")));
346358 } else {
347359 List<String> columnExpressions = new ArrayList<String>();
348360 for (final String columnName : columnsInTable) {
旧リポジトリブラウザで表示