某图书馆的图书借还业务使用如下关系模式:
书目(ISBN,书名,出版社,在库数量)
图书(书号,ISBN,当前位置)
其中在库数量为当前书目可借出的图书的数量,每本图书入库后都会有当前位置,借出后当前位置字段改为空值。每一条书目信息对应多本相同的图书,每一本图书只能对应一条书目。
借还书业务的基本流程如下描述:
(1)读者根据书名查询书目,当前书目的在库数量大于0时可借阅。
(2)读者借出一本图书时,进行出库操作:根据该图书的书号将该图书的当前位置字段值改为空值,并根据其ISBN号将对应书目的在库数量减1。
(3)读者归还一本图书时,进行入库操作:系统根据当前书架的空余位置自动生成该本书的存放位置,并根据该图书的书号将其当前位置字段值改为生成的存放位置,然后将对应书目的在库数量加1。
(4)借还书时,逐一扫描每本图书的书号并进行出、入库操作。
【问题1】(7分)
引入两个伪指令:a= R(X)表示将在库数量X值读入到变量a中;W(a,X)表示将变量a的值写入到在库数量X中。入库操作用下标I表示,出库操作用下标O表示。
将出库和入库操作分别定义为两个事务,针对并发序列:ao=Ro(X),aI=RI(X),ao=ao-1,Wo(ao,X),aI-aI+1,WI(aI,X)。其中变量 aI和 ao分别代表入库事务和出库事务中的局部变量。
(1)假设当前X的值为3,则执行完上述并发序列的伪指令后,X的值是多少?简述产生这一错误的原因(100字以内)。
(2)为了解决上述问题,引入独占锁指令XLock(X)对数据X进行加锁,解锁指令Unlock(X)两对数据X进行解锁。入库操作用下标I表示,如XLockI(X);出库操作用下标O表示,如Unlocko(X)。请根据上述的并发序列,给出一种可能的执行序列,使其满足2PL协议。
【问题2】(8分)
下面是用SQL实现的出入库业务程序的一部分,请补全空缺处的代码。
CREATE PROCEDURE IOstack(IN BookNo VARCHAR(20), IN Amount INT){
//输入合法性验证
if not(Amount=1 or Amount=-1) return -1;
//修改图书表当前位置
UPDATE 图书 SET 当前位置=GetPos(BookNo,Amount)//系统生成
WHERE (a) ;
if error then {ROLLBACK;return -2;}
//修改在库数量
UPDATE 书目 SET 在库数量= (b)
WHERE EXISTS(
SELECT *
FROM 图书
WHERE 书号=BookNo AND
(c) );
if error then {ROLLBACK;return -3;}
(d) ;
return 0;
}
正确答案及解析
正确答案
解析
【问题1】(7分)
(1)4,发生了丢失更新,入库事务更新操作覆盖出库事务更新操作
【问题2】(8分)
(a)书号=BookNo
(b)在库数量+Amount
(c)图书.ISBN=书目.ISBN
(d)COMMIT
包含此试题的试卷
你可能感兴趣的试题
Advancements in ( )have contributed to the growth of the automotive industry through the creation and evolution of self-driving vehicles.
-
- A.Artificial Intelligence
- B.Cloud Computing
- C.Internet of Things
- D.Big Data
- 查看答案
In project human resource management , ( )is not a source of power for the project manager.
-
- A.referent power
- B.expert power
- C.reward power
- D.audit power
- 查看答案
At the project establishment stage , the feasibility study mainly includes techinical feasibility analysis , ( ), operation environment feasibility analysis and other aspects of feasibility analysis.
-
- A.detail feasibility analysis
- B.opportunity analysis
- C.economic feasibility analysis
- D.risk analysis
- 查看答案
( )is a grid that shows the project resources assigned to each work package.
-
- A.Stakeholder engagement assessment matrix
- B.Requirements traceability matrix
- C.Probability and impact matrix
- D.Responsibility assignment matrix
- 查看答案
Xinhua News Agency reported in January 2022,Chian will further promote the developmet of a digital economy during the 14th Five-Year Plan eriod(2021-2025). The plan also emphasized industrial ( )transformation.
-
- A.digital
- B.networking
- C.intelligentize
- D.informatization
- 查看答案