diff --git a/pmd/scripts/history.js b/pmd/scripts/history.js index 0491fc686..d6d5ef324 100644 --- a/pmd/scripts/history.js +++ b/pmd/scripts/history.js @@ -100,7 +100,7 @@ function and_or(index) { } /** - * To display details of obects(where,rename,aggregate,groupby,orderby) + * To display details of obects(where,rename,aggregate,groupby,orderby,having) * * @param index index of history_array where change is to be made * @@ -124,6 +124,16 @@ function detail (index) { if (type == "OrderBy") { str = 'OrderBy ' + history_array[index].get_column_name() ; } + if (type == "Having") { + str = 'Having '; + if (history_array[index].get_obj().get_operator() != 'None') { + str += history_array[index].get_obj().get_operator() + '( ' + history_array[index].get_column_name() + ' )'; + str += history_array[index].get_obj().getrelation_operator() + history_array[index].get_obj().getquery(); + } + else { + str = 'Having ' + history_array[index].get_column_name() + history_array[index].get_obj().getrelation_operator() + history_array[index].get_obj().getquery(); + } + } return str; } @@ -137,6 +147,12 @@ function detail (index) { **/ function history_delete(index) { + for(var k =0 ;k < from_array.length;k++){ + if(from_array[k] == history_array[index].get_tab()){ + from_array.splice(k,1); + break; + } + } history_array.splice(index,1); var existingDiv = document.getElementById('ab'); existingDiv.innerHTML = display(0,0); @@ -162,6 +178,16 @@ function history_edit(index) { document.getElementById('query_where').style.zIndex = '9'; document.getElementById('query_where').style.visibility = 'visible'; } + if (type == "Having") { + document.getElementById('hQuery').value = history_array[index].get_obj().getquery(); + document.getElementById('hrel_opt').value = history_array[index].get_obj().getrelation_operator(); + document.getElementById('hoperator').value = history_array[index].get_obj().get_operator(); + document.getElementById('query_having').style.left = '230px'; + document.getElementById('query_having').style.top = '330px'; + document.getElementById('query_having').style.position = 'absolute'; + document.getElementById('query_having').style.zIndex = '9'; + document.getElementById('query_having').style.visibility = 'visible'; + } if (type == "Rename") { document.getElementById('query_rename_to').style.left = '230px'; document.getElementById('query_rename_to').style.top = '330px'; @@ -209,6 +235,14 @@ function edit(type) { } document.getElementById('query_where').style.visibility = 'hidden'; } + if (type == "Having") { + if (document.getElementById('hrel_opt').value != '--' && document.getElementById('hQuery').value !="") { + history_array[g_index].get_obj().setquery(document.getElementById('hQuery').value); + history_array[g_index].get_obj().setrelation_operator(document.getElementById('hrel_opt').value); + history_array[g_index].get_obj().set_operator(document.getElementById('hoperator').value); + } + document.getElementById('query_having').style.visibility = 'hidden'; + } var existingDiv = document.getElementById('ab'); existingDiv.innerHTML = display(0,0); panel(1); @@ -287,6 +321,7 @@ function history(ncolumn_name,nobj,ntab,nobj_no,ntype) { * **/ + var where = function (nrelation_operator,nquery) { var relation_operator; var query; @@ -306,6 +341,33 @@ var where = function (nrelation_operator,nquery) { this.setrelation_operator(nrelation_operator); }; +var having = function (nrelation_operator,nquery,noperator) { + var relation_operator; + var query; + var operator; + this.set_operator = function(noperator) { + operator = noperator; + }; + this.setrelation_operator = function(nrelation_operator) { + relation_operator = nrelation_operator; + }; + this.setquery = function(nquery) { + query = nquery; + }; + this.getquery = function() { + return query; + }; + this.getrelation_operator = function() { + return relation_operator; + }; + this.get_operator = function() { + return operator; + }; + this.setquery(nquery); + this.setrelation_operator(nrelation_operator); + this.set_operator(noperator); +}; + /** * rename object closure,makes an object with all information of rename * @@ -342,7 +404,29 @@ var aggregate = function(noperator) { this.set_operator(noperator); }; +function unique(arrayName) { + var newArray=new Array(); + label:for(var i=0; i 0) { + for (key3 in contr[K][key][key2]) { + parts1 = contr[K][key][key2][key3][0].split("."); + if(found(tab_left,parts1[1]) > 0) { + query += "\n" + 'LEFT JOIN '; + query += '`' + parts1[0] + '`.`' + parts1[1] + '` ON ' ; + query += '`' + parts[1] +'`.`' + key3 + '` = '; + query += '`' + parts1[1] + '`.`' + contr[K][key][key2][key3][1] + '` '; + t_tab_left.push(parts1[1]); + } + } + } + } + } + } + K = 0; + t_tab_left = unique (t_tab_left); + tab_used = add_array(t_tab_left,tab_used); + tab_left = remove_array(t_tab_left,tab_left); + t_tab_left = []; + for (K in contr) { + for (key in contr[K]) { + for (key2 in contr[K][key]){// table name + parts = key2.split("."); + if(found(tab_left,parts[1]) > 0) + { + for (key3 in contr[K][key][key2]) // field name + { + parts1 = contr[K][key][key2][key3][0].split("."); + if(found(tab_used,parts1[1]) > 0) { + query += "\n" + 'LEFT JOIN '; + query += '`' + parts[0] + '`.`' + parts[1] + '` ON ' ; + query += '`' + parts1[1] + '`.`' + contr[K][key][key2][key3][1] + '` = '; + query += '`' + parts[1] + '`.`' + key3 + '` '; + + t_tab_left.push(parts[1]); + } + } + } + } + } + } + t_tab_left = unique (t_tab_left); + tab_used = add_array(t_tab_left,tab_used); + tab_left = remove_array(t_tab_left,tab_left); + t_tab_left = []; + } + for (k in tab_left) { + quer += " , `" + tab_left[k] + "`"; + } + query = quer + query; + from_array = t_array; + return query; +} + /* document.write(key3+";"); //master_field + document.write(contr[K][key][key2][key3][0]+";"); // foreign_table + document.write(contr[K][key][key2][key3][1]+";"); //forieign_feild */ + +function add_array(add,arr){ + for( var i=0; i