2022年minisql系統(tǒng)詳細(xì)設(shè)計(jì)說(shuō)明書(shū)_第1頁(yè)
2022年minisql系統(tǒng)詳細(xì)設(shè)計(jì)說(shuō)明書(shū)_第2頁(yè)
2022年minisql系統(tǒng)詳細(xì)設(shè)計(jì)說(shuō)明書(shū)_第3頁(yè)
2022年minisql系統(tǒng)詳細(xì)設(shè)計(jì)說(shuō)明書(shū)_第4頁(yè)
2022年minisql系統(tǒng)詳細(xì)設(shè)計(jì)說(shuō)明書(shū)_第5頁(yè)
已閱讀5頁(yè),還剩35頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、文檔編號(hào): 2 版 本 號(hào): 1.00 文檔名稱(chēng) : 具體設(shè)計(jì)報(bào)告項(xiàng)目名稱(chēng):MiniSQL 數(shù)據(jù)庫(kù)系統(tǒng)設(shè)計(jì)開(kāi)發(fā)時(shí)間 : 2022 年 10 月12 月開(kāi)發(fā)人員 : 組長(zhǎng): 周森 3991102440 運(yùn)算機(jī) 99F 組員: 郭振宇 3991102462 韓璟璐 3991102438 指導(dǎo)老師 : 孫建伶王淮 3991102449 何遙 3991102461 1. 引言 1.1 項(xiàng)目名稱(chēng) MiniSQL 數(shù)據(jù)庫(kù)系統(tǒng)設(shè)計(jì)與實(shí)現(xiàn);1.2 項(xiàng)目背景和內(nèi)容概要 數(shù)據(jù)庫(kù)系統(tǒng)設(shè)計(jì)與實(shí)現(xiàn)試驗(yàn);主要目的:通過(guò)試驗(yàn)加深對(duì) DBMS 及其內(nèi)部實(shí)現(xiàn)技術(shù)的懂得;實(shí)踐系統(tǒng)軟件開(kāi)發(fā)的工程化方法;1.3 相關(guān)資料、縮略語(yǔ)、定

2、義 MiniSQL: Mini Structural Query Language Engine API: application programming interface. 2. 系統(tǒng)結(jié)構(gòu) 2.1 系統(tǒng)結(jié)構(gòu)圖Control Interface Cmd Interpreter MiniSQL用戶(hù)部分B+ API Lib Error Lib Catalog Manager Record Manager Buffer Manager MiniSQL 內(nèi)核部分 Figure 1 Figure 1 :MiniSQL 數(shù)據(jù)庫(kù)系統(tǒng) 系統(tǒng)結(jié)構(gòu)圖 圖中各標(biāo)號(hào)簡(jiǎn)明說(shuō)明:判定并接受用戶(hù)字符輸入,使做為說(shuō)明器的輸

3、入;說(shuō)明器對(duì)用戶(hù)輸入進(jìn)行翻譯,產(chǎn)生操作數(shù)(所需 執(zhí)行選定的 API ,返回用戶(hù)所需的輸出;API 編碼以及參數(shù)數(shù)組) ;BPlus、Record、Catalog 類(lèi)方法注冊(cè)至API LIB, 并整合生成適合于用戶(hù)調(diào)用的API ;BPlus、 Record、Catalog 類(lèi)調(diào)用 Buffer 類(lèi)的方法實(shí)現(xiàn)自己各自的方法;Buffer 類(lèi)方法對(duì)數(shù)據(jù)庫(kù)文件進(jìn)行直接操作;2.2 系統(tǒng)目錄結(jié)構(gòu)MiniSQL 根目錄MiniSQL bin include Docs data 可執(zhí)行可用于系統(tǒng)運(yùn)數(shù)據(jù)存程序二次開(kāi)行相關(guān)放目錄DB1 發(fā)的頭文檔 ,用DBn 文件戶(hù)手冊(cè)DB2 數(shù)據(jù)庫(kù)名稱(chēng)做 為該數(shù)據(jù)庫(kù)數(shù)據(jù)存放的

4、根目DATA DATA 錄FILE1 FILEn Figure 2 Figure2: MiniSQL 數(shù)據(jù)庫(kù)系統(tǒng)的文件結(jié)構(gòu) 其中 bin 目錄下存放 MiniSQL 可執(zhí)行文件;include 目錄下存放 MiniSQL.h 文件和相關(guān)的 lib 文件, 可以應(yīng)客戶(hù)的需求進(jìn)行應(yīng) 用級(jí)開(kāi)發(fā);Docs 目錄下存放一些系統(tǒng)開(kāi)發(fā)文檔,系統(tǒng)安裝文檔,系統(tǒng)保護(hù)文檔以及版權(quán)信息文檔等等; 同時(shí)也供應(yīng)系統(tǒng)對(duì)比已經(jīng)商業(yè)化的DBMS ,尚未開(kāi)發(fā)的功能的相關(guān)文檔;Data 目錄下存放數(shù)據(jù)文件,其下一級(jí)目錄為各個(gè)數(shù)據(jù)庫(kù)的名稱(chēng),再下一級(jí)為各個(gè)數(shù)據(jù)庫(kù)的具體數(shù)據(jù)文件;數(shù)據(jù)文件類(lèi)型: 對(duì)應(yīng)于每一個(gè)table 建立兩個(gè)文件,

