?? 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 + -