An SRTransport Tutorial
Getting Started
Open the application SRTransport and choose New in the Info Panel (or New Transport in the Document menu).
Choose a file as your data source
Click on the Detail button of the data source. When you're asked for the type, choose Data File, existing, and then in the Open File panel, find and choose an existing data file.
Now you are in the File Transport Adaptor window where you can describe the columns of your file. You can use field lengths or terminators, and to test your format, you can use the Preview button.
When you leave this window and go back to the main transport window, your column names are copied there as the data source.
Choose a table as your data destination
Click on the Detail button of the data destination. When you're asked for the type, choose Sybase table or view, and then login to your Sybase database and choose a table as your data destination.
When you leave this window and go back to the main transport window, your column names are copied there as the data destination.
Configure the transport
Now that you've specified the data source and the data destination, you must configure how data is mapped from one to the other.
To control how the data is transfered from the source to the destination, you enter expressions in the destination matrix (the matrix with three columns). To get a quick start, you can choose the button "Match By Name", which matches all columns in the source with all columns of the same name in the destination. Here are some examples of transformations that you can do.
- math expressions on numbers: age + 3
- constant values: 145/3 or "doctor"
- string concatenation: fname + " " + lname
- functions: upper(name)
Save the transport
Choose Save from the Document menu. In the Save Panel, choose a directory and type in a filename. The filename will automatically be suffixed with .transport.
Opening an existing transport
Choose Open Transport from the Document menu. In the Open Panel, find and choose a file. If the opened transport references a database, you'll be asked to login to that database (and possibly twice, once for the source and again for the destination).
What's next
You should read the section on describing a file next. Then you can try transfering information. Show the trace window to see the rejected records.
Describing a Data File
File columns
The Flat File Transport Adaptor allows you to describe the columns of data in a flat file (ASCII, not binary).
To describe a new column in the file, choose New->After popup menu. For this new field, you can specify the field name, its length and its terminator and finally its datatype. Prefix is not used at this time.
You can use cut, copy and paste to configure your files columns.
Terminators
Your field terminator can be any sequence of characters, but is normally only one. You can use special escape codes listed below.
- \t - for a tab
- \n - for a carriage return
- \b - for a space
- \r - line feed
Length
Length is used for fixed width fields. The algorythm SRTransport uses for parsing a field, is: It looks for the specified terminator and the specified length. The field is complete when either condition is met.
Datatypes
The Flat File Transport Adaptor defines these datatypes:
- string
- integer
- float
- text
- binary
- hex
Expressions
| string + string
|
Concatenate strings.
|
| salary / 2000
|
Math expressions.
|
| a between b and c
|
Between clause.
|
| + - * /
|
Arithmatic.
|
| = != < > >= <=
|
Boolean operators return 0 or 1.
|
| 7+3/2 = 8.5
|
With normal associativity.
|
| (7+3)/2 = 5
|
Parentheses control the order of execution.
|
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.
|
| 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")
|
| isnull(a,b)
|
If a is null, substitute b.
|
| isnotnull(a,b)
|
If a is not null, substitute b.
|
| 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" )
|
| 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.
|
| position(substr,str)
|
Find the position of substr within str. Zero (0) is returned if a match is not found.
|
| length(...)
|
Returns the length of a string, or of a list or of a tuple.
|
| 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.
|
| convert(type,exp)
|
Convert an expression to the specified type. Supported types are integer, string and double. For example: convert(string,i*12).
|
| hex(string)
|
Convert the hex codes to a string or binary value. The result of function hex() is TText.
|
Statements
| system <string>
|
Executes the commands in a Unix shell (using the C system() call). Standard output is directed to the log. This command effects the way signals are handled.
|
Reject file and log file
All rejected rows are written to both the log and the reject files. Error messages are written to the log only. If either the reject filename or the log file name are file extensions (begining with a period such as .log), then that extension is appended to the basename of the current transport
document. This allows you to specify log and reject files in the same directory as the transport document. The log is copied to the trace-window in the Transporter-room as well as to the file. The log file is never truncated (it is appended).
|