The document describes a C database library that provides functions for opening, closing, reading, writing, and deleting records from hash table, B-tree, and simple record number oriented database files. The library defines a DB structure containing function pointers for common database operations and a DBT structure for representing key/value record pairs. It also outlines the basic functions for opening, closing, reading sequentially or by key, and modifying the database.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
19 views9 pages
5database Library@
The document describes a C database library that provides functions for opening, closing, reading, writing, and deleting records from hash table, B-tree, and simple record number oriented database files. The library defines a DB structure containing function pointers for common database operations and a DBT structure for representing key/value record pairs. It also outlines the basic functions for opening, closing, reading sequentially or by key, and modifying the database.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9
Database Library
Dbopen() – opens all three types of files.
DB structure – Collection of function pointers. #include<db.h> Typedef struct_db{ DBTYPE type; int (*close)(struct_db *); int (*del)(const struct_db *, const DBT *,u_int); int (*get)(const struct_db *, const DBT *,u_int); int (*put)(const struct_db *, const DBT *,u_int); int (*seq)(const struct_db *, const DBT *,u_int); int (*sync)(const struct_db *, u_int); int (*fd)(const struct_db *); Void *internal; }DB; TYPES OFDATABASES Hash tables For large amount of Btrees databases (efficient) Simple record number oriented access All database types treated as key/value pairs. DBT RECORD #include<db.h> typedef struct { Void *data; Size_t size; }DBT; BASIC OPERATIONS 1. Opening a db file DB *dbopen(char *filename, int flags, int mode, DBTYPE type, const void *openinfo); Flags and mode – same as file open. Type – DB_HASH, DB_BTREE or DB_RECNO Last parameter set to null and DB use default. If dbopen success returns pointer Otherwise returns NULL. CLOSING A DATABASE int close(const DB *db); OBTAINING FILE DESCRIPTOR File descriptor – for locking purpose Int fd(DB *db); File descriptor returned for the database file always refers the same file. ----locking SYNCING THE DATABASE Int sync(const DB *db, unsigned int flags); Db caches data in RAM Kernal caches disk writes To ensure On disk database is consistent with buffered structures -- synchronize Db flushes internal buffers and calls fsync(). Flags: DB_HASH , DB_BTREE -0 DB_RECNO---- R_RECNOSYNC READING RECORDS 2 ways Looking up a record by its key Reading sequential key/value pairs Int seq(const DB *db, DBT *key, DBT *value, unsigned int flags); Flags --- R_CURSOR R_FIRST R_NEXT R_LAST R_PREV Reading a particular record • Int get (const DB *db, const DBT *key, DBT *value, unsigned int flags);
Modifying the database – adding & deleting
records • int put(const DB *db, const DBT *key, DBT *value, unsigned int flags); • int del(const DB *db, const DBT *key, unsigned int flags);