5、dbf 文件為具體數(shù)據(jù)存放文件,同時(shí)關(guān)于該table 的目錄信息亦存放于dbf 文件的頭信息處, idx 文件為為 primary key建立的索引文件;2.3 程序文件清單用模塊名程序文件名運(yùn)行平臺(tái)語(yǔ)言簡(jiǎn)要描述說(shuō)明器Interpreter.h Windows/Linux C/C+ 說(shuō)明器模塊頭文件Interpreter.cpp Windows/Linux C/C+ 說(shuō)明器模塊實(shí)現(xiàn)文件戶(hù)API 集成Ctrl_Center.h Windows/Linux C/C+ API Lib 頭文件接反常處理Ctrl_Center.cpp Windows/Linux C/C+ API Lib 實(shí)現(xiàn)文件口Er

6、ror.h Windows/Linux C/C+ Error Lib 頭文件系B+樹(shù)Error.cpp Windows/Linux C/C+ Error Lib 實(shí)現(xiàn)文件ZBtree.h Windows/Linux C/C+ B+ 樹(shù)模塊頭文件ZBtree.cpp Windows/Linux C/C+ B+ 樹(shù)模塊實(shí)現(xiàn)文件Record Record.h Windows/Linux C/C+ Record 模塊頭文件統(tǒng)Catalog Record.cpp Windows/Linux C/C+ Record 模塊實(shí)現(xiàn)文件內(nèi)Catalog.h Windows/Linux C/C+ Catalog 模

7、塊頭文件核Catalog.cpp Windows/Linux C/C+ Catalog 模塊實(shí)現(xiàn)文件系Buffer Buffer.h Windows/Linux C/C+ Buffer 模塊頭文件Buffer.cpp Windows/Linux C/C+ Buffer 模塊實(shí)現(xiàn)文件Main MiniSQL.h Windows/Linux C/C+ 系統(tǒng)主程序頭文件統(tǒng)Gvariable MiniSQL.cpp Windows/Linux C/C+ 系統(tǒng)主程序?qū)崿F(xiàn)文件集Glob_Var.h Windows/Linux C/C+ 系統(tǒng)全局變量頭文件成Glob_Var.cpp Windows/Linu

8、x C/C+ 系統(tǒng)全局變量實(shí)現(xiàn)文件2.4 基本設(shè)計(jì)概念1系統(tǒng)目標(biāo)設(shè)計(jì)并實(shí)現(xiàn)一個(gè)精簡(jiǎn)潔用戶(hù) 功能;其中:SQL engine ,并在其中實(shí)現(xiàn)表定義、索引、標(biāo)記錄操作(1)表定義中列(屬性)的類(lèi)型至少支持三種 integer、char、float; 2 每個(gè)表上要求至少建一個(gè)主鍵上的B+樹(shù),支持多屬性主鍵;(3)記錄的插入、刪除、修改等,即時(shí)更新相應(yīng)的索引;(4)記錄的搜尋至少實(shí)現(xiàn)按主鍵查找,只是主鍵上的范疇查找,包含遍歷;2結(jié)構(gòu)清楚(1)用戶(hù)模塊和內(nèi)核模塊完全分開(kāi);(2)內(nèi)核部分 B+ 、Record、Catalog 三個(gè)模塊之間堅(jiān)決不能相互調(diào)用方法和函數(shù);Buffer 模塊(3)內(nèi)核部分 B+

9、 、Record、Catalog 三個(gè)模塊不能拜訪(fǎng)物理文件,而由實(shí)現(xiàn)物理文件操作的全部細(xì)節(jié);4)API Lib 依據(jù) B+ 、Record、Catalog 三個(gè)模塊的方法整合生成 適合用戶(hù)模塊調(diào) 用的 API ;5 內(nèi)核各個(gè)模塊只向上負(fù)責(zé),簡(jiǎn)化了各個(gè)模塊之間的調(diào)用關(guān)系;2.5 程序模塊說(shuō)明 2.5.1 Gvariable 模塊(系統(tǒng)集成子系統(tǒng))1目標(biāo):定義系統(tǒng)各種全局變量 2程序文件: Glob_Var.h, Glob_Var.cpp 3主要數(shù)據(jù)結(jié)構(gòu):由 buffer 模塊供應(yīng) class public: unsigned long ; / 頁(yè)編號(hào) unsigned int Offset; /

10、 頁(yè)內(nèi)偏移 void Initialize; /初始化為 0,0 void* MemAddr; / 轉(zhuǎn)化為當(dāng)前內(nèi)存地址,由 buffer 負(fù)責(zé)轉(zhuǎn)換 void ShiftOffsetint offset; / 相對(duì)當(dāng)前地址滑動(dòng) offset ; 其他全局的主要數(shù)據(jù)結(jié)構(gòu)見(jiàn) API 集成模塊;4調(diào)用的其他模塊:Buffer 模塊 5算法:無(wú) 6規(guī)律流程圖:無(wú) 7測(cè)試要點(diǎn):變量聲明和定義,測(cè)試略;2.5.2 Main 模塊(系統(tǒng)集成子系統(tǒng))1目標(biāo):和諧各其他各模塊之間的關(guān)系 ,最終負(fù)責(zé)系統(tǒng)運(yùn)行 2程序文件: MiniSQL.h, MiniSQL.cpp 3主要數(shù)據(jù)結(jié)構(gòu):MSG 定義的是 Get_Com

