diff --git a/main.js b/main.js index dbcfd61..5373cf0 100644 --- a/main.js +++ b/main.js @@ -154,7 +154,7 @@ function loadTemplate(name) case 'basicsql': $('#ta').width(800); $('#leftpanel').show(); - document.getElementById('ta').value = 'SELECT aaa from bbb where ccc="ddd"'; + document.getElementById('ta').value = "SELECT aaa from bbb where ccc='ddd'"; //$('#rightpanel').empty().load('html/basic.html'); $('#rightpanel').empty(); $('#mode').html('SQL'); diff --git a/vkbeautify.js b/vkbeautify.js index 8699885..d963f67 100644 --- a/vkbeautify.js +++ b/vkbeautify.js @@ -36,7 +36,7 @@ function vkbeautify(){ this.shift = ['\n']; // array of shifts //var step = ' ', // 2 spaces - this.step = ' ', // 2 spaces + this.step = ' ', // 2 spaces maxdeep = 100, // nesting level ix = 0; @@ -186,6 +186,10 @@ vkbeautify.prototype.css = function(text) { //---------------------------------------------------------------------------- +function isSubquery(parenthesisLevel, str) { + return parenthesisLevel - (str.replace(/\(/g,'').length - str.replace(/\)/g,'').length ) +} + function split_sql(str) { return str.replace(/\s{1,}/g," ") @@ -201,12 +205,14 @@ function split_sql(str) { .replace(/ INNER\s{1,}JOIN /ig,"~#~INNER JOIN ") .replace(/ LEFT\s{1,}JOIN /ig,"~#~LEFT JOIN ") .replace(/ RIGHT\s{1,}JOIN /ig,"~#~RIGHT JOIN ") - .replace(/ LIKE /ig,"~#~LIKE ") .replace(/ ON /ig,"~#~ON ") .replace(/ OR /ig,"~#~\tOR ") .replace(/ ORDER\s{1,}BY/ig,"~#~ORDER BY ") + //.replace(/\s{0,}SELECT /ig,"~#~SELECT ") - .replace(/\s{0,}SELECT /ig,"~#~SELECT~#~") + //.replace(/\(\s{0,}SELECT /ig," (SELECT ") + .replace(/\(\s{0,}SELECT /ig,"~#~(SELECT ") + .replace(/ UNION /ig,"~#~UNION~#~") .replace(/ USING /ig,"~#~USING ") .replace(/ WHEN /ig,"~#~WHEN ") @@ -214,16 +220,18 @@ function split_sql(str) { .replace(/ WITH /ig,"~#~WITH ") //.replace(/\,\s{0,}\(/ig,",~#~( ") - .replace(/\,/ig,",~#~") + + //.replace(/\,/ig,",~#~") .replace(/ All /ig," ALL ") .replace(/ AS /ig," AS ") .replace(/ ASC /ig," ASC ") .replace(/ DESC /ig," DESC ") - .replace(/ DISTINCT /ig,"\DISTINCT ") + .replace(/ DISTINCT /ig," DISTINCT ") .replace(/ EXISTS /ig," EXISTS ") .replace(/ NOT /ig," NOT ") .replace(/ NULL /ig," NULL ") + .replace(/ LIKE /ig," LIKE ") .replace(/~#~{1,}/g,"~#~") .split('~#~'); @@ -239,7 +247,7 @@ vkbeautify.prototype.sql = function(text) { deep = 0, inComment = true, inQuote = false, - secondTouch = false, + parenthesisLevel = 0, str = '', ix = 0; @@ -254,6 +262,33 @@ vkbeautify.prototype.sql = function(text) { len = ar.length; for(ix=0;ix