Chapter 1 Dynamo Tags
This section lists the function, syntax, attributes, and examples for each Dynamo tag.
Use the COMPONENT tag to embed Jaguar components in HTML documents.
For SQL access:
<!--COMPONENT ACCESS_METHOD= SQL PKG=packagename COMPONENT_NAME=componentname METHOD=methodname
parameter(s)
-->
For ActiveX access:
<!--COMPONENT ACCESS_METHOD= ACTIVEX PKG=packagename COMPONENT_NAME=componentname METHOD=methodname HOST=hostname
parameter(s)
-->
For Java access:
<!--COMPONENT ACCESS_METHOD= JAVA PKG=packagename COMPONENT_NAME=componentname METHOD=methodname MANAGER_URL=url USERID=id PASSWORD=password NARROW_INTERFACE=narrowinterface
parameter(s)
-->
The COMPONENT
tag
is used to call and manipulate Jaguar components. The same attributes
associated with the SQL tag may be used with the COMPONENT
tag.
The default name of the query object when using
the COMPONENT
tag is COMPONENT,
in
the same way that the default name of the query object is SQL when
the SQL
tag is being used.
The following example calls the setMessage
method of a Jaguar component. $message
is
equal to saying document.value.message
(passes
in a variable from a form in a previously accessed document):
<!--COMPONENT PKG=Demo_Components COMPONENT_NAME=SharedMsg METHOD=setMessage
$message
-->
The following example calls the getMajors method of the SVUMetaData component which is part of the SVU package included with Jaguar:
<HTML>
<!--COMPONENT PKG=SVU COMPONENT_NAME=SVUMetaData METHOD=getMajors
-->
<!--formatting NAME=COMPONENT--><TR>
<!--/formatting-->
</HTML>
The following example calls the getMajors method of the SVUEnrollment component which is part of the SVU package included with Jaguar. The access method for this example is Java. The GetValue function is used to return the appropriate datatype for each column. For more information on result sets, see the Jaguar documentation.
<!--COMPONENT ACCESS_METHOD=JAVA PKG=SVU COMPONENT_NAME=SVUEnrollment METHOD=getMajors MANAGER_URL=iiop://localhost:9000 USERID=jagadmin PASSWORD=""
-->
<!--SCRIPT
function GetValue(query, metadata, column ) {
type = metadata.getColumnType( column );
switch( type ) {
case 1: //CHAR
return query.getString( index );
case 2: //NUMERIC
case 3: //DECIMAL
return query.getBigDecimal( index, this.metadata.getScale(index) ).floatValue();
case 4: //INTEGER
return query.getInt( index );
case 5: //SMALLINT
return query.getShort( index );
case 6: //FLOAT
case 7: //REAL
return query.getFloat( index );
case 8: //DOUBLE
return query.getDouble( index );
case 12: //VARCHAR
return query.getString( index );
case 0: //NULL
return null
case 1111: //OTHER
return query.getObject( index );
case 91: //DATE
return query.getDate( index );
case 92: //TIME
return query.getTime( index );
case 93: //TIMESTAMP
return query.getTimestamp( index );
default:
if( type < 0 ) {
if( type == -1 ) { //LONGVARCHAR
return query.getString( index );
} else if( type == -2 ) { //BINARY
return query.getBytes( index );
} else if( type == -3 ) { //VARBINARY
return query.getBytes( index );
} else if( type == -4 ) { //LONGVARBINARY
return query.getBytes( index );
} else if( type == -5 ) { //BIGINT
return query.getLong( index );
} else if( type == -6 ) { //TINYINT
return query.getShort( index );
} else if( type == -7 ) { //BIT
return query.getBytes();
}
} else {
return query.getBytes( index );
}
}
document.writeln( "<H3>Testing SVUEnrollment getmajors</H3>" );
//The result of the tag is stored in the variable
//COMPONENT
prequery = COMPONENT;
//The RecordSet returned needs to fixed using a
//static method call
query = java.CallStaticMethod( "com.sybase.CORBA.jdbc11.SQL","getResultSet",prequery );
received = query.next();
i = 0;
while( received ) {
metadata = query.getMetaData();
for( j = 1; j <= 3; j++ ) {
value = GetValue( query, metadata, j );
document.writeln( value );
}
received = query.next();
i++;
}
-->
"Calling Jaguar Component Methods from PowerDynamo" in the PowerDynamo User's Guide.
The DATA tag allows an undetermined number of rows to be returned from a query.
<!--DATA [ QUERY=queryname ] [ NAME=colname ] -->
When you use a query in a template, and the results are to be formatted as a table or list, you do not know how many rows will be in the result set.
PowerDynamo uses data placeholders, formatted
as comment tags, to describe the formatting of each row of the query
result set. The DATA
tag
is used in conjunction with the FORMATTING
tag.
The data placeholders are marked with comment tags:
<!--DATA-->
Only one row of placeholders is included within a FORMATTING statement. The application server automatically expands the placeholder to as many rows as required to hold the result set.
DATA tags must be between a FORMATTING start tag and a FORMATTING end tag.
The following template fragment defines a table that holds the results of a simple query:
<TABLE BORDER>
<TR>
<TH>name</TH>
<TH>color</TH>
</TR>
<!--FORMATTING--><TR>
<TD><!--DATA--></TD>
<TD><!--DATA--></TD>
</TR><!--/FORMATTING-->
</TABLE>
</BODY>
</HTML>
The DOCUMENT tag allows you to set certain properties of the document, such as the content type, status, whether or not the request should be redirected to an alternate URL, and the duration of time, if any, the request output should be cached.
<!--DOCUMENT [ CONTENT_TYPE = type ]
... [ REDIRECT = URL ]
... [ STATUS = statusCode ]
... [ CACHED_OUTPUT_TIMEOUT = minutes ] -->
This example caches the document output for five minutes.
<HTML>
<TITLE>doctag.stm</TITLE>
<BODY>
<H1>Customer Phone Numbers</H1>
<!--SQL
SELECT customer.fname, customer.lname, customer.phone
FROM DBA.customer customer
-->
<!--DOCUMENT CACHED_OUTPUT_TIMEOUT = "5" -->
<TABLE BORDER>
<TR>
<TH>fname</TH>
<TH>lname</TH>
<TH>phone</TH>
</TR>
<!--formatting--><TR>
<TD><!--DATA--></TD>
<TD><!--DATA--></TD>
<TD><!--DATA--></TD>
</TR><!--/formatting-->
</TABLE>
</BODY>
</HTML>
The ELSE tag allows you to manipulate script flow. If none of the preceding conditions are true, the request associated with the ELSE statement is executed.
<!--ELSE -->
This example uses the IF tag to check if a condition (YearOfBirth=1970) is true or false. If the condition is true the text "You are old enough to participate in this promotion" displays. If the condition is false, the ELSE tag is used and displays "You are not old enough to participate in this promotion."
<HTML>
<!--SCRIPT
YearOfBirth=1970;
-->
<!--IF EXPR="YearOfBirth < 1979" -->
You are old enough to participate in this promotion.
<!--ELSE-->
You are not old enough to participate in this promotion.
<!--ENDIF-->
</HTML>
The ELSEIF tag can be used after an IF tag to check another condition if the first condition associated with the IF tag was false.
<!--ELSEIF EXPR = expression -->
Attribute |
Description |
---|---|
|
The expression determines whether the execution of the tag should continue or be passed over. If the expression is true, execution will continue. |
An example of the ELSEIF tag is as follows:
<HTML>
<!--SCRIPT
var num=22;
-->
<!--IF EXPR="num > 5" -->
<!--IF EXPR="num > 10" -->
num is greater than 10
<!--ELSEIF EXPR="num < 10"-->
num is greater than 5 and less than 10
<!--ELSE-->
num is 10
<!--ENDIF-->
<!--ENDIF-->
</HTML>
The ENDIF tag ends the IF block.
<!--ENDIF -->
The following example has two IF
blocks
that end with the ENDIF
tag:
<HTML>
<!--SCRIPT
var num=22;
-->
<!--IF EXPR="num > 5" -->
<!--IF EXPR="num > 10" -->
num is greater than 10
<!--ELSEIF EXPR="num < 10"-->
num is greater than 5 and less than 10
<!--ELSE-->
num is 10
<!--ENDIF-->
<!--ENDIF-->
</HTML>
The EVALUATE tag allows you to evaluate a DynaScript expression.
<!--EVALUATE EXPR = expression -->
Attribute |
Description |
---|---|
|
The expression to be evaluated. This attribute is required. |
An example of the EVALUATE tag is as follows:
<!--EVALUATE EXPR="j + 1" -->
dollars.
If j is equal to 5, the above example would have an output of:
6 dollars
The EXECUTE tag allows you to execute a system command.
<!--EXECUTE COMMAND = commandname -->
Attribute |
Description |
---|---|
|
The name of the command to be executed. This attribute is required. <!--EXECUTE COMMAND="mycommand"--> |
This example launches notepad.exe:
<!--EXECUTE command = "notepad.exe"-->
Defines the output of a query.
For HTML formatting:
<!--FORMATTING [[FORMAT_AS="HTML" ][ BORDER = borderwidth ] [ LIST = listtype ][ MAXROWS = num ] [ NAME = stmtname ] [STARTROW = rownum ][STRIP_TRAILING_BLANKS]] -->
<!--/FORMATTING -->
For XML formatting:
<!--FORMATTING [[FORMAT_AS="XML"] [RESULTSET_TAG=restultsettagname][ROW_TAG=rowtagname][COLUMN_TAG=columntagname][USE_CDATA ] [ MAXROWS = num ] [ NAME = stmtname ] [STARTROW = rownum ] [STRIP_TRAILING_BLANKS]] -->
<!--/FORMATTING -->
When you use a query in a template, and want the results to be formatted as a table or list, you do not know ahead of time how many rows are going to be in the result set.
PowerDynamo uses data placeholders to describe the formatting of each row of the query result set.
Formatting using scripts
You can also use embedded scripts
to format output. The flexibility of scripts allows more varied
formatting than the formatting tags.
The HTML tags for formatting instructions are slightly different from the tags used for SQL statements. To allow an HTML editor to modify and refine the actual formatting, the formatting description is not inside a comment. Instead, comment tags are used for placeholders for the data, which are replaced on processing by the actual data.
All data placeholders must be between formatting start and end comment tags. The start tag is:
<!--FORMATTING-->
The end tag is:
<!--/FORMATTING-->
There is no restriction on the HTML code that can be included between the tags. The formatting comment tags have no effect on HTML that occurs between them; they affect only the embedded instructions.
This example defines a table that holds the results of a simple query:
<TABLE BORDER>
<TR>
<TH>name</TH>
<TH>color</TH>
</TR>
<!--FORMATTING--><TR>
<TD><!--DATA--></TD>
<TD><!--DATA--></TD>
</TR><!--/FORMATTING-->
</TABLE>
This example performs a query on a product
table with more than 100 product codes. Using the MAXROWS
attribute
results in only the first 3 product codes being returned.
<!--SQL
select code from productlist
-->
<!--FORMATTING MAXROWS=3-->
Product code: <!--DATA-->
<!--/FORMATTING -->
has the output of:
Product code: 111
Product code: 222
Product code: 333
You can nest the FORMATTING
tag
inside other FORMATTING
tags.
For example, this fragment:
<!--FORMATTING NAME=Query1-->
<!--FORMATTING NAME=Query2-->
<!--DATA QUERY=Query1--><!--DATA-->
<!--/FORMATTING-->
<!--/FORMATTING-->
Would have an output similar to:
Fred 26
Fred 32
Fred 27
Fred 34
Jane 26
Jane 32
Jane 27
Jane 34
If you do not specify a QUERY
attribute
on the DATA
tag, the query
specified on the innermost <!--FORMATTING--> block
is assumed.
Using nested FORMATTING statements on databases that do not support backward cursor movement causes a performance degradation. Sybase strongly recommends that you not nest FORMATTING sections unless absolutely necessary.
You may also reference a query that is outside of the formatting block. For example:
<!--formatting NAME=Query1-->
<!--data QUERY=Query3 NAME=title--><!--DATA-->
<!--/formatting-->
This example uses the FORMAT_AS=XML tag to create the output in XML.
<!--SQL
select product.description, product.color
from product
order by product.description
-->
<!--FORMATTING FORMAT_AS="XML" RESULTSET_TAG="MYRESULTSET" ROW_TAG="MYROW"
COLUMN_TAG="MYDESCRIPTION MYCOLOR"-->
<!--/FORMATTING-->
The output would look like this:
<MYRESULTSET>
<MYROW><MYDESCRIPTION>Cloth Visor</MYDESCRIPTION><MYCOLOR>White</MYCOLOR></MYROW>
<MYROW><MYDESCRIPTION>Cotton Cap</MYDESCRIPTION><MYCOLOR>Black</MYCOLOR></MYROW>
<MYROW><MYDESCRIPTION>Cotton
Shorts</MYDESCRIPTION><MYCOLOR>Black</MYCOLOR></MYROW>
<MYROW><MYDESCRIPTION>Crew Neck</MYDESCRIPTION><MYCOLOR>Black</MYCOLOR></MYROW>
<MYROW><MYDESCRIPTION>Hooded
Sweatshirt</MYDESCRIPTION><MYCOLOR>Green</MYCOLOR></MYROW>
<MYROW><MYDESCRIPTION>Plastic Visor</MYDESCRIPTION><MYCOLOR>Black</MYCOLOR></MYROW>
<MYROW><MYDESCRIPTION>Tank Top</MYDESCRIPTION><MYCOLOR>White</MYCOLOR></MYROW>
<MYROW><MYDESCRIPTION>V-neck</MYDESCRIPTION><MYCOLOR>Orange</MYCOLOR></MYROW>
<MYROW><MYDESCRIPTION>Wool cap</MYDESCRIPTION><MYCOLOR>White</MYCOLOR></MYROW>
<MYROW><MYDESCRIPTION>Zipped
Sweatshirt</MYDESCRIPTION><MYCOLOR>Blue</MYCOLOR></MYROW>
</MYRESULTSET>
The ID tag allows for manipulation of script
flow. If the condition associated with the tag is true the text
associated with the IF
tag
will be executed.
<!--IF EXPR=expression -->
<!--ENDIF -->
Attribute |
Description |
---|---|
|
The expression that determines whether the execution of the tag should continue or be passed over. If the expression is true, execution will continue. |
This example uses the IF tag to check if a condition (YearOfBirth < 1979) is true or false. If the condition is true the text "You are old enough to participate in this promotion" displays. If the condition is false, the else statement is used and displays "You are not old enough to participate in this promotion."
<HTML>
<!--SCRIPT
YearOfBirth=1970;
-->
<!--IF EXPR="YearOfBirth < 1979" -->
You are old enough to participate in this promotion.
<!--ELSE-->
You are not old enough to participate in this promotion.
<!--ENDIF-->
</HTML>
Use the INCLUDE tag to include the generated output of another document. The specified path may be a relative or an absolute path or the tilde (~) character may be used.
For information on using the tilde character see "Paths".
<!--INCLUDE NAME = filename -->
Argument |
Description |
---|---|
|
Name of the document that is to have its output included in the output of the current document. |
<HTML>
<TITLE>sample.stm</TITLE>
<BODY>
<H1>Book Stores</H1>
<P>The following book stores are owned by the Read Smart Corporation</P>
<!--INCLUDE name="stores.stm"-->
<P>For detailed information on individual book stores, dial the store directly. If you
have a question about the corporation, dial Read Smart's 1-800 number. </P>
</BODY>
</HTML>
The LABEL tag allows you to return the column name or column alias (as specified in the SQL query) for the colNum column.
<!--LABEL [ NAME = queryname ][ INDEX = columnindex ] -->
Attribute |
Description |
---|---|
|
The name
of the query. If you do not specify |
|
The column index. This attribute is optional. |
You can use the LABEL tag alone or from within a formatting section. When you use it within a formatting section for a query, each subsequent occurrence of the LABEL tag increases the value of INDEX by one.
The following lines:
<!--SQL
select name, color, size from product
-->
<!--FORMATTING-->
<!--LABEL-->: <!--DATA-->
<!--LABEL-->: <!--DATA-->
<!--LABEL-->: <!--DATA-->
<!--/FORMATTING-->
produce the following output:
name: Tee Shirt
color: White
size: Small
name: Tee Shirt
color: Orange
size: Medium
name: Tee Shirt
color: Black
size: One size fits all
Use the MAILPIECE tag to send mail through a SMTP host.
<!--MAILPIECE TO = recipientAddress [ FROM = fromAddress ] [ SUBJECT = subject ] [ SMTPHOST = SMTPAddress ] -->
Body of the mail piece
<!--/MAILPIECE -->
Use the MAILPIECE tag to send mail from PowerDynamo using Dynamo tags and a SMTP host. Enter the body of the mail piece between the start and end mail piece tag. If you do not specify an SMTP host within the script, the default SMTP host specified in Sybase Central is used. If you have not specified an SMTP host in either of these places, an error occurs.
This example sends a mail piece with a subject and body. The SMTP host has been set in Sybase Central:
<HTML>
<!--MAILPIECE TO="elmo@sybase.com" FROM="fred@sybase.com" SUBJECT="My mail piece subject"-->
This is the body of the mail piece.
<!--/MAILPIECE-->
</HTML>
Use the SCRIPT tag to embed DynaScript in HTML documents.
<!--SCRIPT
DynaScript code
-->
All DynaScript scripts begin and end with a
SCRIPT tag (<!--SCRIPT
-->
).
All information within a SCRIPT
tag
is invisible to any Web editing tool-in other words, it
is processed by the Dynamo application server.
document.WriteLn
in
an HTML document:
<HTML>
<TITLE>sample.stm</TITLE>
<BODY>
<H1>DynaScript Sample</H1>
<!--SCRIPT
document.WriteLn("This is DynaScript");
-->
For more information, see "The DynaScript Language".
Use the SQL tag to embed SQL statements are embedded in HTML documents.
<!--SQL [ NAME = queryname ]
... [ CONNECTION_NAME = conname
... | CONNECTION_OBJECT = objname
... | DSN = datasource UID = userid- PWD = password
... | SERVER = servername DBN = databasename UID = userid PWD = password ]
... [ NO_EXECUTE = queryname ]
[ NO_SQL_ERROR ]
SQL query
-->
Only one connection
You can use only one of: CONNECTION_NAME
, CONNECTION_OBJECT,
DSN,
or SERVER
.
Use SQL queries to access and manipulate data that has been stored in a database.
This example has a SQL query embedded in HTML.
<HTML>
<TITLE>sample.stm</TITLE>
<BODY>
<H1>DynaScript Sample</H1>
<!--SQL
SELECT Book.Title, Book.BookID, Book.Price
FROM DBA.Book Book
-->
</BODY>
</HTML>
Performs an insert operation using the document's parameters.
<!--SQL_INSERT TABLE= tableName [ NAME = queryname ]
... [ CONNECTION_NAME = conname
... | CONNECTION_OBJECT = objname
... | DSN = datasource UID = userid- PWD = password
... | SERVER = servername DBN = databasename UID = userid PWD = password ]
... [ NO_EXECUTE = queryname ]
[ NO_SQL_ERROR ]
-->
Only one connection
You can use only one of: CONNECTION_NAME
, CONNECTION_OBJECT,
DSN
,
or SERVER
.
Use SQL_INSERT to enter data into a table. For example, lets's say you have created a form that asks a user to enter the information to add to the table. If the names on the form match the names of the table columns, you can insert the information into the table by calling a simple script that includes:
<!--SQL_INSERT TABLE="tablename"-->
The following template allows a user to add a new product to the database. The first document (newProduct.stm) collects the information and passes it to the second document (insert.ssc) for insertion.
<HTML>
<TITLE>newProduct.stm</TITLE>
<BODY>
<H1>New Product</H1>
<P>Enter the following information</P>
<FORM METHOD=POST ACTION="insert.ssc">
<OL>
<LI><INPUT TYPE="text" NAME="id" >ID of the product<BR>
<LI><INPUT TYPE="text" NAME="name" >Name of the product<BR>
<LI><INPUT TYPE="text" NAME="description" >Description<BR>
<LI><INPUT TYPE="text" NAME="size" >Size<BR>
<LI><INPUT TYPE="text" NAME="color" > Color<BR>
<LI><INPUT TYPE="text" NAME="quantity" > Quantity<BR>
<LI><INPUT TYPE="text" NAME="unit_price" > Price<BR>
</OL>
<P><INPUT TYPE="submit"></p>
<P><INPUT TYPE="RESET" VALUE="Clear Form"></P>
</FORM>
</BODY>
</HTML>
calls:
<HTML>
<TITLE>insert.ssc</TITLE>
<BODY>
<H1>DynaScript Sample</H1>
<!--SQL_INSERT TABLE="product" -->
</BODY>
</HTML>
The above example would be equivalent to:
<!--SQL
insert into product ( id, name, description, size, color, quantity, unit_price )
values ( 999, 'dog', 'furry', 'dog_sized', 'brown', 1, 123 )
-->
The SQL condition tags allow you to specify a certain condition that must be fulfilled for the code between the conditional start and end tags to be executed.
<!--SQL_ON_type [ NAME = queryname ]-->
<!--/SQL_ON_type -->
type:
NO_ERROR | ERROR | NO_ROWS | ROWS
Attribute |
Description |
---|---|
|
Name of a query. This attribute is optional. If you do not provide a query name, "SQL" is assumed. |
The following table lists the conditions that are supported by Dynamo. If the condition is fulfilled, the source between the conditional start and end tag is included in the output.
You can use one or more types of tags (SQL, SCRIPT etc.) between a conditional start and end tag.
This example provides output only if the SQL query does not produce an error.
<!--SQL
select Fname, Lname, accno, amount
from savings where accno = :account
-->
<!--SQL_ON_NO_ERROR-->
<!--SCRIPT
document.WriteLn("You have " + account.amount + " in your account.");
-->
<!--/SQL_ON_NO_ERROR-->
The SQL_ERROR_CODE tag allows you to return the current error code. If a SQL instruction is carried out successfully an error code of 0 is returned.
<!--SQL_ERROR_CODE [ NAME = queryname ] -->
Attribute |
Description |
---|---|
|
Name of a query. This attribute is optional. If you do not provide a query name, "SQL" is assumed. |
This example returns 0 as well as the output generated from the SQL query as long as no errors are encountered during execution.
<!--SQL
SELECT Stock."Quantity", Stock."BookID"
FROM "DBA"."Stock" Stock
-->
<!--SQL_ERROR_CODE-->
<TABLE BORDER>
<TR>
<TH>Quantity</TH>
<TH>BookID</TH>
</TR>
<!--formatting--><TR>
<TD><!--DATA--></TD>
<TD><!--DATA--></TD>
</TR><!--/formatting-->
</TABLE>
</BODY>
</HTML>
The SQL_ERROR_INFO tag allows you to return a description of the error information.
<!--SQL_ERROR_INFO [ NAME = queryname ] -->
Attribute |
Description |
---|---|
|
Name of a query. This attribute is optional. If you do not provide a query name, "SQL" is assumed. |
This example displays error information for
a query named myQuery
:
<!--SQL NAME=myQuery
select lname, fname from customer
-->
<!--SQL_ERROR_INFO NAME="myQuery" -->
<!--SCRIPT
while (myQuery.MoveNext()) {
document.WriteLn(myQuery.GetValue(1) + "," + myQuery.GetValue(2));
}
myQuery.MoveFirst();
-->
The SQL_STATE tag returns the current SQL state of a query.
<!--SQL_STATE [ NAME = queryname ] -->
Attribute |
Description |
---|---|
|
Name of a query. This attribute is optional. If you do not provide a query name, "SQL" is assumed. <!---SQL_STATE NAME="myquery"--> |
This example displays the state of the SQL query:
<!--SQL
select lname, fname from customer
-->
<!--SQL_STATE-->
<!--SCRIPT
while (SQL.MoveNext()){
document.WriteLn(SQL.GetValue(1) + "," + SQL.GetValue(2));
}
-->
Copyright © 1999 Sybase, Inc. All rights reserved. |