11、mand 返回的消息,用于消息循環(huán) enum MSG CREATE, SELECT, INSERT, UPDATE, DELETE, DROP, QUIT msg; 4調(diào)用的其他模塊:API 集成模塊 , Gvariable 模塊 windows 消息機(jī)制;5算法:參考 6規(guī)律流程圖:1主程序流程:int main Init_MiniSQL; /初始化一些基本配置Run_MiniSQL; /交互操作,是本程序的主體Exit_MiniSQL; /先善后操作,再退出 2Run_MiniSQL 程序流程 函數(shù)采納的是類(lèi)似 MFC 的消息循環(huán)機(jī)制,從 Get_Command 得到 MSG 消息,在調(diào)用

12、相應(yīng)的處理函數(shù) 來(lái)自 API lib ;void Run_MiniSQL; msg = SELECT; / 使得 MSG 不等于 QUIT, 進(jìn)入循環(huán)while MSG .= QUIT /消息循環(huán)try msg = Get_Command; /依據(jù)消息調(diào)用各處理 switchmsg case CREATE : Create.; break; 創(chuàng)建記錄case SELECT : Select.; break; 挑選記錄case INSERT : Insert.; break; 插入記錄case UPDA TE : Update.; break; 更新記錄case DELETE : Delete.

13、; break; 刪除記錄case DROP : Drop .; break; 刪除表case QUIT : return; catch int ERROR_CODE /依據(jù) ERROR_CODE ,打印錯(cuò)誤信息 7測(cè)試要點(diǎn):變量聲明和定義,測(cè)試略;2.5.3 反常處理模塊(用戶(hù)接口子系統(tǒng))1目標(biāo):反常處理模塊,定義系統(tǒng)全部可能的反常情形 2程序文件: error.h,error.cpp 3主要數(shù)據(jù)結(jié)構(gòu):#define ErrorName ErrorCode; /反常宏定義 char* ErrorMessage; /相關(guān)反常信息 4調(diào)用的其他模塊:無(wú) 5算法:無(wú) 6規(guī)律流程圖:無(wú),并安排反常代

14、號(hào);7測(cè)試要點(diǎn):模擬 ErrorCode ,調(diào)用 DispatchErrorint errorcode 函數(shù)處理反常;2.5.4 API 集成模塊 用戶(hù)接口子系統(tǒng) 1目標(biāo):依據(jù) B+ 、Record、Catalog、Interpreter 四個(gè)模塊所供應(yīng)的方法整合生成適合于用戶(hù)調(diào)用的 API ;此模塊同時(shí)要求最終實(shí)現(xiàn) include 目錄下用于應(yīng)用級(jí)開(kāi)發(fā)所需的頭文件;2程序文件: Ctrl_Center.h、 Ctrl_Center.cpp 3主要數(shù)據(jù)結(jié)構(gòu):見(jiàn)規(guī)律流程圖4調(diào)用的其他模塊:Gvariable 模塊、 B+模塊、 Record 模塊、 Catalog 模塊、 Interpreter

15、模塊、 Gvariable 模塊;5算法:在流程圖里6規(guī)律流程圖:其中各主要操作流程(為直觀計(jì),相關(guān)的全局主要數(shù)據(jù)結(jié)構(gòu)即列在一邊)Create:翻譯命令成參數(shù)函數(shù):InterpreterCatalog.CreateTB_Create_Info&,char* TB_Create_Info 參數(shù)來(lái)自 InterpreterZBTree.Createchar*參數(shù)表示 B+Tree的key有屬性組成信息Catalog.creat eZBTree.create有效性檢查 及 新表的創(chuàng)建Btree 的初始化/interpreter對(duì)命令說(shuō)明得到的 /使用者 :catalogcreate的各種信息type

16、def struct Create_Column *pCreate_Column;typedef struct Create_Column char ColumnName32; / 字段名(規(guī)定最長(zhǎng)為 32位) Column_Type ColType; / 字段類(lèi)型,如 int,float, char int length; /字段類(lèi)型長(zhǎng)度,如 char8 Column_Value min; / 下限,如例中的 00000000 Column_Value max; / 上限,如例中的 12345678 Operator_Type OperType; / 關(guān)系運(yùn)算符類(lèi)型,如 =, = 等等 bo

17、ol IsNull; /isnull 1,就此字段有 is null 的限制 bool IsPrimary; /isprimary=1, 就此字段是 primary key pCreate_Column next;class TB_Create_Info TB_Create_Info; TB_Create_Info; int TotalColumn; /字段總數(shù) pCreate_Column head; /字段鏈表頭 char TableName32; /表名(規(guī)定最長(zhǎng)為 32位);/catalog分析建表的信息后按 index的要求給出的組成主鍵的信息/使用者: indexchar* Key

18、Info / 例如 “ c12fiic34f”Figure 3 Select:函數(shù)體Interpreter 翻譯命令成參數(shù) Catalog.SelectTB_Select_Info,Condition_Info,Select_Rec_InfoZBTree.SelectCondition_Info,Key_Location,Key_LocationRecord.Print GetCurRecKey_Location,Select_Rec_Info ;whileCatalog.sele 正確性檢查 Move Nextct 及約束檢查 Record.PrintGetCurRecKey_Locatio

19、n,Select_Rec_Info;對(duì)命令說(shuō)明后得到的 select的各種信息/使用者: catalogZBTree.selec 查找滿(mǎn)意 typedef Select_Column *pSelect_Column;t 條件的記錄 typedef Select_Condition *pSelect_Condition;typedef struct Select_Column /挑選的字段char ColumnName32;/字段名(限定最長(zhǎng) 32位)pSelect_Column next; /下一個(gè)字段Record.Selec ;t typedef struct Select_Conditio

20、n /挑選條件( where )char PrimaryKey32; /主鍵名Column_Value max; /上限Column_Value min; /下限Column_Type ColType;Operator_Type OperType; /關(guān)系運(yùn)算符pSelect_Condition next; /下一個(gè)挑選條件;Record.Print class TB_Select_InfopSelect_Column ColumnHead; /挑選的字段鏈表pSelect_Condition ConditionHead; /挑選的條件鏈表N int ColumnNum; /所要挑選的字段個(gè)數(shù)

21、int ConditionNum; /條件鏈表的長(zhǎng)度char TableName32; /表名N=0 ;/得出的查找的范疇信息/使用者: BTreetypedef struct Condition_Info;Y Operator_Type Oper_Type; /查找的范疇信息/關(guān)系運(yùn)算符pKey_Attr min; /依據(jù)次序鏈接的屬性的范疇下限pKey_Attr max; /依據(jù)次序鏈接的屬性的范疇上限;/Index 查找之后得到的結(jié)果/B+Tree中滿(mǎn)意條件的一串索引頭指針和尾指針)/使用者: Control Center typedef struct Node_Key /Catalog

22、得出的關(guān)于挑選需要的字段信息 ZBTreeNode *pNode; /滿(mǎn)意條件的節(jié)點(diǎn)頭指針/使用者: Recordtypedef struct Selete_Cell *pSelete_Cell; ;int offset; /節(jié)點(diǎn)內(nèi)偏移typedef structchar ColumnName32; /字段名便利打印 class Select_Rec_Info Column_Typeintint PriorLength;ColLength; ColType; /字段類(lèi)型便利打印 /記錄頭到此字段之間的長(zhǎng)度 /字段類(lèi)型的長(zhǎng)度 pSelect_Cellint head;ColumnNum;Sele

23、ct_Cell; pSelect_Cell next; /下一個(gè)字段信息 Select_Rec_Info;Select_Rec_Info;Figure 4 Insert:翻譯命令成參數(shù)函數(shù)體InterpreterCatalog.InsertTB_Insert_Info,Condition_Info,Rec_InfoZBTree.SelectCondition_Info,Key_Location,Key_LocationRecord.InsertRec_Info,FilePtr; ZBTree.InsertpKey_Attr,FilePtr*Catalog.正確性檢查typedef struct

24、 Cell_Info *pCell_Info; typedef struct Cell_Info /記錄單個(gè)屬性上的信息 Column_Type ColType; /屬性類(lèi)型 Column_Value value; int PriorLength; / 記錄頭到當(dāng)前字段之間的長(zhǎng)度 int ColLength; / 當(dāng)前字段的長(zhǎng)度 pCell_Info next; ; class Rec_Info pCell_Info head; int ColNum; Rec_Info; Rec_Info; ;insert_check及約束檢查Index.檢查記錄是否已Insert_check存在(依據(jù)主鍵)

25、Record.inser記錄插入tIndex.insert索引插入typedef union Column_Value int IntValue; char* pCharValue; float FloatValue; ; typedef Insert_Column *pInsert_Column; typedef struct Insert_Column char ColumnName32; Column_Type Col_Type; Column_Value value; pInsert_Column next; ; class TB_Insert_Info TB_Insert_Info;

26、 char TableName32; pInsert_Column head; int ColumnNum; TB_Insert_Info; ; /Catalog 給出的指向待插入記錄主鍵的指針 /使用者: Index pKey_Attr pPrimaryKey;/整形值 /字符串指針 /浮點(diǎn)型值/插入的記錄的其中一個(gè)字段信息 /字段名 /此字段的類(lèi)型/下一個(gè)字段信息/插入的記錄/所要插入的表名 /全部字段信息鏈表 /鏈表長(zhǎng)度Figure 5 Update: 函數(shù)體Catalog.UpdateTB_Update_Info,Condition_Info,Rec_InfoInterpreter翻譯

27、命令成參數(shù)ZBTree.SelectCondition_Info,Key_Location,Key_LocationRecord.UpdateGetCurRecKey_Location,Rec_Info;while Move next Record.UpdateGetCurRecKey_Location,Rec_Info;Catalog.upda 正確性檢查te 及約束檢查 /Catalog 得出的查找的范疇信息 / 使用者: Indextypedef struct Condition_Info; / 查找的范疇信息Operator_Type OperType; / 關(guān)系運(yùn)算符pKey_Att

