19.10.2015 Views

workbench-en.a4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 22. Customizing DBDoc Model Reporting Templates<br />

This docum<strong>en</strong>t aims to provide an overview of creating and modifying DBDoc Model Reporting templates, as used by MySQL<br />

Workb<strong>en</strong>ch.<br />

The MySQL Workb<strong>en</strong>ch DBDoc Model Reporting system is based on the Google Template System. This docum<strong>en</strong>t does not attempt<br />

to explain the Google Template System in detail. The Google docum<strong>en</strong>t How To Use the Google Template System provides<br />

a useful overview of how the Google Template System works.<br />

The templates employed by the DBDoc Model Reporting system are text files that contain Markers. These text files are processed<br />

by the template system built into MySQL Workb<strong>en</strong>ch, and the markers replaced by actual data. The output files are th<strong>en</strong><br />

g<strong>en</strong>erated. It is these output files, typically HTML or text, that are th<strong>en</strong> viewed by the user.<br />

Markers can be of six types:<br />

1. Template Include<br />

2. Comm<strong>en</strong>t<br />

3. Set delimiter<br />

4. Pragma<br />

5. Variable<br />

6. Section start and Section <strong>en</strong>d<br />

The last two are the most commonly used in MySQL Workb<strong>en</strong>ch templates and these important markers will be briefly described<br />

in the following sections.<br />

1. Variables<br />

The use of variables in the templates is straightforward. Any variables d<strong>en</strong>oted by markers in the template file, will be replaced<br />

by their corresponding data, prior to the output file being g<strong>en</strong>erated. The mapping betwe<strong>en</strong> variables and their corresponding<br />

data is stored by MySQL Workb<strong>en</strong>ch in what is known as a Data Dictionary. In the data dictionary the variable name<br />

is the key and the variable's corresponding data is the value. The data dicionaries are built by MySQL Workb<strong>en</strong>ch and filled<br />

with the data contained in the model being processed.<br />

By way of example, the following code snippet shows part of a template file:<br />

Total number of Schemata: {{SCHEMA_COUNT}}<br />

In the g<strong>en</strong>erated output file the variable {{SCHEMA_COUNT}} will be replaced by the number of schemata in the model:<br />

Total number of Schemata: 2<br />

A variable can appear as many times as required in the template file.<br />

2. Sections<br />

Sections are used to perform iteration in the templates. Wh<strong>en</strong> MySQL Workb<strong>en</strong>ch exchanges the variables in a section for<br />

data it will do so iteratively, using all data in the data dictionary in which the variable is defined. MySQL Workb<strong>en</strong>ch builds<br />

the data dictionaries according to the model curr<strong>en</strong>tly being processed.<br />

Again, this is best illustrated by example:<br />

{{#SCHEMATA}}<br />

Schema: {{SCHEMA_NAME}}<br />

{{/SCHEMATA}}<br />

In the previous code snippet the section start is indicated by the {{#SCHEMATA}} marker. The <strong>en</strong>d of the section is indicated<br />

by the {{/SCHEMATA}} marker. Wh<strong>en</strong> the template is processed, MySQL Workb<strong>en</strong>ch will note the section and iterate the<br />

section until the variable data for {{SCHEMA_NAME}} in the corresponding data dictionary is exhausted. For example, if the<br />

model being processed contains two schemata, the output for the section might resemble the following:<br />

Schema: Airlines<br />

Schema: Airports<br />

75

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!