--- /dev/null
+drop procedure if exists fix_all_vectors;
+drop function if exists get_fix_vector;
+delimiter //
+/* compute correct vector for node */
+create function get_fix_vector (node INT) returns varchar(80)
+BEGIN
+ declare np,mynode,safe int;
+ declare vector varchar(80);
+
+ set safe=100; /* loop detection, max tree depth*/
+ set mynode=node;
+ set vector='';
+ REPEAT
+ select node_parent into np from nodes where node_id = mynode;
+ select concat(lpad(mynode,8,'00000000'),vector) into vector;
+ set mynode=np;
+ set safe=safe - 1;
+ UNTIL np = NULL or np = 0 or safe = 0 or np = node
+ END REPEAT;
+
+ if safe = 0 then
+ return 'loooped';
+ end if;
+ return vector;
+
+END//
+
+/* fix vector for all the nodes*/
+create procedure fix_all_vectors ()
+begin
+ update nodes set node_vector=get_fix_vector(node_id);
+end//
+delimiter ;
delimiter //
create function k_get_node_weigth (node INT, user INT) returns DOUBLE
BEGIN
- declare vector,node2,len,n_owner,offset int;
+ declare vector,node2,len,n_owner,offset int; /* vector type*/
declare final,n_weight,o_weight,s_weight double;
select node_vector into vector from nodes where node_id = node;
and node_created>now()-interval 20 day;
-- select * from tmp_table order by k_weight desc;
+end//
+
+create function get_fix_vector (node INT) returns varchar(80)
+BEGIN
+ declare np,mynode int;
+
+ set mynode=node;
+ REPEAT
+ select node_parent into np from nodes where node_id = mynode;
+ /* XXX padding */
+ vector=concat(node_parent,vector);
+ set mynode=node_parent;
+ UNTIL node_parent != NULL and node_parent > 0
+ END REPEAT;
+
+ return vector;
+
+END//
+
+create procedure fix_all_vectors ()
+begin
+
end//
delimiter ;
+