28、r min; / 依據(jù)次序鏈接的屬性的范疇下限Index.select 查找滿(mǎn)意條件記錄 ;pKey_Attr max; / 依據(jù)次序鏈接的屬性的范疇上限/catalog 給出的修改的字段的信息/使用者: Recordtypedef struct Cell_Info *pCell_Info;typedef struct Cell_Info /記錄單個(gè)屬性上的信息Column_Type ColType; /屬性類(lèi)型N=0 Column_Value value;int PriorLength; /記錄頭到當(dāng)前字段之間的長(zhǎng)度int ColLength; /當(dāng)前字段的長(zhǎng)度適用于多個(gè) pCell_Inf

29、o next;記錄的刪除 ;class Rec_InfoRecord.updat 修改紀(jì)錄 pCell_Info head;e(一次一條)intRec_Info; ColNum;Rec_Info; typedef Update_Column *pUpdate_Column;typedef Update_Condition *pUpdate_Condition;struct Update_Column / 修改的記錄的其中一個(gè)字段信息char ColumnName32; /字段名Column_Type ColType; /此字段的類(lèi)型Column_Value value;Update_Colum

30、n next; /下一個(gè)字段信息 ;struct Update_Condition /修改的范疇的條件(where )char Primary_Key32; /主鍵名Column_Value max; /上限Column_Value min; /下限Operator_Type OperType; / 關(guān)系運(yùn)算符Update_Condition next; /下一個(gè)條件;class TB_Update_Info /修改信息TB_Update_Info;pUpdate_Column ColumnHead; /所要修改的字段及其值的鏈表pUpdate_Condition ConditionHead;

31、 /修改的范疇的查詢(xún)條件鏈表int ColumnNum; /字段數(shù)int ConditionNum; /條件數(shù)char TableName32; /要執(zhí)行修改的表名 TB_Update_Info; ;Figure 6 適用于多個(gè)Delete:翻譯命令成參數(shù)函數(shù)體InterpreterCatalog.DeleteTB_Delete_Info,Condition_InfoZBTree.SelectCondition_Info,Key_Location,Key_LocationRecord.Delete GetCurRecKey_Location ;Catalog.Dele te正確性檢查ZBTre

32、e.Delete pKey_Attr,FilePtr*;while move Next Record.Delete GetCurRecKey_Location ;及約束檢查 ZBTree.Delete pKey_Attr,FilePtr*;ZBTree.Select查找滿(mǎn)意條件記錄typedef Delete_Condition *pDelete_Condition;struct Delete_Condition /刪除范疇的條件 char PrimaryKey32; /主鍵名 Column_Value max; /上限 Column_Value min; /下限 Operator_Type

33、OperType; /關(guān)系運(yùn)算符 pDelete_Condition next; /下一個(gè)條件;class TB_Delete_Info /刪除信息 char TableName32; /要進(jìn)行刪除的表名 pDelete_Condition head; /條件鏈表 int ConditionNum; /條件鏈表長(zhǎng)度TB_Delete_Info; TB_Delete_Info;N=0刪除紀(jì)錄Record.Delete(一次一條)記錄的刪除刪除相應(yīng)索引ZBTree.Delet e/Catalog得出的查找的范疇信息 /使用者: Index typedef struct Condition_Info

34、; Operator_Type OperType; pKey_Attr min; pKey_Attr max; ;/查找的范疇信息 /關(guān)系運(yùn)算符 /依據(jù)次序鏈接的屬性的范疇下限 /依據(jù)次序鏈接的屬性的范疇上限/Index查找之后得到的結(jié)果 /B+Tree中滿(mǎn)意條件的一串索引頭指針和尾指針)/使用者: Control Center typedef struct Node_Key ZBTreeNode *pNode; /滿(mǎn)意條件的節(jié)點(diǎn)頭指針 int offset; /節(jié)點(diǎn)內(nèi)偏移 ;7測(cè)試要點(diǎn):2.5.5 說(shuō)明器模塊(用戶(hù)接口子系統(tǒng))1目標(biāo): 命令說(shuō)明器的基本功能就是將用戶(hù)的輸入命令進(jìn)行語(yǔ)法分析和語(yǔ)

35、義解析并得到需要的命令參數(shù),最終將該命令參數(shù)封裝成對(duì)應(yīng)命令的參數(shù)類(lèi)對(duì)象,傳回到APILIB 模塊2程序文件: interpreter.h、interpreter.cpp 3主要數(shù)據(jù)結(jié)構(gòu):1 有意字串 : 所謂有意字串即指一個(gè)以回車(chē)或空格或標(biāo)志符來(lái)分割的有獨(dú)立含義的字符串不包括空格 ,回車(chē) ,但標(biāo)志符入 ” , “ ,” ; “視作有意字串 ,如一條命令create table tablename variblename1 type1, variblename2 type2 ; 就 create ,” table”,”tablename” , ”“,” variblename1” ,”type1

36、” 等都是一個(gè)有意字串2VSTR_BLK_PTR定義一個(gè)數(shù)據(jù)結(jié)構(gòu)typedef struct *VSTR_BLK_PTR; typedef struct VSTR_BLK string strValstr; / 有意字串VSTR_BLK_PTR p_vbpNext;/ 指向下一個(gè)有意字串的 VSTR_BLK 指針; 該數(shù)據(jù)結(jié)構(gòu)用于記錄輸入的有意字串 ,一個(gè)該變量表示一個(gè)有意字串 . 3.支持多類(lèi)型enum Column_Type i, c, f; /iint cchar ffloat 4 支持 = = = .= between and 等關(guān)系運(yùn)算符; enum Operator_Type B,

