CREATEPROCEDURE modifyRootEntry() BEGIN DECLARE done INTDEFAULTFALSE; DECLARE userId INT; DECLARE userIdIter CURSORFORSELECTDISTINCT user_id from entries; OPEN userIdIter;
read_loop: LOOP FETCH userIdIter INTO userId; IF done THEN LEAVE read_loop; END IF; INSERTINTO entries (id, name, user_id, parent_id) VALUES(0, 'root_parent', userId, 0); UPDATE entries SET parent_id=0where user_id=userId AND name='file_root'AND parent_id isNULL; END LOOP;
CREATEPROCEDURE modifyRootEntry() BEGIN DECLARE done INTDEFAULTFALSE; DECLARE userId INT; DECLARE userIdIter CURSORFORSELECTDISTINCT user_id from entries; START TRANSACTION; // here ! OPEN userIdIter; read_loop: LOOP FETCH userIdIter INTO userId; IF done THEN LEAVE read_loop; END IF; INSERTINTO entries (id, name, user_id, parent_id) VALUES(0, 'root_parent', userId, 0); END LOOP; UPDATE entries SET parent_id=0where user_id=userId AND name='file_root'AND parent_id isNULL; // here! CLOSE userIdIter; COMMIT;// here ! END;
CREATEPROCEDURE pFastCreateNums (cnt INT UNSIGNED) BEGIN DECLARE s INT UNSIGNED DEFAULT1; TRUNCATETABLE Nums; INSERTINTO Nums SELECT s; WHILE s*2<= cnt DO BEGIN INSERTINTO Nums SELECT a+s FROM Nums; SET s = s*2; END; END WHILE; END;