Database access


Database access from the Hbasic IDE

Other documents about database access

Database access from Hbasic programs

Additional information


One of the very interesting features of a development environment is to give the developer the possibility for simple database access. Therefore should also include this feature in two ways. The first method is to access a database directly from the IDE . With HBasic you can connect to a database with the data access methods of QT3 and fetch or store data from tables of the database. There will also be some functions to edit the structure of tables or create queries to select data from the database.

The second form of functions gives you access to the data within a database at runtime of a HBasic program. The database interface of HBasic lets the developer create statements to read or write data from tables of the database.

Remember that the functions for database access are in a very early state. The following examples only show that it is possible to access some tables within a database. Many functions are missing or they do not work stable. One of the next steps in HBasic development will be to extend these functions and make the code for it stable. These examples currently only work in the same environment that I use for testing. The following paragraph shows you how to set up this environment.  

Preparing the database environment

To run the database examples I used the following environment:
Database: MySQL + MySQLClient
Library QT3.* which is the first to support database access.

With this software I started to set up the following software and definitions.

hbasic|Test database for HBasic examples|root|password|localhost
(see format of the database description file for more info)

After you created this configuration it should be possible to connect to the database from HBasic.

Accessing a table from the IDE

When you want to see the contents of a tabel or change data in a table you can select a table within the GUI and call the table content editor. Before HBasic can show a table contents for editing you have to execute the following steps:

Changing data in a table

After you have selected one table of the database and opened the depending dialog you may now update or delete old records or insert new recors into this table. To change data in the table click on the value that you want to change. HBasic now sets the editor buffer to the line of this field. You can see this at the arrow on the left side of the table window. You may now change the data in this edit buffer.

If you want to insert a new row click on the last line in the table view which is marked with a star at the left side of the table window. HBasic now creates a new empty record in the table starts the edit mode for the empty line. You may now insert new data into this new record. Behind this new line in edit mode you can see an additional empty line marked with a star. Always use the last line to create more new records.

Creating a new table in the database

HBasic may create new tables in a connected database through a special dialog. You can create a new table by selecting File / New in the menubar or clicking on the New toolbar button. This opens a dialog where you can select an icon to create a new database table as a new structure.


Another method to open up the create-table dialog is to click on table or common entries in the project tree with the right mouse button. In the create-table dialog each line represents a row in the table. You may change the type of the selected row or create a new one by clicking on the empty row (marked with a * at the left side) below the currently defined rows.


Changing the structure of tables

Calling this edit-table dialog from the project_tree window may be used to edit the structure of a table later. Just click on the name of the table that you want to change and select Edit table from the popup menu that will be displayed.