Siby - 2013-03-03

Hello,
To acces to technical documentation under version MT0.10 use
http://localhost/MT0.10/indextech.php

To acces to demi tree
http://localhost/demo/

Only available with full package

Here below, 3 storage procedure to do a mass creation of node in demo tree

How to add 50 new nodes in English demo tree ??

call generation_demo(50,'ENG');

CREATE DEFINER=root@localhost PROCEDURE add_arbo_enfant_demo(IN param_parent INT(10), IN language VARCHAR(3))
BEGIN
DECLARE v1 INT;
DECLARE a INT;
DECLARE b INT;
DECLARE c VARCHAR(200);
DECLARE cur1 CURSOR FOR SELECT parent, order, MD5(ROUND(RAND()*10000) ) VAL_RANDOM FROM mt_demo WHERE parent = param_parent ORDER BY order DESC LIMIT 1;

OPEN cur1;

FETCH cur1 INTO a, b,c;

SET v1 = b + 1;

INSERT INTO `magictree`.`mt_demo` (
`application_release` ,
`id` ,
`parent` ,
`order`
)
VALUES ('MT0.10', NULL, a, v1);

INSERT INTO `magictree`.`mt_demo_caption` (
`application_release` ,
`id` ,
`language` ,
`title`,
`description`
)
VALUES ('MT0.10', LAST_INSERT_ID() , language, c, c);

INSERT INTO `magictree`.`mt_demo_feature` (
`application_release` ,
`id`
)
VALUES ('MT0.10', LAST_INSERT_ID());

CLOSE cur1;

END

CREATE DEFINER=root@localhost PROCEDURE add_arbo_parent_demo(IN param_parent INT(10), IN param_enfant INT(10), IN language VARCHAR(3))
BEGIN
DECLARE nouveau INT DEFAULT 0;
DECLARE v1 INT;
DECLARE a INT;
DECLARE b INT;
DECLARE c VARCHAR(200);
DECLARE cur1 CURSOR FOR SELECT parent, order, MD5(ROUND(RAND()*10000) ) VAL_RANDOM FROM mt_demo WHERE parent = param_enfant ORDER BY order DESC LIMIT 1;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET nouveau = 1;

OPEN cur1;

FETCH cur1 INTO a, b,c;

IF nouveau = 0 THEN

    SET v1 = b + 1;

    INSERT INTO `magictree`.`mt_demo` (
    `application_release` ,
    `id` ,
    `parent` ,
    `order`
    )
    VALUES ('MT0.10', NULL, param_enfant, v1);

ELSE
    SET c = MD5(ROUND(RAND()*10000) );
    INSERT INTO `magictree`.`mt_demo` (
    `application_release` ,
    `id` ,
    `parent` ,
    `order`
    )
    VALUES ('MT0.10', NULL, param_enfant, 0);

END IF;

INSERT INTO `magictree`.`mt_demo_caption` (
`application_release` ,
`id` ,
`language` ,
`title`,
`description`
)
VALUES ('MT0.10', LAST_INSERT_ID(), language, c, c);

INSERT INTO `magictree`.`mt_demo_feature` (
`application_release` ,
`id`
)
VALUES ('MT0.10', LAST_INSERT_ID());

CLOSE cur1;

END

CREATE DEFINER=root@localhost PROCEDURE generation_demo(IN nombre INT(10), IN language VARCHAR(3))
BEGIN

DECLARE v1 INT;
DECLARE a INT;
DECLARE b INT;
DECLARE ordre INT;
DECLARE alea INT;
DECLARE cur1 CURSOR FOR SELECT parent, id FROM (SELECT CONF.`parent`, CONF.`id`, ROUND(RAND()*10000) VAL_RANDOM FROM `mt_demo` CONF ORDER BY VAL_RANDOM) TAB1 LIMIT 1;

SET v1 = nombre;


WHILE v1 > 0 DO

OPEN cur1;

FETCH cur1 INTO a, b;

set alea =  ROUND(RAND()*2) - 1;

IF alea > 0 THEN
    call add_arbo_enfant_demo(a,language);
ELSE
    call add_arbo_parent_demo(a,b,language);
END IF;

CLOSE cur1;

SET v1 = v1 - 1;

END WHILE;

END

 

Last edit: Siby 2013-03-05