Chapter 9. Use a query
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

      #define HAVE_SSTREAM 1
      #include <hk_classes.h>
      #include <iostream>
      int main()
      {
      hk_drivermanager* mydrivermanager = new hk_drivermanager();
      if (mydrivermanager==NULL) {cout <<"error creating mydrivermanager"<<endl;exit(1);}
      hk_connection* myconnection = mydrivermanager->new_connection();
      if (myconnection==NULL) {cout <<"error creating myconnection"<<endl;exit(1);}
      myconnection->connect();

      hk_database* mydatabase=myconnection->new_database("exampledb");
      if (mydatabase==NULL) {cout <<"error creating mydatabase"<<endl;exit(1);}
      hk_datasource* mydatasource= mydatabase->new_resultquery();
      mydatasource->set_sql("SELECT * FROM literature");
      if (mydatasource==NULL) {cout <<"error creating mydatasource"<<endl;exit(1);}
      mydatasource->enable();
      //the following internal debugging command should not be used. It is used here for
      //demonstration purposes only!!!!
      mydatasource->dump_data(); // DON'T USE THIS COMMAND IN YOUR PROGRAMMS!!!

      delete mydrivermanager;
      }

Prev |  |
Chapter 8. Searching a column | Home |