Please note : This help page is not for the latest version of Enterprise Architect. The latest help can be found here.
Custom SQL Fragments
You can create a Template Fragment to return data from an SQL Query. You do this by defining an SQL Query in the Document Options of the Template Fragment, then adding fields within the Custom section of your Template Fragment that refer to the columns returned by the SQL Query. The Query is DBMS dependent and so might vary according to the DBMS you are using.
Create an SQL Query Fragment
Step |
Action |
See also |
---|---|---|
1 |
Open or create a Template Fragment in the Document Template Editor. |
|
2 |
In the Document Template Editor, right-click on the Template background and select File | Document Options. The Document Options dialog displays.
|
|
3 |
Select the Custom Query tab.
|
|
4 |
In the Template Fragment type panel, select the Custom SQL radio button.
|
|
5 |
In the main text field on the tab, type the SQL Query that is to be run on your model. This Query must return one or more columns; for example:
SELECT DocName AS TemplateName, Author AS TemplateLocation FROM t_document WHERE DocType = 'SSDOCSTYLE' and (IsActive = 1)
SELECT Count(Object_Type) AS CountOfActors FROM t_object WHERE Object_Type = "Actor" and Package_ID = #PACKAGEID#
You can also make your column entries into hyperlinks to the element entries in the generated document. The column header field (in the template text itself, in the Custom panel) must contain the suffix -Hyperlink; for example:
Elements-Hyperlink (Elements.Hyperlink is also valid for non-Jet repositories)
The column entries, or values, must have the format:
{guid}LABEL
In this format, {guid} is the GUID of the element to link to and LABEL is the hyperlink text (such as the element name), either manually inserted or returned from another command. For example:
{123-456-7890}Class2
In the generated report this displays as Class2, which links to the description of Class2 in the document.
This example returns the hyperlinked name of each base (parent) Class of the element currently being reported:
SELECT t_object.ea_guid CONCAT t_object.Name FROM t_object, t_connector WHERE t_connector.Start_Object_ID = #OBJECTID# AND t_connector.Connector_Type = 'Generalization'
(For Access repositories, replace CONCAT with &. For SQL repositories the correct syntax is: CONCAT (t_object.ea_guid,t_object.Name))
This query could return multiple entries, in which case the entries are reported one per line. You can, if required, have multiple Hyperlink query statements, separated by commas. You can hyperlink to reported elements, attributes, operations, diagrams and Packages.
|
|
6 |
Click on the OK button to close the Document Options dialog.
|
|
7 |
In the Document Template Editor, in the Sections panel, select the Custom checkbox to generate the Custom section.
|
|
8 |
Within the Custom section, right-click and select the Insert Custom Field context menu option. A prompt displays for the name of the field to create.
|
|
9 |
In response to the prompt, type the name of the column that is being returned by your Query; for example, CountOfActors. Click on the OK button.
|
|
10 |
Repeat steps 8 and 9 for each column that you want to include in your report. Add any other formatting and content you need, to the Template Fragment.
|
|
11 |
Save the Template Fragment, and add it to a normal document template. |
Adding Fragments to a Document Template
|
Notes
· | An Element Filter will not apply to the Custom section in a Template Fragment |
· | You can test your SQL Query using the SQL Editor in the Model Search window |
Learn more
Learning Center topics
· | Alt+F1 | Enterprise Architect | Reporting | RTF Template Fragments | |
· | Create a SQL based Fragment 1 |
· | Create a SQL based Fragment 2 |