<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<game format-version="2" db-system="sqlite" db-system-min-version="3.37.0">
    <head>
        <title>One Miserable Night</title>
        <teaser>Please let this night come to an end.

After a blackout, you search for your wallet. It's going to be one miserable night.</teaser>
        <copyright>Sami B.</copyright>
    </head>
    <scenes>
        <text-scene>
            <text>You wake up in a toilet, your pockets are empty, and you can't even remember what happened tonight. Your black wallet with the yellow star is missing.</text>
        </text-scene>
        <text-scene>
            <text>You need to find your wallet (no idea how to spell that). First, check who's in the club.

The database represents this story. Use `SELECT` to read clues and choose people to talk to; use `UPDATE` to transfer items. `SeenAt` and `FoundAt` record observations from the start of the night and stay unchanged even if someone moves later. `Holder` is the `ID` in `People` of the person currently carrying an item, not necessarily the person who owns it. `NULL` means no one is carrying it. You are listed as “You” in `People`.</text>
        </text-scene>
        <select-scene is-row-order-relevant="false" is-col-order-relevant="false" are-col-names-relevant="false">
            <text>Check who's in the club. Show all details for people whose `SeenAt` value is “Club”. The order does not matter.</text>
            <sql-solution>SELECT * FROM People
WHERE SeenAt = 'Club';</sql-solution>
            <sql-placeholder></sql-placeholder>
            <hints>
                <expected-result-hint />
            </hints>
        </select-scene>
        <text-scene>
            <text>The bartender looks trustworthy. Go and talk to him.</text>
        </text-scene>
        <select-scene is-row-order-relevant="false" is-col-order-relevant="false" are-col-names-relevant="false">
            <text>Find the bartender. Show all details for the person whose `Occupation` is “Bartender”.</text>
            <sql-solution>SELECT * FROM People
WHERE Occupation = 'Bartender';</sql-solution>
            <sql-placeholder></sql-placeholder>
            <hints>
                <expected-result-hint />
            </hints>
        </select-scene>
        <text-scene>
            <text>Hey, bartender, where are we, and what happened?</text>
        </text-scene>
        <text-scene>
            <text>Bartender: Looks like you slept well. We're at Club dé Abstúrz, and you really overdid it.
