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

SqlServer GetLiteralLimit corrupts query if it query consists of multiple parts #330

Open
GoogleCodeExporter opened this issue Apr 24, 2015 · 0 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. Create query with where statement, in which a variable is used
2. Add Skip() and Take() to force calling GetLiteralLimit method
3. Print resultant query

What is the expected output? What do you see instead?
EXPECTED:

SELECT *
FROM (
    SELECT [field1], [field2]
    ROW_NUMBER() OVER(ORDER BY [field1], [field2]
) AS [__ROW_NUMBER]
    FROM [dbo].[Table]
WHERE ([field1] LIKE @variable)    ) AS [t0]
WHERE [__ROW_NUMBER] BETWEEN 0+1 AND 0+10
ORDER BY [__ROW_NUMBER]

INSTEAD:
SELECT *
FROM (
    SELECT [field1], [field2]
    ROW_NUMBER() OVER(ORDER BY [field1], [field2]
) AS [__ROW_NUMBER]
    FROM [dbo].[Table]
WHERE ([field1] LIKE     ) AS [t0]
WHERE [__ROW_NUMBER] BETWEEN 0+1 AND 0+10
ORDER BY [__ROW_NUMBER]

-- Note That after LIKE everything is missing from the original query

What version of the product are you using? On what operating system?
DbLinq 0.19
Ubuntu Linux OS

Please provide any additional information below.

I have traced the problem to GetLiteralLimit function in svn/  trunk/ src/ 
DbLinq.SqlServer/ SqlServerSqlProvider.cs

It recieves SqlStatement select, but instead of using the whole resulting query 
only uses select[0].Sql
In my example select[0] would be whole query till first @variable, and the 
@variable itself is in select[1] which is just never used in returned statement.

Easy fix is replace every "select[0].Sql" with "select.ToString()" then the 
result is correct.

Original issue reported on code.google.com by kris...@gmail.com on 7 Mar 2012 at 2:28

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant