VisualAge provides a Single-Row Query part for constructing and issuing SQL statements that return exactly one row of information from a database. This part is useful for looking up records in a database by a key, such as looking up an employee from the STAFF table using the ID as a key. The functions and interface for this part are similar to the SQL Statement part. The main difference between these parts is the connections you can make. The Single-Row Query part has a few additional actions, attributes, and events for updating, deleting, and creating new rows in a table:
Actions
Attributes
Events
The resultRow part, which you can tear off of the Single-Row Query part, is similar in function to the currentRow part of the Multi-row Query part, but it has two additional attributes: isInDatabase and isNotInDatabase. These attributes both return either true or false.
| Note: | If you use this part to issue a query that returns more than one row, then an error will be returned. The SQL Editor provides no means for checking that your SQL will return a single row. It is up to you to ensure that your SQL returns a single row. |
The following example illustrates how to use the Single-Row Query part. It focuses on using the new actions, attributes, and events described above. For some of the other tasks required to build this example, refer to previous database examples in this book:

, the Single-Row Query part, from the Database Functions category, and add it
to the free-form surface of the Composition Editor to create the following
query.
SELECT *
FROM STAFF
WHERE (STAFF.ID = :id)
The Single-Row Query settings window is similar to the settings view
for the SQL Statement part and you can use it the same way. For
information on creating host variables, refer to Using a host variable.
Your window should now appear as follows:

Adding a message box
You can use the rowNotFound event of the Single-Row Query part to inform the user that the ID selected from the spin button does not correspond to an entry in the table:
Adding a new row
You can obtain an empty row for a user to fill with information and add it to the database as follows:
These connections obtain an empty row and place the cursor in the text field so that the user can add information to the text fields.
These connections add the new row to the database with the information in the text fields.
Updating a row
You can update an existing row in the database as follows:
These connections allow information that has been changed in the text entry fields to be applied to the result row.
Deleting a row
You can delete an existing row in the database as follows:
These connections allow the row displayed in the text entry fields to be deleted from the database.
When you test the window, try selecting ID 500 to display the message box. Then add a new entry to the database and try updating and deleting it.