Creating a database report

Contents



Overview


To present the data of a database table or the resultset of a database query in a more comfortable way you may set up a database report with HBasic. With a database report you may not only add a layout that describes how your data should be presented, you can also sort your data, group it or add calculated fields. Remember that the current state of the HBasic report designer is a prealpha version. Many of the features that are neccessary to edit reports will be added later.

If you have connected your HBasic project to a database you can open the report designer by creating a new database report in the new form dialog which appears when you select New in the menubar or click on the new icon in the project tree toolbar or HBasic global toolbar.

new_doc  

Next a popup dialog asks you for the name of the new report. Insert a unique name for your report and press the OK button. You should now see the report editor dialog which looks like the following image.

report_edit    

In this image the following steps to define a report have already been executed:
Editing database reports

This document should explain how you can set up your own report definitions. The reports you have created will be stored with your HBasic project. You can see a list of all defined reports in the project tree. When you want to change or execute your report later click on the name of the report in the project tree with the right mouse button and select Edit or Execute in the popup menu that will be displayed.



Prerequisites


Before you may create and start a database report you have to prepare the following steps:
db_in_project


Select database and connect to project

Since a report description will be stored in the project files of your current HBasic project you have to select a database  and connect it to the project first.  Open the database window with the menu entry view / database window or click on the small database icon in the toolbar.

HBasic will open a new dialog where you can edit the list of known databases or connect to one database. Remember to compile the database plugin for your favourite database backend before trying to use the database connection in HBasic. (See setting up database access with HBasic).

To connect a database to your project add the database description to the list of known databases on top of the database window and click on the button to project to connect the current selected database to your project description 



Select table for your report

For the following description we assume that you have already connected your project to a database and opened the report designer by creating a new database report.

The data fields used in your report should be taken from a database table. Click on the Add table button in the report designer. You will now see a new dialog that lists all the tables from the database that is connected to your project. Mark the tables that you want to use with a mouseclick and click on the Add button. If you cannot see any table in this dialog check if you correctly connected to a database (with correct user and password) and the database is online.



Connect a table column

The main contents of a report are report fields which display a predefined text or values from database columns. You can create new database fields by selecting the type of the field on the left side of the report designer. Click on the Label button to select creating text items or click on the Lineedit button to creat a report field that may display table column values.

Next click on the position in the report designer where the report item should be inserted. After you have inserted new report items you may move them to a new position or resize them mith mouse clicks.

The property editor will display the properties for the item that is currently selected in the report designer. To insert the text that should be displayed with the Label entry change the Text property of this fields. To connect a Lineedit item to a column of the database table that has been selected for the report change the Display property of this items.


Execute report

After you set up all this parts of a report you can start execution by clicking on the Preview button. The right side of the current dialog shows the result data of your report.

Beside showing the preview of a report you can also start the print function which will print the result of the report to a printer (or file) that may be selected in a special dialog that pops up after clicking the Print button.

After leaving the report designer you can see a list of all defined reports in the project tree. When you want to change or execute your report later click on the name of the report in the project tree with the right mouse button and select Edit or Execute in the popup menu that will be displayed. You may also select the report with the left mouse button and click on the Start button in the project tree window.