📄 tableblocks.cpp
字号:
// TableBlocks.cpp: implementation of the TableBlocks class.
//
//////////////////////////////////////////////////////////////////////
#include "TableBlocks.h"
#include "BufferManager.h"
#include "api_inte_struct.h"
#include <memory.h>
#include <string.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
TableBlocks::TableBlocks()
{
}
TableBlocks::~TableBlocks()
{
}
void TableBlocks::add_table(table_info *ti,int attri_block,int record_block,int index_block)
{
//find empty place
int *i = new int;
*i = 0;
char* emptyPos = this->find_table_name((char*)i);
//表示找空的表名,代表没放东西的位置
if (emptyPos == 0)
return;
struct tableDefinition td;
//复制需要的内容
memcpy(&td.table_name , &ti->table_name, 20);
td.n_attribute = ti->n_attribute;
td.ith_primary_key = ti->ith_primary_key;
td.attri_start_block = attri_block;
td.record_start_block = record_block;
td.index_start_blcok = index_block;
memcpy(emptyPos,&td,sizeof(td));
// new a block for attributes
// new a block for records
//add info
delete i;
}
int TableBlocks::get_attri_start_block(char *table_name)
{
struct tableDefinition* td;
td = (struct tableDefinition*) find_table_name(table_name);
return td->attri_start_block;
}
int TableBlocks::get_record_start_block(char *table_name)
{
struct tableDefinition* td;
td = (struct tableDefinition*) find_table_name(table_name);
return td->record_start_block;
}
int TableBlocks::get_index_start_block(char *table_name)
{
struct tableDefinition* td;
td = (struct tableDefinition*) find_table_name(table_name);
return td->index_start_blcok;
}
// 返回该table 所在位置指针
// 传入空字符串表示找空的位置
char* TableBlocks::find_table_name(char *table_name)
{
int i = 0;
struct tableDefinition *td;
while ((i+1) * ST_TABLEDEFI_SIZE < BLOCK_SIZE)
{
td=(struct tableDefinition *)(Block_head + i * ST_TABLEDEFI_SIZE);
if (strcmp(td->table_name ,table_name) == 0)
return Block_head + i * ST_TABLEDEFI_SIZE;
i++;
}
return 0;
}
char* TableBlocks::get_table_info(char *table_name)
{
struct tableDefinition* td;
td = (struct tableDefinition*) find_table_name(table_name);
struct table_info* ti = new struct table_info;
memcpy(ti->table_name , td->table_name, sizeof(td->table_name));
ti->n_attribute = td->n_attribute;
ti->ith_primary_key = td->ith_primary_key;
return (char*) ti;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -