X-Git-Url: http://git.harvie.cz/?a=blobdiff_plain;f=wwwroot%2Fbackend%2Fmysql%2Fbackend.inc;h=87e1d2d744bd09297fafed0b8050e5eb81d66d78;hb=ccb9c667e7fdb56dfc2aa3c800328511a26dffb8;hp=dd0c4f7cf82b6512973aa03e88a741dca6029364;hpb=12c388b0b02de8bccec72660602d8b4476161324;p=mirrors%2FKyberia-bloodline.git diff --git a/wwwroot/backend/mysql/backend.inc b/wwwroot/backend/mysql/backend.inc index dd0c4f7..87e1d2d 100644 --- a/wwwroot/backend/mysql/backend.inc +++ b/wwwroot/backend/mysql/backend.inc @@ -341,18 +341,48 @@ function getKNeurons($user_id,$interval) { return $k_array; } -// Set synapse weight, +// setSynapse -// XXX TODO +// Set synapse weight. +// If synapse does not exists, create a new one. +// Secure. +// Returns true on sucess, otherwise false. -function setSynapse($src,$dst,$weight) { +function setSynapse($params){ global $db,$node,$error,$error_messages; - // XXX security fix -// $q="update neurons set synapse_weight='$synapse_weight' where dst = '$dst' and src = '$src'"; -// $q="insert into neurons values('$synapse_weight','$dst','$src',NULL,'synapse',XXX,now(),XXX,$src)"; + // security check + if ((!is_numeric($params['src'])) + or (!is_numeric($params['dst'])) + or (!is_numeric($params['weight']))) { -// $set=$db->query($q); + return false; + } + + $src=$params['src']; + $dst=$params['dst']; + $weight=$params['weight']; + + // weight could be only positive + if ( $weight < 0) { + return false; + } + + // if already exists + $q="select count(src) from neurons where dst ='$dst' and src = '$src'"; + $set=$db->query($q); + $set->next(); + $isrc=$set->getString('count(src)'); + + if ( $isrc > 0 ) { + $q="update neurons set synapse_weight='$weight' + where dst = '$dst' and src = '$src'"; + } else { + // FIXME no vector set + $q="insert into neurons values('$weight','$dst','$src',0,'synapse', + CURRENT_TIMESTAMP(),now(),NULL,$src)"; + } + $set=$db->query($q); return true; }