⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 database.h

📁 1.简介 本程序是用纯C语言编的一个基于菜单命令行的数据库系统。可以创建多个数据库
💻 H
字号:
/*------------------------------------------
	// Head file for database.c
  ------------------------------------------*/

#define MAX_NAME	20
#define FILE_NAME	50
#define MAX_STR		20
#define LEN_DATABASE	sizeof(struct database)
#define LEN_TABLE		sizeof(struct table)
#define LEN_COLUMN		sizeof(struct column)
#define LEN_DATA		sizeof(struct data)

//////////////////////////////////////
//	Struction
typedef struct
{
	int		year;
	int		month;
	int		day;
	int		hour;
	int		minute;
}TIME;

typedef union 
{
	int		iValue;
	char	cValue;
	char	strValue[MAX_STR];
	float	fValue;
}UNIONTYPE;

struct database
{
	char	cName[MAX_NAME];
	TIME	tCreateTime;
	char	cCreatorName[MAX_NAME];
	int		iTableNum;			// the number of tables of the database
	struct database *next;		// point to next database
	struct table	*tablehead;	// point to the first table of the database
};

struct table
{
	char	cName[MAX_NAME];
	TIME	tCreateTime;
	int		iColNum;			// the number of columns of the table
	struct table	*next;		// point to next table
	struct column	*columnhead;// point to the first column of the table
};

struct column
{
	char	cName[MAX_NAME];
	char	cType;
	int		iLineNum;			// the number of lines of the column
	struct column	*next;		// point to next column
	struct data		*datahead;	// point to the first data of the column
};

struct data
{
	UNIONTYPE	value;
	struct data		*next;		// point to the next data of a column
};

struct dataindex				// for record sort
{
	UNIONTYPE	value;
	int index;
	struct dataindex *next;
};

//////////////////////////////////////
// Global varibles
struct database *databasehead;
char com[50][MAX_STR];
//////////////////////////////////////
//	Function Declaration

// menu handle
void mainhandle(void);
void File(void);
void New(void);
void Edit(void);
void Query(void);

// menu 
void MainMenu(void);
void EditMenu(void);
void FileMenu(void);
void NewMenu(void);
void QueryMenu(void);

// help info
void Help(void);

// for edit
struct data *InputRecord(struct table *table);
void ShowRecord(struct table *table,int index);
void AddRecord(struct table *table,struct data *record);
void DeleteRecord(struct table *table,struct column *column,struct data *data);
int FindRecord(struct table *table,struct column *column,struct data *data);
void ModifyRecord(struct table *table,struct column *column,struct data *data);
void SortRecord(struct table *table,struct column *column,int ascend);
void ShowAllRecord(struct table *table);
void SortTable(void);

// for file
void Open(void);
void Save(void);

// for new
void CreateDatabase(void);
void CreateTable(void);
void CreateColumn(void);
void  AddDataToTable(void);

// for edit and query
struct database *GetDatabase(char databasename[]);
struct table *GetTable(struct database * pdb,char tablename[]);
struct column *GetColumn(struct table *ptab,char columnname[]);

// for query
void ShowTableInfo(struct database *pdb);
void ShowDatabaseInfo(void);
void ShowColumnInfo(struct database *pdb,struct table *ptab);
void QueryColumnInfo(void);
void QueryTableInfo(void);
void QueryRecords(void);

void Find(void);
void Modify(void);
void Delete(void);

void SQL(void);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -