Database Guide : Database programming guide : Querying databases : Using database classes for scripts
Using database classes for scripts
You can use the database query classes illustrated in the previous section to write VA Smalltalk 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 VA Smalltalk script. To use this code in a script, follow these steps:
1. Create a visual part with a text field, a label, a push button, and a multi-line editor as follows:
frdbview
2. 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: 'SampleConSpec'.
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.
3. 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.
4. Save the script and return to the Composition Editor.
5. Make the following connections:
a. The clicked event of the push button to the executeQuery script.
b. The object attribute of the multi-line editor to the result attribute of the executeQuery script.
6. Now test the visual part as follows:
a. Type a number into the text field.
b. 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.
Last modified date: 06/01/2018