
Database Query
Components User's Guide
65
Writing the Database Query Component
A simple Database Query Component is structured as follows:
<nexus:component classid="nexus/components/DBQuery"
code="$nexusComponents"
datasource="
path to data source asset
"
query="
SQL SELECT statement
">
$node.column("Column name")
</nexus:component>
It includes two sections:
1
The opening tag, which specifies the data source and the query to submit to the data
source.
2
The body section, which specifies which columns to display from the result set, and
how to format the results.
The following sections describe in detail how to write each part of the component,
followed by complete examples.
Writing the Database Query Opening Tag
The opening tag specifies the following:
The path to the data source asset (.nds file) which Collage should use to access the
database.
Either the name of the SQL query file (.sql) which Collage should pass to the
database, or a simple inline SQL SELECT statement which Collage should use to query
the database.
Optionally, a maximum number of rows to return.
Optionally, the number of initial rows to skip.
Optionally, the path to a layout file which will be used to generate details pages for
linked fields.
A complete opening tag might look something like:
<nexus:component classid="nexus/components/DBQuery"
code="$nexusComponents"
datasource="/System/Data%20Sources/Company%20Database.nds"
query="SELECT Name, Position, FROM Employee WHERE Salary > 4000">
In this example, you can optionally replace the
query
property with a
queryfile
property, which can then define a path to a SQL query file in Collage. For example:
<nexus:component classid="nexus/components/DBQuery"
code="$nexusComponents"
datasource="/System/Data%20Sources/Company%20Database.nds"
queryfile="/System/Data%20Sources/emp_name_positions.sql">
In this example, the linked query file, emp_name_positions.sql, may contain just the
same simple SELECT statement. You can also store much more complex queries in a
linked file.
Commenti su questo manuale