Database Guide
To insert a new row into a database table, you use the
following technique:
- 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.
- Send the AbtTable>>emptyRow message to the table to create a
new row. This message returns an instance of AbtRow.
- 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.
- 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:
- Declares temporary variables for the connection, the database, the new
row, and the table
- Returns the connection for the database manager
- Opens the SAMPLE database
- Opens the CUSTOMERS table
- Creates an empty row and add column data to it
- 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: 'SAMPLE'.
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.
[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]