Add check on page delete if it's the last one

master
Yury Kurlykov 2019-10-31 01:47:54 +10:00
parent 7bfa64403e
commit a2a25826cf
1 changed files with 7 additions and 1 deletions

View File

@ -346,10 +346,16 @@ YDB_Error ydb_replace_current_page(YDB_Engine *instance, YDB_TablePage *page) {
}
YDB_Error ydb_delete_current_page(YDB_Engine *instance) {
// TODO check if it's only page in table
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 && instance->next_page_offset == 0) {
fseek(instance->fd, instance->curr_page_offset + 9, SEEK_SET); // Skip page flags + next ptr
YDB_PageSize tmp = 0;
fwrite(&tmp, sizeof(YDB_PageSize), 1, instance->fd);
return YDB_ERR_SUCCESS;
}
// Mark page as deleted
fseek(instance->fd, instance->curr_page_offset, SEEK_SET);
fputc(YDB_TABLE_PAGE_FLAG_DELETED, instance->fd);