home *** CD-ROM | disk | FTP | other *** search
/ CD Shareware Magazine 1999 April / CD_Shareware_Magazine_31.iso / WIN95 / INTERNET / h12395co.exe / data.1 / sqlscr.hei < prev    next >
Encoding:
Text File  |  1997-11-05  |  3.2 KB  |  126 lines

  1. <include sesfield.hei>
  2. <include layout/heilay.hei>
  3.  
  4. <session mode="create">  // We are working in session mode now
  5.  
  6.  
  7. <heitmlpage title="SQL Scroll Form" mis/67//h>
  8.  
  9. Now you can enter an arbitrary SQL-Query on our example database. Here are a
  10. few variations on the SELECT command that you might like to try:
  11. <p>
  12.  
  13. <let x = = 5> 
  14.  
  15. <box>
  16. <FONT SIZE="-1"><b>
  17. <ul>
  18. <li>  SELECT * FROM guestbook 
  19. <li>  SELECT Guest_Name FROM guestbook ORDER BY Guest_Name
  20. <li>  SELECT DISTINCT  Guest_Name, Email, Address FROM guestbook ORDER BY Guest_Name 
  21. <li>  SELECT COUNT (*) FROM guestbook
  22. <li>  SELECT COUNT (*) FROM guestbook WHERE Country="USA"
  23. <li>  SELECT * FROM guestbook WHERE Guest_Name LIKE 'R%'
  24. </ul>
  25. </FONT></b>
  26. </box>
  27.  
  28. <p>
  29. Watch how the Query Result changes depending on the form of the SELECT command that you enter. 
  30.  
  31.  
  32. /******************************************************************
  33.  Here is the input form that allows the user to enter
  34.  an SQL query. It is a sessionForm, displaying and updating
  35.  session variables.
  36. ******************************************************************/
  37. <sessionForm>
  38. <sessionButton name="SQuery" value="Query">
  39. <INPUT TYPE="reset"  VALUE="Reset"> 
  40. <a href="demo.hei"> Back </a>
  41. <sessionButton name="Apply">
  42. <br>
  43. <if (isempty(se.query));  se.query="SELECT * FROM guestbook"; /if>
  44. <sessionTextArea "Query" ROWS=6 COLS=55 wrap="physical"> 
  45. <p>
  46. Maximal Number of rows to read :
  47. <let se.max=default(se.max,100); sessionFi "max" 10 type="i"><br>
  48. Number of Rows per page:
  49. <let se.pgsize=default(se.pgsize,5); sessionFi "pgsize" 10 type="i">
  50. </sessionForm>
  51.  
  52. // We do the following, when the QUERY button has been pressed
  53. <if !isempty(ff.Squery) && SrvDebug;
  54.    i=0; SrvMax=se.max;
  55.    se.buffer=array(1);       // Create an empty array
  56.    se.pos=0; 
  57.    dbquery q> <? se.query> < // Do the query
  58.    dbrow   resize(se.buffer,i+1);  // and add each record to the array
  59.        se.buffer[i]= clone(q); 
  60.        i=i+1;
  61.    dbempty
  62.          se.buffer=null;   // in case the result is empty
  63.    /db;
  64. /if>
  65.  
  66.  
  67.  
  68. /*************** End of SQL query input FORM ************/
  69.  
  70.  
  71. // Now we show the buffer (if its not empty)
  72. <if !isempty(se.buffer);
  73.  
  74.      // First handle the scroll buttons
  75.      if (!isempty(ff.next)); se.pos=se.pos+se.pgsize; /if   
  76.      if (!isempty(ff.prev)); se.pos=se.pos-se.pgsize; /if
  77.      if (len(se.buffer)<se.pos); se.pos=len(se.buffer)-se.pgsize; /if;
  78.      if (se.pos<0); se.pos=0; /if;
  79.  
  80.      >  <h1> Query Result </h1> 
  81.         Contains <? len(se.buffer)> Records. 
  82.      <table border>
  83.      <tr>
  84.      <let i=0;
  85.       h=se.buffer[0];
  86.       > <th> Nr </th> <
  87.       while (i<len(h));
  88.     >  <th> <? fname(h[i])> </th> <
  89.     let i=i+1;
  90.       /while;
  91.  
  92.       l=0;
  93.       while l<se.pgsize && l+se.pos<len(se.buffer);
  94.     > <tr> <
  95.     let h=se.buffer[l+se.pos];
  96.     > <td> <? l+se.pos> </td> <
  97.     let i=0;
  98.         while (i<len(h));
  99.       >  <td> <? h[i]> </td> <
  100.       let i=i+1;
  101.         /while;
  102.     > </tr> <
  103.         let l=l+1;
  104.       /while;
  105.    > 
  106.    </table>
  107.    <let par=emptytuple; par.next="t">
  108.    <sa par=par>next</sa>
  109.    <let par=emptytuple; par.prev="t">
  110.    <sa par=par>prev</sa>
  111.    <
  112. /if;
  113.  
  114. /heitmlpage;
  115. /session>
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.