## ## Document History ## ## Created (peeje01) ## 27-Apr-1999 (peeje01) ## Change include file name from -h.html to _h.html ## 02-Apr-2004 (fanra01) ## Bug 112091 ## Editorial changes from griel02. ## Page to Run a Simple the Select Statement

Page to Run a Simple the Select Statement

One of the simplest things we can do is to select a set of rows from a table. (The full contents of the plays table are available). We will go through the process of creating the Web Deployment Option macro to generate the required code by using the Web Deployment Option Design Tool step by step for this file. Once we have generated the macro code we will cut and paste it into the file play_all.html.

Paint the Select Macro

  1. Open the ICE Design tool
  2. Select the plus symbol next to the "Macro Commands" option in the menu tree to expand the structure.
  3. Select the plus symbol next to the "SQL statement"
  4. Select Database
    1. Ensure "icetutor" is the selected database.
    2. Press 'next' Next to move to
      Statement
    3. Ensure the SQL query is select * from plays
    4. Press 'next' Next to move to
      Transaction
    5. Ensure the transaction name is "Complete"
    6. Press 'next' Next to move to
      Cursors
    7. Ensure the cursor name is "Works"
    8. Press 'next' Next to move to
      Rows
    9. Ensure the number of rows is set to "5"
    10. Press 'next' Next to move to
      Formatting the Layout
    11. Ensure that the radio button "Table" is selected.

You should see the following macro command displayed:

<!-- #ICE
DATABASE = `icetutor`
SQL=`select * from plays`
TRANSACTION=`Complete`
CURSOR=`Works`
ROWS=`5`
TYPE=`TABLE`
-->


And following that you should see the sample output:


compordertitleplaywrightperformedactstype
1Two Gentlemen of VeronaShakespeare15985comedy
2Taming of The ShrewShakespeare5comedy
3Henry VI part 1Shakespeare15915history
4Henry VI part 3Shakespeare15955history
5Titus AndronicusShakespeare5tragedy

ii_rowcount = 5

Cut & Paste Macro

We are happy (for now) with this output, so cut and paste the red macro text into your "play_all.html" file. The result should be as follows:

File: play_all.html (initial)

<html>
<head>
<title>Shakespeare's Plays</title>
</head>
<body>
<h1>Shakespeare's Plays</h1>


	  <!-- #ICE
          DATABASE = `icetutor`
          SQL=`select * from plays`
          TRANSACTION=`Complete`
          CURSOR=`Works`
          ROWS=`5`
          TYPE=`TABLE`
          -->


</body>
</html>

If you have already registered the file you can now view it in the administration tool or by loging on to your site and specifying its URL.

Notice that the only way or retrieving the next set of rows is by reloading the page. (Press the Refresh button on your browser.)

Add a More Button

We now need a way of retrieving the next set of 5 plays. Since we have opened both a transaction (Complete) and a cursor (Works) and the action of the cursor is to retrieve the next set of rows, we simply need to re-load the document. You might like to try this with your document. Although this will work, it is not quite as user friendly as we would like! We would much prefer to add a Buton to get more plays. The action of the button is to revisit the document. We know from the HTML Primer that a button exists on a form, so we need a form whose action is the URL of the current document. The button type that submits the form to the Web server is SUBMIT. The end result of all this is that the Submit button acts just like the Refresh button on your browser. We assign a meaningful name to the button, say, "More". We are now ready to present the document with our new More button:

File: play_all.html (with MORE button)

<html>
<head>
<title>Shakespeare's Plays</title>
</head>
<body>
<h1>Shakespeare's Plays</h1>

<!-- #ICE
          DATABASE = `icetutor`
          SQL=`select * from plays`
          TRANSACTION=`Complete`
          CURSOR=`Works`
          ROWS=`5`
          TYPE=`TABLE`
          -->

<p>


<FORM ACTION="/ice-bin/oiice.dll/playgroup/plays[play_all.html]"
	METHOD="POST">
<INPUT TYPE="submit" NAME="More" VALUE="More" ALT="Show more plays">
</FORM>


</body>
</html>

Include Generic Session Control

We would obviously like to give the user some way of returning to the home page, or logging out. We can easily do this with the following macro statements:
<hr width="50%" >
<h2>Where would you like to go now:</h2>
<table border=0 cellspacing=3>
<tr>
<td>
<A HREF="/ice-bin/oiice.dll/plays[play_home.html]">Globe Home Page:</A>
<td>
<A HREF="/ice-bin/oiice.dll/plays[play_home.html]">
    <img src="OldGlobe.gif" alt="Return to Globe Home Page"
</A>
<tr>
<td>
<p>
<A HREF="/ice-bin/oiice.dll/plays[play_login.html]?ii_action=disconnect">logout:<A>
<td>
<A HREF="/ice-bin/oiice.dll/plays[play_login.html]?ii_action=disconnect">
    logout GIF
</A>
</table>
<hr>

Clearly we could insert this directly into our file. And then every other one that we create. And then re-visit every file whenever we wish to change something. You get the idea. It would be much easier to have one version of this in a seperate file and INCLUDE it as needed. To do this, save the code in the file play_SessionControl_h.html and add the include line to the file play_all.html.

