Skip to content

Weird behavior with select case when construct with GET parameter #818

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

Closed
nip1904 opened this issue Feb 20, 2025 · 2 comments · Fixed by #825
Closed

Weird behavior with select case when construct with GET parameter #818

nip1904 opened this issue Feb 20, 2025 · 2 comments · Fixed by #825
Labels
bug Something isn't working mysql MySQL-specific issues sqlite

Comments

@nip1904
Copy link

nip1904 commented Feb 20, 2025

Introduction

If I use select with multiple case when construct I do not get the expected behavior. I tested with severla older versions but it has the same problem. Tried some workaround but this time I have no clue to mitigate the problem.
This is no special problem with one component and testing against a database works as expected.

To Reproduce

List of steps to reproduce the behavior. Include the sql file you are using and the eventual relevant parts of your database schema

select 
    'text'                       as component;
select 
   'The value of y: ' || $y      as contents;
select 
   case 
      when $x = 't1' 
         then 'value of x:  ' || $x || ' - value of y: ' || $y
      when $x = 't2' 
         then 'value of x:  ' || $x || ' - value of y: ' || $y
      else 
         'Unknown'
   end                           as contents,
   TRUE                          as break;
--
select
   'divider' as component;
--
select 
    'text'                       as component;
select 
   'The value of y is ' || $y    as contents;
select 
   case $x
      when 't1' 
         then 'value of x:  ' || $x || ' - value of y: ' || $y
      when 't2'     
         then 'value of x:  ' || $x || ' - value of y: ' || $y
      --when $z = 't3'
      -- then 'text t3: ' || $y
      else 
         'Unknown'
   end                           as contents,
   TRUE                          as break;

--
select
   'divider' as component;
-- 
select
   'debug' as component;
   select $x as x;
   select $y as y;
   --select $z as z;

Actual behavior

Different output - I attache some screenshots

your error message here

Screenshots

Image

Image

Image

Image

Expected behavior

A clear and concise description of what you expected to happen.

Version information

  • OS:
  • Database [e.g. SQLite, Postgres]
  • SQLPage Version [found when hovering the default footer of pages]:

Additional context

Add any other context about the problem here.

@nip1904 nip1904 added the bug Something isn't working label Feb 20, 2025
@lovasoa
Copy link
Collaborator

lovasoa commented Feb 20, 2025

Thanks for the report ! I can confirm the bug and I'll work on it.

Minimal reproduction:

select 
   case 
      when $x = 't1' 
         then 'value of x:  ' || $x || ' - value of y: ' || $y
      when $x = 't2' 
         then 'blah'
   end;

and from the logs:

[2025-02-20T14:45:39.075Z DEBUG sqlpage::webserver::database::execute_queries] Preparing statement: SELECT CASE WHEN CAST(? AS TEXT) = 't1' THEN 'value of x:  ' || CAST(? AS TEXT) || ' - value of y: ' || CAST(? AS TEXT) WHEN CAST(? AS TEXT) = 't2' THEN 'blah' END;
[2025-02-20T14:45:39.075Z DEBUG sqlpage::webserver::database::execute_queries]  parameter 1: t1
[2025-02-20T14:45:39.075Z DEBUG sqlpage::webserver::database::execute_queries]  parameter 2: t1
[2025-02-20T14:45:39.075Z DEBUG sqlpage::webserver::database::execute_queries]  parameter 3: t1
[2025-02-20T14:45:39.075Z DEBUG sqlpage::webserver::database::execute_queries]  parameter 4: debug_test

the order of parameters is incorrect

@lovasoa
Copy link
Collaborator

lovasoa commented Feb 22, 2025

Ok, it was more work than expected, but the issue is finally fixed. Thank you very much for surfacing this issue, @nip1904. It would have been frustratingly hard to debug for final users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mysql MySQL-specific issues sqlite
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants