Schema  > Products  > SRTransport  > Documentation  > DataScript Reference

 
  DataScript Reference

For a more detailed explanation of DataScript see Using DataScript

Syntax

DataScript's syntax is shell-like in that a carrige return ends the current expression. Don't add semicolons.

Operators/key words

There are a number of keywords in DataScript. You don't need to use most of them but you must be aware of them. If a column in a table has the same name as a keyword you must use the identifier(keyword) proceedure in the 'Value Expression' column.

The keywords are:

add, allocate, and, append, archive, ast, at
begin, break
call, choice, column, commit, continue, copy, create
dbchannel, deallocate, declare, diagram, dictionary, do, double
else, end, execute, exit
file, float, for, foreach, from
get, go
hex
icon, if, in, inform, integer
key, keywords, kill
line, list, load, login
memory, move
nokeyword, not, null
obj_alias, obj_comment, or
paren, parse, pass, print, procedure, procedures, push
quit
redirect, reset, remove, return, row
set, sendquery, show, string, switch, sys, system
table, text, to, tuple, type
user
value, verify, via
while, wrap

also TList, TText, TTuple

 

Data types

The data types that are used in transports are :

  • integer 4 bytes
  • double 8 bytes
  • string length is limited to 1000 bytes.
  • text is a large text or binary data
  • list and tuple

(List and tuple are used internally by SRTransport and are not usually needed for row processing.)

Tuple
A tuple is like a dictionary or hash. It contains keys (names) and values.
The source and destination rows are represented internally as tuples.
Values are accessed by the variable's name.
   can hold any data type
   must call 'declare someTuple tuple' then 'allocate someTuple'
   next call 'declare someData [type] in someTuple' then 'set someTuple.someData = someValue')
List
A list is like an array.
   call 'declare someList list' then 'allocate someList'
   to add something call 'list someList append someValue'
   to remove something call 'list someList remove someValue')

 

Variables

All variables are global.
First you must declare someVariable, set its value, use it and then remove it.
Use the following syntax -

   declare x integer
   set x = 1
   set x = x + 55
   print x
   remove x

You may also initialize a variable at the same time it is declared and you may declare more than one variable at a time -

   declare y double = 9.9, s string = "foo"

 

Expressions

string + stringConcatenate strings.
+ - * /Math expressions.
salary / 2000
a between b and cBetween clause.
= != < > >= <=Boolean operators return 0 or 1.
7+3/2 = 8.5With normal associativity.
(7+3)/2 = 5Parentheses control the order of execution.

 

Flow control

if x, else if y, else
while [condition]

The if and while don't need parenthesies around the conditional. If there is only one expression in a conditional block braces are not needed.

 

Functions and Procedures

Functions that return a value are called with the syntax - set someVariable = someFunction().

Functions that do not return values are called with the syntax - call someFunction().

 

Built-in Functions

getdate()Produces todays date and time.
strip(salary,"$,")strip("$1,3233.00",",$") => "13233.00"
lower(string)Converts a string to lower case.
upper(string)Converts a string to upper case.
trim (string)Remove white space (spaces, tabs, CR's) from the left and right edge of the string.
ltrim(string)Remove white space from the left edge of the string.
rtrim(string)Remove white space from the right edge of the string.
position(substr,str)Find the position of substr within str. Zero (0) is returned if a match is not found.
substr(a,s,w)Results in a substring from string a, that starts at position s and is w characters wide.
substitute1 (key-string, substitute-column, key-column, table)Look for a given key-string in the key-column of the table. If the key-string is found, return the associated value found in the substitute-column of the same table. If the key-value is not found in the key-column of the table, then the empty string is returned.
substitute2 (key-string, default-string {,value, substitute}+)Look for a given key-string in the various value's. If the key-string matches one of the values, then return the corresponding substitute value. If the key-string does not match any of the values, return the default-string.
Example: substitute2 (var, "Unknown Color", "R", "Red", "G", "Green", "B", "Blue")
substitute3 (key-string, filename)Look for the key-string in the file and returns its substitute. If the key-string is not found, return the empty string. The file is formatted with a pipe (|) separating the key-value pairs, each pair on its own line.
Example: given a file "color_map" with this data,
    R|Red
    G|Green
    B|Blue
You would write substitute3 (var, "color_map" )
length(...)Returns the length of a string, or of a list or of a tuple.
convert(type,exp)Convert an expression to the specified type. Supported types are integer, string and double.
For example: convert(string,i*12).
isnull(a,b)If a is null, substitute b.
isnotnull(a,b)If a is not null, substitute b.
execsql("select...")The first column of the first row of the queries result is returned. The datatype of depends upon the datatype in the database.
Example: execsql ("select max(eid)+1 from customer")
sys(cmd)The command is executed (by /bin/sh) and the stdout is returned as a TText (can convert to a string). This system call effects the way SRTransport handles signals, which is especailly important when running in batch mode.
hex(string)Convert the hex codes to a string or binary value. The result of function hex() is TText.