- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
BEGIN
DECLARE uid INT DEFAULT 0;
DECLARE sid INT DEFAULT 0;
DECLARE nextid INT DEFAULT 0;
DECLARE gold FLOAT DEFAULT 3.34;
DECLARE cgold FLOAT DEFAULT 0;
DECLARE c CURSOR FOR
SELECT `id`, `statid` from users;
OPEN c;
size: LOOP
FETCH c INTO uid, sid;
if sid = 0
THEN
SET nextid = (SELECT AUTO_INCREMENT FROM information_schema.tables WHERE table_name = 'goldstat' AND table_schema = DATABASE() LIMIT 0,1);
UPDATE `users` SET `statid`= nextid WHERE (`id`= uid);
INSERT INTO `goldstat` VALUES (nextid, uid, gold, '0', '0', '0', '0', '0', '0', '0', '0');
ELSE
SET cgold = (SELECT `overall_b` from goldstat WHERE `owner_id` = uid LIMIT 0,1);
IF cgold = 0
THEN
SET cgold = cgold + gold;
UPDATE `goldstat` SET `overall_b`= cgold WHERE (`owner_id`= uid);
END IF;
END IF;
END LOOP size;
CLOSE c;
END
Комментарии (0) RSS
Добавить комментарий