• 沒有找到結果。

程式碼剖析引擎模組說明

4 系統模組說明

4.1 程式碼剖析引擎模組說明

此模組將存在於程式原始碼中,有關存取資料,即新增(INSERT)、修改 (UPDATE)及刪除(DELETE)等相關的資訊擷取出來,並將相關的資料表及欄位,

以及程式碼名稱及位於此程式碼的行數等相關資料,存入資料庫。

4.1.1 剖析原始碼中新增資料的資訊(INSERT)

剖析原始碼中新增資料的資訊(INSERT)的流程如下圖 4.1:

圖 4.1 剖析原始碼中新增資料的資訊之流程圖

以下以實際例子的說明,以下為存在於資料庫應用程式中關於新增資料操作 的一行SQL敘述:

sql="insert into patent (p_number,p_title,p_inventor,p_claim,p_asbstact) values ('" &

p_number.text & "','" & p_title.text & "','" & p_inventor.text & "','" & p_claim.text &

"','" & p_abstract.text & "')"

程式會逐行讀取原始碼檔案直到讀取到檔尾結束(EOF),首先會判斷此行是

if the line is not comment Y

if the line containing keyword

“INSERT ”

N if the line containing keyword

“ VALUES”

split with the delimiter “ ” after the

Y

Y

keyword “INSERT ” get the value of the first array N

Y

get the value of the first array N

if the tablename had not been existed

insert the tablename into the database in the source code

split with the delimiter “ ” after

Y N

if the value of the first array is “INTO”

the keyword “ INTO”

get the value of the first array

否為

4.1.2 剖析原始碼中修改資料的資訊(UPDATE)

剖析原始碼中修改資料的資訊(UPDATE)的流程如下圖 4.2:

註解行(即第一個字元為”’”);若非註解行,判斷是否有”INSERT”關鍵字;

若是,繼續判斷是否有”VALUES” 關鍵字;若是,從”INSERT”關鍵字之後以空 白字元” “分隔,取出各 token 的值,存入陣列(Array)中,判斷陣列的第一個 token 的值是否為”INTO” 關鍵字;若是,從” INTO”關鍵字之後以空白字元” “分隔,

取出各 token 的值,存入陣列(Array)中,第一個 token 的值(patent)即為欲得到的 資料表名稱;若不是,即為欲得到的資料表名稱(patent)。因程式允許使用者可 重複執行,程式最後會判斷資料庫中是否已存在此資訊(patent),若尚未存在,

則將此新增的資料表存入資料庫中。

圖 4.2 剖析原始碼中修改資料的資訊之流程圖

Source Code N

Readline

EOF ? N

Y

if the line is not comment Y

if the line containing keyword

End

“UPDATE ”

N if the line containing keyword “SET ”

split with the delimiter “ ” after the

Y

Y N

N

Y

keyword “UPDATE ” get the value of the first array if the tablename had not been existed

insert the tablename into the database in the source code

以下以實際例 於修改資料操作 的一行 SQL 敘述:

子的說明,以下為存在於資料庫應用程式中關

sql = "update group_supplier set s_name='" & TextBoxName.Text & "', s_keyman = '" & TextBoxKeyman.Text & "', s_email='" & TextBoxEmail.Text & "',s_tel = '" &

TextBoxTel.Text & "', s_fax = '" & TextBoxFax.Text & "', s_address= '" &

TextBoxAddress.Text & "' where s_code='" & TextBoxCode.Text & "'"

程式會逐行讀取原始碼檔案直到讀取到檔尾結束(EOF),首先會判斷此行是 否為註解行(即第一個字元為”’”);若非註解行,判斷是否有”UPDATE”關鍵字;

若是,繼續判斷是否有 關鍵字;若是,從 關鍵字之後以空白字

元 分隔,取出各 的值,存入陣列 中,第一個

即為欲得到的資料表名稱;若不是,即為欲得到的資料表名稱

。因 程式最後會判斷資料庫中是否

,若尚未存在,則將此修改的資料表存入資料庫中。

下圖 4.3:

”SET” ”UPDATE”

” “ token (Array) token 的值

(group_supplier)

(group_supplier) 程式允許使用者可重複執行,

已存在此資訊(group_supplier)

4.1.3 剖析原始碼中刪除資料的資訊(DELETE)

剖析原始碼中刪除資料的資訊(UPDATE)的流程如

Source Code N

圖 4.3 剖析原始碼中刪除資料的資訊之流程圖

以下以實際例子的說明,以下為存在於資料庫應用程式中關於刪除資料操作 的一行SQL敘述:

sql= "delete m016 where m016_subjectid = " & subjectid

,首先會判斷此行是

if the line is not comment Y

if the line containing keyword

“DELETE ”

N if the line not start with the keyword

“DELETE ”

split with the delimiter “ ” after the

Y

Y

keyword “DELETE ” get the value of the first array N

if the tablename had not been existed

insert the tablename into the database in the source code

N

Y

if the character before the keyword

“DELETE ” not a English alphabet N

Y

split with the delimiter “ ” after get the value of the first array

Y N

N

if the value of the first array is the keyword “FROM”

the keyword “FROM ” get the value of the first array

否為

4.1.4 資料庫綱要設計

資料庫綱要(schema)的實體關係圖(Entity Relationship),如下圖 4.4,有兩個資料

源路徑。

稱。

PSC 訊,各欄位說明如下:

註解行(即第一個字元為”’”);若非註解行,判斷是否有”DELETE”關鍵字;

若是,判斷此行是否不是以” DELETE”開始;若是,繼續判斷”DELETE”的前一 個字元是否非英文字元;若是,從” DELETE”關鍵字之後以空白字元” “分隔,取 出各 token 的值,存入陣列(Array)中,判斷陣列的第一個 token 的值是否為”FROM ” 關鍵字;若是,從” FROM”關鍵字之後以空白字元” “分隔,取出各 token 的值,存入陣列(Array)中,第一個 token 的值(m016)即為欲得到的資料表名稱;

若不是,即為欲得到的資料表名稱(m016)。因程式允許使用者可重複執行,程式 最後會判斷資料庫中是否已存在此資訊(m016),若尚未存在,則將此刪除的資料 表存入資料庫中。

表,分別為資料表 PSCT 及資料表 PSCF, 資料表 PSCT 存放原始碼中有關資料表 相關的資訊,共有 11 個欄位,各欄位說明如下:

psc_id:資料表主鍵值(Primary Key)。

psc_sc:程式原始碼名稱。

psc_type:存取類別。

psc_table:資料表名稱。

psc_line:行數。

psc_dir:原始碼來

psc_flag:原始碼來源類型。

psc_sysname:系統(或模組)名 psc_filetyp:原始碼檔案種類。

psc_refData:程式碼說明。

psc_refURL:程式碼說明連結 F 為存放資料表中相關聯的欄位資

f_id:資料表主鍵值(Primary Key)。

f_fsn:為一外來鍵(Foreign Key),參考到 PSCT 資料表的 psc_id 欄位。

相關文件