Inserting rows in a table
To insert a new row into a database table, you use the following technique:
1. Open the database table you want to add a new row to by sending the openTableNamed: message to an instance of the database. This message returns an instance of AbtTable.
2. Send the AbtTable>>emptyRow message to the table to create a new row. This message returns an instance of AbtRow.
3. For each column in the row, send the row the message at:put: with the name of each column in the table and the data to place in each column.
4. Send the table the addRow: message with the new row.
 
Note:
To find the column names for a table, send the table the AbtTable>>columnNames message.
The following sample code inserts a new row into a table in the SAMPLE database as follows:
1. Declares temporary variables for the connection, the database, the new row, and the table
2. Returns the connection for the database manager
3. Opens the SAMPLE database
4. Opens the CUSTOMERS table
5. Creates an empty row and add column data to it
6. Adds the new row to the table
To use this block of code, evaluate it with the Inspect command.
"Insert a row in a table"
| connection newRow table |
connection := AbtDbmSystem activeDatabaseConnectionWithAlias: 'SampleConSpec'.
table := (connection openTableNamed: 'STAFF').
newRow := table emptyRow.
newRow at: #NAME put: 'Delancey';
at: #ID put: 999;
at: #DEPT put: 10;
at: #JOB put: 'Clerk';
at: #SALARY put: 15000;
at: #YEARS put: 2;
at: #COMM put: 185.
table addRow: newRow.
^table asStrings.
Last modified date: 01/29/2015