From 1946cc242ba2fea84cee725a66089d500cb695d9 Mon Sep 17 00:00:00 2001 From: Vadim Kiryukhin Date: Sat, 25 Feb 2012 22:40:59 -0800 Subject: [PATCH] commit before subquery_check() function is implemented --- vkbeautify.js | 139 ++++---------------------------------------------- 1 file changed, 9 insertions(+), 130 deletions(-) diff --git a/vkbeautify.js b/vkbeautify.js index fd7dbc4..8699885 100644 --- a/vkbeautify.js +++ b/vkbeautify.js @@ -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 ") @@ -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 ") @@ -233,48 +227,6 @@ 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) { @@ -282,71 +234,15 @@ 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