A record is a data structure that contains one or more columns along with an expression that determines the datatype and value for the column. One or more columns in the record can be defined as key columns. Each record also has an operation code with the default operation code being "insert". The compiler implicitly determines the type for each of the columns based on the type of the column expression. A record that is created can be output to a stream or stored in a record variable with a compatible record type.
A record type contains one or more column names, each associated with a datatype. One or more of the columns can be identified as key columns.
You can declare a record type inside any block of SPLASH code, including Global/Local declare blocks, functions, and the ON method of a Flex operator using the following syntax:
[ [columnType column; [...] [|] ] name or [ [ columnType column; [...] | ] columnType column; [...] ] name
columnType is the datatype of the column. column is the name of the column in the record. A column name must be unique within a record and is case-sensitive. name is the name of the record type
The outer square brackets are part of the syntax and do not represent an optional element. Any columns appearing before the | character represent the key columns in the record type. The semicolon following the last column before the key separator | and/or the trailing ] is optional.
The following example declares a record variable called traderec with the specified record definition that has two key columns, TradeId and Symbol, and three other columns, Volume, Price and TradeTime:
[ integer TradeId; string Symbol; | integer Volume; float Price; date TradeTime; ] traderec;
The previous example
[ column = value; [...] [|] ] or [ [ column = value; [...] | ] column = value; [...] ]
column is the name of a column in the record. A column name must be unique within a record and is case-sensitive.
value is a value of any datatype. The column type is determined by the compiler based on this datatype.
The outer square brackets are part of the syntax and do not represent an optional element. Any columns appearing before the | character represent the key columns in the record type. The semicolon following the last column before the key separator | and/or the trailing ] is optional.
When a record is created its opcode is set to 'insert' by default. You can change the operation code using the setOpcode function as described in the following example:
[ integer TradeId; string Symbol; | integer Volume; float TradePrice; date TradeTime; ] traderec; traderec := [ TradeId = 1; Symbol = 'SAP'; | Volume = 100; TradePrice = 150.0; undate('2012-03-01 10:30:35'); ];
In the above example the record variable traderec is assigned a record object with particular values.
Operations on records:
Type: The value returned has the type of the field.
Example: rec.data1
Syntax: record.field := value
Type: The value must be a value matching the type of the field of the record. The expression returns a record.
Example: rec.data1 := 10
Examples:
Record object assignment outTrades := [ TradeId = 1; Symbol = 'SAP'; | Volume = 100; TradePrice = 150.0; undate('2012-03-01 10:30:35'); ];
Assigning one record variable to another: outTrades := inTrades;
See Record Casting Rules section for information on how the compiler casts records of different types.
Syntax: copyRecord(record)
Type: The function accepts a record, and returns a record.
Example: copyRecord(Trades1)
1 means "insert"
3 means "update"
5 means "delete"
7 means "upsert"(insert if not present, update otherwise)
13 means "safedelete"(delete if present, ignore otherwise)
Syntax: getOpcode(record)
Type: The argument must be an event. The function returns an integer.
Example: getOpcode(input)
Syntax: setOpcode(record,opCodenumber)
Type: The first argument must be a record, and the second an integer. The function returns the modified record.
Example: setOpcode(input,insert)
The ESP compiler does the necessary implicit casting when assigning a source record to a target record variable where the types and column names do not match exactly. This allows you to assign either a source record to a target that does not have all the columns in the target, or a source that has more columns than the target record variable type. The following casting rules are used by the compiler:
In the following example, the volume and TradeCost columns in outTrade are set to NULL because there are no corresponding columns in the source record srcTrade. Symbol is cast as an attribute column in the target, even though it is a key column in the source.
[ integer TradeId; string Symbol; | integer Volume; float TradePrice; date TradeTime; ] srcTrade; [ integer TradeId; | string Symbol; integer volume; float TradeCost; date TradeTime; ] outTrade; outTrade := srcTrade