Skip to content

Fix SQLite examples having PostgreSQL :: syntax #903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions examples/corporate-conundrum/game.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ select * FROM sqlpage_shell;
-- Display the list of players with a link for each one to start playing
INSERT INTO players(name, game_id)
SELECT $Player as name,
$id::integer as game_id
CAST($id AS INTEGER) as game_id
WHERE $Player IS NOT NULL;

SELECT 'list' as component,
Expand All @@ -17,7 +17,7 @@ SELECT name as title,
)
) as link
FROM players
WHERE game_id = $id::integer;
WHERE game_id = CAST($id AS INTEGER);
---------------------------
-- Player insertion form --
---------------------------
Expand All @@ -35,7 +35,7 @@ INSERT INTO game_questions(
impostor,
game_order
)
SELECT $id::integer as game_id,
SELECT CAST($id AS INTEGER) as game_id,
questions.id as question_id,
-- When the true answer is small, set the wrong answer to just +/- 1, otherwise -25%/+75%.
-- When it is a date between 1200 and 2100, make it -25 % or +75 % of the distance to today
Expand All @@ -50,8 +50,8 @@ SELECT $id::integer as game_id,
random() as game_order
FROM questions
LEFT JOIN game_questions ON questions.id = game_questions.question_id
AND game_questions.game_id = $id::integer
AND game_questions.game_id = CAST($id AS INTEGER)
WHERE game_questions.question_id IS NULL
AND $Player IS NOT NULL
ORDER BY random()
LIMIT 1;
LIMIT 1;
18 changes: 9 additions & 9 deletions examples/corporate-conundrum/wait.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
-- Redirect to the next question when all players have answered
set page_params = json_object('game_id', $game_id, 'player', $player);
select CASE
(SELECT count(*) FROM answers WHERE question_id = $question_id AND game_id = $game_id::integer)
WHEN (SELECT count(*) FROM players WHERE game_id = $game_id::integer)
(SELECT count(*) FROM answers WHERE question_id = $question_id AND game_id = CAST($game_id AS INTEGER))
WHEN (SELECT count(*) FROM players WHERE game_id = CAST($game_id AS INTEGER))
THEN '0; ' || sqlpage.link('next-question.sql', $page_params)
ELSE 3
END as refresh,
Expand All @@ -11,22 +11,22 @@ FROM sqlpage_shell;

-- Insert the answer into the answers table
INSERT INTO answers(game_id, player_name, question_id, answer_value)
SELECT $game_id::integer as game_id,
SELECT CAST($game_id AS INTEGER) as game_id,
$player as player_name,
$question_id::integer as question_id,
$answer::integer as answer_value
CAST($question_id AS INTEGER) as question_id,
CAST($answer AS INTEGER) as answer_value
WHERE $answer IS NOT NULL;
-- Redirect to the next question
SELECT 'text' as component,
'Waiting for other players to answer... The following players still have not answered: ' as contents;
select group_concat(name, ', ') as contents,
TRUE as bold
from players
where game_id = $game_id::integer
where game_id = CAST($game_id AS INTEGER)
and not EXISTS (
SELECT 1
FROM answers
WHERE answers.game_id = $game_id::integer
WHERE answers.game_id = CAST($game_id AS INTEGER)
AND answers.player_name = players.name
AND answers.question_id = $question_id::integer
);
AND answers.question_id = CAST($question_id AS INTEGER)
);
4 changes: 2 additions & 2 deletions examples/plots tables and forms/index.sql
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ FROM nums as a, nums as b
WHERE -- The powerful thing is here
$x IS NULL
OR -- The syntax $x allows us to extract the value 'a' when the URL ends with '?x=a'. It will be null if the URL does not contain '?x='
b.x = $x::DECIMAL
b.x = CAST($x AS DECIMAL)
ORDER BY a.x, b.x;
-- So when we click the card for "a times b", we will reload the page, and display only the multiplication table of a
---------------------------
Expand Down Expand Up @@ -164,4 +164,4 @@ select 'checkbox' as type,
select 'debug' as component;
select $x as x,
:"First Name" as firstName,
:checks as checks;
:checks as checks;
Loading