From: niekt0 Date: Thu, 3 Mar 2011 00:17:55 +0000 (+0100) Subject: added script for fixing vectors X-Git-Url: https://git.harvie.cz/?a=commitdiff_plain;h=9ed37a87c196a6199e7cb4bef32c8a58c5606127;p=mirrors%2FKyberia-bloodline.git added script for fixing vectors --- diff --git a/wwwroot/backend/mysql/sys.sql b/wwwroot/backend/mysql/sys.sql new file mode 100644 index 0000000..7cdb1e0 --- /dev/null +++ b/wwwroot/backend/mysql/sys.sql @@ -0,0 +1,33 @@ +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 ; diff --git a/wwwroot/backend/mysql/test.sql b/wwwroot/backend/mysql/test.sql index 893b92d..338db8b 100644 --- a/wwwroot/backend/mysql/test.sql +++ b/wwwroot/backend/mysql/test.sql @@ -3,7 +3,7 @@ drop function if exists k_get_node_weigth; 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; @@ -41,5 +41,28 @@ begin 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 ; +