[Release SQL] Change startmap coords and map

08/05/2012 20:15 Mashkin#16
Quote:
Originally Posted by MAXIMAXCRAK View Post
Really this it's a good system, only uploads map_index=0 where is insert any date, no update, for this reason the speed of DB musn't be delayed (excuse for my english)
Your procedure "proceso()" checks all rows for "map_index=0" on every update. Since map_index isn't (by default) an index or a primary key, this can take very long.

I would suggest to pass the id of the updated player to the procedure. The procedure then can process just the right row without reading all rows.
Code:
DELIMITER $$
DROP TRIGGER IF EXISTS espera $$

CREATE TRIGGER espera
AFTER UPDATE ON player_index
FOR EACH ROW
begin
IF NEW.map_index = 0 THEN
CALL proceso(NEW.id, NEW.account_id);
END IF;
end $$
DELIMITER ;
Code:
delimiter $$

DROP PROCEDURE IF EXISTS `proceso` $$

CREATE PROCEDURE `proceso`(p_id INT, a_id INT)
begin

    declare p_empire integer;

    SELECT empire INTO p_empire FROM player_index WHERE id = a_id LIMIT 1;

    IF p_empire = 1 THEN
    UPDATE player SET x=1111, y=1111, map_index=1 where id = p_id;
    
    ELSEIF p_empire = 2 THEN
    UPDATE player SET x=2222, y=2222, map_index=2 where id = p_id;
    
    ELSEIF p_empire = 3 THEN
    UPDATE player SET x=3333, y=3333, map_index=3 WHERE id = p_id;
    
    END IF;

end $$
delimiter ;
08/05/2012 20:36 MAXIMAXCRAK#17
Quote:
Originally Posted by M@shkin View Post
Your procedure "proceso()" checks all rows for "map_index=0" on every update. Since map_index isn't (by default) an index or a primary key, this can take very long.

I would suggest to pass the id of the updated player to the procedure. The procedure then can process just the right row without reading all rows.
Code:
DELIMITER $$
DROP TRIGGER IF EXISTS espera $$

CREATE TRIGGER espera
AFTER UPDATE ON player_index
FOR EACH ROW
begin
IF NEW.map_index = 0 THEN
CALL proceso(NEW.id, NEW.account_id);
END IF;
end $$
DELIMITER ;
Code:
delimiter $$

DROP PROCEDURE IF EXISTS `proceso` $$

CREATE PROCEDURE `proceso`(p_id INT, a_id INT)
begin

    declare p_empire integer;

    SELECT empire INTO p_empire FROM player_index WHERE id = a_id LIMIT 1;

    IF p_empire = 1 THEN
    UPDATE player SET x=1111, y=1111, map_index=1 where id = p_id;
    
    ELSEIF p_empire = 2 THEN
    UPDATE player SET x=2222, y=2222, map_index=2 where id = p_id;
    
    ELSEIF p_empire = 3 THEN
    UPDATE player SET x=3333, y=3333, map_index=3 WHERE id = p_id;
    
    END IF;

end $$
delimiter ;
I'ts good, :handsdown::handsdown: I'm new in sql sorry xddd

Thx for improve this code, Really may be better.
08/05/2012 21:57 Mashkin#18
Quote:
Originally Posted by MAXIMAXCRAK View Post
I'ts good, :handsdown::handsdown: I'm new in sql sorry xddd

Thx for improve this code, Really may be better.
Well, I' m no SQL veteran.
My thoughts were not specific to SQL but simply logical.
You should always think about what your code/script/query does exactly and ask yourself how you could improve it.

You'll come to the clue, that - on an update to a specific row - you already know the row you are going to modify with your procedure.
So you should try to use the given information instead of searching for it again. :)

BTW: I had to read through about six MySQL documentation pages to write the code I posted above.
08/10/2012 00:03 asdstyle#19
Quote:
Originally Posted by M@shkin View Post
Well, I' m no SQL veteran.
My thoughts were not specific to SQL but simply logical.
You should always think about what your code/script/query does exactly and ask yourself how you could improve it.

You'll come to the clue, that - on an update to a specific row - you already know the row you are going to modify with your procedure.
So you should try to use the given information instead of searching for it again. :)

BTW: I had to read through about six MySQL documentation pages to write the code I posted above.

i using u code but this problem can you help ?
1054 - Unknown column 'map_index' in 'NEW'
08/10/2012 00:12 Sphinx²#20
Quote:
Originally Posted by asdstyle View Post
i using u code but this problem can you help ?
1054 - Unknown column 'map_index' in 'NEW'
I think you use the wrong table.
08/10/2012 00:31 nagger12#21
Thanks hat geklappt ;)
08/14/2012 06:02 masterdj39#22
Can someone please tell me if that works?

Im trying but everytime i login to an account and i want to go ingame, i just get logged out.

If someone know how to put that working, please give me an explanation.

Thank you
08/14/2012 14:04 Mijago#23
Quote:
Originally Posted by .Nagato View Post
Hallo,

Hierfür muss man nichtmal SQL können.
Englisch sollte ausreichen, wobei das auch wieder so eine Sache sein kann. oó
Really nice!
Ich sags anders - Für SQL muss man nur Englisch können ;)
08/23/2012 06:46 masterdj39#24
Someone had done that without any problems?