From 6e6c7df9a306fc1bad3eae1d4a680661837c750f Mon Sep 17 00:00:00 2001 From: Yury Kurlykov Date: Thu, 5 Dec 2019 00:19:49 +1000 Subject: [PATCH] Add seeking to the first page --- inc/YeltsinDB/ydb.h | 13 +++++++++---- src/ydb.c | 11 +++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/inc/YeltsinDB/ydb.h b/inc/YeltsinDB/ydb.h index 1096290..58af0bb 100644 --- a/inc/YeltsinDB/ydb.h +++ b/inc/YeltsinDB/ydb.h @@ -122,11 +122,16 @@ YDB_TablePage* ydb_get_current_page(YDB_Engine* instance); YDB_Error ydb_delete_current_page(YDB_Engine* instance); /** - * @brief Seek to the last page. - * @param instance A YeltsinDB instance + * @brief Seek to the first page. + * @param instance A YeltsinDB instance. + * @return Operation status. + */ +YDB_Error ydb_seek_to_begin(YDB_Engine* instance); + +/** + * @brief Seek to the last page. + * @param instance A YeltsinDB instance. * @return Operation status. - * - * @warning Could break an instance if ydb_ */ YDB_Error ydb_seek_to_end(YDB_Engine* instance); diff --git a/src/ydb.c b/src/ydb.c index d384df4..e6043b9 100644 --- a/src/ydb.c +++ b/src/ydb.c @@ -409,6 +409,17 @@ YDB_Error ydb_delete_current_page(YDB_Engine *instance) { return __ydb_read_page(instance); } +YDB_Error ydb_seek_to_begin(YDB_Engine *instance) { + THROW_IF_NULL(instance, YDB_ERR_INSTANCE_NOT_INITIALIZED); + THROW_IF_NULL(instance->in_use, YDB_ERR_INSTANCE_NOT_IN_USE); + + if (instance->prev_page_offset == 0) + return YDB_ERR_SUCCESS; + + instance->curr_page_offset = instance->prev_page_offset; + return __ydb_read_page(instance); +} + YDB_Error ydb_seek_to_end(YDB_Engine *instance) { THROW_IF_NULL(instance, YDB_ERR_INSTANCE_NOT_INITIALIZED); THROW_IF_NULL(instance->in_use, YDB_ERR_INSTANCE_NOT_IN_USE);