Database access from the Hbasic IDE
Other documents about database access
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
With this software I started to set up the following software and definitions.
hbasic|Test database for HBasic examples|root|password|localhost
- Install MySQL server software and MySQLClient
- Log in to mysql and create a database with name
hbasic (create database hbasic).
- Create a table tab1 (create table tab1( col1 integer,
col2 integer, col3 integer, primary key col1)).
- Insert some rows of dummy data into this table
(insert into tab1 values( 1, 11, 111)).
- Install QT3 and don't forget to compile the MySQL
- Create a file "/usr/local/hbasic/used_databases.info
which describes the test database. The content of this file is a
text line with the following data.
- Remember to include the package hbasic_dbaccess
into your project if you want to access a database from your
(see format of the database description file for more
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:
- Open the database window and select a database
- Edit the database properties to create a connection
to the database
- Select one database and connect it to your current
- Open the table selection view in the project tree
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
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.