Reading from a Database
Retrieving data from a table within a database, commonly known as "selecting" or "fetching" data, is referred to as "reading" data when using databases with Eggplant Functional. This returned data can then be used to inform your testing, such as when doing Data Driven Testing with Eggplant Functional.
Reading Table Contents
Fetching the contents of a database table can be as simple as asking for all of its records.
Set the writable
database connection list property to No
if you do not need to modify the database, and instead just want to read from it.
Example:
The below code will set the Members
variable to be a list of records, one for each row in the table. Each item in the list will be a Record
object: a property list containing the values of that row in the table, with a property key for each column in the table. For more on Records, see Records vs. Property Lists.
put the records of memberTable into Members
When a single record is all that is expected or needed, you can use record
instead of records
. This will return a single Record object rather than a list of Records.
Reading all of the records of a large table into a variable as this example does is not recommended. Use a where
expression or iterate through the records as discussed in Iterating over Records of a Database.
Example:
This example uses the Get
command to fetch only the data for the records where the lastName column is equal to "Smith". A where
clause can include a variety of criteria for choosing records.
get the records of memberTable where lastName is "Smith"
To fetch all records for member names that begin with "S" but excluding the name "Smith" the request would look like this:
get records of memberTable where lastName begins with "S" and lastName isn't "Smith"