• R/O
  • SSH
  • HTTPS

format-sql: Commit


Commit MetaInfo

Revision68 (tree)
Time2018-08-25 20:19:21
Authorkimur058

Log Message

with句を対応

Change Summary

Incremental Difference

--- trunk/DMLBreaker3.x/DMLBreaker.js (revision 67)
+++ trunk/DMLBreaker3.x/DMLBreaker.js (revision 68)
@@ -119,7 +119,7 @@
119119 formatResult = formatResult.replace(/'[^']*'|"[^"]*"/g, "__QUOTATION__");
120120
121121 // 整形対象の文字列を退避してから変換
122- var regExp = new RegExp("__LF__ *(select|insert|update|delete)[ _][^;]*;", "gi");
122+ var regExp = new RegExp("__LF__ *(select|insert|update|delete|with)[ _][^;]*;", "gi");
123123 var formatArray = formatResult.match(regExp);
124124 formatResult = formatResult.replace(regExp, "__LF____FORMAT__");
125125
@@ -198,7 +198,7 @@
198198 wkSql = wkSql.replace(/ and\(/g, " and (");
199199
200200 // SELECT
201- if (wkSql.match(/^select /i) != null) {
201+ if (wkSql.match(/^select /i) != null || wkSql.match(/^with .*select /i) != null) {
202202
203203 while (true) {
204204
@@ -324,6 +324,7 @@
324324 function formatSelect() {
325325
326326 var formatSql = "";
327+ var withFlg = false;
327328
328329 unionFlg = false;
329330
@@ -337,6 +338,12 @@
337338 formatSql = wkSql.substring(startNo, startNo + 6) + "\n\t" + tab;
338339 startNo += 7;
339340
341+ } else if (wkSql.substring(startNo).match(/^with /i) != null) {
342+
343+ formatSql = wkSql.substring(startNo, startNo + 4) + "\n\t" + tab;
344+ startNo += 5;
345+ withFlg = true;
346+
340347 } else {
341348
342349 formatSql = "\t";
@@ -434,9 +441,12 @@
434441
435442 var parenthesis_bk = parenthesis;
436443
444+ if (parenthesis > 0 || !withFlg) {
445+ tab = tab.concat("\t");
446+ }
447+
437448 startNo = i - 6;
438449 parenthesis = 0;
439- tab = tab.concat("\t");
440450 formatSql += wkAdd.substring(0, wkAdd.length - 7) + "\n" + tab;
441451 wkAdd = "";
442452
@@ -583,7 +593,6 @@
583593 wkAdd = "";
584594
585595 if (parenthesis == 0) {
586-
587596 formatSql += "\n" + tab;
588597 }
589598
Show on old repository browser