From e0fac05dc599cfd0df43965232995a0ff04264ca Mon Sep 17 00:00:00 2001 From: ppom <> Date: Tue, 29 Apr 2025 12:00:00 +0200 Subject: [PATCH] Fix SQLite examples having PostgreSQL :: syntax According to discussion here https://github.com/sqlpage/SQLPage/pull/897#issuecomment-2835516830 --- examples/corporate-conundrum/game.sql | 10 +++++----- examples/corporate-conundrum/wait.sql | 18 +++++++++--------- examples/plots tables and forms/index.sql | 4 ++-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/examples/corporate-conundrum/game.sql b/examples/corporate-conundrum/game.sql index 9c8976d2..ab620aa9 100644 --- a/examples/corporate-conundrum/game.sql +++ b/examples/corporate-conundrum/game.sql @@ -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, @@ -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 -- --------------------------- @@ -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 @@ -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; \ No newline at end of file +LIMIT 1; diff --git a/examples/corporate-conundrum/wait.sql b/examples/corporate-conundrum/wait.sql index 8880ef05..c6124823 100644 --- a/examples/corporate-conundrum/wait.sql +++ b/examples/corporate-conundrum/wait.sql @@ -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, @@ -11,10 +11,10 @@ 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, @@ -22,11 +22,11 @@ SELECT 'text' as component, 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 - ); \ No newline at end of file + AND answers.question_id = CAST($question_id AS INTEGER) + ); diff --git a/examples/plots tables and forms/index.sql b/examples/plots tables and forms/index.sql index df12e84b..0a41f0a3 100644 --- a/examples/plots tables and forms/index.sql +++ b/examples/plots tables and forms/index.sql @@ -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 --------------------------- @@ -164,4 +164,4 @@ select 'checkbox' as type, select 'debug' as component; select $x as x, :"First Name" as firstName, - :checks as checks; \ No newline at end of file + :checks as checks;