Executes the SQL query provided and returns the
result as specified.
<!-- #ICE [REPEAT]
SQL=`query`
[TYPE=`TABLE|SELECTOR|PLAIN|UNFORMATTED`]
[DATABASE=`database_name`]
[TRANSACTION=`transaction_name`]
[CURSOR=`cursor_name`]
[ROWS=`number_of_rows`]
[USER=`user_name`]
[PASSWORD=`password`]
[LINKS=`{column_name,
URI}[,…]`]
[HEADERS=`{column_name,
text}[,…]`]
[ATTR=`attribute`]
[EXT=`extension`]
[NULLVAR=`text`]
[MARKUP=`HTML text with variables`]
-->
The value
of the SQL keyword, query, is
specified by one or more SQL statement(s).
The SQL keyword also provides a variety of options. Ingres/ICE executes the SQL statement(s) and
formats the results as specified by the TYPE option. If the statement is not a select, a message is displayed. The message can be specified using the
ii_success_message and ii_error_message HTML variables.
The SQL
statement may contain parameter markers of the form :variable, where variable is a defined HTML
variable. HTML variables are defined
using the <INPUT> tag. Note that
variables set in an HTML form are not defined until that form is submitted;
variables defined in a form on the same page as an Ingres/ICE macro will not be
defined.
|
Options and Parameters |
The following table lists the parameter and options used with the SQL keyword: |
|
Parameter and Options |
Description |
|
query |
Specifies one or more SQL statement(s). |
|
TYPE=`TABLE|SELECTOR| |
Specifies the type of HTML formatting for the output. See the TYPE option description in this section for information on the valid choices. |
|
DATABASE=`database_name` |
Specifies the database to which the query will be directed. |
|
TRANSACTION= |
Specifies a unique name for a transaction. See the TRANSACTION option description in this section for more information. |
|
Parameter and Options |
Description |
|
CURSOR=`cursor_name` |
Specifies a unique name for a cursor. If not used, a cursor is created by specifying the number of rows required (using the ROWS option). This option may only be specified when associated with a transaction (i.e., the TRANSACTION option is also specified). There is a limitation of one cursor per transaction. See the CURSOR option description in this section for more information. |
|
ROWS=`number_of_rows` |
Specifies the number of rows for retrieval with the cursor. |
|
USER=`user_name` |
Specifies the name of the Ingres/ICE database user with which to associate the query. The actual Ingres user the alias maps to runs the query. This option must be specified with the PASSWORD option as a pair. Note: This option is provided for backward compatibility with Ingres/ICE 2.0 and is not recommended. |
|
Parameter and Options |
Description |
|
PASSWORD=`password` |
Specifies the password for the user specified with the USER option. Note: This option is provided for backward compatibility with Ingres/ICE 2.0 and is not recommended. |
|
LINKS=`{column_name, URI}[,…]` |
Generates a hypertext link to the URI for each item in the column. This option may only be specified when TYPE is not UNFORMATTED. See the LINKS option description in this section for more information. |
|
HEADERS=`{column_name, text}[,…]` |
Allows the definition of the text used in column headers. By default, the SQL column name is used. This option may only be specified when TYPE is not UNFORMATTED. |
|
ATTR=`attribute` |
Specifies a string representing any valid HTML attribute in the context of the TYPE option. This option may only be specified when TYPE is not UNFORMATTED. See the ATTR option description in this section for more information. |
|
Parameter and Options |
Description |
|
EXT=`extension` |
Specifies an extension that overrides the extension used for the temporary file when referring to a binary object. It is only valid when the output of a query contains a single column of binary objects. This option applies to all extracted binary columns. |
|
NULLVAR=`text` |
Specifies the text that should be used when parsing a macro and the variable does not exist. |
|
MARKUP=`HTML text with variables` |
Specifies a format string containing markup tags and column names. When using this option, the TYPE option must be set to UNFORMATTED. See the MARKUP option description in this section for more information. |
TYPE Option The TYPE option specifies the type of HTML formatting for the output. The available values are:
n
TABLE
(default)—formats the result rows as an HTML table. The column headers are the names of the result columns. Each table cell contains a single item in
the result set. If the result set
contains Binary Large Objects (BLOBs), Ingres/ICE writes the BLOBs to temporary
files and generates <IMG> tags to refer to them, indicating that the
files contain image data. This output
type supports the LINKS option.
n
SELECTOR—formats
the results using the HTML SELECT tag.
If the query contains multiple columns, the columns in each row are
concatenated. This output type does not
support the LINKS option.
n
PLAIN—formats
each row of the result set as a paragraph.
If the result set contains BLOBs, Ingres/ICE writes the BLOBs to
temporary files and generates <IMG> tags to refer to them, indicating
that the files contain image data. This
output type is particularly useful for placing images on a page. This output type supports the LINKS option.
n
UNFORMATTED—outputs
the data with no HTML formatting or separators. If the result set contains BLOBS, Ingres/ICE writes the BLOBs to
temporary files and places the URIs of the files on the output page. This output type is useful when you want to
embed references to BLOBs in another HTML tag, for example, to fetch a
background image for a page from a database.
|
TRANSACTION Option |
The TRANSACTION option allows the association of a name with a transaction. |
When writing
Ingres/ICE queries, “auto commit” is the default action. Queries are committed if they complete
successfully. With applications that
require browsing and selecting items from a list (like a shopping cart), it is
necessary to maintain a transaction over many pages and only commit the
transaction when the user has completed.
A transaction is completed with either the COMMIT or the ROLLBACK option
with the transaction name.
CURSOR Option The CURSOR option specifies a unique name for a
cursor. When used, a named cursor is created which allows the
full result set to be displayed page-by-page until the transaction is
ended. If not specified, an anonymous cursor is created and which is
closed when the rows have been returned.
Using this
option, a number of rows on a page is defined by the Web author, which reduces
the volume of data that is transmitted and the amount of time the browser
spends waiting for the data.
LINKS Option The value of the LINKS option has the form `column_name,URI`. For example:
`type,http://www.foo.com/typeinfo.html`
This would
generate links to the URI for each item in the type column in the result set
http://www.foo.com/typeinfo.html.
You can
specify as many comma-separated column and URI pairs as you require. As Ingres/ICE processes the result set, for
each item in a LINKS column, it generates a hyperlink tag to the specified URI
for each item in the column.
To enable
the referenced page to determine which item was clicked on, Ingres/ICE sets an
HTML variable. The variable has the
same name as the column name, and its value is the value clicked on. The referenced page can use this variable,
typically by making it a parameter in another SQL statement. You cannot generate links for a BLOB column.
ATTR Option The ATTR option allows the user to
change the appearance of the page by specifying HTML attributes that will be
applied to the generated HTML.
Ingres/ICE does not parse the value—it simply passes it through to the
output page.
Valid
values for the ATTR option include any HTML that is legal in the context of the
specified output type, specified by the TYPE option:
|
Value of TYPE Option |
Use of ATTR Option |
|
TABLE |
Specify the table border width, color, cell spacing, alignment, or any of the other HTML table attributes. |
|
SELECTOR |
Specify the name of the HTML variable into which the browser will place the selected value. |
|
Value of TYPE Option |
Use of ATTR Option |
|
PLAIN |
Specify the attributes for image output. |
|
UNFORMATTED |
Not available. |
MARKUP Option The MARKUP option provides the ability to
describe a line of HTML or markup language syntax and embed within it variable
placeholders. This enables a developer to
program using HTML tools that provide WYSIWYG rendering. The Ingres/ICE macros can then be added
using the HTML already generated.
This
removes dependence of Ingres/ICE on knowledge of HTML or other markup syntax
when building output.
REPEAT Option See
the FUNCTION keyword for information on the REPEAT option.
The
following examples show several different uses of the SQL macro keyword and a
sample of the source output:
<!-- #ICE
SQL=`select
* from icetable`
DATABASE
= `iceTutorial`
TRANSACTION=`myTransaction`
CURSOR=`myCursor`
ROWS=`10`
TYPE=`TABLE`
-->
<!-- #ICE
SQL=`select * from icetable`
DATABASE
= `iceTutorial`
TRANSACTION=`myTransaction`
CURSOR=`myCursor`
ROWS=`10`
TYPE=`TABLE`
HEADERS=`i_title,Category`
LINKS=`i_title,www.uri.com`
ATTR=`border=1`
-->
<!-- #ICE
SQL
= `select title,lastname from
book,author,bookauthor
where book.bookid =
bookauthor.bookid
and bookauthor.authid =
author.authid`
-->
Source Output An example of the generated ouput produced by
the Ingres/ICE server follows:
<TABLE><TR>
<TH>title</TH>
<TH>lastname</TH>
</TR>
<TR>
<TD>Hamlet
<TD>Shakespeare
</TR>
<TR>
<TD>Macbeth
<TD>Shakespeare
</TR>
<TR>
</TABLE>
COMMIT keyword, ROLLBACK keyword