1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
#include "stdafx.h"
#include "iostream"
#pragma comment (lib, "libdb46.lib")
#include <db_cxx.h>
void main()
{
int temp;
// Hop on fait c'qu'il faut pour ouvrir la DB
Db db(NULL, 0);
u_int32_t oFlags = DB_CREATE;
db.set_cachesize(0, 1024 * 50, 1);
db.open(NULL, "Teste.db", NULL, DB_BTREE, oFlags, 0);
// Ajout
char * x_key = "Teddy";
unsigned long int data =12;
Dbt _key(x_key, strlen(x_key)+1);
Dbt _value(&data, sizeof(unsigned long int));
int exist = db.put(NULL, &_key, &_value, DB_NOOVERWRITE);
if (exist == DB_KEYEXIST) {
std::cout << "This record already exist\n";
}
// Récupération
unsigned long int value;
Dbt _key1;
Dbt data1;
_key1.set_data(x_key);
_key1.set_ulen(strlen(x_key)+1);
data1.set_data(&value);
data1.set_size(sizeof(unsigned long int));
data1.set_flags(DB_DBT_USERMEM);
int found = db.get(NULL, &_key1, &data1, 0);
if (found == DB_NOTFOUND) {
value = 0;
}
std::cout << "Value is " << value;
std::cin >> temp;
db.close(0);
} |
Partager