78 Database Tutorial & Reference
Query Equation and Query Equation(I) blocks
These blocks provide access to over 1,200 ExtendSim ModL functions of the ExtendSim API;
you can also use operators to enter logical statements, write compound conditions, and specify
loops. The most common use of equation blocks is to write if-then-else logic statements.
The equation can be as simple as performing a mathematical operation on the value from an
input connector or it could be as complex as a full programming segment. You can use include
files (See Include Files in the Technical Reference) within your equation to reuse your own
functions among many equation blocks, and you can use the source code debugger (see the
User Reference) to check the equation if you have a problem.
The components of an equation are the input variables, the equation, and the output variables.
An equation-based block takes input variables, uses those values in the equation, and outputs
the results of the calculation. There are several pre-defined input and output variables with
static variables you can use in equations and several of them relate to the ExtendSim database.
For example, DB address, DB database index, DB table index are pre-defined input variables
while DB write value and DB write value using attribute are output variables.
Use with ExtendSim databases
In addition to the Read/Write blocks from the Value and Item libraries, equation-based blocks
also allow you to perform read/write database operations. And while equations require more
effort to access the database, sometimes the added control and flexibility they provide are
needed. For example:
• Searching. Combine reading and looping logic by searching an entire field (reading one
record at a time) for a particular value by calling DBGetDataAsNumber() inside the “for”
loop.
• Reading. Specify a DB Read Value as the input variable in the block, then use the read value
to influence the if-then-else logic in the equation.
• Writing. Use the value of an input connector variable to write different kinds of information
to a database using if-then-else logic.
+ The Equation, Equation(I), and Queue Equation blocks are used extensively whether a model
has a database or not. They are discussed fully in the How To: Math and Statistics chapter of
the User Reference. Since the two Query Equation blocks are only used to perform Extend-
Sim database queries, they are discussed below.
Query Equation and Query Equation(I) blocks
+ Unlike the Read/Write, Data Import Export, and equation-based blocks which have multiple
uses, the Query Equation and Query Equation(I) blocks are unique blocks that are only used
with the ExtendSim database. Therefore, these two blocks are discussed fully here rather than
in the User Reference.
A query finds records in a database according to the criteria you
specify. The Query Equation blocks are used to search an ExtendSim
database, rank the records, and intelligently select one record based
on a ranking rule. A user-defined equation in the block’s dialog is
calculated once for each record in the table; the results are used to
assign a ranking for each record. The record with the best ranking is the one that gets selected.
The query blocks are used when a database holds information that is required for making deci-
sions in a model. While the querying and ranking behavior could be accomplished using the