📄 catalog.h
字号:
#ifndef CATALOG_H
#define CATALOG_H
#include "Glob_Var.h"
#include "Intepretor.h"
#include "Buffer.h"
#define MAX_CHAR_LEN 256
#define NAME_LENGTH 33
#define Update_Condition TSelect_Condition
#define Delete_Condition TSelect_Condition
//字段约束条件中的值的形式
union Limit_Value
{
int IntValue; //整形值
char CharValue[MAX_CHAR_LEN]; //字符串
float FloatValue; //浮点型值
};
//字段上的约束条件
typedef struct TConstraint_Info
{
Operator_Type OperType; // > >= < <= = != between…and…
Limit_Value min; //下限
Limit_Value max; //上限
}Constraint_Info;
//字段信息
typedef struct TColumn_Info
{
int ID; //按用户输入的顺序所规定的ID
char ColumnName[NAME_LENGTH]; //字段名(限定最长为32位)
int IsPrimary; //是否主键的标志:1-是;0-否
int IsNull; //是否可以为空:1-是;0-否
Column_Type ColType; //字段类型:int,char,float
int RequiredLength; //用户要求字段长度
int StoredLength; //实际存储长度
union{
TColumn_Info* next; //下一个字段的内存指针
_F_FileAddr FileNext; //下一个字段的文件指针
}ColumnPtr;
union{
Constraint_Info* constraint; //指向此字段上的约束条件的内存指针
_F_FileAddr FileConstraint; //指向此字段上的约束条件的文件指针
}ConstraintPtr;
}Column_Info;
//表信息
typedef struct TTable_Info
{
TTable_Info();
char TableName[NAME_LENGTH]; //表名(限定最长为32位)
int TotalColumn; //总字段数
int RecordLength; //每个记录长度
int KeyAttrNum; //多属性主键中属性个数
union{
Column_Info* Key; //指向主键的内存指针
_F_FileAddr FileKey; //指向主键的文件指针
}KeyPtr;
}Table_Info;
class HCatalog
{
public:
void Create(TB_Create_Info&,char*); //创建表
void Select(TB_Select_Info&, //查询(Interpreter给出TB_Create_Info&,
Condition_Info&, // Condition_Info&给Index
Select_Rec_Info&); // Select_Rec_Info&给Record)
void Insert(TB_Insert_Info&, //插入(Interpreter给出TB_Insert_Info&,
Key_Attr&, // pKey_Attr给Index,
Rec_Info&); // Record_Info&给Record)
void Update(TB_Update_Info&, //更新(Interpreter给出TB_Update_Info&,
Condition_Info&, // Condion_Info&给Index,
Rec_Info&); // Rec_Info&给Record)
void Delete(TB_Delete_Info&, //删除(Interpreter给出TB_Delete_Info&,
Condition_Info&); // Condition_Info给Index)
private:
Column_Info* Find_Column(char* ) const; //查找并定位字段信息
bool Exist_Column(char*) const; //检查字段是否已存在
bool Check_Key(Column_Info*) const; //检查是否是主键
bool Check_Type(Column_Info*,Column_Type) const; //检查类型是否匹配
bool Check_Value(Column_Info*,Column_Value*) const; //检查插入或更新值是否满足约束条件
bool Check_Length(Column_Info*,Column_Value*) const; //检查char型值的长度是否有效
bool Check_Key_Validation(Column_Type, Column_Value*, Column_Value*) const; //检查key的有效性
Column_Info* Form_ListNode(Create_Column*,int) const; //形成一个字段链表节点
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -