資源簡介
C++實現小型數據庫DBMS,具備建表以及屬性插入功能。
代碼片段和文件信息
#include?
#include?
#include?
#include?
#include?
#define?MAXSIZE?60
using?namespace?std;
/*鏈表每一個節點為table的每個屬性*/
struct?Property?????????????????//鏈表結點即表的屬性
{
????char?property[20];???????????????????????//屬性名
????char?type[20];???????????????????????????//類型
????char???size[20];?????????????????????????//屬性分配的空間
????char??Constraint[40];????????????????????//完整性約束
????struct?Property?*next;???????????????????//下一結點指針
};
struct?Table?????????????????????????????????//table結構體
{
????struct?Property?*head;???????????????????//鏈表頭指針
????int?number;??????????????????????????????//鏈表結點數
????char?TableName[20];??????????????????????//表名
????struct?Table?*next;
};
struct?Schema????????????????????????????????//模式
{
????struct?Table?*head;??????????????????????//模式頭指針
????int?number;??????????????????????????????//模式中表的數量
????char?SchemaName[20];?????????????????????//模式名字
};
/*初始化結構體*/
void?InitSchema?(struct?Schema?&schema)
{
????schema.head?=?NULL;
????schema.number?=?0;
}
void?InitTable?(struct?Table?&table)
{
????table.head?=?NULL;
????table.number?=?0;
}
/*將建表第一行命令中的表名分離出來,保存在TableName中*/
void?DepartTable(char?*CreateTable?char?*TableName)
{
????while(*CreateTable!=‘\0‘)
????????CreateTable++;
????while(*CreateTable?!=?‘?‘)
????????CreateTable--;
????CreateTable++;
????while(*CreateTable!=‘\0‘)
????{
????????*TableName?=?*CreateTable;
????????*CreateTable?=?‘\0‘;
????????CreateTable++;
????????TableName++;
????}
????*TableName?=?‘\0‘;
}
/*刪除輸入屬性每一行的首尾空格*/
void?Delete_Start_End_Blank(char?*Member)
{
????/*去除首部空格*/
????char?temp_1[MAXSIZE]?*p?=?Member;
????while(*p?==?‘?‘)
????????p?++;
????int?j?=?0;
????while(*p?!=?‘\0‘)
????{
????????temp_1[j]?=?*p;
????????j++;
????????p?++;
????}
????temp_1[j]?=?‘\0‘;
????strcpy(Member?temp_1);
????/*去除尾部空格*/
????char?temp_2[MAXSIZE]?*p_1?=?Member?*p_2?=?Member;
????while(*p_1?!=?‘\0‘)
????????p_1?++;
????p_1?--;
????while(*p_1?==?‘?‘)
????????p_1?--;
????p_1++;
????int?i?=?0;
????while(p_2?!=?p_1)
????{
????????temp_2[i]?=?*p_2;
????????i++;
????????p_2?++;
????}
????temp_2[i]?=?‘\0‘;
????strcpy(Member?temp_2);
}
/*建表第一行命令去掉空格并全部轉換為小寫,例如:create?table?stu->createtablestu*/
void?DeleteBlankAndChange(char?*CreateTable)
{
????char?temp[MAXSIZE];
????int?j?=?0;
????for(int?i?=?0;?i?????{
????????if(CreateTable[i]?!=?‘?‘)
????????{
????????????temp[j]?=?CreateTable[i];
????????????if(temp[j]>=65?&&?temp[j]<=90)
????????????????temp[j]?=?temp[j]?+?32;
????????????j++;
????????}
????}
????temp[j]?=?‘\0‘;
????strcpy(CreateTable?temp);
}
/*將每一屬性輸入行分為:propertytypesizeConstraint*/
void?DepartProperty(struct?Property?*Pro?char?Member[])
{
????char?*temp_1;????????????????//保存去掉部分空格后的字符串
????temp_1?=?(char?*)malloc(MAXSIZE?*?sizeof(char));
????char?*temp_2;????????????????//保存‘(‘前去掉空格后的字符串
????temp_2?=?(char?*
評論
共有 條評論