Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Sorry for such messy code - i'm at work = no much time, but should help You. You have to add data into tables: USERS and SOFTWARE. There was problem with NULL handling, and passing query result into variable.</p> <p>EDIT: fix for query "get the id of the just inserted tuple"</p> <pre><code>DELIMITER $$ DROP PROCEDURE IF EXISTS `ChallengeUser`$$ CREATE DEFINER=`root`@`localhost` PROCEDURE `ChallengeUser`( challengedUserID INT, currentUserID INT, startedGamePlayerUsername VARCHAR(255), startedGameID INT, incorrectID INT, alreadyChallengedPlayer INT, alreadyChallengedGameID INT ) BEGIN DECLARE TMP_ID INT DEFAULT 0; DECLARE TMP_W_PLAYER INT DEFAULT 0; DECLARE TMP_B_PLAYER INT DEFAULT 0; SELECT `username` INTO startedGamePlayerUsername FROM chess_users WHERE `user_id` = challengedUserID AND `user_id` != currentUserID LIMIT 1; IF startedGamePlayerUsername IS NOT NULL THEN SELECT `id` INTO TMP_ID FROM `chess_games` WHERE `whiteUserID` = currentUserID AND `blackUserID` = challengedUserID AND `outcome` = -1 LIMIT 1; -- here was bad NULL handling IF TMP_ID IS NULL OR TMP_ID='' THEN SELECT `softwareID` INTO TMP_W_PLAYER FROM chess_users WHERE `user_id`=currentUserID LIMIT 1; SELECT `softwareID` INTO TMP_B_PLAYER FROM chess_users WHERE `user_id`=challengedUserID LIMIT 1; INSERT INTO `chess_games` (`tournamentID`, `whiteUserID`,`blackUserID`, `whitePlayerSoftwareID`,`blackPlayerSoftwareID`, `moveList`) SELECT NULL, currentUserID, challengedUserID, TMP_W_PLAYER, TMP_B_PLAYER, ""; /* Get the id of the just inserted tuple */ SELECT max(`id`) INTO startedGameID FROM chess_games WHERE `whiteUserID` = currentUserID AND `blackUserID` = challengedUserID AND `whitePlayerSoftwareID` = TMP_W_PLAYER AND `blackPlayerSoftwareID` = TMP_B_PLAYER AND `moveList` = ""; ELSE SET alreadyChallengedPlayer = 1; SET alreadyChallengedGameID = TMP_ID; END IF; ELSE SET incorrectID = 1; END IF; SELECT startedGamePlayerUsername,startedGameID, incorrectID , alreadyChallengedPlayer , alreadyChallengedGameID; END$$ DELIMITER ; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload