Adding rows and data
To add information to an existing table, create a new row for the table using the emptyRow method, then use the at:put: method to add information to the row.
The following example uses these methods to add Joe Smith's name and address to the PEOPLE table.
In each at:put: message, the argument passed with at: is the column name and the argument passed with put: is the column value.
"Add a row to a table"
| table connection newRow |
connection := AbtDbmSystem activeDatabaseConnectionWithAlias: 'SampleConSpec'.
table := (connection)
openTableNamed: 'PEOPLE'.
newRow := table emptyRow.
newRow at: #NAME put: 'Joe Smith';
at: #STREET put: '123 Shady Lane';
at: #CITY put: 'Raleigh';
at: #STATE put: 'NC';
at: #ZIPCODE put: 27613;
at: #PHONE put: '919 555-1234'.
table addRow: newRow.
table asStrings.
To display the data you have just added to the table, evaluate the next block of code using the Display or Inspect. This snippet of code returns a result table and converts it to an ordered collection.
"Select a row from a table"
| connection querySpec resultCollection|
resultCollection := OrderedCollection new.
connection := AbtDbmSystem activeDatabaseConnectionWithAlias: 'SampleConSpec'.
querySpec := (AbtQuerySpec new)
statement: 'SELECT * FROM PEOPLE'.
(connection resultTableFromQuerySpec: querySpec)
do: [:eachRow | resultCollection add: (eachRow asString)].
^resultCollection.
Last modified date: 01/29/2015