1 Star 0 Fork 0

Admin/ManageBooks

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
数据库DUMP.sql 28.58 KB
一键复制 编辑 原始数据 按行查看 历史
4f5da2 提交于 2019-04-07 20:18 . minor fixes
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
CREATE DATABASE IF NOT EXISTS `library` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */;
USE `library`;
-- MySQL dump 10.13 Distrib 5.7.17, for Win64 (x86_64)
--
-- Host: 115.159.112.233 Database: library
-- ------------------------------------------------------
-- Server version 5.7.22-0ubuntu0.16.04.1
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Temporary view structure for view `arrive_reminder`
--
DROP TABLE IF EXISTS `arrive_reminder`;
/*!50001 DROP VIEW IF EXISTS `arrive_reminder`*/;
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
/*!50001 CREATE VIEW `arrive_reminder` AS SELECT
1 AS `user_name`,
1 AS `bname`,
1 AS `email`*/;
SET character_set_client = @saved_cs_client;
--
-- Table structure for table `book`
--
DROP TABLE IF EXISTS `book`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `book` (
`book_id` int(11) NOT NULL AUTO_INCREMENT,
`ISBN` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
`location` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
`state` int(11) NOT NULL,
`operator` int(11) NOT NULL,
PRIMARY KEY (`book_id`),
UNIQUE KEY `BID_UNIQUE` (`book_id`),
KEY `op2_idx` (`operator`),
KEY `bo_idx` (`ISBN`),
CONSTRAINT `bo` FOREIGN KEY (`ISBN`) REFERENCES `booklist` (`ISBN`) ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT `op2` FOREIGN KEY (`operator`) REFERENCES `manager` (`manager_id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=176 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `book`
--
LOCK TABLES `book` WRITE;
/*!40000 ALTER TABLE `book` DISABLE KEYS */;
INSERT INTO `book` VALUES (151,'0000000000001','流通室',0,6),(152,'0000000000001','流通室',0,6),(153,'0000000000001','流通室',0,6),(154,'9787100000000','流通室',0,6),(155,'9787100000000','流通室',0,6),(156,'9787100000000','流通室',0,6),(157,'9787100000000','流通室',0,6),(158,'9787100000000','流通室',0,6),(159,'9787100000000','流通室',0,6),(160,'9787100000000','流通室',0,6),(161,'9787100000000','流通室',0,6),(162,'9787111421900','流通室',0,6),(163,'9787111421900','流通室',0,6),(164,'9787115417305','流通室',0,6),(165,'9787115417305','流通室',0,6),(166,'9787115417305','流通室',0,6),(167,'9787115417305','流通室',0,6),(168,'9787115417305','流通室',0,6),(169,'9787115417305','流通室',0,6),(170,'9787121254437','流通室',0,6),(171,'9787121254437','流通室',0,6),(172,'9787121254437','流通室',0,6),(173,'9787121254437','流通室',0,6),(174,'9787121254437','流通室',0,6),(175,'9787121254437','流通室',0,6);
/*!40000 ALTER TABLE `book` ENABLE KEYS */;
UNLOCK TABLES;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8 */ ;
/*!50003 SET character_set_results = utf8 */ ;
/*!50003 SET collation_connection = utf8_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `library`.`book_AFTER_DELETE` AFTER DELETE ON `book` FOR EACH ROW
BEGIN
UPDATE booklist SET number=number-1 WHERE ISBN=old.ISBN;
END */;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
--
-- Table structure for table `booklist`
--
DROP TABLE IF EXISTS `booklist`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `booklist` (
`ISBN` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
`bname` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
`publisher` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
`writer` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
`ptime` date DEFAULT NULL,
`number` int(11) NOT NULL DEFAULT '0',
`operator` int(11) NOT NULL,
`is_popular` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`ISBN`),
UNIQUE KEY `ISBN_UNIQUE` (`ISBN`),
KEY `op_idx` (`operator`),
CONSTRAINT `op` FOREIGN KEY (`operator`) REFERENCES `manager` (`manager_id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `booklist`
--
LOCK TABLES `booklist` WRITE;
/*!40000 ALTER TABLE `booklist` DISABLE KEYS */;
INSERT INTO `booklist` VALUES ('0000000000001','SQL必知必会','芳文社','陈之豪','8102-05-20',3,6,0),('9787100000000','Qian\'s C Compiler——The speed of the art','路边社','钱晨','2018-05-14',8,6,0),('9787111421900','深入理解Java虚拟机','机械工业出版社','周志明','2013-06-01',2,6,1),('9787115417305','spring实战','人民邮电出版社','Adrian Mouat','2017-04-01',6,6,1),('9787121254437','集体智慧编程','人民邮电出版社','Toby Segaran','2015-03-01',6,6,0);
/*!40000 ALTER TABLE `booklist` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `borrow`
--
DROP TABLE IF EXISTS `borrow`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `borrow` (
`borrow_id` int(11) NOT NULL AUTO_INCREMENT,
`book_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`btime` datetime NOT NULL,
`deadline` datetime NOT NULL,
`rtime` datetime DEFAULT NULL,
`operator` int(11) DEFAULT NULL,
PRIMARY KEY (`borrow_id`),
UNIQUE KEY `BWID_UNIQUE` (`borrow_id`),
KEY `boo_idx` (`book_id`),
KEY `re_idx` (`user_id`),
KEY `op3_idx` (`operator`),
CONSTRAINT `boo` FOREIGN KEY (`book_id`) REFERENCES `book` (`book_id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `op3` FOREIGN KEY (`operator`) REFERENCES `manager` (`manager_id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `re` FOREIGN KEY (`user_id`) REFERENCES `reader` (`user_id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=90 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `borrow`
--
LOCK TABLES `borrow` WRITE;
/*!40000 ALTER TABLE `borrow` DISABLE KEYS */;
INSERT INTO `borrow` VALUES (89,162,26,'2018-05-31 10:32:13','2018-07-30 10:32:13','2018-05-31 10:32:19',6);
/*!40000 ALTER TABLE `borrow` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Temporary view structure for view `borrow_detail`
--
DROP TABLE IF EXISTS `borrow_detail`;
/*!50001 DROP VIEW IF EXISTS `borrow_detail`*/;
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
/*!50001 CREATE VIEW `borrow_detail` AS SELECT
1 AS `borrow_id`,
1 AS `btime`,
1 AS `rtime`,
1 AS `deadline`,
1 AS `book_id`,
1 AS `bname`,
1 AS `user_id`,
1 AS `user_name`*/;
SET character_set_client = @saved_cs_client;
--
-- Table structure for table `manager`
--
DROP TABLE IF EXISTS `manager`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `manager` (
`manager_id` int(11) NOT NULL AUTO_INCREMENT,
`pass_wd` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
`mname` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`manager_id`),
UNIQUE KEY `MID_UNIQUE` (`manager_id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `manager`
--
LOCK TABLES `manager` WRITE;
/*!40000 ALTER TABLE `manager` DISABLE KEYS */;
INSERT INTO `manager` VALUES (5,'123456','admin_czh'),(6,'123456','admin_czc'),(7,'123456','admin_qc');
/*!40000 ALTER TABLE `manager` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `reader`
--
DROP TABLE IF EXISTS `reader`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `reader` (
`user_id` int(11) NOT NULL AUTO_INCREMENT,
`user_name` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
`pass_wd` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
`rname` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
`phone` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
`email` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`user_id`),
UNIQUE KEY `RID_UNIQUE` (`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `reader`
--
LOCK TABLES `reader` WRITE;
/*!40000 ALTER TABLE `reader` DISABLE KEYS */;
INSERT INTO `reader` VALUES (26,'czc_reader','123456','陈至成','13800138000','1966557473@qq.com'),(27,'czh_reader','123456','czh','00000000000','1797079433@qq.com');
/*!40000 ALTER TABLE `reader` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `reservation`
--
DROP TABLE IF EXISTS `reservation`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `reservation` (
`reservation_id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`book_id` int(11) NOT NULL,
`deadline` datetime DEFAULT NULL,
PRIMARY KEY (`reservation_id`),
UNIQUE KEY `REID_UNIQUE` (`reservation_id`),
UNIQUE KEY `BID_UNIQUE` (`book_id`),
KEY `re2_idx` (`user_id`),
KEY `book_idx` (`book_id`),
CONSTRAINT `book` FOREIGN KEY (`book_id`) REFERENCES `book` (`book_id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `re2` FOREIGN KEY (`user_id`) REFERENCES `reader` (`user_id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=145 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `reservation`
--
LOCK TABLES `reservation` WRITE;
/*!40000 ALTER TABLE `reservation` DISABLE KEYS */;
/*!40000 ALTER TABLE `reservation` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `reservation_arrived`
--
DROP TABLE IF EXISTS `reservation_arrived`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `reservation_arrived` (
`reservation_arrived_id` int(11) NOT NULL AUTO_INCREMENT,
`reservation_id` int(11) NOT NULL,
PRIMARY KEY (`reservation_arrived_id`),
KEY `res_id_fk_idx` (`reservation_id`),
CONSTRAINT `res_id_fk` FOREIGN KEY (`reservation_id`) REFERENCES `reservation` (`reservation_id`) ON DELETE CASCADE ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `reservation_arrived`
--
LOCK TABLES `reservation_arrived` WRITE;
/*!40000 ALTER TABLE `reservation_arrived` DISABLE KEYS */;
/*!40000 ALTER TABLE `reservation_arrived` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Temporary view structure for view `reservation_detail`
--
DROP TABLE IF EXISTS `reservation_detail`;
/*!50001 DROP VIEW IF EXISTS `reservation_detail`*/;
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
/*!50001 CREATE VIEW `reservation_detail` AS SELECT
1 AS `user_id`,
1 AS `user_name`,
1 AS `reservation_id`,
1 AS `book_id`,
1 AS `bname`,
1 AS `deadline`*/;
SET character_set_client = @saved_cs_client;
--
-- Temporary view structure for view `return_reminder`
--
DROP TABLE IF EXISTS `return_reminder`;
/*!50001 DROP VIEW IF EXISTS `return_reminder`*/;
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
/*!50001 CREATE VIEW `return_reminder` AS SELECT
1 AS `user_name`,
1 AS `btime`,
1 AS `bname`,
1 AS `email`*/;
SET character_set_client = @saved_cs_client;
--
-- Temporary view structure for view `sec_kill`
--
DROP TABLE IF EXISTS `sec_kill`;
/*!50001 DROP VIEW IF EXISTS `sec_kill`*/;
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
/*!50001 CREATE VIEW `sec_kill` AS SELECT
1 AS `ISBN`,
1 AS `bname`,
1 AS `publisher`,
1 AS `writer`,
1 AS `ptime`,
1 AS `number`*/;
SET character_set_client = @saved_cs_client;
--
-- Dumping events for database 'library'
--
--
-- Dumping routines for database 'library'
--
/*!50003 DROP PROCEDURE IF EXISTS `borrow_from_res` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8 */ ;
/*!50003 SET character_set_results = utf8 */ ;
/*!50003 SET collation_connection = utf8_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `borrow_from_res`(in res_id int, in op int)
BEGIN
declare bid int;
declare uid int;
declare num int;
declare t_error integer default 0;
declare continue handler for sqlexception set t_error=1;
start transaction;
select count(*) into num from reservation where reservation_id=res_id;
if num > 0 then
select book_id, user_id into bid, uid from reservation where reservation_id=res_id;
insert into borrow(book_id, user_id, btime, deadline, operator) values (bid, uid, now(), date_add(now(), interval 60 day), op);
DELETE from reservation where book_id=bid;
UPDATE book SET state=2 where book_id=bid;
end if;
if t_error=1 then
rollback;
else
commit;
end if;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `do_sec_kill` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8 */ ;
/*!50003 SET character_set_results = utf8 */ ;
/*!50003 SET collation_connection = utf8_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `do_sec_kill`(IN bn varchar(30), IN uid int, OUT st int)
BEGIN
declare num int;
declare bid int;
declare t_error integer default 0;
declare continue handler for sqlexception set t_error=1;
start transaction;
select count(*) into num from book where ISBN=bn and state=0;
select book_id into bid from book where ISBN=bn and state=0 order by book_id limit 0, 1;
if num > 0 then
insert into reservation(user_id, book_id, deadline) values(uid, bid, date_add(now(), interval 10 day));
update book set state=1 where book_id=bid;
set st = 1;
else
set st=0;
end if;
if t_error=1 then
rollback;
set st=-4;
else
commit;
end if;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `make_reservation` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8 */ ;
/*!50003 SET character_set_results = utf8 */ ;
/*!50003 SET collation_connection = utf8_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `make_reservation`(IN bn varchar(30), IN uid int, OUT st int)
BEGIN
declare num int;
declare ispop int;
declare bid int;
declare stat int;
declare t_error integer default 0;
declare continue handler for sqlexception set t_error=1;
start transaction;
select count(*) into num from book where ISBN=bn and (state=0 or (state=2 and book_id not in (select reservation.book_id from reservation))) order by state;
select is_popular into ispop from booklist where booklist.ISBN=bn;
if ispop > 0 then
set st=-1;
else
if num > 0 then
select state, book_id into stat, bid from book where ISBN=bn and (state=0 or (state=2 and book_id not in (select reservation.book_id from reservation))) order by state limit 0, 1;
if stat > 0 then
insert into reservation(user_id, book_id) values(uid, bid);
set st = 2;
else
insert into reservation(user_id, book_id, deadline) values(uid, bid, date_add(now(), interval 10 day));
update book set state=1 where book_id=bid;
set st = 1;
end if;
else
set st=0;
end if;
end if;
if t_error=1 then
rollback;
set st=-4;
else
commit;
end if;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `new_book` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8 */ ;
/*!50003 SET character_set_results = utf8 */ ;
/*!50003 SET collation_connection = utf8_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `new_book`(IN ISBN varchar(30),IN bname varchar(45), IN publisher varchar(45), IN writer varchar(45), IN ptime date, IN num int, IN operator int,IN location varchar(45),IN state int)
BEGIN
DECLARE i int;
declare t_error integer default 0;
declare continue handler for sqlexception set t_error=1;
start transaction;
insert into booklist(ISBN,bname, publisher, writer, ptime, number, operator)values (ISBN, bname, publisher, writer, ptime, num, operator);
SET i=0;
while i<num DO
insert into book(ISBN,location,state,operator) values(ISBN,location,state,operator);
SET i=i+1;
end while;
if t_error=1 then
rollback;
else
commit;
end if;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `return_book` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8 */ ;
/*!50003 SET character_set_results = utf8 */ ;
/*!50003 SET collation_connection = utf8_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `return_book`(in bor_id int)
BEGIN
declare num int;
declare bid int;
declare n int;
declare resid int;
declare t_error integer default 0;
declare continue handler for sqlexception set t_error=1;
start transaction;
select count(*) into n from borrow where borrow_id=bor_id and rtime is null;
if n > 0 then
select book_id into bid from borrow where borrow_id=bor_id;
select count(*) into num from reservation where book_id=bid;
if num > 0 then
update borrow set rtime=now() where borrow_id=bor_id;
update book set state=1 where book_id=bid;
update reservation set deadline=now() where book_id=bid;
select reservation_id into resid from reservation where book_id=bid;
insert into reservation_arrived (reservation_id) values (resid);
else
update borrow set rtime=now() where borrow_id=bor_id;
update book set state=0 where book_id=bid;
end if;
end if;
if t_error=1 then
rollback;
else
commit;
end if;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
--
-- Final view structure for view `arrive_reminder`
--
/*!50001 DROP VIEW IF EXISTS `arrive_reminder`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
/*!50001 SET @saved_col_connection = @@collation_connection */;
/*!50001 SET character_set_client = utf8 */;
/*!50001 SET character_set_results = utf8 */;
/*!50001 SET collation_connection = utf8_general_ci */;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `arrive_reminder` AS select `reader`.`user_name` AS `user_name`,`booklist`.`bname` AS `bname`,`reader`.`email` AS `email` from ((((`reservation_arrived` join `reservation`) join `reader`) join `book`) join `booklist`) where ((`reservation_arrived`.`reservation_id` = `reservation`.`reservation_id`) and (`reservation`.`user_id` = `reader`.`user_id`) and (`reservation`.`book_id` = `book`.`book_id`) and (`book`.`ISBN` = `booklist`.`ISBN`)) */;
/*!50001 SET character_set_client = @saved_cs_client */;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;
--
-- Final view structure for view `borrow_detail`
--
/*!50001 DROP VIEW IF EXISTS `borrow_detail`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
/*!50001 SET @saved_col_connection = @@collation_connection */;
/*!50001 SET character_set_client = utf8 */;
/*!50001 SET character_set_results = utf8 */;
/*!50001 SET collation_connection = utf8_general_ci */;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `borrow_detail` AS select `borrow`.`borrow_id` AS `borrow_id`,`borrow`.`btime` AS `btime`,`borrow`.`rtime` AS `rtime`,`borrow`.`deadline` AS `deadline`,`borrow`.`book_id` AS `book_id`,`booklist`.`bname` AS `bname`,`borrow`.`user_id` AS `user_id`,`reader`.`user_name` AS `user_name` from (((`borrow` join `book`) join `booklist`) join `reader`) where ((`borrow`.`book_id` = `book`.`book_id`) and (`booklist`.`ISBN` = `book`.`ISBN`) and (`borrow`.`user_id` = `reader`.`user_id`)) */;
/*!50001 SET character_set_client = @saved_cs_client */;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;
--
-- Final view structure for view `reservation_detail`
--
/*!50001 DROP VIEW IF EXISTS `reservation_detail`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
/*!50001 SET @saved_col_connection = @@collation_connection */;
/*!50001 SET character_set_client = utf8 */;
/*!50001 SET character_set_results = utf8 */;
/*!50001 SET collation_connection = utf8_general_ci */;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `reservation_detail` AS select `reader`.`user_id` AS `user_id`,`reader`.`user_name` AS `user_name`,`reservation`.`reservation_id` AS `reservation_id`,`book`.`book_id` AS `book_id`,`booklist`.`bname` AS `bname`,`reservation`.`deadline` AS `deadline` from (((`booklist` join `book`) join `reader`) join `reservation`) where ((`reservation`.`user_id` = `reader`.`user_id`) and (`reservation`.`book_id` = `book`.`book_id`) and (`book`.`ISBN` = `booklist`.`ISBN`)) */;
/*!50001 SET character_set_client = @saved_cs_client */;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;
--
-- Final view structure for view `return_reminder`
--
/*!50001 DROP VIEW IF EXISTS `return_reminder`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
/*!50001 SET @saved_col_connection = @@collation_connection */;
/*!50001 SET character_set_client = utf8 */;
/*!50001 SET character_set_results = utf8 */;
/*!50001 SET collation_connection = utf8_general_ci */;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `return_reminder` AS select `reader`.`user_name` AS `user_name`,`borrow`.`btime` AS `btime`,`booklist`.`bname` AS `bname`,`reader`.`email` AS `email` from (((`borrow` join `reader`) join `book`) join `booklist`) where ((`reader`.`user_id` = `borrow`.`user_id`) and (`borrow`.`book_id` = `book`.`book_id`) and (`book`.`ISBN` = `booklist`.`ISBN`) and isnull(`borrow`.`rtime`)) */;
/*!50001 SET character_set_client = @saved_cs_client */;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;
--
-- Final view structure for view `sec_kill`
--
/*!50001 DROP VIEW IF EXISTS `sec_kill`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
/*!50001 SET @saved_col_connection = @@collation_connection */;
/*!50001 SET character_set_client = utf8 */;
/*!50001 SET character_set_results = utf8 */;
/*!50001 SET collation_connection = utf8_general_ci */;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `sec_kill` AS select `booklist`.`ISBN` AS `ISBN`,`booklist`.`bname` AS `bname`,`booklist`.`publisher` AS `publisher`,`booklist`.`writer` AS `writer`,`booklist`.`ptime` AS `ptime`,(select count(0) from `book` where ((`book`.`ISBN` = `booklist`.`ISBN`) and (`book`.`state` = 0))) AS `number` from `booklist` where (`booklist`.`is_popular` = 1) */;
/*!50001 SET character_set_client = @saved_cs_client */;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2018-05-31 12:56:01
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/godzilla_1_0/ManageBooks.git
git@gitee.com:godzilla_1_0/ManageBooks.git
godzilla_1_0
ManageBooks
ManageBooks
master

搜索帮助