Skip to content

Commit f205b65

Browse files
authored
Fix SQLite examples having PostgreSQL :: syntax (#903)
According to discussion here #897 (comment) Co-authored-by: ppom <>
1 parent b05316d commit f205b65

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

examples/corporate-conundrum/game.sql

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ select * FROM sqlpage_shell;
33
-- Display the list of players with a link for each one to start playing
44
INSERT INTO players(name, game_id)
55
SELECT $Player as name,
6-
$id::integer as game_id
6+
CAST($id AS INTEGER) as game_id
77
WHERE $Player IS NOT NULL;
88

99
SELECT 'list' as component,
@@ -17,7 +17,7 @@ SELECT name as title,
1717
)
1818
) as link
1919
FROM players
20-
WHERE game_id = $id::integer;
20+
WHERE game_id = CAST($id AS INTEGER);
2121
---------------------------
2222
-- Player insertion form --
2323
---------------------------
@@ -35,7 +35,7 @@ INSERT INTO game_questions(
3535
impostor,
3636
game_order
3737
)
38-
SELECT $id::integer as game_id,
38+
SELECT CAST($id AS INTEGER) as game_id,
3939
questions.id as question_id,
4040
-- When the true answer is small, set the wrong answer to just +/- 1, otherwise -25%/+75%.
4141
-- When it is a date between 1200 and 2100, make it -25 % or +75 % of the distance to today
@@ -50,8 +50,8 @@ SELECT $id::integer as game_id,
5050
random() as game_order
5151
FROM questions
5252
LEFT JOIN game_questions ON questions.id = game_questions.question_id
53-
AND game_questions.game_id = $id::integer
53+
AND game_questions.game_id = CAST($id AS INTEGER)
5454
WHERE game_questions.question_id IS NULL
5555
AND $Player IS NOT NULL
5656
ORDER BY random()
57-
LIMIT 1;
57+
LIMIT 1;

examples/corporate-conundrum/wait.sql

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
-- Redirect to the next question when all players have answered
22
set page_params = json_object('game_id', $game_id, 'player', $player);
33
select CASE
4-
(SELECT count(*) FROM answers WHERE question_id = $question_id AND game_id = $game_id::integer)
5-
WHEN (SELECT count(*) FROM players WHERE game_id = $game_id::integer)
4+
(SELECT count(*) FROM answers WHERE question_id = $question_id AND game_id = CAST($game_id AS INTEGER))
5+
WHEN (SELECT count(*) FROM players WHERE game_id = CAST($game_id AS INTEGER))
66
THEN '0; ' || sqlpage.link('next-question.sql', $page_params)
77
ELSE 3
88
END as refresh,
@@ -11,22 +11,22 @@ FROM sqlpage_shell;
1111

1212
-- Insert the answer into the answers table
1313
INSERT INTO answers(game_id, player_name, question_id, answer_value)
14-
SELECT $game_id::integer as game_id,
14+
SELECT CAST($game_id AS INTEGER) as game_id,
1515
$player as player_name,
16-
$question_id::integer as question_id,
17-
$answer::integer as answer_value
16+
CAST($question_id AS INTEGER) as question_id,
17+
CAST($answer AS INTEGER) as answer_value
1818
WHERE $answer IS NOT NULL;
1919
-- Redirect to the next question
2020
SELECT 'text' as component,
2121
'Waiting for other players to answer... The following players still have not answered: ' as contents;
2222
select group_concat(name, ', ') as contents,
2323
TRUE as bold
2424
from players
25-
where game_id = $game_id::integer
25+
where game_id = CAST($game_id AS INTEGER)
2626
and not EXISTS (
2727
SELECT 1
2828
FROM answers
29-
WHERE answers.game_id = $game_id::integer
29+
WHERE answers.game_id = CAST($game_id AS INTEGER)
3030
AND answers.player_name = players.name
31-
AND answers.question_id = $question_id::integer
32-
);
31+
AND answers.question_id = CAST($question_id AS INTEGER)
32+
);

examples/plots tables and forms/index.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ FROM nums as a, nums as b
112112
WHERE -- The powerful thing is here
113113
$x IS NULL
114114
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='
115-
b.x = $x::DECIMAL
115+
b.x = CAST($x AS DECIMAL)
116116
ORDER BY a.x, b.x;
117117
-- So when we click the card for "a times b", we will reload the page, and display only the multiplication table of a
118118
---------------------------
@@ -164,4 +164,4 @@ select 'checkbox' as type,
164164
select 'debug' as component;
165165
select $x as x,
166166
:"First Name" as firstName,
167-
:checks as checks;
167+
:checks as checks;

0 commit comments

Comments
 (0)