-- THis is a debbuging sql script to test queries for real in SQLite
-- without using Adminer in case there is some parsing issues with the tool.
-- Adminer's errors are not clear

UPDATE holding SET quantity = quantity + 1000,
cost = cost + 1 * (SELECT stock.current_price FROM stock WHERE fk_stock = 4)
WHERE fk_player = ( SELECT fk_active_player FROM game) AND fk_stock = 4;

/*
DROP TRIGGER IF EXISTS log_roll_dice;

CREATE TRIGGER log_roll_dice
AFTER INSERT ON roll
BEGIN
   INSERT INTO log (turn, fk_player, message)
   SELECT
        g.turn_number,
        g.fk_active_player,
        ( 'Roll: ' || stock.code || ' ' ||
        CASE NEW.move WHEN -1 THEN 'DOWN' WHEN 0 THEN 'DIV' WHEN 1 THEN 'UP' END
        || ' ' || NEW.number )
   FROM game g
   JOIN stock ON NEW.fk_stock = stock.pk;
END;
*/
/*WITH SELECT fk_event_triggered FROM game
UPDATE player
SET fk_event = NULL
WHERE fk_event_triggered IS NOT NULL
AND fk_event_triggered = fk_event;
*/
--UPDATE stock
--SET current_price = current_price + 20
--WHERE stock.pk % 2 = 0;

--UPDATE holding SET quantity = quantity + 2500 WHERE fk_player = 3 AND fk_stock = 3;
--UPDATE holding SET quantity = quantity + 1000 WHERE fk_player = 1 AND fk_stock = 1;
--UPDATE holding SET quantity = quantity - 2000 WHERE fk_player = 2 AND fk_stock = 2;

-- reset and reassign to trigger update.
--UPDATE stock SET isdivpaid = 'N';
--UPDATE stock SET isdivpaid = 'Y' WHERE pk = 2;
--UPDATE stock SET isdivpaid = 'Y' WHERE pk = 5;

DELETE FROM roll;
INSERT INTO roll ( fk_stock, move, number)
VALUES
(5, 1, 20), -- GOLD UP 20
(0, -1, 5), -- GRAIN DOWN 5
(2, 0, 10); -- BONDS DIV 10

SELECT * FROM log;
