• R/O
  • SSH
  • HTTPS

format-sql: Commit


Commit MetaInfo

Revision77 (tree)
Time2019-01-23 19:59:51
Authorkimur058

Log Message

case文の整形不備を修正

Change Summary

Incremental Difference

--- trunk/DMLBreaker3.x/DMLBreaker.js (revision 76)
+++ trunk/DMLBreaker3.x/DMLBreaker.js (revision 77)
@@ -17,6 +17,8 @@
1717 var tab = "";
1818 // 括弧の未完回数
1919 var parenthesis = 0;
20+// CASE句の未完回数
21+var caseCount = 0;
2022 // BETWEEN句の発生フラグ
2123 var betweenFlg = false;
2224 // UNION句の発生フラグ
@@ -59,6 +61,7 @@
5961 endNo = 0;
6062 tab = "";
6163 parenthesis = 0;
64+ caseCount = 0;
6265 betweenFlg = false;
6366 unionFlg = false;
6467 }
@@ -199,6 +202,8 @@
199202 wkSql = wkSql.replace(/ or\(/g, " or (");
200203 wkSql = wkSql.replace(/ and\(/g, " and (");
201204
205+ //console.log(wkSql);
206+
202207 // SELECT
203208 if (wkSql.match(/^select /i) != null || wkSql.match(/^with .*select /i) != null) {
204209
@@ -932,6 +937,7 @@
932937 formatSql += wkAdd;
933938 wkAdd = "";
934939 tab = tab.concat("\t");
940+ caseCount++;
935941
936942 } else if (wkAdd.match(/ when | else /i) != null) {
937943
@@ -938,12 +944,13 @@
938944 formatSql += wkAdd.substring(0, wkAdd.length - 6) + "\n\t" + tab + wkAdd.slice(-6);
939945 wkAdd = "";
940946
941- } else if (wkAdd.match(/ end |^end |\tend | end\r| end\n| end | end\(/i) != null) {
947+ } else if (caseCount > 0 && wkAdd.match(/ end|^end|\tend/i) != null) {
942948
943- var len = wkAdd.match(/^end /i) != null ? -4 : -5;
949+ var len = wkAdd.match(/^end/i) != null ? -3 : -4;
944950 formatSql += wkAdd.substring(0, wkAdd.length + len) + "\n\t" + tab + wkAdd.slice(len);
945951 wkAdd = "";
946952 tab = tab.replace("\t", "");
953+ caseCount--;
947954 }
948955
949956 return formatSql;
Show on old repository browser