What is Berkeley DB? (Wikipedia) - Official page (Oracle site)
| Main downloads: | |
| Unit db_h.pas with the Berkeley DB access API (db.h conversion) | download |
| File with the necessary DLLs for using Berkeley DB | download |
| Delphi project with examples of Berkeley DB access | download |
| Supplementary downloads: | |
| Validator of correctness of Delphi conversion | download |
| db.h file from which db_h.pas was created | download |
| Complete Berkeley DB 5.1.25 (installer) | download |
type
PKey = ^TKey;
TKey = record
Id: integer;
end;
PData = ^TData;
TData = record
Name: array[0..50] of AnsiChar;
end;
var
FDB: PDB;
cursor: PDBC;
dbtKey, dbtData: DBT;
key: PKey;
data: PData;
begin
// initialize API
InitBerkeleyDB;
// create access handle
CheckBDB(db_create(FDB, nil, 0));
try
// open database
CheckBDB(FDB.open(FDB, nil, 'Test.db', 'Test', DB_BTREE, DB_CREATE_, 0));
// create a cursor for retrieving the records in key order
CheckBDB(FDB.cursor(FDB, nil, @cursor, 0));
try
FillChar(dbtKey, Sizeof(DBT), 0);
FillChar(dbtData, Sizeof(DBT), 0);
// iterate thru all the records and print each one
while CheckAndFoundBDB(cursor.get(cursor, @dbtKey, @dbtData, DB_NEXT)) do begin
key := PKey(dbtKey.data);
data := PData(dbtData.data);
Memo.Lines.Add('Key: '+IntToStr(key.Id));
Memo.Lines.Add('Data: '+data.Name);
end;
finally
// free cursor
CheckBDB(cursor.close(cursor));
end;
finally
// close database and free handle
CheckBDBandNil(FDB.close(FDB, 0), FDB);
end;
end;