Skip to content

Commit

Permalink
commit before subquery_check() function is implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
vkiryukhin committed Feb 26, 2012
1 parent 59812ca commit 1946cc2
Showing 1 changed file with 9 additions and 130 deletions.
139 changes: 9 additions & 130 deletions vkbeautify.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,11 @@ vkbeautify.prototype.css = function(text) {
return str.replace(/^\n{1,}/,'');
}

//----------------------------------------------------------------------------

function split_sql(str) {

return str.replace(/\s{1,}/g," ")
//.replace(/~#~/g," ")
//.replace(/\,/ig,",~#~")

.replace(/ AND /ig,"~#~\tAND ")
.replace(/ BETWEEN /ig,"~#~BETWEEN ")
.replace(/ CASE /ig,"~#~CASE ")
Expand All @@ -206,21 +205,16 @@ function split_sql(str) {
.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 ")
.replace(/ WHERE /ig,"~#~WHERE ")
.replace(/ WITH /ig,"~#~WITH ")

.replace(/\,\s{0,}\(/ig,",~#~( ")
//.replace(/\,/ig,",~#~")
//.replace(/ \)\s{0,}\,/ig,"),\n ")
//.replace(/\)/ig,")~#~ ")
//.replace(/\'/ig,"~#~\'")
//.replace(/\,\s{0,}\(/ig,",~#~( ")
.replace(/\,/ig,",~#~")

.replace(/ All /ig," ALL ")
.replace(/ AS /ig," AS ")
Expand All @@ -233,120 +227,22 @@ function split_sql(str) {

.replace(/~#~{1,}/g,"~#~")
.split('~#~');

/*
return str.replace(/\s{1,}/g," ")
//.replace(/~#~/g," ")
.replace(/ AND /ig,"\nAND ")
.replace(/ BETWEEN /ig,"\nBETWEEN ")
.replace(/ CASE /ig,"\nCASE ")
.replace(/ FROM /ig,"\nFROM ")
.replace(/ GROUP \s{1,}BY/ig,"\nGROUP BY ")
.replace(/ HAVING /ig,"\nHAVING ")
.replace(/ IN /ig,"\nIN ")
.replace(/ JOIN /ig,"\nJOIN ")
.replace(/ CROSS\s{1,}JOIN /ig,"\nCROSS JOIN ")
.replace(/ INNER\s{1,}JOIN /ig,"\nINNER JOIN ")
.replace(/ LEFT\s{1,}JOIN /ig,"\nLEFT JOIN ")
.replace(/ RIGHT\s{1,}JOIN /ig,"\nRIGHT JOIN ")
.replace(/ LIKE /ig,"\LIKE ")
.replace(/ ON /ig,"\nON ")
.replace(/ OR /ig,"\nOR ")
.replace(/ ORDER\s{1,}BY/ig,"\nORDER BY ")
.replace(/\s{0,}SELECT /ig,"\nSELECT ")
.replace(/ USING /ig,"\nUSING ")
.replace(/ WHEN /ig,"\nWHEN ")
.replace(/ WHERE /ig,"\nWHERE ")
.replace(/ WITH /ig,"\nWITH ")
.replace(/\,\s{0,}\(/ig,",\n( ")
//.replace(/ \)\s{0,}\,/ig,"),\n ")
.replace(/\)/ig,")\n ")
//.replace(/\'/ig,"~#~\'")
.replace(/ DISTINCT /ig,"\DISTINCT ")
.replace(/ NOT /ig," NOT ")
.replace(/ NULL /ig," NULL ")
.replace(/ All /ig," ALL ")
.replace(/ AS /ig," AS ")
.replace(/ EXISTS /ig," EXISTS ")
.replace(/ ASC /ig," ASC ")
.replace(/ DESC /ig," DESC ")
.replace(/\n{1,}/g,"\n");
*/
}

vkbeautify.prototype.sql = function(text) {

var ar_by_quote = text.replace(/\s{1,}/g," ")
.replace(/\'/ig,"~#~\'")
.split('~#~'),
/*
var ar = text.replace(/\s{1,}/g," ")
//.replace(/~#~/g," ")
//.replace(/\,/ig,",~#~")
.replace(/ AND /ig,"~#~\tAND ")
.replace(/ BETWEEN /ig,"~#~BETWEEN ")
.replace(/ CASE /ig,"~#~CASE ")
.replace(/ FROM /ig,"~#~FROM ")
.replace(/ GROUP\s{1,}BY/ig,"~#~GROUP BY ")
.replace(/ HAVING /ig,"~#~HAVING ")
.replace(/ IN /ig,"~#~IN ")
.replace(/ JOIN /ig,"~#~JOIN ")
.replace(/ CROSS\s{1,}JOIN /ig,"~#~CROSS JOIN ")
.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(/ UNION /ig,"~#~UNION~#~")
.replace(/ USING /ig,"~#~USING ")
.replace(/ WHEN /ig,"~#~WHEN ")
.replace(/ WHERE /ig,"~#~WHERE ")
.replace(/ WITH /ig,"~#~WITH ")
//.replace(/\,\s{0,}\(/ig,",~#~( ")
//.replace(/\,/ig,",~#~")
//.replace(/ \)\s{0,}\,/ig,"),\n ")
//.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(/ EXISTS /ig," EXISTS ")
.replace(/ NOT /ig," NOT ")
.replace(/ NULL /ig," NULL ")
.replace(/~#~{1,}/g,"~#~")
.split('~#~'),
*/
len = ar_by_quote.length,
//len = ar.length,
ar = [],
deep = 0,
inComment = true,
inQuote = false,
secondTouch = false,
str = '',
ix = 0;
/*
if( /\'/.exec(ar_by_quote[ix]) && inQuote ) {
str += ar_by_quote[ix];
inQuote = inQuote ? false : true;
} else {
str += replace_sql(ar_by_quote[ix]);
}
*/

for(ix=0;ix<len;ix++) {
if(ix%2) {
ar = ar.concat(ar_by_quote[ix]);
Expand All @@ -359,34 +255,18 @@ vkbeautify.prototype.sql = function(text) {
for(ix=0;ix<len;ix++) {

if( /SELECT/.exec(ar[ix])) {

str += this.shift[deep++]+ar[ix];
//deep++;
secondTouch = true;
} else
if( /FROM/.exec(ar[ix])) {
str += this.shift[--deep]+ar[ix];
} else
if( /\'/.exec(ar[ix]) ) {
//inComment = inComment ? false : true;

str += ar[ix];

}
else {
str += this.shift[deep]+ar[ix];
}
/*
if( /\'/.exec(ar[ix]) && inComment ) {
str += ar[ix];
inComment = inComment ? false : true;
} else
if( /\'/.exec(ar[ix]) && inComment ) {
str += ar[ix];
inComment = inComment ? false : true;
} else {
str += replace_sql(ar[ix]);
}
*/
}

str = str.replace(/^\n{1,}/,'')/*.replace(/\n[ \t]{0,}/g,"\n");*/.replace(/\n{1,}/g,"\n");
Expand Down Expand Up @@ -429,7 +309,6 @@ vkbeautify.prototype.cssmin = function(text, preserveComments) {
}

vkbeautify.prototype.sqlmin = function(text) {
//return text.replace(/\s{1,}/g," ");
return text.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")");
}

Expand Down

0 comments on commit 1946cc2

Please sign in to comment.