We alter now the data of the column. Just give the new value as a parameter to the method hk_column::set_asstring().
Example 5.1. Alter data of 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);} mycolumn->set_asstring("my new data"); mydatasource->store_changed_data(); delete mydrivermanager; }
The method mydatasource->store_changed_data(); will store the changes. The data will also be stored when you move the rowselector to another row (hk_datasource::goto_row()) or when you disable the datasource (hk_datasource::disable()).