[ Previous ] [ Contents ] [ Index ] [ Next ]

Working with Ns_Set and Form Data

An AOLserver operation procedure often manipulates sets of key-value pairs of string data, for example:

rows of data from the database
HTTP header information
HTML form data (see page 32)

Ns_Set Data Structure

In the AOLserver C API these data are manipulated using the Ns_Set data structure. In the Tcl API the ns_set command can be used to manipulate underlying Ns_Set data structures that are generated by the AOLserver communications layer or the database services module.

The example below shows a typical use of the ns_set Tcl command to manipulate Ns_Set structures.

# Example 2: Show header data
    #
    # Things to notice:
    # * The same function is registered for two different URLs
    # with different context.
    #
    # * The headers are pulled out of the conn using the
    # ns_conn function.
    #
    # * The value for a particular header line is extracted
    # with "ns_set get".
    
    ns_register_proc GET /example/showbrowser \
    	showheader USER-AGENT
    ns_register_proc GET /example/showrefer \
    	showheader REFER
    
    proc showheader {conn key} {
    	  set value [ns_set get [ns_conn headers $conn] $key]
    	  ns_return $conn 200 text/plain "$key: $value"
    }

Form Data

Some Database Services Tcl functions take formdata arguments. You can get the form data for a form by calling ns_conn form. An ns_set structure containing key/value pairs is returned, which you can manipulate using the ns_set function. The key/value pairs for search, entry, and update forms are provided below.

Search Form Data

Key

Value

ColSelected.columnname

"on" or "off"

ColOperator.columnname

search operator

(=, <, >, <=, >=, is null, is not null)

ColValue.columnname

search value for text, integer, real, or boolean fields

ColValue.columnname.NULL

"t" or "f" (true or false), indicates whether to search for the specified date, time, or timestamp field

ColValue.columnname.month

month portion of search value for date and timestamp fields

ColValue.columnname.day

day portion of search value for date and timestamp fields

ColValue.columnname.year

year portion of search value for date and timestamp fields

ColValue.columnname.time

time portion of search value for time and timestamp fields

ColValue.columnname.ampm

"AM" or "PM" designation of search value for time and timestamp fields

OrderBy.n

name of column to order the results by (where n is 0 for the first order by column, 1 for the second order by column, and so on)

Queryinfo.Distinct

"on" or "off", indicates whether query should eliminate duplicate records

Pref.MaxToReturn

integer, maximum number of records to return

Entry Form Data

Key

Value

ColValue.columnname

value for text, integer, real, or boolean fields

ColValue.columnname.NULL

"t" or "f" (true or false), indicates whether a date, time, or timestamp field is null or the value specified in the date/time portions

ColValue.columnname.month

month portion of value for date and timestamp fields

ColValue.columnname.day

day portion of value for date and timestamp fields

ColValue.columnname.year

year portion of value for date and timestamp fields

ColValue.columnname.time

time portion of value for time and timestamp fields

ColValue.columnname.ampm

"AM" or "PM" designation of value for time and timestamp fields

Update/Delete Form Data

Key

Value

ColValue.columnname

value for text, integer, real, or boolean fields

ColValue.columnname.NULL

"t" or "f" (true or false), indicates whether a date, time, or timestamp field is null or the value specified in the date/time portions

ColValue.columnname.month

month portion of value for date and timestamp fields

ColValue.columnname.day

day portion of value for date and timestamp fields

ColValue.columnname.year

year portion of value for date and timestamp fields

ColValue.columnname.time

time portion of value for time and timestamp fields

ColValue.columnname.ampm

"AM" or "PM" designation of value for time and timestamp fields

RowID.columnname

all the RowID values that specify the row to update or delete

Top of Page

[ Previous ] [ Contents ] [ Index ] [ Next ]
Copyright © 1998-99 America Online, Inc.