From acfa3a3bac3aa09d1bda4a2ac172a8377fabe644 Mon Sep 17 00:00:00 2001 From: Vadim Kiryukhin Date: Wed, 29 Feb 2012 23:31:03 -0800 Subject: [PATCH] set ver 0.96.00.beta, edit doc, clean up code --- html/basicsql.html | 6 +++--- main.js | 2 +- vkbeautify.js | 26 ++++++++++++-------------- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/html/basicsql.html b/html/basicsql.html index bb32102..6d03baf 100644 --- a/html/basicsql.html +++ b/html/basicsql.html @@ -7,9 +7,9 @@

This is an example of a SQL statement.

-vkBeautify SQL parser covers only SELECT statement as most javascript developers most time have deal with SELECT. -As SQL syntax itself is very large and complex, some complex statements can be formatted not as perfect as you'd -make it manually. But anyway, this tool helps you to save time on reading unformatted SQL statement. +vkBeautify SQL parser covers only SELECT statement as most javascript developers have deal with SELECT-based queries. +As SELECT syntax itself is very large and flexible, some complex nested statements can be formatted not as perfect as you'd +make it manually. But anyway, it helps you to save time on reading unformatted SQL statement.

Click on "Pretty Print" button to beatify the text.

Click on "Minify" button to minify the text (not sure if anybody needs it, but I keep it for consistency :)

diff --git a/main.js b/main.js index 4fab4cd..5624cb7 100644 --- a/main.js +++ b/main.js @@ -152,7 +152,7 @@ function loadTemplate(name) break; case 'basicsql': - $('#ta').width(600); + $('#ta').width(500); $('#leftpanel').show(); document.getElementById('ta').value = "SELECT ca.proj_id AS proj_id, ca.ca_name AS proj_name, ca.ca_date_start AS proj_start, ca.ca_date_end AS proj_end,(SELECT COUNT(*) FROM rotations r WHERE r.proj_id = proj_id AND r.r_status = 'R' GROUP BY r.proj_id) r_count, (SELECT count(*) FROM rotations r WHERE r.proj_id = proj_id AND r.channel_id = 24 ) r_rtb_count FROM projs ca, clients c, proj_auth caa WHERE ca.client_id = 12345 AND ca.client_id = c.client_id AND ca_type = 'zzz' AND c.agency_id = 0 AND ca.client_id = NVL( caa.client_id, ca.client_id ) AND proj_id = NVL( caa.proj_id, proj_id ) AND caa.contact_id = 7890"; $('#rightpanel').empty().load('html/basicsql.html'); diff --git a/vkbeautify.js b/vkbeautify.js index 7910727..447808a 100644 --- a/vkbeautify.js +++ b/vkbeautify.js @@ -1,7 +1,7 @@ /** * vkBeautify - javascript plugin to pretty-print or minify text in XML, JSON and CSS formats. * -* Version - 0.95.01.beta +* Version - 0.96.00.beta * Copyright (c) 2012 Vadim Kiryukhin * vkiryukhin @ gmail.com * http://www.eslinstructor.net/vkbeautify/ @@ -10,8 +10,8 @@ * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * -* vkbeautify.xml|json|css(text ) - pretty print XML, JSON or CSS text; -* vkbeautify.xmlmin|jsonmin|cssmin(text, preserveComments ) - minify XML, JSON or CSS text; +* vkbeautify.xml|json|css|sql(text ) - pretty print XML, JSON, CSS or SQL text; +* vkbeautify.xmlmin|jsonmin|cssmin|sqlmin(text, preserveComments ) - minify XML, JSON, CSS or SQL text; * * PARAMETERS: * @@ -22,12 +22,14 @@ * * USAGE: * -* vkbeautify.xml(text); -* vkbeautify.json(text); -* vkbeautify.css(text); -* vkbeautify.xmlmin( text [, true]); -* vkbeautify.jsonmin(text); -* vkbeautify.cssmin( text [, true]); +* var foo = vkbeautify.xml(text); +* var foo = vkbeautify.json(text); +* var foo = vkbeautify.css(text); +* var foo = vkbeautify.sql(text); +* var foo = vkbeautify.xmlmin( text [, true]); +* var foo = vkbeautify.jsonmin(text); +* var foo = vkbeautify.cssmin( text [, true]); +* var foo = vkbeautify.sqlmin(text); * */ @@ -35,7 +37,6 @@ function vkbeautify(){ this.shift = ['\n']; // array of shifts - //this.step = ' '; // 2 spaces this.step = ' '; // 4 spaces var maxdeep = 100, // nesting level ix = 0; @@ -277,18 +278,15 @@ vkbeautify.prototype.sql = function(text, brakeOnComma) { if( /\s{0,}\(\s{0,}SELECT\s{0,}/.exec(ar[ix])) { deep++; - //parenthesisLevel = isSubquery(ar[ix], parenthesisLevel); str += this.shift[deep]+ar[ix]; } else if( /\'/.exec(ar[ix]) ) { - //parenthesisLevel = isSubquery(ar[ix], parenthesisLevel); if(parenthesisLevel<1 && deep) { deep--; } str += ar[ix]; } else { - //parenthesisLevel = isSubquery(ar[ix], parenthesisLevel); str += this.shift[deep]+ar[ix]; if(parenthesisLevel<1 && deep) { deep--; @@ -297,7 +295,7 @@ vkbeautify.prototype.sql = function(text, brakeOnComma) { var junk = 0; } - str = str.replace(/^\n{1,}/,'')/*.replace(/\n[ \t]{0,}/g,"\n");*/.replace(/\n{1,}/g,"\n"); + str = str.replace(/^\n{1,}/,'').replace(/\n{1,}/g,"\n"); return str; }