* --- Change - now the whole source *
When I debug it at the end, "get" and "value" have different meanings! Perhaps I will convert to void * and return to the User incorrectly?
#include <db_cxx.h>
#include <stdio.h>
struct User{
User(){}
int name;
int town;
User(int a){};
inline int get_index(int a){
return town;
}
};
int main(){
try {
DbEnv* env = new DbEnv(NULL);
env->open("./",
DB_CREATE | DB_INIT_MPOOL | DB_THREAD |
DB_INIT_LOCK | DB_INIT_TXN | DB_RECOVER | DB_INIT_LOG, 0);
Db* datab = new Db(env, 0);
datab->open(NULL, "db.dbf", NULL, DB_BTREE, DB_CREATE | DB_AUTO_COMMIT, 0);
Dbt key, value, get;
char a[10] = "bbaaccd";
User u;
u.name = 1;
u.town = 34;
key.set_data(a);
key.set_size(strlen(a) + 1 );
value.set_data((void*)&u);
value.set_size(sizeof(u));
get.set_flags(DB_DBT_MALLOC);
DbTxn* txn;
env->txn_begin(NULL, &txn, 0);
datab->put(txn, &key, &value, 0);
datab->get(txn, &key, &get, 0);
txn->commit(0);
User g;
g = *((User*)&get);
printf("%d", g.town);
getchar();
return 0;
}catch (DbException &e){
printf("%s", e.what());
getchar();
}
Decision
create a kind of "serializer" to convert all PODs to void *, and then combine these fragments
PS Or I would rewrite the user in the POD type, and everything will be fine, I hope.
Add
This is strange, but ... I throw a defenetly non-pod object into void * and vice versa (it has std :: string inside), and everything is fine (without sending it to db and vice versa). How could this happen? And after I said and sent the 'trough' db defenetly pod object (no additional methods, all pod members, this is a simple structure {int a; int b; ...}). What is wrong with my approach?
'
... , , , ! !.. !... AAh!.. Lord... ( 99,999 - "", ... ...) - ? ?