From c561879625c252d06b09c5c5b0d0409d211ada84 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 16 Feb 2022 09:33:40 +0000 Subject: [PATCH] more TDB --- source/libs/tdb/src/db/tdb.c | 5 +++++ source/libs/tdb/src/db/tdbPgFile.c | 4 ++++ source/libs/tdb/test/tdbTest.cpp | 14 +++++++++----- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/source/libs/tdb/src/db/tdb.c b/source/libs/tdb/src/db/tdb.c index 6fcb2686fd..81bc35e87c 100644 --- a/source/libs/tdb/src/db/tdb.c +++ b/source/libs/tdb/src/db/tdb.c @@ -172,6 +172,11 @@ int tdbGetDup(TDB *pDb) { } } +int tdbInsert(TDB *pDb, const void *pKey, int nKey, const void *pData, int nData) { + // TODO + return 0; +} + static int tdbDefaultKeyCmprFn(int keyLen1, const void *pKey1, int keyLen2, const void *pKey2) { int mlen; int cret; diff --git a/source/libs/tdb/src/db/tdbPgFile.c b/source/libs/tdb/src/db/tdbPgFile.c index 5db0c4dcc3..55a89aae63 100644 --- a/source/libs/tdb/src/db/tdbPgFile.c +++ b/source/libs/tdb/src/db/tdbPgFile.c @@ -22,6 +22,10 @@ typedef struct SPage1 { uint32_t nFree; // number of free pages } SPage1; +typedef struct SFreePage { + /* TODO */ +} SFreePage; + TDB_STATIC_ASSERT(sizeof(SPage1) <= TDB_MIN_PGSIZE, "TDB Page1 definition too large"); static int pgFileRead(SPgFile *pPgFile, pgno_t pgno, uint8_t *pData); diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index 4433d3288d..fc4cc31cda 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -3,7 +3,7 @@ #include "tdb.h" TEST(tdb_test, simple_test) { - TENV* pEnv; + TENV * pEnv; TDB * pDb1, *pDb2, *pDb3; pgsz_t pgSize = 1024; cachesz_t cacheSize = 10240; @@ -20,14 +20,12 @@ TEST(tdb_test, simple_test) { GTEST_ASSERT_EQ(tdbEnvOpen(pEnv), 0); #if 1 - - tdbEnvBeginTxn(pEnv); // DB GTEST_ASSERT_EQ(tdbCreate(&pDb1), 0); - GTEST_ASSERT_EQ(tdbSetKeyLen(pDb1, 8), 0); + // GTEST_ASSERT_EQ(tdbSetKeyLen(pDb1, 8), 0); - GTEST_ASSERT_EQ(tdbGetKeyLen(pDb1), 8); + // GTEST_ASSERT_EQ(tdbGetKeyLen(pDb1), 8); // GTEST_ASSERT_EQ(tdbSetValLen(pDb1, 3), 0); @@ -39,8 +37,14 @@ TEST(tdb_test, simple_test) { // GTEST_ASSERT_EQ(tdbSetCmprFunc(pDb1, NULL), 0); + tdbEnvBeginTxn(pEnv); + GTEST_ASSERT_EQ(tdbOpen(pDb1, "db.db", "db1", pEnv), 0); + // char *key = "key1"; + // char *val = "value1"; + // tdbInsert(pDb1, (void *)key, strlen(key), (void *)val, strlen(val)); + tdbEnvCommit(pEnv); #if 0 -- GitLab