]> git.rm.cloudns.org Git - xonotic/xonstatdb.git/commitdiff
Function to merge two players.
authorAnt Zucaro <azucaro@gmail.com>
Wed, 29 Feb 2012 12:05:05 +0000 (07:05 -0500)
committerAnt Zucaro <azucaro@gmail.com>
Wed, 29 Feb 2012 12:05:05 +0000 (07:05 -0500)
functions/merge_players.sql [new file with mode: 0644]

diff --git a/functions/merge_players.sql b/functions/merge_players.sql
new file mode 100644 (file)
index 0000000..0a77026
--- /dev/null
@@ -0,0 +1,34 @@
+create or replace function merge_players(p_winner_player_id players.player_id%TYPE, p_loser_player_id players.player_id%TYPE) RETURNS void as
+$$
+declare
+   rowcount integer;   
+begin
+   -- start with weapon stats
+   update player_weapon_stats
+   set player_id = p_winner_player_id
+   where player_id = p_loser_player_id;
+
+   get diagnostics rowcount = ROW_COUNT;
+   raise notice '% weapon stat rows updated.', rowcount;
+
+   -- then game stats
+   update player_game_stats
+   set player_id = p_winner_player_id
+   where player_id = p_loser_player_id;
+
+   get diagnostics rowcount = ROW_COUNT;
+   raise notice '% game stat rows updated.', rowcount;
+
+   -- then hashkeys (winner takes the loser's hashkey)
+   update hashkeys
+   set player_id = p_winner_player_id
+   where player_id = p_loser_player_id;
+   
+   get diagnostics rowcount = ROW_COUNT;
+   raise notice '% hashkeys copied.', rowcount;
+
+   -- and finally deactivate the old player record
+   update players set active_ind = false where player_id = p_loser_player_id;
+end;
+$$
+language plpgsql;
\ No newline at end of file