[TOC] [Prev] [Next] [Bottom]



<@ASSIGN>

Syntax

<@ASSIGN NAME=name VALUE=value [SCOPE=myscope] [EXPIRES=timestamp] [PATH=path] [DOMAIN=domain] [SECURE=true|false]>

Description

Assigns a value to a variable. If the specified variable does not yet exist, it is created.

For more details on variables, see Chapter 8 of the User's Guide.

The value may be text or an array. If the variable being assigned to exists and contains an array, this tag also lets you set the values of individual elements in that array. <@ASSIGN> can assign an array (or array section) to a variable, or to another array (or array section). Array assignments require that the source and target arrays (or array sections) have the same dimensions.

The NAME attribute specifies the name of the variable to assign the value to. The following restrictions apply to the value specified in the NAME attribute:

Variable names are case insensitive; for example, myVar is the same variable as MYVAR and MyVaR.

If you are assigning to an array variable element or section, the name includes the element or section specification specified within square brackets as [rownumber,colnumber], with an asterisk indicating all rows or all columns; for example, NAME=myArray[1,2] or NAME=myArray[*,3].

The VALUE attribute specifies the value to assign to the variable. If you are assigning to an array section, the value specified here must match the dimensions of the array variable specification in NAME.


! Note: You can add rows to an array, but not columns. For more information, see <@ADDROWS>. Resizing an array variable is not supported, but you may assign a new array (of any dimension) to an existing variable. Assigning subset shapes is not possible where such shapes cannot be described with the wildcard syntax "*".


The SCOPE attribute specifies the name of the scope in which to assign the variable. If this attribute is omitted, the following steps are taken to determine the scope in which the assignment takes place:

For more information, see defaultScope.

Cookie Attributes

For more information, see "Cookie Scope" in Chapter 8 of the User's Guide.

The EXPIRES, PATH, DOMAIN, and SECURE attributes are only valid when SCOPE=COOKIE.

If the EXPIRES attribute is omitted, the cookie expires when the user quits their Web browser. This is the default cookie behavior as described in the cookie specifications. Otherwise, a GMT timestamp must be specified in the following format:

Wdy, DD-Mon-YY HH:MM:SS GMT

The following EXPIRES attribute is a combination of meta tags that specifies a GMT date in the correct format based on the current timestamp plus one week (604,800 seconds):

EXPIRES=<@TOGMT TS=<@SECSTOTS SECS='<@CALC EXPR="<@TSTOSECS TS=<@CURRENTTIMESTAMP>>+604800">'> FORMAT="datetime:http">

For more information, see <@CURRENTDATE>, <@CURRENTTIME>, <@CURRENTTIMESTAMP>, <@TSTOSECS>, <@SECSTOTS>, and <@TOGMT>.

If the DOMAIN attribute is omitted, the Domain value is omitted from the Set-Cookie line, causing the cookie to be valid for the current server. Otherwise you can specify any domain string up to 63 characters. .example.com, for example, would cause the cookie to be sent back to www.example.com, demo.example.com, sales.example.com, and so on.

In the PATH attribute, server root (/) specifies that the cookie be sent for all paths within the specified domain. You can specify a path string up to 63 characters. For example, /tango/ would cause the cookie to be sent back only for URLs below the tango folder. If no PATH is specified, the default is server root.

The SECURE attribute specifies whether a secure connection is required for client send. Possible values are TRUE (enabled) or FALSE (disabled). This option sets the Secure value of the Set-Cookie line. If the value is set to TRUE, then the cookie is sent back by the Web browser only if a secure connection is being made. The default is FALSE, which is used if no secure attribute is found.

Examples

<@ASSIGN NAME="foo" VALUE="123456" SCOPE="user">

This example assigns the value "123456" to the variable foo in user scope.

<@ASSIGN NAME="foo2" VALUE="abcdef">

This example either assigns the value "123456" to the variable foo2 in local, user, application, domain or system scope, depending on the first instance of foo2 that Tango Server encounters; or, if it does not exist, it creates a new variable called foo2 in default scope and assigns the value "123456" to it.

<@ASSIGN NAME=fred SCOPE=cookie VALUE="You were here." EXPIRES="<@TOGMT TS=<@SECSTOTS SECS='<@CALC EXPR="<@TSTOSECS TS=<@CURRENTTIMESTAMP>>+604800">'> FORMAT="datetime:http">">

This example sends a cookie named fred that is valid for the current server and path, has the value "You were here." and expires in one week.

<@ASSIGN NAME="foo3" SCOPE="user" VALUE="<@ARRAY ROWS=5 COLS=3>">

This example assigns an array of five rows and three columns to the user variable foo3.

<@ASSIGN NAME="foo4" SCOPE="user" VALUE="<@POSTARGNAMES>">

This example assigns the evaluated value of the meta tag <@POSTARGNAMES> (an array) to the user variable foo4.

<@ASSIGN NAME="initValue" VALUE="1,2,3;4,5,6;7,8,9;a,b,c;d,e,f;g,h,i">
<@ASSIGN NAME="array2" VALUE="<@ARRAY ROWS='5'
COLS='3' VALUE=@@initValue CDELIM=','
RDELIM=';'>">
<@ASSIGN NAME="foo5" SCOPE="user"
VALUE="@@array2[*,2]">

This example creates an array variable called array2, initializes it, and then creates a new one-column array variable (foo5), containing all the values in column 2 of array2.

<@ASSIGN NAME="orders[1,*]" VALUE="@@myOrder" SCOPE="user">

This example puts the single-row array stored in the myOrder variable into the first row of the orders user variable, replacing the existing values. This assignment generates an error if myOrder is not an array, contains more than one row, or does not contain the same number of columns as the orders array.

<@ASSIGN NAME="zips" VALUE="@@orders[*,4]" SCOPE="local">

Assigns to the local variable zips a one-column array of all the values from column 4 of the orders array.

<@ASSIGN NAME="curr_cust" VALUE="@@orders[1,1]">

Assigns the value from the first cell in the first row of the orders array to the curr_cust variable, using default scoping rules.

<@ASSIGN NAME="race_results[*,3]" VALUE="<@VAR NAME='new_results[*,1]'>">

Copies the values from column 1 of the new_results array to the third column of the race_results array. Both arrays must contain the same number of rows, or an error occurs.

See Also

<@ARRAY>
<@PURGE>
<@VAR>



[TOC] [Prev] [Next] [Bottom]



docs@pervasive.com

Copyright © 1999, Pervasive Software. All rights reserved.