From 638cee4decf831773cefabe50edd750da430e371 Mon Sep 17 00:00:00 2001 From: ankitg Date: Wed, 28 Jul 2010 12:00:46 +0530 Subject: [PATCH] where orderby groupby clauses --- pmd/scripts/history.js | 48 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/pmd/scripts/history.js b/pmd/scripts/history.js index 1c76f15c6..0491fc686 100644 --- a/pmd/scripts/history.js +++ b/pmd/scripts/history.js @@ -357,7 +357,11 @@ function build_query(formtitle, fadin) { q_select += select_field[i] + temp +","; } } - q_select = q_select.substring(0,q_select.length - 1); + q_select = q_select.substring(0,q_select.length - 1); + q_select += " FROM WHERE "; + q_select += query_where(); + if(query_groupby() != "") { q_select += "GROUP BY" + query_groupby(); } + if(query_orderby() != "") { q_select += "ORDER BY" + query_orderby(); } var box = document.getElementById('box'); document.getElementById('filter').style.display='block'; var btitle = document.getElementById('boxtitle'); @@ -375,6 +379,48 @@ function build_query(formtitle, fadin) { // document.getElementById('hint').style.visibility = "visible"; } +function query_groupby() { + var i = 0; + var str = ""; + for(i; i < history_array.length;i++) { + if(history_array[i].get_type() == "GroupBy") { str +=history_array[i].get_column_name() + ", ";} + } + str = str.substr(0,str.length -1); + return str; +} + +function query_orderby() { + var i = 0; + var str = "" ; + for(i; i < history_array.length;i++) { + if(history_array[i].get_type() == "OrderBy") { str += history_array[i].get_column_name() + " , "; } + } + str = str.substr(0,str.length -1); + return str; +} + +function query_where(){ + var i = 0; + var and = "("; + var or = "("; + for(i; i < history_array.length;i++) { + if(history_array[i].get_type() == "Where") { + if(history_array[i].get_and_or() == 0) { + and += "( " + history_array[i].get_column_name() + " " + history_array[i].get_obj().getrelation_operator() +" " + history_array[i].get_obj().getquery() + ")"; and += " AND "; + } + else { + or +="( " + history_array[i].get_column_name() + " " + history_array[i].get_obj().getrelation_operator() + " " + history_array[i].get_obj().getquery() +")"; or +=" OR " ; + } + } + } + if ( or != "(") { or = or.substring(0,(or.length - 4 )) + ")"; } + else { or = "" ;} + if (and !="(") {and = and.substring(0,(and.length - 5)) + ")"; } + else {and = "" ;} + and = and + " OR " + or + " )"; + return and; +} + function check_aggregate(id_this) { var i = 0; for(i;i < history_array.length;i++) {