You were hanging out with some shady characters earlier, but they've already gone outside. Maybe someone by the entrance saw where they went.</text>
        </text-scene>
        <text-scene>
            <text>Okay, thanks. I'll take a look outside, then.</text>
        </text-scene>
        <select-scene is-row-order-relevant="false" is-col-order-relevant="false" are-col-names-relevant="false">
            <text>(You're outside now.)
Check who's out on the street. Show all details for people whose `SeenAt` value at the start of the night was “Street”. The order does not matter.</text>
            <sql-solution>SELECT * FROM People
WHERE SeenAt = 'Street';</sql-solution>
            <sql-placeholder></sql-placeholder>
            <hints>
                <expected-result-hint />
            </hints>
        </select-scene>
        <text-scene>
            <text>There's quite a lot going on out here, too. Maybe the homeless man on the bench saw something. He introduces himself as Manuel.</text>
        </text-scene>
        <select-scene is-row-order-relevant="false" is-col-order-relevant="false" are-col-names-relevant="false">
            <text>Find the homeless man. Show all details for Manuel by looking him up by name.</text>
            <sql-solution>SELECT * FROM People
WHERE Name = 'Manuel';</sql-solution>
            <sql-placeholder></sql-placeholder>
            <hints>
                <expected-result-hint />
            </hints>
        </select-scene>
        <text-scene>
            <text>Homeless man: Evening, lad. Got any spare change?</text>
        </text-scene>
        <text-scene>
            <text>No, sorry, my wallet is missing, and I'm trying to work out what happened. Did you happen to see any suspicious-looking people coming out of the club?</text>
        </text-scene>
        <text-scene>
            <text>Homeless man: Hmm, maybe I did.
You know, I could really use a glass bottle to fill with something to drink. An empty, clean one from the roadside would be good. The labelled one belongs to Norbert.</text>
        </text-scene>
        <text-scene>
            <text>Okay, I know what you're after.
Maybe I can find one lying around here.</text>
        </text-scene>
        <select-scene is-row-order-relevant="false" is-col-order-relevant="false" are-col-names-relevant="false">
            <text>Check whether there's a bottle lying around.
Ideally, it shouldn't belong to anyone, so you don't get into trouble. Show all details for glass bottles whose `FoundAt` value is “Street” and which no one is carrying. `Holder` must therefore be `NULL`; the bottle in the club won't do.</text>
            <sql-solution>SELECT * FROM Items
WHERE Name = 'Glass bottle'
  AND FoundAt = 'Street'
  AND Holder IS NULL;</sql-solution>
            <sql-placeholder></sql-placeholder>
            <hints>
                <expected-result-hint />
                <text-hint>Check for missing holders with `IS NULL`, not `= NULL`. Combine the conditions with `AND`.</text-hint>
            </hints>
        </select-scene>
        <text-scene>
            <text>Perfect, I'll take that one. Remember its item ID: several items can have the same name.</text>
        </text-scene>
        <manipulate-scene>
            <text>Pick up only the bottle you just found. Use `UPDATE` to set its `Holder` to your person ID, 9. Use `WHERE` to limit the change to this bottle's `ID`; all other items must remain unchanged.</text>
            <sql-solution>UPDATE Items
SET Holder = 9
WHERE ID = 5 AND Holder IS NULL;</sql-solution>
            <sql-check>SELECT * FROM Items;</sql-check>
            <sql-placeholder></sql-placeholder>
            <hints>
                <expected-result-hint />
                <text-hint>The template is: `UPDATE table_name SET column_name = value WHERE condition;` Use the person ID in `SET` and the item ID in `WHERE`.</text-hint>
            </hints>
        </manipulate-scene>
        <select-scene is-row-order-relevant="false" is-col-order-relevant="false" are-col-names-relevant="false">
            <text>Take the bottle to the homeless man. First, look up Manuel by name in `People` and show only his `ID`. You'll need this person ID to hand over the bottle.</text>
            <sql-solution>SELECT ID FROM People
WHERE Name = 'Manuel';</sql-solution>
            <sql-placeholder></sql-placeholder>
            <hints>
                <expected-result-hint />
            </hints>
        </select-scene>
        <manipulate-scene>
            <text>Here you go, here's the bottle. Give Manuel the bottle you just picked up: use `UPDATE` to set its `Holder` to the person ID you found for him. Use the item ID again and change nothing else.</text>
            <sql-solution>UPDATE Items
SET Holder = 6
WHERE ID = 5 AND Holder = 9;</sql-solution>
            <sql-check>SELECT * FROM Items;</sql-check>
            <sql-placeholder></sql-placeholder>
            <hints>
                <expected-result-hint />
            </hints>
        </manipulate-scene>
        <text-scene>
            <text>Homeless man: Thanks a lot. You know, those mobsters or gangsters hurried off that way earlier, into the side alley. Their names are Berndt and Peter. One of them was holding a black wallet.</text>
        </text-scene>
        <text-scene>
            <text>You run in the direction the homeless man pointed and soon come across two figures. One is holding a black wallet with a yellow star. It looks exactly like yours.</text>
        </text-scene>
        <select-scene is-row-order-relevant="false" is-col-order-relevant="false" are-col-names-relevant="false">
            <text>Check them out. Show your wallet's `ID` and `Description`, along with the `Name` of the person carrying it. Its `Name` in `Items` is “Wallet”, and its `Description` is “Black with a yellow star”. Use `JOIN` to connect `Items` and `People` through `Items.Holder = People.ID`.</text>
            <sql-solution>SELECT Items.ID, Items.Description, People.Name
FROM Items
JOIN People ON Items.Holder = People.ID
WHERE Items.Name = 'Wallet'
  AND Items.Description = 'Black with a yellow star';</sql-solution>
            <sql-placeholder></sql-placeholder>
            <hints>
                <expected-result-hint />
                <text-hint>The join condition comes after `ON`. Both tables have `ID` and `Name` columns; qualify these columns with the table name.</text-hint>
            </hints>
        </select-scene>
        <text-scene>
            <text>You hear them talking about how they robbed you, and you decide to step in. Berndt has your wallet. There's a baseball bat next to you. In your anger, you think you'd better take it along.</text>
        </text-scene>
        <manipulate-scene>
            <text>Pick up the baseball bat. Use `UPDATE` to set its `Holder` to your person ID, 9. Use its `Name`, the `FoundAt` value “Side alley”, and its current `Holder` value of `NULL` to change only this item.</text>
            <sql-solution>UPDATE Items
SET Holder = 9
WHERE Name = 'Baseball bat'
  AND FoundAt = 'Side alley'
  AND Holder IS NULL;</sql-solution>
            <sql-check>SELECT * FROM Items;</sql-check>
            <sql-placeholder></sql-placeholder>
            <hints>
                <expected-result-hint />
            </hints>
        </manipulate-scene>
        <text-scene>
            <text>You walk up to them and demand your wallet back.
BUT ONE OF THEM PULLS OUT A WEAPON AND CLOBBERS YOU OVER THE HEAD!</text>
        </text-scene>
        <text-scene>
            <text>YOU wake up in hospital, without your wallet and with a lump on your head.
Not every ending is a happy one.</text>
        </text-scene>
    </scenes>
    <initial-sql-script>PRAGMA foreign_keys = ON;
BEGIN TRANSACTION;
CREATE TABLE Places (
    Name TEXT PRIMARY KEY NOT NULL
);
INSERT INTO Places (Name) VALUES ('Club'), ('Street'), ('Side alley');

CREATE TABLE People (
    ID INTEGER PRIMARY KEY,
    Name TEXT NOT NULL,
    Occupation TEXT,
    Money INTEGER NOT NULL CHECK (typeof(Money) = 'integer' AND Money &gt;= 0),
    SeenAt TEXT NOT NULL REFERENCES Places (Name)
);
INSERT INTO People (ID, Name, Occupation, Money, SeenAt) VALUES
    (2, 'Berndt', NULL, 100, 'Street'),
    (3, 'Robert', 'Bouncer', 21, 'Club'),
    (4, 'Norbert', 'Bartender', 0, 'Club'),
    (5, 'Peter', NULL, 100, 'Street'),
    (6, 'Manuel', NULL, 0, 'Street'),
    (7, 'Hendrok', 'Office clerk', 5600, 'Street'),
    (8, 'Roman', 'Police officer', 0, 'Street'),
    (9, 'You', NULL, 0, 'Club');

CREATE TABLE Items (
    ID INTEGER PRIMARY KEY,
    Name TEXT NOT NULL,
    Description TEXT NOT NULL,
    Holder INTEGER REFERENCES People (ID),
    FoundAt TEXT NOT NULL REFERENCES Places (Name)
);
INSERT INTO Items (ID, Name, Description, Holder, FoundAt) VALUES
    (1, 'Knife', 'Small pocket knife', NULL, 'Street'),
    (2, 'Pistol', 'Service weapon', 8, 'Street'),
    (3, 'Rifle', 'Rifle with a wooden stock', 2, 'Street'),
    (4, 'Baseball bat', 'Worn wooden bat', NULL, 'Side alley'),
    (5, 'Glass bottle', 'Empty, clean and unlabelled', NULL, 'Street'),
    (6, 'Glass bottle', 'Labelled with Norbert''s name', 4, 'Street'),
    (7, 'Glass bottle', 'Empty bottle next to the dance floor', NULL, 'Club'),
    (8, 'Wallet', 'Black with a yellow star', 2, 'Street'),
    (9, 'Wallet', 'Brown with no sticker', 7, 'Street');
COMMIT;</initial-sql-script>
</game>