37、 BE, L, LE, E, NE,BETWEEN;4調(diào)用的其他模塊:反常處理模塊本模塊較為關(guān)鍵的幾個(gè)處理:string InString 負(fù)責(zé)從用戶(hù)的輸入中讀取一個(gè)有意字串,以構(gòu)成VstringBlk的鏈表 .5 算法 :Step1. Void GetCommand MakeVstrBlk; /利用一個(gè)讀取函數(shù)將用戶(hù)的全部輸入整合成一個(gè)VstringBlk 鏈表 .依據(jù) VSTR_BLK 鏈表中的第一個(gè)有意字串來(lái)調(diào)用相應(yīng)的函數(shù) ,封裝回傳的參數(shù)類(lèi) ; return; 用戶(hù)輸入命令之后 ,給出提示要求用戶(hù)鍵入命令 ,利用一個(gè)讀取函數(shù)將用戶(hù)的全部輸入 以該行最終一個(gè)字符是否” ; ”為標(biāo)記 中的

38、有意字串讀入 ,拂過(guò)全部的空格和回車(chē) .所以在處理過(guò)程中只需一個(gè)全局變量 VSTR_BLK_PTR p_vbpCmdPos 表示對(duì)當(dāng)前的命令的處理處于何位置 ,這樣很簡(jiǎn)潔得知掌握的流程 . 此時(shí)處于start state,對(duì)所輸入的信息進(jìn)行處理,依據(jù)命令的第一個(gè)有意字串進(jìn)行分處理 ,如用戶(hù)鍵入的第一個(gè)命令是 終將會(huì)進(jìn)入 create function. 規(guī)律流程圖所以該部分需要的函數(shù)列表如下typedef char *string; 基本函數(shù) : ” create table tablename CR” CR 代表回車(chē) ,就最Figure 8 1string InString 負(fù)責(zé)從用戶(hù)的輸入

39、中讀取一個(gè)有意字串, 2MakeVstrBlkList負(fù)責(zé)將有意字串鏈成鏈表. boolean StrComparestring s1,string s2,boolean case 依據(jù) case 值( 0忽視大小寫(xiě), 1大小寫(xiě)敏銳)來(lái)比較 string s1 和 string s2,返回比較結(jié)果return value:0-string 1 string s2 3 TB_Create_Info& CreateProcess 進(jìn)入 create function, 最終返回一個(gè)有關(guān)表的類(lèi) 4 TB_Insert_Info& InsertProcess 進(jìn)入 insert function, 最

40、終返回一個(gè)有關(guān)表的類(lèi) 5 TB_Select_Info& SelectProcess 進(jìn)入 select function, 最終返回一個(gè)有關(guān)表的類(lèi) 6 TB_Delete_Info& DeleteProcess 進(jìn)入 delete function, 最終返回一個(gè)有關(guān)表的類(lèi) 7 TB_Update_Info& UpdateProcess 進(jìn)入 update function, 最終返回一個(gè)有關(guān)表的類(lèi)TB_Create_Info 詳見(jiàn)數(shù)據(jù)結(jié)構(gòu) TB_Create_Info 詳見(jiàn)數(shù)據(jù)結(jié)構(gòu) TB_Select_Info 詳見(jiàn)數(shù)據(jù)結(jié)構(gòu) TB_Delete_Info 詳見(jiàn)數(shù)據(jù)結(jié)構(gòu) TB_Update_

41、Info 詳見(jiàn)數(shù)據(jù)結(jié)構(gòu) Step2 在進(jìn)入具體的供應(yīng)的 5 個(gè)具體功能的處理后 ,模塊作的就是對(duì)用戶(hù)的整個(gè)命令進(jìn) 行解析 ,最終給出一個(gè)封裝了全部該種處理所需參數(shù)的類(lèi) . 如create function, TB_Create_Info& CreateProcess 檢驗(yàn)每次輸入是否符合要求直到 state1.3; whilenot “ ; ” make a Create_Column; /得到一個(gè)有關(guān)列全部信息的類(lèi)對(duì)象將所得到的Create_Column 對(duì)象和前面得到的的鏈起來(lái); 將全部的列對(duì)象封裝成一個(gè)表對(duì)象信息 TB_Create_Info. Return; 如下圖 ,途中各條線(xiàn)代表I

42、nString 得到的輸入 ,下面對(duì)幾個(gè)要點(diǎn)說(shuō)明一下:Figure 9 a. 任何狀態(tài)下得到的輸入和標(biāo)示的不符,就記錄該出錯(cuò)的行數(shù),給用戶(hù)一個(gè)提示, ,并throw errorcode, 然后返回 API 掌握中心 ; b. 處理過(guò)程中 , ” , “ 代表的含義是換行,所以有關(guān)行數(shù)的變量會(huì)加1,這個(gè)行數(shù)信息用于給出出錯(cuò)地點(diǎn)信息; Stept2.1 規(guī)律流程Stept2.1.0 state1.1-state1.3 均是一些常用狀態(tài) ,用于過(guò)渡 ; Stept2.1.1 state1.3得到一個(gè) variablename 時(shí)得到一個(gè)列名信息,此時(shí)需要對(duì)列名進(jìn)行合法性檢驗(yàn), boolean Che

