You can use the EGL get statement
to retrieve one or more rows from a relational database.
To retrieve multiple rows, reference an entity list (entity[ ]).
In that case, data from the accessed rows is read into the corresponding
elements of the entity list; and the elements are allocated if they
do not already exist.
If you do not reference an entity list and if multiple rows are
returned, only the first row is processed.
Syntax
- entity
- Name of the entity, which is a variable based on an External type,
Handler type, or Record type. The values in that entity are used in
the corresponding SQL SELECT statement.
If you specify an entity
and do not specify the SQL statement, the following default is used:
SELECT
column_1, column_2... column_n
FROM tableName
WHERE ID_column_1 = ? AND ID_column_2 = ? ... AND ID_column_n = ?
The
default SELECT statement retrieves data from all columns in the table:
- The order of the column fields in the statement reflects the
order of the fields in the type definition.
- A column entry such as column_1 is a name; specifically,
the value of the Column annotation for a field in the type
definition. If that annotation is missing from the field in the type
definition, the name in the statement is the name of the field in
the type definition.
The value of tableName is the value of the Table annotation
that is set on the entity type. If that annotation is missing from
the type definition, the value of tableName is the type name.
The
default WHERE clause references only the key fields, which
are the entity fields that have an ID annotation. The order
of the columns listed in the WHERE clause reflects the order of the
key fields.
When you are specifying an entity, each question
mark is replaced with a value:
- For default processing, the behavior is as follows:
- If you do not specify the using clause, the replacement
value is the corresponding value in the entity.
- If you specify a using clause, the replacement value is
the corresponding value in the using clause.
- If you specify an entity and a custom SQL SELECT statement, the
behavior is as follows:
- If you do not specify the using clause, the replacement
value is the corresponding value in the entity.
A question mark
represents the value of a key field, with the first question mark
corresponding to the first key field, the second question mark to
the second key field, and so forth. The statement can include fewer
question marks than the number of key fields but cannot include more.
- If you specify a using clause, the replacement value is
the corresponding value in the using clause. In this case,
you can reference fields other than key fields.
- entity[ ]
If you specify an entity list and do not specify an SQL statement,
the default statement is as explained earlier but without a WHERE
clause. The effect is to return all rows from the table.
If
you specify a custom SELECT statement and include a WHERE clause,
the question marks must be resolved by values in the using clause,
not by values in the entity list. In this case, you can reference
table columns other than those that are identified by key fields.
- simpleValue
- A value of an EGL simple type that is compatible with the corresponding
database column. The list of simple values is set into the values
clause to match the list of column entries.
If you are adding simple
values instead of an entity, you must specify an SQL SELECT statement.
The statement format is as shown for entity.
- SQLDataSource
- A variable of type SQLDataSource. The variable includes
connection details or references an EGL deployment descriptor entry
that provides access to the connection details.
If you issue a prepared
statement, the variable is optional and is ignored if present.
- SQLResultSet
- An SQL result set that was established by an open statement.
In this case, the get statement fetches the current row.
- stmt
- A single SQL SELECT statement, which is not required to end with
a semicolon but can. You can use a prepared statement in place of
#sql{stmt}.
For further details, see the documentation for entity,
which shows the statement format, and for entity[ ] and simpleValue.
Compatibility
Table 1. Compatibility
Target |
Issue |
Java |
No issues |
JavaScript |
Database access is not supported in JavaScript.
|