How we can verify the correctness of database systems with triggers in early design phase?. Our contribution is building a tool called S2B which can automatic translate form databas
Trang 1DEVELOPING A TOOL TO VERIFY TRIGGERS IN DBMS
1 Supervisor : Assoc Prof Dr Truong Ninh Thuan
Co-supervisor : MSc Le Hong Anh Student : Dang Minh Dung
Trang 22
Trang 3Motivation 3
No table employee yet.
Some SQL statements are only
checked when they execute
How we can verify the
correctness of database systems
with triggers in early design phase? Infinite loop
Example 1
Example 2
Trang 4 In a previous work [1], a new method was introduced by using Event-B formal method to solve above issue
Our contribution is building a tool (called S2B) which can
automatic translate form database systems to event-b models and partly supports modelling process with the Rodin platform 4
[1] Hong Anh Le, and Ninh Thuan Truong "Modeling and verifying DML triggers using event-B." Intelligent Information and
Database Systems Springer Berlin Heidelberg, 2013 539-548
Trang 5Database systems
ECA (Event – Condition – Action) form
5
Actions
Condition
Event
TRIGGER <trigger_name> <event>
WHEN <conditions> BEGIN
<actions>
END;
Generalize
Trang 6Event-B is a formal method for system-level modelling and analysis.
Key features:
• using set theory as modelling notation
• using refinement to represent systems at different level
• Using mathematical proof to verify consistency
Context
A context describes the static part of a Event-B model.
A machine describes the dynamic behaviour of a Event-B model.
o Event
Event describe when and how machine state changes over the time Event also has the form of an EAC.
The Rodin Platform is an Eclipse-based IDE for Event-B.
6
Trang 7S2B Tool
event-b model.
7
S2B tool architecture
Trang 8Database Adapter
schema.
E:\SQL-to-EventB\res\test\db\demo.db
8
SELECT sql FROM
(SELECT * FROM sqlite_master UNION ALL
SELECT * FROM sqlite_temp_master)
WHERE type!='meta'
ORDER BY tbl_name, type DESC, name
Trang 9SQL Extractor
Functionality: eliminate redundant information and
transform schema into a standard form
2 steps:
o Parsing SQL statements
o Normalizing database models
Step 1: Parsing SQL statements
o Using ANTLR library.
o Define SQLite grammar then ANTLR generate lexer and parser
o Output: Abstract Syntax Tree (AST)
9
Abstract Syntax Tree
Trang 10SQL Extractor
o Reasons for normalizing database models
AST is sequential access
Exists opposite statements as CREATE, ALTER, DROP in schema
Unnecessary statements as DML statements (INSERT, UPDATE, DELETE)
We want to create a unified format across DBMS schema.
o Use visitor design pattern to travel AST
Extend default visitor.
Use symbol table to manager identifiers.
o Output: database models – a unified form of schema
o After SQL extractor module, we can detect some compilation errors…
10
Trang 11S2B Translator
event-b model.
Base on bellow translation rules[1]:
11
Database definitions Event-B concepts Rule 1 𝑑𝑏 = 𝑇, 𝐶, 𝐺 𝑑𝑏𝐶𝑜𝑛𝑡𝑒𝑥𝑡, 𝑑𝑏𝑀𝑎𝑐ℎ𝑖𝑛𝑒
Rule 2 Table 𝑡 ∈ 𝑇 𝑇𝑎𝑏𝑙𝑒 = 𝑇𝑦𝑝𝑒1 × 𝑇𝑦𝑝𝑒2 × ⋯ × 𝑇𝑦𝑝𝑒𝑛
Rule 3 Primary key constraint Invariant 𝑝𝑘: 𝑑𝑜𝑚(Type1 × ⋯ × 𝑇𝑦𝑝𝑒𝑖) ⤖
𝑟𝑎𝑛(Typei+1× ⋯ × 𝑇𝑦𝑝𝑒𝑛)
Rule 4 Constraint 𝑐 ∈ 𝐶 Invariant 𝑖
Rule 5 Trigger 𝑔 ∈ 𝐺 Event 𝑒
[1] Hong Anh Le, and Ninh Thuan Truong "Modeling and verifying DML triggers using event-B." Intelligent Information and Database Systems Springer Berlin Heidelberg, 2013 539-548
Trang 12S2B Translator 12
MACHINE dbMachine
SEES dbContext
VARIABLES
t1_rec t2_rec t1_pk t2_pk
INVARIANTS
inv1 t1_rec ∈ P(table1) inv2 t2_rec ∈ P(table2) inv3 t1_pk ∈ TYPE1 ⤖ TYPE2
inv4 t1_pk ∈ TYPE3 ⤖ TYPE4
inv5 I
EVENTS
Event G1
. Event G2
.
END
A part of Event-B specification of database system
Trang 13S2B Translator
Trigger and event both have the form of an ECA (Event-Condition-Action)
A trigger is translated to an Event-B event:
13
TRIGGER <trigger_name>
<event>
WHEN <conditions>
BEGIN
<actions>
END;
EVENT <event_name>
WHEN
<event>
<conditions>
THEN
<actions>
END
Trang 14S2B Translator
Translation of trigger actions:
14
SQL EVENT-B
INSERT INTO T
VALUES (value1, value2, … valuen)
ANY r
WHEN r ∈ T ∧ e ∧ c
THEN T := T ∪ r
END
DELETE FROM T
WHERE (column1 = some_value)
ANY v
WHEN v ∈ TYPE 1 ∧ e ∧ c
THEN T := {v} ⩤ T
END
UPDATE T
SET column1 = value1,
column2 = value2,…
WHERE (column1 = some_value)
ANY u
WHEN u ∈ T ∧ e ∧ c
THEN T := T ◁ u
END
⩤ : is domain subtraction operator ◁ : is relational override operator
Trang 15S2B Translator
In order to
• decouple translation implementations form database model
• Create a common API for all database elements
We apply visitor design pattern.
Translation rules are implemented directly
15
Trang 16// S2BTranslator.java
rodinPrj = new RodinProject (database.getName());
preTranslate();
for ( Table tbl : database.getTables()) { translate(tbl);
}
translate(trg);
} postTranslate();
}
}
}
S2B Translator
Translating algorithm
16
Translate each table Translate each trigger
Implementation of table translation
Implementation of trigger translation
Trang 17Event-B Builder
Functionality: export event-b models into a Rodin project
Rodin files are XML-base files
Using a template engine call StringTemplate to help
generating Rodin files
17
Trang 18 Experiments
18
S2B tool GUIParse Tree Inspector
Generated Event-B project after imported into Rodin
Packages in S2B tool
Trang 19Conclusion and future works
o First step building successfully S2B tool
o Partly support modelling database systems
o Expends translations rule
o Decouple rules into separated files
o Support other DBMSs
19
Trang 20Thanks for listening.
20