43、ckColNamestring strColName Stept2.1.2 state1.4得到一個(gè) type 時(shí)得到一個(gè)類(lèi)型信息 ,需要對(duì)該類(lèi)型信息進(jìn)行檢驗(yàn) ,此類(lèi)型信息可能含有長(zhǎng)度信息 ,如 char8,所以仍要對(duì)類(lèi)型信息進(jìn)行處理 ,利用一個(gè)函數(shù)boolean GetTypeInfocolumn_type ctColType, int iColLength Stept2.1.3 由于一個(gè)列信息可能有可能仍含有約束條件 如在列類(lèi)型信息后不是緊跟”,”就之間必只是約束條件 ,但為了處理便利 ,將實(shí)際上并沒(méi)有約束條件的情形視作有約束條件但該條件為空 ,所以在 state1.5 仍必需要對(duì)列類(lèi)型后

44、的有意字串進(jìn)行解析 ,需要考慮的約束條件只有typedef struct CONSTRAINTCOND int min; /下限,如例中的 00000000 int max; /上限,如例中的 12345678 Operator_Type Oper_Type; /關(guān)系運(yùn)算符類(lèi)型,如 =, = 等等bool notnull; /isnull 1,就此字段有 is null 的限制bool isprimary; 所以仍需要一個(gè)約束條件檢驗(yàn)函數(shù) , CONSTRAINTCOND& GetStraintInfo Stept2.1.4 state1.6 要對(duì)每一行進(jìn)行處理 ,這些每一行都代表一條列信息

45、,所以在 state1.6 中需要對(duì)該行讀到的列名 ,列類(lèi)型 ,約束信息進(jìn)行封裝處理成一個(gè) Create_Column 類(lèi)將它連接到上一個(gè) Create_Column 類(lèi)對(duì)象上state1.6可能直接遇到 ; 意即連續(xù)的兩個(gè)有意字串是” “和 “ ; “,就可直接跳入該過(guò)程的最終狀態(tài) state1.7,在該狀態(tài)中將全部的已連好的 Create_Column 類(lèi)對(duì)象封裝成一個(gè) TB_Create_Info 對(duì)象 ,傳出去至此 ,該 CreateProcess過(guò)程終止 . 而對(duì)于其他幾個(gè) function 如 TB_Insert_Info& InsertProcess TB_Insert_Info

46、& SelectProcess TB_Delete_Info& DeleteProcess TB_Update_Info& UpdateProcess 其基本過(guò)程一樣,下面給出狀態(tài)圖,其流程不再詳述. Figure 10 Figure 11 Figure 12 Figure 13 6測(cè)試要點(diǎn):1留意程序的健壯性,對(duì)用戶(hù)的各種輸入錯(cuò)誤都要有很好的檢測(cè),并檢驗(yàn) errorcode 有無(wú)失誤 ; 2 本程序?qū)崭窈突剀?chē)挑選了視而不見(jiàn)的處理方式將其略去不管 ,所以測(cè)試要證明這種做法不會(huì)對(duì)程序的正確性和健壯性產(chǎn)生影響 ; 2.5.6 B+ 樹(shù)模塊(系統(tǒng)內(nèi)核子系統(tǒng))1目標(biāo):供應(yīng)數(shù)據(jù)庫(kù)快速檢索功能,并實(shí)現(xiàn)

47、B樹(shù)自身調(diào)整;2程序文件: ZBTree.h 、ZBTree.cpp 3主要數(shù)據(jù)結(jié)構(gòu):索引文件頭信息 Typedef struct FirstEmptyBlock; LastEmptyBlock; FirstNewBlock; / the address of the first empty block / the address of the last empty block / the address of the first new block root; KeyAttrNum; / the address of the root start; / the address of the

48、most left node int / the number of fieldsattributes in primary key int KeySize; / sizeofKey_Attr * KeyAttrNum int MaxItemNum; / the max number of keys in a nodeIndex_Head; ZBTree_Index 是一個(gè)治理索引文件的類(lèi) ,定義如下 : class ZBTree_Index public: ZBTree_Index; ZBTree_Index; void Create_Headchar* KeyStr; / produce

49、the information in the IdxHead void WriteHeadToFile; / write the information to the head of the file void ReadHeadFromFile; / read the information form the head of the file void SetKeyInfochar* Key_Info; / calculate the Keysize and KeyAttrNum GetRoot; / get of the root GetStartNode; / get of the lef

50、tmost node int GetKeySize; / get the size of a key int GetKeyAttrNum; / get the key attribute number in a key int GetMaxItemNum; / get the max number of items in a key char* GetKeyInfo; / get the key information private: Index_Head IdxHead; / the head of the index B+ tree char* KeyInfo; / a string r

51、ecord the information of the key ; Block 里的數(shù)據(jù),放在block 中的尾部 ,Block 為空時(shí),此數(shù)據(jù)有效,如圖NextBlock; / point the previous empty block B+Tree 的節(jié)點(diǎn)信息(主鍵內(nèi)容,指針) 主鍵是由 Key_Attr 結(jié)構(gòu)的鏈表組成 ,如右圖:Next_Block typedef struct Key_Attr *pKey_Attr; typedef struct Key_Attr Key_Arrt Key_Arrt Figure 14 Limit_Value value; pKey_Attr n

