Creating Containers
When you create a container in OmniScript you declare the length of the key for each record as well as how many of each type of field you will be using in the container. As with OmniScript variables, there is only one type of numeric field but there are three different types of text fields based on the length of the string. There are 10 byte, 40 byte and 200 byte text fields. So you determine how many of each field you will need and declare them in the container create statement.
Adding and Updating Container Records
Once the container is created you can add records or update existing records based on the unique record key. Numeric fields can be set or added to or subtracted from. Text fields can only be set but through a two step process you can read what is in them, append to that string, and then reset them. Any record fields that are not set when the record is added to the container default to 0 for numeric fields or null for text fields.
Because each key is unique and the records in a container are sorted by the key, containers are useful for both sorting and consolidating duplicates.
Accessing Container Records
Individual records in a container can be accessed with a get statement by specifying the record key.
Just like with the built in sets of records in the recordkeeping database you can loop through the records in a container. You can either loop through all records or you can use a key prefix to only loop through the records that have a key starting with the string provided. This allows you to create one container with a primary set of records and then create a second container that has a varying number of records that relate to the records in the first container, in a one to many relationship. The key of each item in the second container begins with the key of the corresponding item in the first container.
And so then you can loop through the first container and for each item in that container you loop through the second container with the key of the first container being used as a keyprefix for the loop on the second container.
Cleaning up Containers
Naturally, container items can be deleted and containers can be emptied and reused as needed. When you are done with them it is also important to destroy containers to clear them out of memory and free that memory up.
Containers are definitely one of the strengths of OmniScript and a very useful tool in managing data.
No comments:
Post a Comment