资源描述:
《minsql-interpreter 模块与api模块文档说明》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、Interpreter模块与API模块文档说明本次设计中将interpreter和API两个模块合并在一起,实现的文件包括objects.h和inter1.cpp两个文件。InterTest.txt为此模块的单独测试文件。一.此模块的执行流程:“启动并初始化à‘接收命令、处理命令、显示命令结果’循环à退出”流程。其中,接受命令包括从console直接输入与execfile选项的文件输入。而命令的处理为分别调用recordmanager、Catalogmanager和indexmanager的相应接口进行
2、处理。1)对命令的接收与整理:翻译器从终端读入一个SQL语句,并对其进行语法分析,建立成储存相应类型语句的数据结构(不同类的对象),具体类的结构可见objects.h内的申明。在此举两例阐述:1.Createtable语句:typedefvectorvstring;classCreate//createatable的语句{stringcommand;//记录语句类型,在此为createTablepublic:stringtableName;stringprimary;intnumOfAt
3、tr;vectorunique;vstringtuples;vstringproperties;voidprintOut(void);Create(stringtable):command("createTable"),tableName(table),numOfAttr(0){}};如上为相应与每个createtable语句的类对象结构。变量tableName为要创建的表的名称,变量primary储存了这个表的primarykey。Int型的numOfAttr为这个表包含的属性(tuple)
4、的个数。注意到vstring为被typedef成一个string的动态数组,两个vstring类型的tuples变量和properties变量分别为储存每个属性(tuple)的名称和每个属性(tuple)的数据类型(int,char(*),float)。Unique为一个int型的数组,记录着每个属性(tuple)是否unique,”1”表示是,”0”表示否。printOut函数为测试所用的一个输出函数。具体的比如对如下这句SQL语句:createtablerecords(aintunique,bcha
5、r(10),cfloatunique,primarykey(a));翻译器会创建出一个Create类的对象,其tableName=”records”,primary=”a”,numOfAttr=3,而三个数组都有三个元素,其值分别为:unique:unique[0]=1,unique[1]=0,unique[2]=1;tuples:tuples[0]=”a”,tuples[1]=”b”tuples[2]=”c”;properties:properties[0]=”int”,properties[1]=”
6、char(10)”,properties[2]=”float”;2.select语句:由于含where语句,其结构如下:classSelect_object//select语句{stringcommand;//记录语句类型,在此为Selectpublic:stringselect;stringtableName;//fromtableboolwhere_flag;Where_objectw1;voidprintOut();Select_object(stringselect1,stringtable,b
7、oolflag):select(select1),command("select"),tableName(table),where_flag(flag){}intread_where(istream&cin);};以及where的结构:classWhere_object//{public:Where_object():numOfConditions(0){}vstringlvalue;vstringop;vstringrvalue;intnumOfConditions;voidprintOut(void
8、);};可以看见,在select语句所对应的对象中包含了一个where语句的对象w1,并有一个标志位where_flag来记录是否存在无何若语句。Select对象中select存放了要select的属性(tuple)名,tableName存放了要select的表的名字。intread_where(istream&cin);函数用语在翻译阶段翻译where条件并建立where的对象w1。Where语句的类where_object包括了三个vs