📄 intepretor.h
字号:
/******************************************************************
** 文件名: Intepretor.h
** Copyright (c) 2001-2002 计算机99F MiniSQL开发小组其一
** 创建人: 王淮
** 日 期: 2001-12_10
** 修改人: 王淮
** 日 期: 2002-01-07
** 描 述: 定义了MiniSQL Intepretor模块除对磁盘文件操作之外的所有类和结构
** 版 本: 1.00
******************************************************************/
/*----------------------------------------------------------*/
#ifndef INTEPRETOR_HPP
#define INTEPRETOR_HPP
#define INPUTMAX 256
#define NAMEMAXLEN 32
#define ECMD_TYPE enum MSG
#define ECOL_TYPE enum Column_Type
#define EOPE_TYPE enum Operator_Type
#define COLVAL Column_Value
#define Conds TSelect_Condition
#define Delete_Condition TSelect_Condition
#define pDel_Cond pSel_Cond
#define Del_Cond TSelect_Condition
#define pConds pSel_Cond
#define Sel_Col TSelect_Column
#define Ins_Col TInsert_Column
#define Upd_Col TUpdate_Column
#define isprimary IsPrimary
#include "show.h"
#include "Glob_Var.h"
#include <iostream>
/***********************类型声明***********************/
//--------------以下注释掉的均已在Glob_Var.h中声明
//enum MESS { CREATE, SELECT, INSERT, UPDATE, DELETE, DROP, QUIT, SHOWDB, SHOWTABLE};
//enum MSG {CREATE,SELECT,INSERT,UPDATE,DELETE,DROP,QUIT,SHOWDB,SHOWTABLE,USE,HELP,UNORMAL,NEW};
//enum Column_Type {I, C, F}; //i---int c---char* f---float
//enum Operator_Type {B, BE, L, LE, E, NE,BETWEEN};
//-----------------------------------------------------
enum ErrType {RESOLVE,COMMON,COLUMNTYPE,KEYWORD,COLNAMEERR_IN_CHECK,GET_OP_ERR,NOCOL};
enum GnlErrType{NOSUCHDB,NOSUCHTB,NODBUSED,SUCHDBEXIST,SUCHTBEXIST,WITHOUTMATCH,NOPRIMARYKEY};
/***********************类型声明***********************/
/***********************结构体声明(或定义)***********************/
//*** 类型说明:表示输入过程中的一个有意字串的结构体
typedef struct TVSTR_BLK* VSTR_BLK_PTR;
typedef struct TVSTR_BLK
{
char* str; //有意字串,有意字串的定义见文档
VSTR_BLK_PTR next; //指向下一个有意字串的VSTR_BLK指针
~TVSTR_BLK(){delete str;delete next;}
}VSTR_BLK;
//*** 类型说明:表示错误类型和错误编码的结构体信息
// 字符串输入错误,需要给出可能的错误输入字串和其所在的行号
typedef struct ErrInfo
{
int iErrType; //错误类型号
int iLineNo; //错误所在的行号
char* pErrStr; //错误可能出现的有意字串
ErrInfo(){};
ErrInfo(const ErrInfo& src)
{this->iErrType = src.iErrType;
this->iLineNo = src.iLineNo;
int i = strlen(src.pErrStr);
this->pErrStr = new char[i+1];
strcpy(this->pErrStr,src.pErrStr);}
~ErrInfo()
{delete [] pErrStr; //由于pErrStr接收的是new出来的字串
}
}TErrInfo;
//*** 类型说明:表示一般性错误类型的结构体信息
// 一般性错误,所谓一般性错误,是指无需指明行号的错误,如在没有指定数据库之前就使用表
typedef struct GnlErrInfo
{
int iErrType;
}TGnlErrInfo;
//*** 类型说明:表示Create命令中一列信息的结构体
typedef struct Create_Column* pCreate_Column;
typedef struct Create_Column
{
char ColumnName[NAMEMAXLEN]; //字段名(规定最长为32位)
ECOL_TYPE ColType; //字段类型,如int,float,char
int length; //字段类型长度,如char(8)
COLVAL min; //下限,如例中的00000000
COLVAL max; //上限,如例中的12345678
EOPE_TYPE OperType; //关系运算符类型,如<, >=, =等等
bool IsNull; //isnull=0,则此字段有not null的限制
bool IsPrimary; //isprimary=1, 则此字段是primary key
pCreate_Column next;
Create_Column(char* str,ECOL_TYPE coltype,int strlen,bool not_null,bool ispri);
//** 功能描述:初始化函数,尤其注意对min和max的初始化,默认min>max
~Create_Column(){delete next;};
void SetColValstr(EOPE_TYPE optype,char* chMin,char* chMax);
//** 功能描述:将Create_Column()里未根据实际初始的min.pCharValue,max.pCharValue初始一下,并设定好长度
void SetColValint(EOPE_TYPE optype,int iMin,int iMax);
//** 功能描述:将Create_Column()里未根据实际初始的min.IntValue,max.IntValue初始一下
void SetColValfloat(EOPE_TYPE optype,float fMin,float fMax);
//** 功能描述:将Create_Column()里未根据实际初始的min.FloatValue,max.FloatValue初始一下
void SetColVal(EOPE_TYPE optype,COLVAL &tMin ,COLVAL &tMax);
//** 功能描述:根据tMin和tMax来设置min和max
}TCreate_Column;
/***********************结构体声明(或定义)***********************/
/***********************类定义***********************/
//*** 类型说明:是表述一个Create命令的所有参数的参数类
class TB_Create_Info
{
public:
int TotalColumn; //字段总数
pCreate_Column head; //字段链表头
char TableName[32]; //表名(规定最长为32位)
TB_Create_Info(int,pCreate_Column,char*);
//** 功能描述:初始化函数,将所有的列信息整合成一张表
~TB_Create_Info(){delete head;}
};
typedef struct TSelect_Column *pSel_Col;
typedef struct TSelect_Column
{ //选择的字段
char ColumnName[NAMEMAXLEN]; //字段名(限定最长32位)
TSelect_Column* next; //下一个字段
TSelect_Column(char* strColName){next=NULL;strcpy(ColumnName,strColName);}
~TSelect_Column(){delete next;}
}Select_Column;
typedef struct TSelect_Condition *pSel_Cond;
typedef struct TSelect_Condition
{ //选择条件(where…)
char PrimaryKey[NAMEMAXLEN]; //主键名
COLVAL max; //上限
COLVAL min; //下限
Column_Type ColType; //属性的类型
Operator_Type OperType; //关系运算符
TSelect_Condition* next; //下一个选择条件
TSelect_Condition(){next=0;}
~TSelect_Condition(){delete next;}
TSelect_Condition(char* str,COLVAL tMin,COLVAL tMax,Column_Type tcoltype,Operator_Type toptype){
strcpy(PrimaryKey,str); //拷贝条件中的主键的名字
max = tMax;
min = tMin; //赋条件值
ColType = tcoltype; //属性类型
OperType = toptype; //操作类型
next = 0;}
}Select_Condition;
class TB_Select_Info
{
public:
TSelect_Column* ColumnHead; //选择的字段链表
TSelect_Condition* ConditionHead; //选择的条件链表
int ColumnNum; //所要选择的字段个数
int ConditionNum; //条件链表的长度
char TableName[NAMEMAXLEN]; //表名
//初始化Select的各个私有成员
TB_Select_Info(char* strTBname,int i,TSelect_Column* pColHead,int j,pSel_Cond pCondHead)
{
ColumnHead = pColHead;
ConditionHead = pCondHead;
ColumnNum = i;
ConditionNum = j;
strcpy(TableName,strTBname);
}
TB_Select_Info(){
ColumnHead = NULL;
ConditionHead = NULL;
ColumnNum = 0;
ConditionNum = 0;
strcpy(TableName,"");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -