Parcourir la source

update db file

iaun il y a 5 ans
Parent
commit
1452234e72
1 fichiers modifiés avec 78 ajouts et 30 suppressions
  1. 78 30
      db.sql

+ 78 - 30
db.sql

@@ -47,7 +47,7 @@ CREATE TABLE `log` (
   PRIMARY KEY (`id`),
   KEY `log_uid` (`uid`),
   CONSTRAINT `log_uid` FOREIGN KEY (`uid`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
-) ENGINE=InnoDB AUTO_INCREMENT=155 DEFAULT CHARSET=utf8mb4;
+) ENGINE=InnoDB AUTO_INCREMENT=246 DEFAULT CHARSET=utf8mb4;
 /*!40101 SET character_set_client = @saved_cs_client */;
 
 --
@@ -79,7 +79,7 @@ CREATE TABLE `user` (
   `name` varchar(255) DEFAULT NULL,
   `password` varchar(255) DEFAULT NULL,
   PRIMARY KEY (`id`)
-) ENGINE=InnoDB AUTO_INCREMENT=55 DEFAULT CHARSET=utf8mb4;
+) ENGINE=InnoDB AUTO_INCREMENT=56 DEFAULT CHARSET=utf8mb4;
 /*!40101 SET character_set_client = @saved_cs_client */;
 
 --
@@ -96,9 +96,37 @@ CREATE TABLE `user` (
 /*!50003 SET sql_mode              = '' */ ;
 DELIMITER ;;
 CREATE DEFINER=`root`@`%` PROCEDURE `add_log`(u int(11), t tinyint(4), am varchar(255))
-BEGIN
-	#Routine body goes here...
-	insert into `log` (`time`,`uid`,`type`,`admin_msg`) values (NOW(), u, t, am);
+BEGIN
+	#Routine body goes here...
+	insert into `log` (`time`,`uid`,`type`,`admin_msg`) values (NOW(), u, t, am);
+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 `get_log_admin` */;
+/*!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  = utf8mb4 */ ;
+/*!50003 SET character_set_results = utf8mb4 */ ;
+/*!50003 SET collation_connection  = utf8mb4_general_ci */ ;
+/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
+/*!50003 SET sql_mode              = '' */ ;
+DELIMITER ;;
+CREATE DEFINER=`root`@`%` PROCEDURE `get_log_admin`(p int, l int)
+BEGIN
+	#Routine body goes here...
+	# select UNIX_TIMESTAMP(`log`.`time`), `user`.`name`, `log`.`type`, `log`.`admin_msg` from `log` LEFT JOIN `user` on `log`.`uid` = `user`.`id` order by `log`.`time` desc
+	select count(1) from `log`;
+	set @stmt = CONCAT("select UNIX_TIMESTAMP(`log`.`time`), `user`.`name`, `log`.`type`, `log`.`admin_msg` from `log` LEFT JOIN `user` on `log`.`uid` = `user`.`id` WHERE `log`.`id` <= (select `id` from `log` order by `id` desc limit ?, 1) order by `log`.`time` desc, `log`.`id` desc limit ?");
+	set @last = l* (p-1);
+	set @len = l;
+	prepare stmt from @stmt;
+	EXECUTE stmt using @last, @len;
+	deallocate prepare stmt;
+	-- select * from `log` where id > p limit 10;
 END ;;
 DELIMITER ;
 /*!50003 SET sql_mode              = @saved_sql_mode */ ;
@@ -116,9 +144,29 @@ DELIMITER ;
 /*!50003 SET sql_mode              = '' */ ;
 DELIMITER ;;
 CREATE DEFINER=`root`@`%` PROCEDURE `get_log_details`()
-BEGIN
-	#Routine body goes here...
-	select `user`.`id`,`user`.`name`,UNIX_TIMESTAMP(min(IF(`log`.`type`=1, `log`.`time`, null))), sum(case when `log`.`type`=2 THEN 1 ELSE 0 END) as fail from `user` left join `log` on `log`.`uid`=`user`.`id` group by `user`.`id` order by isnull(min(IF(`log`.`type`=1, `log`.`time`, null))), min(IF(`log`.`type`=1, `log`.`time`, null)), `user`.`id`;
+BEGIN
+	#Routine body goes here...
+	select `user`.`id`,`user`.`name`,UNIX_TIMESTAMP(min(IF(`log`.`type`=1, `log`.`time`, null))), sum(case when `log`.`type`=2 THEN 1 ELSE 0 END) as fail from `user` left join `log` on `log`.`uid`=`user`.`id` group by `user`.`id` order by isnull(min(IF(`log`.`type`=1, `log`.`time`, null))), min(IF(`log`.`type`=1, `log`.`time`, null)), `user`.`id`;
+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 `get_user_key` */;
+/*!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  = utf8mb4 */ ;
+/*!50003 SET character_set_results = utf8mb4 */ ;
+/*!50003 SET collation_connection  = utf8mb4_general_ci */ ;
+/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
+/*!50003 SET sql_mode              = '' */ ;
+DELIMITER ;;
+CREATE DEFINER=`root`@`%` PROCEDURE `get_user_key`(i int)
+BEGIN
+	#Routine body goes here...
+	select UNIX_TIMESTAMP(`time`), `admin_msg` from `log` where `type` = 3 AND `uid` = i;
 END ;;
 DELIMITER ;
 /*!50003 SET sql_mode              = @saved_sql_mode */ ;
@@ -136,13 +184,13 @@ DELIMITER ;
 /*!50003 SET sql_mode              = '' */ ;
 DELIMITER ;;
 CREATE DEFINER=`root`@`%` PROCEDURE `set_key`(u int(11), a varchar(255), s varchar(255))
-BEGIN
-	#Routine body goes here...
-	IF NOT EXISTS(SELECT 1 FROM  `key` where `uid`= u) THEN
-		insert into `key`(`uid`, `ak`, `sk`) values (u, a, s);
-	ELSE
-		update `key` set `ak` = a, `sk` = s where `uid` = u;
-	END IF;
+BEGIN
+	#Routine body goes here...
+	IF NOT EXISTS(SELECT 1 FROM  `key` where `uid`= u) THEN
+		insert into `key`(`uid`, `ak`, `sk`) values (u, a, s);
+	ELSE
+		update `key` set `ak` = a, `sk` = s where `uid` = u;
+	END IF;
 END ;;
 DELIMITER ;
 /*!50003 SET sql_mode              = @saved_sql_mode */ ;
@@ -160,13 +208,13 @@ DELIMITER ;
 /*!50003 SET sql_mode              = '' */ ;
 DELIMITER ;;
 CREATE DEFINER=`root`@`%` PROCEDURE `set_url`(u int(11), ur varchar(255))
-BEGIN
-	#Routine body goes here...
-	IF NOT EXISTS(SELECT 1 FROM  `url` where `uid`= u) THEN
-		insert into `url`(`uid`, `url`, `status`) values (u, ur, 0);
-	ELSE
-		update `url` set `status` = 0, `url` = ur, `msg` = "" where `uid` = u;
-	END IF;
+BEGIN
+	#Routine body goes here...
+	IF NOT EXISTS(SELECT 1 FROM  `url` where `uid`= u) THEN
+		insert into `url`(`uid`, `url`, `status`) values (u, ur, 0);
+	ELSE
+		update `url` set `status` = 0, `url` = ur, `msg` = "" where `uid` = u;
+	END IF;
 END ;;
 DELIMITER ;
 /*!50003 SET sql_mode              = @saved_sql_mode */ ;
@@ -184,13 +232,13 @@ DELIMITER ;
 /*!50003 SET sql_mode              = '' */ ;
 DELIMITER ;;
 CREATE DEFINER=`root`@`%` PROCEDURE `user_register`(un varchar(255), pw varchar(255))
-BEGIN
-	#Routine body goes here...
-	IF NOT EXISTS(SELECT 1 FROM  `user` where `name`= un) THEN
-		insert into `user`(`name`,`password`) values (un, pw);
-		select LAST_INSERT_ID();
-	END IF;
-
+BEGIN
+	#Routine body goes here...
+	IF NOT EXISTS(SELECT 1 FROM  `user` where `name`= un) THEN
+		insert into `user`(`name`,`password`) values (un, pw);
+		select LAST_INSERT_ID();
+	END IF;
+
 END ;;
 DELIMITER ;
 /*!50003 SET sql_mode              = @saved_sql_mode */ ;
@@ -207,4 +255,4 @@ DELIMITER ;
 /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
 /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
 
--- Dump completed on 2021-01-07 10:51:11
+-- Dump completed on 2021-01-07 22:46:26