Note: Any include files need to be registered with the ICE server.

File: play_all.html (include session control file)

<html>
<head>
<title>Shakespeare's Plays</title>
</head>
<body>
<h1>Shakespeare's Plays</h1>

<!-- #ICE
          DATABASE = `icetutor`
          SQL=`select * from plays`
          TRANSACTION=`Complete`
          CURSOR=`Works`
          ROWS=`5`
          TYPE=`TABLE`
          -->

<p>

<FORM ACTION="/ice-bin/oiice.dll/playgroup/plays[play_all.html]"
	METHOD="POST">
<INPUT TYPE="submit" NAME="More" VALUE="More" ALT="Show more plays">
</FORM>


<!-- #ICE REPEAT INCLUDE=`plays[play_SessionControl_h.html]` -->

</body>
</html>

Add Transaction Control

The document, as it stands, opens a transaction 'Complete' but never closes it with a commit or rollback. We obviously cannot commit the transaction on the same page because then we would only ever retrieve the first result subset. We could create an extra page that we visit for the sole purpose of committing the transaction but we effectively already have such a page, our home page. A good time to commit the transaction would be when we transfer to the home page. There could be many transactions that use this mechanism, so we choose a variable to contain the name of the transaction to be committed and a further variable to record the fact that the transaction is either available to be committed or has already been committed (since it is the nature of HTML and HTTP that we have no control over how the user arrives at the home page or how often).

File: play_all.html final version (with Transaction control information)

<html>
<head>
<title>Shakespeare's Plays</title>
</head>
<body>
<h1>Shakespeare's Plays</h1>

<!-- #ICE
          DATABASE = `icetutor`
          SQL=`select * from plays`
          TRANSACTION=`Complete`
          CURSOR=`Works`
          ROWS=`5`
          TYPE=`TABLE`
          -->


<!-- #ICE DECLARE=`session.e_playTxn=Complete` -->
<!-- #ICE DECLARE=`session.e_playTxnCommitted=FALSE` -->

<p>

<FORM ACTION="/ice-bin/oiice.dll/playgroup/plays[play_all.html]"
	METHOD="POST">
<INPUT TYPE="submit" NAME="More" VALUE="More" ALT="Show more plays">
</FORM>

<!-- #ICE REPEAT INCLUDE=`plays[play_SessionControl_h.html]` -->
</body>
</html>

Variable Naming Convention

There are various variable scopes available to us: server, session, and page. The naming convention used in this tutorial is scope_name where scope is one of the following:
PrefixScope Level
sServer
esEssion
pPage
This means that the variable e_playTxnCommitted is a session level variable.

We now need some code to use these variables to commit the transaction at the appropriate time. The code that achieves this conditional transaction commital appears below:

File: play_TxnCndCmt_h.html

<!-- #ICE REPEAT IF (DEFINED (e_playTxnCommitted))
	THEN=``
	ELSE=`<!-- #ICE DECLARE=``session.e_playTxnCommitted=TRUE`` -->`
-->
<!-- #ICE REPEAT IF (DEFINED(e_playTxn) AND (`:e_playTxnCommitted` != `TRUE`))
	THEN=`<!-- #ICE COMMIT=``:e_playTxn`` --><!-- #ICE DECLARE=``session.e_playTxnCommitted=TRUE`` -->`
-->

We add an ICE IF statement to our next document. Suffice it to say for now that the first part of this code tests if the variable e_playTxnCommitted exists; if it does not then it is created and set to the value TRUE. We need to do this because the first time we visit the home page, no variables will be set.

Then, if the variable e_playTxn exists and the transaction has not yet been committed, it is committed. We need to perform these checks because it is an error to commit a nonexistent transaction.

It only remains to include this file in our home page, play_home.html as follows:

File: play_home.html

<html>
<head>
<title>Shakespeare's Plays Home Page</title>
</head>
<body>
<center>
<h1>Shakespeare's Plays Home Page</h1>
</center>
This is the home page for Shakespeare's plays hosted on the server <b>globe</b>
<h2>
View Shakespeares Plays
</h2>

<!-- #ICE REPEAT INCLUDE=`plays[play_TxnCndCmt_h.html]` -->


<ol>
<li> <a href="/ice-bin/oiice.dll/playgroup/plays[play_all.html]">All</a>
</ol>
Please
<A HREF="/ice-bin/oiice.dll/plays[play_login.html]?ii_action=disconnect">logout</A>,
don't time out!
<!-- // #ICE REPEAT FUNCTION=`play_NewOrder.newOrder`
	HTML=`<hr>test: next order number is :out_orderNumber<hr>`
-->
</body>
</html>

Summary

In this example we showed how to create a macro statement with the design tool. We embedded the macro into a simple Web Deployment Option document.

We took advantage of the cursor feature to add a More button to the document, enabling us to view the sequence of plays by subset.

Finally we arranged to commit the transaction upon returning to the home page. This code was placed in a seperate file and INCLUDEd into the home page and the play_all.html document. Communication of the transaction name was achieved with web Deployment Optionsession variables

The next page illustrates the use of the if keywords.