Scripting Reference
All text in a RIO program is either plain text or program text. Plain text is just text not enclosed in <# and #> while program text is enclosed in it.
Definitions
RIO programs consist of statements like if, while, for and uses variables, operators and constants combined into expressions. These are all defined in the following sections.
Variables
Variables are used for storing values. All variables must start with the dollar sign $. The characters after the $ must be alphabetic or numeric, e.g $Hello, $My9hole. The names are case sensitive so $Fred is different from $fred.
The types of values that can be stored in a variable are as follows:
- Integer – these are whole numbers like 1, 9876, -55
- Double – these are floating point number like 77.3456
- Date – e.g. getDate(“12-22-2010”)
- String – like “This is a string” – basically a series of characters wrapped in double quotes OR single quotes.
- List – simple a list of values separated by commas
- Record – this is a row in a table
- Table – this is a reference to a database table
Operators
These are symbols that are used to perform operations on variables, e.g add or multiply. A complete list of operators is below:
- + - used to add to integers or numbers together, also to concatenate strings, i.e. join them end to end, e.g. 1.2 + 2.3 is processed as 3.5 but "Hello " + "there" is processed as "Hello there".
- * - multiply two integers or doubles, e.g. 3 * 4 = 12. If either argument is a double then the result is a double.
- / - divide two integers or doubles, e.g. 8 / 2 = 4.
- >, < , <=, >=, == , != these are respectively, greater than, less than, less than or equal to, greater than or equal to, equals, not equals
- and – logical combine to values both must be true for the result to be true
- or - logical combine to values either can be true for the result to be true
- : - the format operator. The left side of the format operator is the value to be formatted. The right hand side is the format string. E.g. $Subject["DOB"]:"MM-dd-yyyy".
- .. - the range operator. The format is first value:last value, e.g 10:100 is all the numbers from 10 to 100 inclusive. The range can optionally also have a step, e.g. 1:10:2 means step from 1 to 10 in increments of 2.
- , - the comma joins values into lists so e.g. 2,3 is a list consisting of two values
- [index] – this is the indexer and it operates on the argument to its left to fetch one element from it either by position or name. The way it works depends on what is to the left of it. If the left argument is a table then an integer index will return the Nth bookmark (record) in the table while a string index will return the record of that name (i.e. the first column of the table). If the left argument is a bookmark then an integer index will return the Nth field (Name is the 0th, Sex is the 1st, DOB is the3 2nd) and if the index is a string it will return the field of that name from the record so $p[“DOB”] will return the date of birth field for that record.
Functions
There are no user definable functions in RIO (yet) but the following predefined functions are available:
- pedigree, ancestors, reversePedigree, htmlPedigree – all these functions take two arguments: a record, number of generations and an optional string field expression
- relations, fullSiblings, sireSiblings, damSiblings, damLine, sireLine, offspring – all these functions take a record followed by an optional field expression.
- messageBox – takes a string argument which it prints in a popup dialog box with an OK button. It is useful for giving messages e.g. like how many records your script marked.
- getDate – takes a string argument in your current date format (this will be what you see in say your DOB field if it is set to automatic – which it is by default). As an example in the US you could pass the following string in getDate(“11-27-2011”).
- query - this takes a string argument and runs the argument as an SQL query against the current database. This provides a very fast way of running some reports. For more information see the next section.
- expr - this takes a record and field expression. An example is println
Query
The query function provides a fast way of running some reports. Basically any report where there is a statement like the following will be slow.for $p in $Pedigree where $p["Sex"] == "M"
The above is going to be slow because it is reading every single record from the database table, THEN filtering it. It is much faster to run a database query which does the filtering itself as shown below.
for $p in query("select name, sex from pedigree where sex='M'")
Another example is the following report which lists all the entries bred by the Breeder in the current record.
[# $breeder = $Subject["Breeder"] println "Entries bred by this breeder: ", $breeder if $breeder != "" then for $p in $Pedigree where $p["Breeder"] == $breeder println $p["PreTitles"], $p["Name"], $p["PostTitle"] end end #]The faster method using the query function is as follows.
[# $breeder = $Subject["Breeder"] println "Entries bred by this breeder: ", $breeder for $p in query("select * from pedigree where breeder like '@breeder' order by name") println $p["PreTitle"], $p["Name"], $p["PostTitle"]// this version just prints names and titles! end #]
A few technical points about the query command:
- Any valid SQL statement is allowed. Basic SQL is similar for both SQLite, which is what is used for desktop .DB files, and for MySQL servers. However if you use SQL commands or syntax specific to SQLite or MySQL then the report will only work for that database.
- Note that @breeder in the query string gets replaced with the value of that variable and if that value is a string then the string is "escaped". Escaping is required for strings because strings are always delimited with single quotes, therefore the strings themselves can't have single quotes within them.
- If the variable has a datetime value then it is formatted as 'yyyy-MM-dd HH:mm:ss' which is the standard format for datetime in SQLite and MySQL. Note that it adds the single quotes areound the value whereas for strings the single quotes are not added so you need to add them yourself. The reason for this is that the string value might be part of a "like" statement which is used when you want to match anywhere in a string.
Methods
Methods are similar to functions but they occur after an argument and a dot. For example:
“Hello there!”.pad(5)
Would produce the result:
Hello
The method in this case is “pad”.
The currently supported methods are:
- arg.toLower()– converts the string to all lower case so “Hello There”.toLower(0 will produce “hello there”
- arg.toUpper() – converts the string to all upper case
- arg.like(text) – returns true if arg contains the string text anywhere within it regardless of case
- arg.pad(n) – arg must be a string and n is an integer. This method modifies arg to be a string padded out with spaces on the right to n characters. If the string is longer than n then it is truncated to n.
- arg.setMark(n) – arg must be a record and n an integer. The mark on this record is set to n where n is a bit mask so setting 1 sets the primary mark red, setting two sets orange but setting three sets both red and orange.
Statements
The following statements are supported:
For statement
The format is:
for VARIABLE1 in VARIABLE2 where CONDITION
do something
end for
The “where CONDITION” is optional.
While statement
The format is:
while EXPRESSION then
do something
end while
EXPRESSION can be anything which can be evaluated as true or false.
If statement
The format is:
if EXPRESSION then
do something
else
do something else
end if
EXPRESSION can be anything which can be evaluated as true or false. The else part is optional
Print statement
The print statement just prints the comma separated arguments to its right. The println statement is similar except it appends a new line character to the end. Print and Println will put a space automatically between arguments if the previous argument is not blank.
Miscellaneous
Expressions
Expressions are the same as described elsewhere in the user manuals. They are simple strings which contain either normal text or references to fields in a record. The references are the name of the field inside square brackets. If text is NOT inside square brackets then it is output as is. In the example below the println statement includes a call to expr() which returns a string which is the $expr text with the field references replaced by the value of those fields in the $Subject record.$expr1 = "[PreTitle] [Name] [PostTitle] [Registration]" println "Pedigree of: ", expr($Subject, $expr1)