The hk_classes programmer's tutorial
Prev |  |

# Chapter 9. Use a query

A result query works like a table. Note: the SQL statement has no delimiter at the end, even if the used database needs one.

Example 9-1. Use a query

       1
       2   #include <hk_classes.h>
       3   #include <iostream>
       4   int main()
       5   {
       6   hk_drivermanager* mydrivermanager = new hk_drivermanager();
       7   if (mydrivermanager==NULL) {cout <<"error creating mydrivermanager"<<endl;exit(1);}
       8   hk_connection* myconnection = mydrivermanager->new_connection();
       9   if (myconnection==NULL) {cout <<"error creating myconnection"<<endl;exit(1);}
      10   myconnection->connect();
      11
      12   hk_database* mydatabase=myconnection->new_database("exampledb");
      13   if (mydatabase==NULL) {cout <<"error creating mydatabase"<<endl;exit(1);}
      14   hk_datasource* mydatasource= mydatabase->new_resultquery();
      15   mydatasource->set_sql("SELECT * FROM literature");
      16   if (mydatasource==NULL) {cout <<"error creating mydatasource"<<endl;exit(1);}
      17   mydatasource->enable();
      18   //the following internal debugging command should not be used. It is used here for
      19   //demonstration purposes only!!!!
      20   mydatasource->dump_data(); // DON'T USE THIS COMMAND IN YOUR PROGRAMMS!!!
      21
      22   delete mydrivermanager;
      23   }

Prev | Home |
Searching a column |  |