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

Fix query with lots of nullable columns creating stack overflow #10

Merged
merged 6 commits into from
Feb 15, 2021

Conversation

davidtme
Copy link
Contributor

This is a test for #9

src/DbTests/SQL/MenyColumns.sql Outdated Show resolved Hide resolved
src/DbTests/ExecuteTests.fs Outdated Show resolved Hide resolved
src/DbTests/ExecuteTests.fs Outdated Show resolved Hide resolved
src/DbTests/facil.yaml Outdated Show resolved Hide resolved
Split out read
@davidtme davidtme changed the title Add test to create stack overflow Fix query with lots of nullable columns creating stack overflow Feb 15, 2021
@@ -0,0 +1,601 @@
SELECT
Copy link
Owner

@cmeeren cmeeren Feb 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you replace this script with the following, which does the same in a lot fewer lines?

DECLARE @numCols INT = 600
DECLARE @sql NVARCHAR(MAX) = 'SELECT '

DECLARE @colNo INT = 1

WHILE (@colNo <= @numCols)
BEGIN
  SET @sql += 'Column' + CAST(@colNo AS NVARCHAR) + ' = NULL' + CASE @colNo WHEN @numCols THEN '' ELSE ', ' END
  SET @colNo += 1
END

EXEC sp_executesql @sql

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code swapped out

@@ -192,6 +192,8 @@ rulesets:
tvp:
type: dbo.SingleColNonNull

- for: ManyColumns.sql
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty for has no effect, this can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

yield! indent [
for c in cols do
if c.IsNullable then
$"let ``value_{c.Name.Value}`` = if reader.IsDBNull ``ordinal_{c.Name.Value}`` then {outOptionNone} else reader.{c.TypeInfo.SqlDataReaderGetMethodName} ``ordinal_{c.Name.Value}`` |> {outOptionSome}"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any point to prefixing with value_? If not, I suggest removing the prefix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value_ has been removed

@davidtme
Copy link
Contributor Author

I think there could be some other places let getItem is rendered so I'll update them

@davidtme davidtme changed the title Fix query with lots of nullable columns creating stack overflow [WIP] Fix query with lots of nullable columns creating stack overflow Feb 15, 2021
@davidtme
Copy link
Contributor Author

davidtme commented Feb 15, 2021

@cmeeren I have run the code gen on my project that was throwing the stack overflow and it now works :)

@davidtme davidtme changed the title [WIP] Fix query with lots of nullable columns creating stack overflow Fix query with lots of nullable columns creating stack overflow Feb 15, 2021
@cmeeren cmeeren merged commit c051e17 into cmeeren:master Feb 15, 2021
@cmeeren
Copy link
Owner

cmeeren commented Feb 15, 2021

Thanks a lot!

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

Successfully merging this pull request may close these issues.

None yet

2 participants