Skip to content
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

[BUG] MSSQL Safe SQL Parameter Not Working #3799

Open
1 of 3 tasks
alexwijoyo opened this issue Jul 16, 2024 · 6 comments
Open
1 of 3 tasks

[BUG] MSSQL Safe SQL Parameter Not Working #3799

alexwijoyo opened this issue Jul 16, 2024 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@alexwijoyo
Copy link

Description

When I run query using safe SQL parameter, I got Incorrect syntax near '?'.

Steps to reproduce

  1. Create Safe parameterized select statement using MSSQL Resource
  2. Click on Save
  3. Clic on Run
  4. You will get run action error: mssql: Incorrect syntax near '?'.
  5. Sent SQL:
    exec sp_executesql N'select der.*
    from DailyExchangeRate der
    where der.SrcCurrencyId<>''USD'' and
    Date between ? and ?',N'@p1 nvarchar(max),@p2 nvarchar(max)',@p1=N'',@p2=N''
  6. Should be:
    exec sp_executesql N'select der.*
    from DailyExchangeRate der
    where der.SrcCurrencyId<>''USD'' and
    Date between @p1 and @p2',N'@p1 nvarchar(10),@p2 nvarchar(10)',@p1=N'2024-03-01',@p2=N'2024-07-31'

Version

self-host

ILLA Builder Version

latest

Browser

No response

Operating System

  • macOS
  • Windows
  • Linux

Additional Information

No response

@alexwijoyo alexwijoyo added the bug Something isn't working label Jul 16, 2024
@naj1n
Copy link
Contributor

naj1n commented Jul 16, 2024

This is an example provided by the third-party library the illa-builder is using: https://github.com/microsoft/go-mssqldb?tab=readme-ov-file#parameters. The ? is not supported as a parameter placeholder.

@alexwijoyo
Copy link
Author

@naj1n the problem is because illa-builder send the query using positional ? parameter placeholder not named parameter such as @p1. Please read my step 5 & 6. That a trace from sql server profiler.

@naj1n
Copy link
Contributor

naj1n commented Jul 16, 2024

According to the code comments at https://github.com/illacloud/builder-backend/blob/8664551df998df0fe2711b51d6ef8e439fa8b2d5/src/utils/parser/sql/escaper.go#L371, changes need to be made in the way SQL is written.

@alexwijoyo
Copy link
Author

@naj1n ,
How should I rewrite my sql:
select der.* from DailyExchangeRate der where der.SrcCurrencyId<>'USD' and Date between '{{dtrDer.value[0]}}' and '{{dtrDer.value[1]}}'

@alexwijoyo
Copy link
Author

@naj1n ,
Any progress about this?

@naj1n
Copy link
Contributor

naj1n commented Jul 23, 2024

I will try to run some tests and will update here with any progress.

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

No branches or pull requests

3 participants