NA01
08-01-2006, 19:35
il codice che vi posto viene da mille copai incolla da varie funzioni di varie classi in modo da renderlo il più compatto possibile
auth è un banale enum, la classe dell'eccezione è una classe completamente vuota.
il problema è che metto il record con la chiave, e quando chiamo la get....
puf!!!
il record non esiste più :(
se qualcuno mi può dare una mano...
grazie, ciao!
#include <iostream>
#include <string>
#include <db_cxx.h>
#include "Projects/NA++/Entry.h"
#include "Projects/NA++/Exceptions.h"
void insertRecord(Entry record,std::string insertKey, Db* db){
Dbt key(const_cast<char*>(insertKey.c_str()), insertKey.length() + 1);
Dbt data(&record, sizeof(Entry));
db->put(NULL, &key, &data, 0);
}
Entry* getRecord(std::string getKey, Db* db){
Dbt key, data;
key.set_data(const_cast<char*>(getKey.c_str()));
key.set_ulen(getKey.length() + 1);
key.set_flags(DB_DBT_USERMEM);
if(db->get(NULL, &key, &data, 0) == DB_NOTFOUND){
throw NotFound();
}
return (Entry*)data.get_data();
}
int main(){
try{
Db* db;
db = new Db(NULL, 0);
u_int32_t oFlags = DB_CREATE;
db->open(NULL, "db.db", NULL, DB_BTREE, oFlags, 0);
std::string key1 = "key1", key2 = "key2";
Auth status = DENIED;
Entry entry1, entry2;
strncpy(entry1.hash, "abcdefasjkjnklke", 17);
strncpy(entry2.hash, "lkjhgfdsaqwertyu", 17);
entry1.status = entry2.status = status;
insertRecord(entry1, key1,db);
insertRecord(entry2,key2,db);
Entry* entry3 = getRecord(key1,db);
Entry* entry4 = getRecord(key2,db);
}catch(NotFound e){
std::cout << "Ma pork!!!\n";
}
}
auth è un banale enum, la classe dell'eccezione è una classe completamente vuota.
il problema è che metto il record con la chiave, e quando chiamo la get....
puf!!!
il record non esiste più :(
se qualcuno mi può dare una mano...
grazie, ciao!
#include <iostream>
#include <string>
#include <db_cxx.h>
#include "Projects/NA++/Entry.h"
#include "Projects/NA++/Exceptions.h"
void insertRecord(Entry record,std::string insertKey, Db* db){
Dbt key(const_cast<char*>(insertKey.c_str()), insertKey.length() + 1);
Dbt data(&record, sizeof(Entry));
db->put(NULL, &key, &data, 0);
}
Entry* getRecord(std::string getKey, Db* db){
Dbt key, data;
key.set_data(const_cast<char*>(getKey.c_str()));
key.set_ulen(getKey.length() + 1);
key.set_flags(DB_DBT_USERMEM);
if(db->get(NULL, &key, &data, 0) == DB_NOTFOUND){
throw NotFound();
}
return (Entry*)data.get_data();
}
int main(){
try{
Db* db;
db = new Db(NULL, 0);
u_int32_t oFlags = DB_CREATE;
db->open(NULL, "db.db", NULL, DB_BTREE, oFlags, 0);
std::string key1 = "key1", key2 = "key2";
Auth status = DENIED;
Entry entry1, entry2;
strncpy(entry1.hash, "abcdefasjkjnklke", 17);
strncpy(entry2.hash, "lkjhgfdsaqwertyu", 17);
entry1.status = entry2.status = status;
insertRecord(entry1, key1,db);
insertRecord(entry2,key2,db);
Entry* entry3 = getRecord(key1,db);
Entry* entry4 = getRecord(key2,db);
}catch(NotFound e){
std::cout << "Ma pork!!!\n";
}
}