Last week, we announced the release of Five Version 2.5, a major new release of our rapid application development environment. Our latest release comes with a report writer, which lets developers generate PDF reports on an SQL database.
This makes Five a great SQL reporting tool that covers the entire process from database creation to PDF report generation.
Five gives you a built-in MySQL database, or it can be connected to an external MS SQL Server or MySQL database. PDF reports can be created on any of these data sources in just a few clicks and with a lot of useful helper functions that make report generation quick and efficient.
In this walkthrough, we will create a PDF report on Five’s built-in MySQL database. Make sure to sign up for free to follow along.
Generating a SQL report is a common development task. Traditional SQL admin tools or GUIs, however, do not support PDF report generation.
With Five, a rapid application development environment, developers can rapidly build and deploy database-driven web apps that contain PDF reports (or forms, charts, dashboards, etc.).
Let’s explore how we can go from database to PDF reports in a few simple steps. Here’s a simple scenario: your business needs a new monthly inventory report (yet again). Let’s check out how quickly we can build this in Five.
First up, Five gives developers a dedicated MySQL database. This built-in MySQL can be created using Five’s Table Wizard or its visual Database Modeler.
We will generate our report on top of this integrated MySQL database. Of course, a report can also be generated on any external, pre-existing relational database.
Here’s what our database looks like for this example. We have a single table that stores information about Warehouses.
To create this database, follow these steps:
If you are struggling with any of these steps, watch this tutorial, beginning at 9 min:
Next, click on Visual > Reports. You can now generate, adjust, customize, and manage MySQL PDF reports. Five lets you create reports on any data source, including its built-in MySQL database, any query, or any external database connected to Five.
Inside Reports,
You’re now inside a rich text editor that allows you to design PDF reports the same way you would design a Word document. On top of the text and document design features, the report generator also lets you select any data field from your data source.
For example, you can add a table to a report that contains each field that is stored inside the warehouse table. To do so,
You can use the Insert Fields functionality to add the captions of your database fields into the top row of your table, and each record into all subsequent records. Here’s how to set this up:
If you don’t enjoy working with the rich text editor, copy this piece of HTML into the code view of the report generator. Open the code view by clicking on </> in the top left corner of the report generator. Paste this code into it:
<div><strong>Warehouse Report</strong></div>
<div><strong><br></strong></div>
<div><strong><br></strong></div>
<table style="width: 100%;">
<tbody>
<tr>
<td>Location</td>
<td>ID</td>
</tr>
<tr class="fiveReportHelper" contenteditable="false">
<td class="fiveReportHelper">{{#each @root.[Warehouse].[Records] as | Warehouse |}}</td>
</tr>
<tr>
<td>{{Warehouse.[Location]}}</td>
<td>{{Warehouse.[ID]}}</td>
</tr>
<tr>
<td>{{/each}}</td>
<td><br></td>
</tr>
</tbody>
</table>
<div><strong><br></strong></div>
<div><strong><br></strong></div>
Save everything by clicking the Tick marks.
IMPORTANT: Don’t forget to add your report to the menu of your application.
To preview your SQL report that now turns the data stored in your MySQL database into an easy-to-use, printable, and shareable PDF document, launch your application by clicking the ▶️ button in the top right corner of your development environment.
After a few seconds, the application will launch, and you’ll see your PDF report right in front of you!
You might be wondering why this report is empty. Well, we didn’t add any data to our database table. But of course, we could have done so by importing a CSV, or by creating a form in our application for users to add data.
Last, we could have worked on the formatting of our SQL report (and the look of the application surrounding it) by using the rich text editor or by customizing Five’s application themes.
The above report turns existing MySQL database records into a table shown on a PDF document. This is the easiest example of an SQL report. What if you need more complex reports?
Five lets you add code to your report to manipulate data or add logic to your template. You could, for example, add a calculated field (such as a monthly total). Moreover, you can add custom screen fields to a report. A screen field lets users add data to their report from inside the end-user application rather than the database. In this way, the end-user of your report can make adjustments inside the report before generating it.
Watch our Developer Advocate Pranoy explain the PDF report generator in more detail in our full product demo here (to jump straight to the SQL report writer start watching from 21m and 40s):
Sign up and get started with Five at no cost.