Chapter 8. Searching a column
Prev |  | Next

## Chapter 8. Searching a column

The method unsigned int hk_column::find (const string& searchtext) searchs in a column whether there is a dataset which contains the needed value. There are different types of this method. See the documentation of hk_column for further details.

It returns the row number if it has found a row with the searchtext, otherwise max rows +1.

Example 8.1. Searching a column

    #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("mysql");
       if (myconnection==NULL) {cout <<"error creating myconnection"<<endl;exit(1);}
       myconnection->set_host("localhost");
       myconnection->set_user("root");
       myconnection->set_password("mypasswd");
       myconnection->connect();

       hk_database* mydatabase=myconnection->new_database("exampledb");
       if (mydatabase==NULL) {cout <<"error creating mydatabase"<<endl;exit(1);}
       hk_datasource* mydatasource= mydatabase->new_table("authors");
       if (mydatasource==NULL) {cout <<"error creating mydatasource"<<endl;exit(1);}
       mydatasource->enable();

       hk_column* mycolumn = mydatasource->column_by_name("name");
       if (mycolumn==NULL) {cout <<"error getting column"<<endl;exit(1);}

       unsigned int result=mycolumn->find("searchtext");

       delete mydrivermanager;
    }

Prev |  | Next
Chapter 7. Delete a row | Home | Chapter 9. Use a query