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
1 #include <hk_classes.h> 2 #include <iostream> 3 int main() 4 { 5 hk_drivermanager* mydrivermanager = new hk_drivermanager(); 6 if (mydrivermanager==NULL) {cout <<"error creating mydrivermanager"<<endl;exit(1);} 7 hk_connection* myconnection = mydrivermanager->new_connection("mysql"); 8 if (myconnection==NULL) {cout <<"error creating myconnection"<<endl;exit(1);} 9 myconnection->set_host("localhost"); 10 myconnection->set_user("root"); 11 myconnection->set_password("mypasswd"); 12 myconnection->connect(); 13 14 hk_database* mydatabase=myconnection->new_database("exampledb"); 15 if (mydatabase==NULL) {cout <<"error creating mydatabase"<<endl;exit(1);} 16 hk_datasource* mydatasource= mydatabase->new_table("authors"); 17 if (mydatasource==NULL) {cout <<"error creating mydatasource"<<endl;exit(1);} 18 mydatasource->enable(); 19 20 hk_column* mycolumn = mydatasource->column_by_name("name"); 21 if (mycolumn==NULL) {cout <<"error getting column"<<endl;exit(1);} 22 mycolumn->set_asstring("my new data"); 23 mydatasource->store_changed_data(); 24 delete mydrivermanager; 25 } |
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()).