history.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  1. /* vim: set expandtab sw=4 ts=4 sts=4: */
  2. /**
  3. * @fileoverview function used in this file builds history tab and generates query.
  4. *
  5. * @requires jQuery
  6. * @requires moves.js
  7. * @version $Id$
  8. */
  9. var history_array = []; // Global array to store history objects
  10. var select_field = []; // Global array to store informaation for columns which are used in select clause
  11. var g_index;
  12. /**
  13. * function for panel, hides and shows toggle_container <div>,which is for history elements uses {@link JQuery}.
  14. *
  15. * @param index has value 1 or 0,decides wheter to hide toggle_container on load.
  16. **/
  17. function panel(index)
  18. {
  19. if (!index) {
  20. $(".toggle_container").hide();
  21. }
  22. $("h2.tiger").click(function() {
  23. $(this).toggleClass("active").next().slideToggle("slow");
  24. });
  25. }
  26. /**
  27. * Sorts history_array[] first,using table name as the key and then generates the HTML code for history tab,
  28. * clubbing all objects of same tables together
  29. * This function is called whenever changes are made in history_array[]
  30. *
  31. *
  32. * @param {int} init starting index of unsorted array
  33. * @param {int} finit last index of unsorted array
  34. *
  35. **/
  36. function display(init,finit)
  37. {
  38. var str,i,j,k,sto;
  39. // this part sorts the history array based on table name,this is needed for clubbing all object of same name together.
  40. for (i = init; i < finit; i++) {
  41. sto = history_array[i];
  42. var temp = history_array[i].get_tab() ;//+ '.' + history_array[i].get_obj_no(); for Self JOINS
  43. for (j = 0; j < i; j++) {
  44. if (temp > (history_array[j].get_tab())) {//+ '.' + history_array[j].get_obj_no())) { //for Self JOINS
  45. for (k = i; k > j; k--) {
  46. history_array[k] = history_array[k-1];
  47. }
  48. history_array[j] = sto;
  49. break;
  50. }
  51. }
  52. }
  53. // this part generates HTML code for history tab.adds delete,edit,and/or and detail features with objects.
  54. str =''; // string to store Html code for history tab
  55. for (var i=0; i < history_array.length; i++) {
  56. var temp = history_array[i].get_tab(); //+ '.' + history_array[i].get_obj_no(); for Self JOIN
  57. str += '<h2 class="tiger"><a href="#">' + temp + '</a></h2>';
  58. str += '<div class="toggle_container">\n';
  59. while ((history_array[i].get_tab()) == temp) { //+ '.' + history_array[i].get_obj_no()) == temp) {
  60. str +='<div class="block"> <table width ="250">';
  61. str += '<thead><tr><td>';
  62. if (history_array[i].get_and_or()) {
  63. str +='<img src="' + pmaThemeImage + 'pmd/or_icon.png" onclick="and_or('+i+')" title="OR"/></td>';
  64. } else {
  65. str +='<img src="' + pmaThemeImage + 'pmd/and_icon.png" onclick="and_or('+i+')" title="AND"/></td>';
  66. }
  67. str +='<td style="padding-left: 5px;" class="right">' + PMA_getImage('b_sbrowse.png', 'column name') + '</td><td width="175" style="padding-left: 5px">' + history_array[i].get_column_name();
  68. if (history_array[i].get_type() == "GroupBy" || history_array[i].get_type() == "OrderBy") {
  69. str += '</td><td class="center">' + PMA_getImage('b_info.png', detail(i)) + '<td title="' + detail(i) +'">' + history_array[i].get_type() + '</td></td><td onmouseover="this.className=\'history_table\';" onmouseout="this.className=\'history_table2\'" onclick=history_delete('+ i +')>' + PMA_getImage('b_drop.png', 'Delete') + '</td></tr></thead>';
  70. } else {
  71. str += '</td><td class="center">' + PMA_getImage('b_info.png', detail(i)) + '</td><td title="' + detail(i) +'">' + history_array[i]. get_type() + '</td><td <td onmouseover="this.className=\'history_table\';" onmouseout="this.className=\'history_table2\'" onclick=history_edit('+ i +')>' + PMA_getImage('b_edit.png', PMA_messages['strEdit']) + '</td><td onmouseover="this.className=\'history_table\';" onmouseout="this.className=\'history_table2\'" onclick=history_delete('+ i +')><img src="themes/original/img/b_drop.png" title="Delete"></td></tr></thead>';
  72. }
  73. i++;
  74. if (i >= history_array.length) {
  75. break;
  76. }
  77. str += '</table></div><br/>';
  78. }
  79. i--;
  80. str += '</div><br/>';
  81. }
  82. return str;
  83. }
  84. /**
  85. * To change And/Or relation in history tab
  86. *
  87. *
  88. * @param {int} index of history_array where change is to be made
  89. *
  90. **/
  91. function and_or(index)
  92. {
  93. if (history_array[index].get_and_or()) {
  94. history_array[index].set_and_or(0);
  95. } else {
  96. history_array[index].set_and_or(1);
  97. }
  98. var existingDiv = document.getElementById('ab');
  99. existingDiv.innerHTML = display(0,0);
  100. panel(1);
  101. }
  102. /**
  103. * To display details of obects(where,rename,Having,aggregate,groupby,orderby,having)
  104. *
  105. * @param index index of history_array where change is to be made
  106. *
  107. **/
  108. function detail (index)
  109. {
  110. var type = history_array[index].get_type();
  111. var str;
  112. if (type == "Where") {
  113. str = 'Where ' + history_array[index].get_column_name() + history_array[index].get_obj().getrelation_operator() + history_array[index].get_obj().getquery();
  114. }
  115. if (type == "Rename") {
  116. str = 'Rename ' + history_array[index].get_column_name() + ' To ' + history_array[index].get_obj().getrename_to();
  117. }
  118. if (type == "Aggregate") {
  119. str = 'Select ' + history_array[index].get_obj().get_operator() + '( ' + history_array[index].get_column_name() + ' )';
  120. }
  121. if (type == "GroupBy") {
  122. str = 'GroupBy ' + history_array[index].get_column_name() ;
  123. }
  124. if (type == "OrderBy") {
  125. str = 'OrderBy ' + history_array[index].get_column_name() ;
  126. }
  127. if (type == "Having") {
  128. str = 'Having ';
  129. if (history_array[index].get_obj().get_operator() != 'None') {
  130. str += history_array[index].get_obj().get_operator() + '( ' + history_array[index].get_column_name() + ' )';
  131. str += history_array[index].get_obj().getrelation_operator() + history_array[index].get_obj().getquery();
  132. } else {
  133. str = 'Having ' + history_array[index].get_column_name() + history_array[index].get_obj().getrelation_operator() + history_array[index].get_obj().getquery();
  134. }
  135. }
  136. return str;
  137. }
  138. /**
  139. * Deletes entry in history_array
  140. *
  141. * @param index index of history_array[] which is to be deleted
  142. *
  143. **/
  144. function history_delete(index)
  145. {
  146. for (var k = 0; k < from_array.length; k++) {
  147. if (from_array[k] == history_array[index].get_tab()) {
  148. from_array.splice(k,1);
  149. break;
  150. }
  151. }
  152. history_array.splice(index,1);
  153. var existingDiv = document.getElementById('ab');
  154. existingDiv.innerHTML = display(0,0);
  155. panel(1);
  156. }
  157. /**
  158. * To show where,rename,aggregate,having forms to edit a object
  159. *
  160. * @param{int} index index of history_array where change is to be made
  161. *
  162. **/
  163. function history_edit(index)
  164. {
  165. g_index = index;
  166. var type = history_array[index].get_type();
  167. if (type == "Where") {
  168. document.getElementById('eQuery').value = history_array[index].get_obj().getquery();
  169. document.getElementById('erel_opt').value = history_array[index].get_obj().getrelation_operator();
  170. document.getElementById('query_where').style.left = '530px';
  171. document.getElementById('query_where').style.top = '130px';
  172. document.getElementById('query_where').style.position = 'absolute';
  173. document.getElementById('query_where').style.zIndex = '9';
  174. document.getElementById('query_where').style.visibility = 'visible';
  175. }
  176. if (type == "Having") {
  177. document.getElementById('hQuery').value = history_array[index].get_obj().getquery();
  178. document.getElementById('hrel_opt').value = history_array[index].get_obj().getrelation_operator();
  179. document.getElementById('hoperator').value = history_array[index].get_obj().get_operator();
  180. document.getElementById('query_having').style.left = '530px';
  181. document.getElementById('query_having').style.top = '130px';
  182. document.getElementById('query_having').style.position = 'absolute';
  183. document.getElementById('query_having').style.zIndex = '9';
  184. document.getElementById('query_having').style.visibility = 'visible';
  185. }
  186. if (type == "Rename") {
  187. document.getElementById('query_rename_to').style.left = '530px';
  188. document.getElementById('query_rename_to').style.top = '130px';
  189. document.getElementById('query_rename_to').style.position = 'absolute';
  190. document.getElementById('query_rename_to').style.zIndex = '9';
  191. document.getElementById('query_rename_to').style.visibility = 'visible';
  192. }
  193. if (type == "Aggregate") {
  194. document.getElementById('query_Aggregate').style.left = '530px';
  195. document.getElementById('query_Aggregate').style.top = '130px';
  196. document.getElementById('query_Aggregate').style.position = 'absolute';
  197. document.getElementById('query_Aggregate').style.zIndex = '9';
  198. document.getElementById('query_Aggregate').style.visibility = 'visible';
  199. }
  200. }
  201. /**
  202. * Make changes in history_array when Edit button is clicked
  203. * checks for the type of object and then sets the new value
  204. *
  205. * @param index index of history_array where change is to be made
  206. **/
  207. function edit(type)
  208. {
  209. if (type == "Rename") {
  210. if (document.getElementById('e_rename').value != "") {
  211. history_array[g_index].get_obj().setrename_to(document.getElementById('e_rename').value);
  212. document.getElementById('e_rename').value = "";
  213. }
  214. document.getElementById('query_rename_to').style.visibility = 'hidden';
  215. }
  216. if (type == "Aggregate") {
  217. if (document.getElementById('e_operator').value != '---') {
  218. history_array[g_index].get_obj().set_operator(document.getElementById('e_operator').value);
  219. document.getElementById('e_operator').value = '---';
  220. }
  221. document.getElementById('query_Aggregate').style.visibility = 'hidden';
  222. }
  223. if (type == "Where") {
  224. if (document.getElementById('erel_opt').value != '--' && document.getElementById('eQuery').value !="") {
  225. history_array[g_index].get_obj().setquery(document.getElementById('eQuery').value);
  226. history_array[g_index].get_obj().setrelation_operator(document.getElementById('erel_opt').value);
  227. }
  228. document.getElementById('query_where').style.visibility = 'hidden';
  229. }
  230. if (type == "Having") {
  231. if (document.getElementById('hrel_opt').value != '--' && document.getElementById('hQuery').value !="") {
  232. history_array[g_index].get_obj().setquery(document.getElementById('hQuery').value);
  233. history_array[g_index].get_obj().setrelation_operator(document.getElementById('hrel_opt').value);
  234. history_array[g_index].get_obj().set_operator(document.getElementById('hoperator').value);
  235. }
  236. document.getElementById('query_having').style.visibility = 'hidden';
  237. }
  238. var existingDiv = document.getElementById('ab');
  239. existingDiv.innerHTML = display(0,0);
  240. panel(1);
  241. }
  242. /**
  243. * history object closure
  244. *
  245. * @param ncolumn_name name of the column on which conditions are put
  246. * @param nobj object details(where,rename,orderby,groupby,aggregate)
  247. * @param ntab table name of the column on which conditions are applied
  248. * @param nobj_no object no used for inner join
  249. * @param ntype type of object
  250. *
  251. **/
  252. function history(ncolumn_name,nobj,ntab,nobj_no,ntype)
  253. {
  254. var and_or;
  255. var obj;
  256. var tab;
  257. var column_name;
  258. var obj_no;
  259. var type;
  260. this.set_column_name = function (ncolumn_name) {
  261. column_name = ncolumn_name;
  262. };
  263. this.get_column_name = function() {
  264. return column_name;
  265. };
  266. this.set_and_or = function(nand_or) {
  267. and_or = nand_or;
  268. };
  269. this.get_and_or = function() {
  270. return and_or;
  271. };
  272. this.get_relation = function() {
  273. return and_or;
  274. };
  275. this.set_obj = function(nobj) {
  276. obj = nobj;
  277. };
  278. this.get_obj = function() {
  279. return obj;
  280. };
  281. this.set_tab = function(ntab) {
  282. tab = ntab;
  283. };
  284. this.get_tab = function() {
  285. return tab;
  286. };
  287. this.set_obj_no = function(nobj_no) {
  288. obj_no = nobj_no;
  289. };
  290. this.get_obj_no = function() {
  291. return obj_no;
  292. };
  293. this.set_type = function(ntype) {
  294. type = ntype;
  295. };
  296. this.get_type = function() {
  297. return type;
  298. };
  299. this.set_obj_no(nobj_no);
  300. this.set_tab(ntab);
  301. this.set_and_or(0);
  302. this.set_obj(nobj);
  303. this.set_column_name(ncolumn_name);
  304. this.set_type(ntype);
  305. }
  306. /**
  307. * where object closure, makes an object with all information of where
  308. *
  309. * @param nrelation_operator type of relation operator to be applied
  310. * @param nquery stores value of value/sub-query
  311. *
  312. **/
  313. var where = function (nrelation_operator,nquery) {
  314. var relation_operator;
  315. var query;
  316. this.setrelation_operator = function(nrelation_operator) {
  317. relation_operator = nrelation_operator;
  318. };
  319. this.setquery = function(nquery) {
  320. query = nquery;
  321. };
  322. this.getquery = function() {
  323. return query;
  324. };
  325. this.getrelation_operator = function() {
  326. return relation_operator;
  327. };
  328. this.setquery(nquery);
  329. this.setrelation_operator(nrelation_operator);
  330. };
  331. /**
  332. * Having object closure, makes an object with all information of where
  333. *
  334. * @param nrelation_operator type of relation operator to be applied
  335. * @param nquery stores value of value/sub-query
  336. *
  337. **/
  338. var having = function (nrelation_operator,nquery,noperator) {
  339. var relation_operator;
  340. var query;
  341. var operator;
  342. this.set_operator = function(noperator) {
  343. operator = noperator;
  344. };
  345. this.setrelation_operator = function(nrelation_operator) {
  346. relation_operator = nrelation_operator;
  347. };
  348. this.setquery = function(nquery) {
  349. query = nquery;
  350. };
  351. this.getquery = function() {
  352. return query;
  353. };
  354. this.getrelation_operator = function() {
  355. return relation_operator;
  356. };
  357. this.get_operator = function() {
  358. return operator;
  359. };
  360. this.setquery(nquery);
  361. this.setrelation_operator(nrelation_operator);
  362. this.set_operator(noperator);
  363. };
  364. /**
  365. * rename object closure,makes an object with all information of rename
  366. *
  367. * @param nrename_to new name information
  368. *
  369. **/
  370. var rename = function(nrename_to) {
  371. var rename_to;
  372. this.setrename_to = function(nrename_to) {
  373. rename_to = nrename_to;
  374. };
  375. this.getrename_to =function() {
  376. return rename_to;
  377. };
  378. this.setrename_to(nrename_to);
  379. };
  380. /**
  381. * aggregate object closure
  382. *
  383. * @param noperator aggregte operator
  384. *
  385. **/
  386. var aggregate = function(noperator) {
  387. var operator;
  388. this.set_operator = function(noperator) {
  389. operator = noperator;
  390. };
  391. this.get_operator = function() {
  392. return operator;
  393. };
  394. this.set_operator(noperator);
  395. };
  396. /**
  397. * This function returns unique element from an array
  398. *
  399. * @param arraName array from which duplicate elem are to be removed.
  400. * @return unique array
  401. */
  402. function unique(arrayName)
  403. {
  404. var newArray=[];
  405. label:for (var i=0; i<arrayName.length; i++ )
  406. {
  407. for (var j=0; j<newArray.length; j++ )
  408. {
  409. if (newArray[j]==arrayName[i]) {
  410. continue label;
  411. }
  412. }
  413. newArray[newArray.length] = arrayName[i];
  414. }
  415. return newArray;
  416. }
  417. /**
  418. * This function takes in array and a value as input and returns 1 if values is present in array
  419. * else returns -1
  420. *
  421. * @param arrayName array
  422. * @param value value which is to be searched in the array
  423. */
  424. function found(arrayName,value)
  425. {
  426. for (var i=0; i<arrayName.length; i++) {
  427. if (arrayName[i] == value) { return 1;}
  428. }
  429. return -1;
  430. }
  431. /**
  432. * This function is the main function for query building.
  433. * uses history object details for this.
  434. *
  435. * @ uses query_where()
  436. * @ uses query_groupby()
  437. * @ uses query_having()
  438. * @ uses query_orderby()
  439. *
  440. * @param formtitle title for the form
  441. * @param fadin
  442. */
  443. function build_query(formtitle, fadin)
  444. {
  445. var q_select = "SELECT ";
  446. var temp;
  447. for (var i = 0;i < select_field.length; i++) {
  448. temp = check_aggregate(select_field[i]);
  449. if (temp != "") {
  450. q_select += temp;
  451. temp = check_rename(select_field[i]);
  452. q_select += temp + ",";
  453. } else {
  454. temp = check_rename(select_field[i]);
  455. q_select += select_field[i] + temp +",";
  456. }
  457. }
  458. q_select = q_select.substring(0,q_select.length - 1);
  459. q_select += " FROM " + query_from();
  460. if (query_where() != "") {
  461. q_select +="\n WHERE";
  462. q_select += query_where();
  463. }
  464. if (query_groupby() != "") { q_select += "\nGROUP BY " + query_groupby(); }
  465. if (query_having() != "") { q_select += "\nHAVING " + query_having(); }
  466. if (query_orderby() != "") { q_select += "\nORDER BY " + query_orderby(); }
  467. var box = document.getElementById('box');
  468. document.getElementById('filter').style.display='block';
  469. var btitle = document.getElementById('boxtitle');
  470. btitle.innerHTML = 'SELECT';//formtitle;
  471. if (fadin) {
  472. gradient("box", 0);
  473. fadein("box");
  474. } else{
  475. box.style.display='block';
  476. }
  477. document.getElementById('textSqlquery').innerHTML = q_select;
  478. }
  479. /**
  480. * This function builds from clause of query
  481. * makes automatic joins.
  482. *
  483. *
  484. */
  485. function query_from()
  486. {
  487. var i;
  488. var tab_left = [];
  489. var tab_used = [];
  490. var t_tab_used = [];
  491. var t_tab_left = [];
  492. var temp;
  493. var query = "";
  494. var quer = "";
  495. var parts = [];
  496. var t_array = [];
  497. t_array = from_array;
  498. var K = 0;
  499. var k;
  500. var key;
  501. var key2;
  502. var key3;
  503. var parts1;
  504. for (i = 0; i < history_array.length ; i++) {
  505. from_array.push(history_array[i].get_tab());
  506. }
  507. from_array = unique( from_array );
  508. tab_left = from_array;
  509. temp = tab_left.shift();
  510. quer = temp;
  511. tab_used.push(temp);
  512. // if master table (key2) matches with tab used get all keys and check if tab_left matches
  513. // after this check if master table (key2) matches with tab left then check if any foreign matches with master .
  514. for (i =0; i<2 ; i++) {
  515. for (K in contr) {
  516. for (key in contr[K]) {// contr name
  517. for (key2 in contr[K][key]) {// table name
  518. parts = key2.split(".");
  519. if (found(tab_used,parts[1]) > 0) {
  520. for (key3 in contr[K][key][key2]) {
  521. parts1 = contr[K][key][key2][key3][0].split(".");
  522. if (found(tab_left,parts1[1]) > 0) {
  523. query += "\n" + 'LEFT JOIN ';
  524. query += '`' + parts1[0] + '`.`' + parts1[1] + '` ON ' ;
  525. query += '`' + parts[1] +'`.`' + key3 + '` = ';
  526. query += '`' + parts1[1] + '`.`' + contr[K][key][key2][key3][1] + '` ';
  527. t_tab_left.push(parts1[1]);
  528. }
  529. }
  530. }
  531. }
  532. }
  533. }
  534. K = 0;
  535. t_tab_left = unique (t_tab_left);
  536. tab_used = add_array(t_tab_left,tab_used);
  537. tab_left = remove_array(t_tab_left,tab_left);
  538. t_tab_left = [];
  539. for (K in contr) {
  540. for (key in contr[K]) {
  541. for (key2 in contr[K][key]) {// table name
  542. parts = key2.split(".");
  543. if (found(tab_left,parts[1]) > 0) {
  544. for (key3 in contr[K][key][key2]) {
  545. parts1 = contr[K][key][key2][key3][0].split(".");
  546. if (found(tab_used,parts1[1]) > 0) {
  547. query += "\n" + 'LEFT JOIN ';
  548. query += '`' + parts[0] + '`.`' + parts[1] + '` ON ' ;
  549. query += '`' + parts1[1] + '`.`' + contr[K][key][key2][key3][1] + '` = ';
  550. query += '`' + parts[1] + '`.`' + key3 + '` ';
  551. t_tab_left.push(parts[1]);
  552. }
  553. }
  554. }
  555. }
  556. }
  557. }
  558. t_tab_left = unique (t_tab_left);
  559. tab_used = add_array(t_tab_left,tab_used);
  560. tab_left = remove_array(t_tab_left,tab_left);
  561. t_tab_left = [];
  562. }
  563. for (k in tab_left) {
  564. quer += " , `" + tab_left[k] + "`";
  565. }
  566. query = quer + query;
  567. from_array = t_array;
  568. return query;
  569. }
  570. /**
  571. * This function concatenates two array
  572. *
  573. * @params add array elements of which are pushed in
  574. * @params arr array in which elemnets are added
  575. */
  576. function add_array(add,arr)
  577. {
  578. for (var i=0; i<add.length; i++) {
  579. arr.push(add[i]);
  580. }
  581. return arr;
  582. }
  583. /* This fucntion removes all elements present in one array from the other.
  584. *
  585. * @params rem array from which each element is removed from other array.
  586. * @params arr array from which elements are removed.
  587. *
  588. */
  589. function remove_array(rem,arr)
  590. {
  591. for (var i=0; i<rem.length; i++) {
  592. for (var j=0; j<arr.length; j++) {
  593. if (rem[i] == arr[j]) {
  594. arr.splice(j,1);
  595. }
  596. }
  597. }
  598. return arr;
  599. }
  600. /**
  601. * This function builds the groupby clause from history object
  602. *
  603. */
  604. function query_groupby()
  605. {
  606. var i;
  607. var str = "";
  608. for (i = 0; i < history_array.length;i++) {
  609. if (history_array[i].get_type() == "GroupBy") { str +=history_array[i].get_column_name() + ", ";}
  610. }
  611. str = str.substr(0,str.length -1);
  612. return str;
  613. }
  614. /**
  615. * This function builds the Having clause from the history object.
  616. *
  617. */
  618. function query_having()
  619. {
  620. var i;
  621. var and = "(";
  622. for (i = 0; i < history_array.length;i++) {
  623. if (history_array[i].get_type() == "Having") {
  624. if (history_array[i].get_obj().get_operator() != 'None') {
  625. and += history_array[i].get_obj().get_operator() + "(" + history_array[i].get_column_name() + " ) " + history_array[i].get_obj().getrelation_operator();
  626. and += " " + history_array[i].get_obj().getquery() + ", " ;
  627. } else {
  628. and += history_array[i].get_column_name() + " " + history_array[i].get_obj().getrelation_operator() + " " + history_array[i].get_obj().getquery() + ", ";
  629. }
  630. }
  631. }
  632. if (and =="(") {
  633. and = "" ;
  634. } else {
  635. and = and.substr(0,and.length -2) + ")";
  636. }
  637. return and;
  638. }
  639. /**
  640. * This function builds the orderby clause from the history object.
  641. *
  642. */
  643. function query_orderby()
  644. {
  645. var i;
  646. var str = "" ;
  647. for (i = 0; i < history_array.length;i++) {
  648. if (history_array[i].get_type() == "OrderBy") { str += history_array[i].get_column_name() + " , "; }
  649. }
  650. str = str.substr(0,str.length -1);
  651. return str;
  652. }
  653. /**
  654. * This function builds the Where clause from the history object.
  655. *
  656. */
  657. function query_where()
  658. {
  659. var i;
  660. var and = "(";
  661. var or = "(";
  662. for (i = 0; i < history_array.length;i++) {
  663. if (history_array[i].get_type() == "Where") {
  664. if (history_array[i].get_and_or() == 0) {
  665. and += "( " + history_array[i].get_column_name() + " " + history_array[i].get_obj().getrelation_operator() +" " + history_array[i].get_obj().getquery() + ")"; and += " AND ";
  666. } else {
  667. or +="( " + history_array[i].get_column_name() + " " + history_array[i].get_obj().getrelation_operator() + " " + history_array[i].get_obj().getquery() +")";
  668. or +=" OR " ;
  669. }
  670. }
  671. }
  672. if (or != "(") {
  673. or = or.substring(0,(or.length - 4 )) + ")";
  674. } else {
  675. or = "" ;
  676. }
  677. if (and !="(") {
  678. and = and.substring(0,(and.length - 5)) + ")";
  679. } else {
  680. and = "" ;
  681. }
  682. if (or != "" ) {
  683. and = and + " OR " + or + " )";
  684. }
  685. return and;
  686. }
  687. function check_aggregate(id_this)
  688. {
  689. var i;
  690. for (i = 0;i < history_array.length;i++) {
  691. var temp = '`' + history_array[i].get_tab() + '`.`' +history_array[i].get_column_name() +'`';
  692. if (temp == id_this && history_array[i].get_type() == "Aggregate") {
  693. return history_array[i].get_obj().get_operator() + '(' + id_this +')';
  694. }
  695. }
  696. return "";
  697. }
  698. function check_rename(id_this)
  699. {
  700. var i;
  701. for (i = 0;i < history_array.length;i++) {
  702. var temp = '`' + history_array[i].get_tab() + '`.`' +history_array[i].get_column_name() +'`';
  703. if (temp == id_this && history_array[i].get_type() == "Rename") {
  704. return " AS `" + history_array[i].get_obj().getrename_to() +"`";
  705. }
  706. }
  707. return "";
  708. }
  709. function gradient(id, level)
  710. {
  711. var box = document.getElementById(id);
  712. box.style.opacity = level;
  713. box.style.MozOpacity = level;
  714. box.style.KhtmlOpacity = level;
  715. box.style.filter = "alpha(opacity=" + level * 100 + ")";
  716. box.style.display="block";
  717. return;
  718. }
  719. function fadein(id)
  720. {
  721. var level = 0;
  722. while (level <= 1) {
  723. setTimeout( "gradient('" + id + "'," + level + ")", (level* 1000) + 10);
  724. level += 0.01;
  725. }
  726. }
  727. function closebox()
  728. {
  729. document.getElementById('box').style.display='none';
  730. document.getElementById('filter').style.display='none';
  731. }