2004-01-16
| Table of Contents: |
| Rate This Article: | Add This Article To: |
( Page 4 of 6 )
Xen">
Table-like structures can be built in Xen, similar to how
CREATE TABLE Customer
( name string NULL,
custid int);
In Xen, this table could be created with the following line of code:
sequence{ string? name; int custid; }* Customer;
Note: For a definition of 'sequence' or other keywords, skip back two pages to
|
|
The collection is made up of a sequence which contains an optional name (string followed by the symbol denoting optional, '?') and an integer custid. The name of the table, Customers, is declared at the end of the line. Notice that the sequence declaration is followed by a '*', that simply means that zero or more sequences can be stored in Customer (in other words, the table can be empty, or may contain any number of records).
Built-In Select Statements
In Xen, you can also write code that performs filtering tasks just like select statements in SQL. Using our just created Customer table, we can retrieve all of the customers who have the name "Fred" and a custid greater than 100.
//Instantiating a Customer table called CustomerTable
Customer CustomerTable;
[Let's assume CustomerTable has some data that was filled in already by a user.]
//Selecting all customers named Fred with a custid greater than 100
Customer* Freds =
CustTable[it.name=="Fred" && it.custid>100];
For a more complex example, let's use the bibliography we created on the
book* OldBooks =
bib.book[it.publisher == "Addison-Wesley" && it.year > 1991];
Note that the implicit variable 'it' is not defined outright, but is understood to be the iterator over all of the books in bib.
![]() |
|


