Prepare HBasic for database access |
Overview |
To access databases from HBasic you normally do not need to install something special. HBasic uses the QT libraries in a version >= 3.0 and this libraries already have build in support to access tables or data within a database. The current release of QT 3.0 supports plugins for the following types of database server.
QODBC3 - ODBC (Open Database Connectivity)
Driver
QOCI8 - Oracle Call Interface Driver
QPSQL7 - PostgreSQL v6.x and v7.x Driver
QTDS7 - Sybase Adaptive Server and Microsoft
SQL Server Driver
QMYSQL3 - MySQL Driver
This means with QT >= 3.0 there is no need to install additional libraries (for ODBC or other backends). This document will describe two steps that may be helpful when trying to start with databases in HBasic. For the example programs I started with the MySQL plugin and the MySQL server software. Therefore in the following description I assume that you also have installed the MySQL Server and client software. If anybody will have problems to use HBasic or the example programs with other server software any information will be welcome.
Compile a QT plugin for MySQL |
To compile the MySQL plugin for QT do the following.
Go to the plugins/src/sqldrivers/mysql subdirectory of
your QT directoty ($QTDIR).
Have a look at the README file in this directory for further information
about how to compile the plugin.
Create the Makefile to compile the MySQL plugin with a qmake command similar
to the one in the README file. My be you have to change the path to your
mysql include-files and mysql shared libraries. Depending on the installation
of your Linux distribution this should be /usr/local/include or /usr/include/mysql
for the INCLUDEPATH and /usr/local/libs or /usr/lib/mysql for the LIBS.
For my installation I put the following command into a new skript, made it executable (chmod 777 <scriptname>) and started the script.
qmake -o Makefile "INCLUDEPATH+=/usr/include/mysql" "LIBS+=-L/usr/lib/mysql -lmysqlclient" mysql.pro
After this qmake should have generated a new Makefile so that you now may start make to compile the plugin. If you do not compile the QT plugin that you want to reference in your HBasic code you will get an error message when starting the program.
Create and configure a test database for HBasic examples |
For the example programs we want to create a database with name "hbasic
" and two tables with name "tab1" and "tab2". To create this database execute
the following statements with the mysql client.
Log in to the mysql client
mysql -u username -p
enter password for your database user
create database hbasic;
create table tab1( col1 integer primary key, col2 integer, col3 integer);
create table tab2( field1 integer, dbl2 double, str3 char(30));
Insert some data into the new created tables with the statements
insert into tab1 values( 1,11,111 );
insert into tab1 values( 2,22,222 );
insert into tab1 values( 333,33,3 );
etc.
Check contents of table tab1 with the statement
select * from tab1;
when you are ready leave the mysql client with the command quit.
This will be all to start the first examples with using HBasic database
access.