FSharp.Data.SqlClient
FSharp.Data.SqlClient copied to clipboard
Cannot use parameter name more than once in a script
Issue Summary
When I try to use @assetId twice error is displayed
MERGE INTO [dbo].[AssetName] AS Target
USING (VALUES
(@assetId, 11, @ukrainianName, 5, N'Afroz Yadwad'),
(@assetId, 10, @russianName, 4, N'Afroz Yadwad')
) AS Source ([AssetId],[LanguageId],[InternalName],[OrderBy],[CreatedBy])
ON Target.[AssetId] = Source.[AssetId]
AND Target.[LanguageId] = Source.[LanguageId]
WHEN NOT MATCHED BY TARGET THEN
INSERT ([AssetId],[LanguageId],[InternalName],[OrderBy],[CreatedBy])
VALUES ([AssetId],[LanguageId],[InternalName],[OrderBy],[CreatedBy])
WHEN MATCHED THEN
UPDATE SET TARGET.[InternalName] = Source.[InternalName]
;
Error
Incorrect syntax near 5
Expected behavior
The parameter name is reused and can be referenced more than once
What you can do
- [x] I am willing to contribute a PR with a unit test showcasing the issue
- [x] I am willing to test the bug fix before the next release
I used to use this provider all the time, but it has been years. It cannot be upgraded to dotnet without a lot of work. IIRC there is a workaround, which is to define a new @variable for each time it is used. You can do it within your script. Declare and set the second variable to the original variable submitted to the script.
@xperiandri this is described in question 4 in the faq: https://fsprojects.github.io/FSharp.Data.SqlClient/faq.html and due to how sys.sp_describe_undeclared_parameters works.
I think it also works if you declare the type in TableVarMapping
TableVarMapping = "@assetId=Int"