Database Guide
You can use the database query classes illustrated in the
previous section to write VisualAge scripts that execute queries using
information provided in a visual part.
The following example shows how to incorporate the sample code in Updating rows in a table into a VisualAge script. To use this code in a
script, follow these steps:
- Create a visual part with a text field, a label, a push button, and a
multi-line editor as follows:

- Switch to the script editor and create a new method called
executeQuery. Paste the following script into the new method
template:
executeQuery
"Script to Update a row in a table"
| connection querySpec oldRow newRow table|
connection := AbtDbmSystem activeDatabaseConnectionWithAlias: 'SAMPLE'.
querySpec := (AbtQuerySpec new)
statement: 'SELECT * from STAFF
where STAFF.NAME = 'Sanders' ';
hostVarsShape: (nil).
oldRow := (connection resultTableFromQuerySpec: querySpec) first.
newRow := (oldRow deepCopy)
at: 'SALARY'
put: ((self subpartNamed: 'Text1') object);
yourself.
table := (connection openTableNamed: 'STAFF')
atRow: oldRow putRow: newRow;
yourself.
^table asStrings.
- Note that the only difference between this sample code and the sample code
in Updating rows in a table is the substitution of the object attribute of
the text field for the hard-coded 20000 and the inclusion of a method name,
executeQuery.
- Save the script and return to the Composition Editor.
- Make the following connections:
- The clicked event of the push button to the
executeQuery script.
- The object attribute of the multi-line editor to the
result attribute of the executeQuery script.
- Now test the visual part as follows:
- Type a number into the text field.
- Select the Update Salary push button.
The multi-line editor shows the same result table shown by the sample
code in Updating rows in a table. The number you typed into the text field appears in
the SALARY column for Sanders.
[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]