diff --git a/source/libs/tdb/inc/tdb.h b/source/libs/tdb/inc/tdb.h index 905b08ee0bffdddd948fc62d70b0d42cf7f6a17b..eee8f8ed33274a0834eea61b879e831c530d6021 100644 --- a/source/libs/tdb/inc/tdb.h +++ b/source/libs/tdb/inc/tdb.h @@ -44,7 +44,7 @@ typedef struct { // TDB Operations TDB_EXTERN int tdbCreateDB(TDB** dbpp, tdb_db_t type); -TDB_EXTERN int tdbOpenDB(TDB* dbp, uint32_t flags); +TDB_EXTERN int tdbOpenDB(TDB* dbp, const char* fname, const char* dbname, uint32_t flags); TDB_EXTERN int tdbCloseDB(TDB* dbp, uint32_t flags); #ifdef __cplusplus diff --git a/source/libs/tdb/src/db/tdbDB.c b/source/libs/tdb/src/db/tdbDB.c index 2af40d8642376ed1720082a6172f845caad7d637..eaf85ea4a1930e2a6304986df43656ee07cb8e20 100644 --- a/source/libs/tdb/src/db/tdbDB.c +++ b/source/libs/tdb/src/db/tdbDB.c @@ -56,9 +56,28 @@ _err: return 0; } -TDB_EXTERN int tdbOpenDB(TDB* dbp, uint32_t flags) { - // TODO - return 0; +TDB_EXTERN int tdbOpenDB(TDB* dbp, const char* fname, const char* dbname, uint32_t flags) { + int ret = 0; + + if ((dbp->fname = strdup(fname)) == NULL) { + ret = -1; + return ret; + } + + // Create the backup file if the file not exists + + // Open the file as a sub-db or a master-db + if (dbname) { + if ((dbp->dbname = strdup(dbname)) == NULL) { + ret = -1; + return ret; + } + // TODO: Open the DB as a SUB-DB in this file + } else { + // TODO: Open the DB as a MASTER-DB in this file + } + + return ret; } TDB_EXTERN int tdbCloseDB(TDB* dbp, uint32_t flags) { diff --git a/source/libs/tdb/src/inc/tdbDB.h b/source/libs/tdb/src/inc/tdbDB.h index fca197dc39f28a1d27ed250bd940f8b1b7055e9d..d0ef9e22d0f625889ee2403c2820b6c3a5fc54d2 100644 --- a/source/libs/tdb/src/inc/tdbDB.h +++ b/source/libs/tdb/src/inc/tdbDB.h @@ -25,6 +25,14 @@ extern "C" { #endif +typedef struct { + // TODO +} TDB_MPOOL; + +typedef struct { + int fd; +} TDB_FH; + struct TDB { pgsize_t pageSize; tdb_db_t type; @@ -35,6 +43,9 @@ struct TDB { TDB_HASH * hash; TDB_HEAP * heap; } dbam; // db access method + + TDB_FH * fhp; // The backup file handle + TDB_MPOOL *mph; // The memory pool handle }; #ifdef __cplusplus diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index 38c3b0b9173fe2bfec0f6a674b63e38dedfcd1e9..f27e17f1ca8f45c8c15feb423d6b706dece79f01 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -6,9 +6,9 @@ TEST(tdb_api_test, tdb_create_open_close_db_test) { int ret; TDB *dbp; - tdbCreateDB(&dbp, TDB_BTREE_T); + // tdbCreateDB(&dbp, TDB_BTREE_T); - tdbOpenDB(dbp, 0); + // tdbOpenDB(dbp, 0); - tdbCloseDB(dbp, 0); + // tdbCloseDB(dbp, 0); } \ No newline at end of file