52、ext; ; Index 文件的結(jié)構(gòu)類(lèi)似于 的頭和尾;節(jié)點(diǎn)結(jié)構(gòu):record,閑暇塊用指針連起來(lái),用兩個(gè)指針治理閑暇塊鏈表IsLeaf |ItemOnNode | p0,k0,p1,k1,pMaxItemNum-1,kMaxItemNum-1,pMaxItemNum 節(jié)點(diǎn)類(lèi)型(葉 /非葉)兒子個(gè)數(shù)P1 K1 P2 K2 Pn-1 Kn-1 Pn Figure 15 節(jié)點(diǎn)類(lèi):class ZBTreeNode public: ZBTreeNode p = new MaxItemNum+1; k = new pKey_AttrMaxItemNum; ZBTreeNode; GatherInBlock

53、; 將節(jié)點(diǎn)的分散空間合在一個(gè)連續(xù)的 block SepaFormBlock; 將一個(gè)連續(xù)的 block 分散到 ZBTreeNode 中private: bool IsLeaf; 是否是葉節(jié)點(diǎn)key 的數(shù)int ItemOnNode; 有效的 key 數(shù)*p; *k; 指向子節(jié)點(diǎn)的指針pKey_Attr key 的指針數(shù)組int MaxItem; 節(jié)點(diǎn)能容納的最大; key 的位置 typedef struct Key_Location* pKey_Location; typedef struct Key_Location int pNode ; 節(jié)點(diǎn)指針?biāo)诠?jié)點(diǎn)的第幾個(gè)key offset;

54、 ; B+Tree 的類(lèi) :治理 b+樹(shù)的的操作 : class ZBTree public: ZBTree; ZBTree; Createint; 初始化ZBTreeNode* GetRoot; 得到根結(jié)點(diǎn)ZBTreeNode* GetStartNode; 得到第一個(gè)葉節(jié)點(diǎn)GetCurRecKey_Location; 得到當(dāng)前的 Record 指針Bool MoveToNextKey_Location; bool Compare_KeypKey_Attr,pKey_Attr; 使 Key_Location 移到 next 比較兩個(gè) key 的大小ZBTreeNode* GetSonnode;

55、 得到內(nèi)存中的字節(jié)點(diǎn)ZBTreeNode* GetParentnodeZBTreeNode*; 得到父節(jié)點(diǎn) pNode_Key * Search_KeypKey_Attr; 定位到某個(gè) key void SelectCondition_Info&, ; void DeletepKey_Attr,int; 在 BTree 中刪除 key 和指針 void InsertpKey_Attr,int; 在 BTree 中插入 key 和指針 void Delete_EntryZBTreeNode*,pKey_Attr,int; 在某個(gè)節(jié)點(diǎn)中刪除 key 和指針 void Insert_EntryZBT

56、reeNode*,pKey_Attr,int; 在某個(gè)節(jié)點(diǎn)中插入 key 和指針private: ZBTreeNode *root; 根節(jié)點(diǎn)ZBTreeNode *start; 第一個(gè)葉節(jié)點(diǎn) ; 4 算法 當(dāng)創(chuàng)建 talbe 的時(shí)候 ,調(diào)用 b+數(shù)的 ZBTree: Create-ZBTree_Index : Create_Headchar* ZBTree_Index : WriteHeadToFile, 運(yùn)算 b+數(shù)的一些必要信息,并寫(xiě)到文件中去. Search 算法描述 : pNode_Key * SearchpKey_Attr SearchKey; 定位到某個(gè)key for; get t

57、he current node; /compare Key with the key in the current node; for; get the current key; compare the key with SearchKey; if = return the address of the key; else value; Memwrite void*insert_place,sizeof ,ptr2write; Ptr2write += sizeof; whiletemp MemWrite i , temp-column_length ,prtr2write; SwitchCo

58、lType case i : Ptr2write += temp-ColLength; break; case f : Ptr2write += temp-ColLength; break; case c :Ptr2write=Ptr2write+temp-ColLength+1; temp = temp-next; return InsertPlace; 傳出的是插入記錄的地址)PlaceFind if del_first=del_last=0 這里需要考慮一下塊的閑暇地方的大小是否小于所要插入的記錄的大小 SwitchColType case i : InsertPlace=InsertL

59、ast+TotalLength+sizeof; break; case f : InsertPlace=InsertLast+TotalLength+sizeof; break; case c : InsertPlace=InsertLast+TotalLength+1+sizeof; InsertPlace=InsertLast+TotalLength+sizeof; Else InsertPlace=DelFirst; DelFirst=DelFirst-; return InsertPlace; record:Delete * temp= * DelTarget.Memaddr; ifD

60、elFirst=DelLast=0 DelFirst=temp; DelLast_=temp; temp-PageID=0; temp-Offset=0; else * p1 = * DelLast.Memaddr; * p2 = * DelTarget.Menaddr; *p1 = DelTarget; DelLast = DelTarget; p2-PageID = 0; p2-Offset = 0; if (勝利)return success flag; record:Select returnMemaddr; record:Updata , Rec_Info&new temp = ne

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論