Contents Index Procedures that handle web requests Automatic character-set conversion

ASA Database Administration Guide
  Using the Built-in Web Server

Working with variables


Variables in HTTP requests come from one of two sources. First, the URI may include a query, which includes various name-value pairs. Get requests are formatted in this manner.

The second way is through the URI path. Setting the URL PATH to either ON or ELEMENTS causes the portion of the path, following the service name, to be interpreted as variable values. This option allows URLs to appear to be requesting a file in a particular directory, as would be the case on a traditional file-based web site, rather than something stored inside a database.

For example, the URL http://localhost/gallery/sunset.jpg appears to request the file sunset.jpg from a directory named gallery, but instead asks the gallery service to retrieve a picture from a database table.

Parameter passed in HTTP requests depends on the setting of URL PATH.

Apart from the location in which they are defined, their is no difference between variables. You access and use all HTTP variables the same way. For example, the values of variables such as url1 are accessed in the same way as paramters that appear as part of a query, such as ?picture=sunset.jpg.

Accessing parameters 

There are main ways to access variables. The first is to mention variables in the statement of the service declaration. For example, the following statement passes the value of multiple variables to the show_table stored procedure:

CREATE SERVICE show_table TYPE 'RAW'
AUTHORIZATION ON
AS CALL show_table( :user_name, :table_name, :limit, :start )

The other way is to use the built in functions next_http_variable and http_variable within the stored procedure that handles the request. If you do not know which variables are defined, you can use the next_http_variable to find out. The http_variable function returns the variable values.

The next_http_variable function allows you to iterate through the names of the defined variables. The first time you call it, you pass in the NULL value. This returns the name of one variable. Calling it subsequent times, each time passing in the name of the prevous variable, returns the next variable name. When the name of the last variable is passed to this function, it returns NULL.

Iterating through the variable names in this manner guarantees that each variable name will be returned exactly once. However, the order that the values are returned may not be related to how they appear in the request. The order may not be consistent. For example, if you iterate through the names a second time, they may be returned in a different order.

To get the value of each variable, use the http_variable function. The first parameter is the name of the variable. Additional parameters are optional. In the case that multiple values were supplied for a variable, the function returns the first value if supplied with only one parameter. Supplying an integer as the second parameter allows you to retrieve additional values.

The third parameter allows you to retrieve variable header-field values from multi-part requests. Supply the name of a header field to retrieve its value. For example, the following lines of SQL retrieve three variable values, then retrieve the header-field values of the image variable.

SET v_id    = http_variable( 'id' );
SET v_title = http_variable( 'title' );
SET v_descr = http_variable( 'descr' );
SET v_name = http_variable( 'image', NULL, 'Content-Disposition' );
SET v_type = http_variable( 'image', NULL, 'Content-Type' );
SET v_image = http_variable( 'image', NULL, '@BINARY' );

Contents Index Procedures that handle web requests Automatic character-set conversion