Database access from HBasic programs |
To
use database access you need to install QT in a version higher than 3.0
and compile the database pluging matching the kind of your database server.
Remember to include the package hbasic_dbaccess if you create new database
examples. If you load the predefined examples from the HBasic distribution
this package will be loaded automatically.
Accessing a table from a HBasic program |
|
Reading all records of a table |
|
Positioning the edit cursor |
| Command | Description |
| MoveNext | Move edit cursor to next record of table |
| MovePrev | Move edit cursor to previous record of table |
| MoveFirst | Move edit cursor to first record of table |
| MoveLast | Move edit cursor to last record of table |
| Seek( position_n ) | Set edit cursor to position_n in table |
After each of this operations you may test if HBasic has found a valid record with the function EOF(). If HBasic cannot position on a valid record the function EOF will give a result of TRUE. You may for example loop through all records of a table with the following While command:
While Not t.eof()
Print t.getValue( "col1" )
t.MoveNext()
Wend
Other methods for database components |
| connect( db_name, user_name, user_password)
|
Create new connection to database <db_name> |
| open( db_connection, table_name ) |
Open recordset for table table_name |
| bool eof( ) |
return TRUE if no more recordsets can be read |
| delete( ) |
Delete current row from table |
| update( ) |
Store values changed with setValue to database |
| addNew( ) |
Add new row to table and make it current row |
| variant getValue( column_name ) |
Read the value of column_name and return as variant |
| setValue( column_name, new_value ) |
Change value of column_name to new_value |
Update current row in database |
Dim v As Variant |
|
t.addNew()
t.setValue( "col1", 3333 )
t.Update()
Dim v As Variant |
Delete current database row |
Dim v As Variant |