To update a row in a database table, you use the following technique:
The SELECT statement you issue to return the row to be updated cannot contain a join operation. You can use this technique only to update rows returned from a single table.
| Note: | To find the column names for a table, send the table the AbtTable>>columnNames message. |
The following sample code updates a row in a table in the SAMPLE database as follows:
To use this block of code, evaluate it using the Inspect command.
"Update rows 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: 20000;
yourself.
table := (connection openTableNamed: 'STAFF')
atRow: oldRow putRow: newRow;
yourself.
^table asStrings.