fsprojects / fsprojects/FSharp.Data.SqlClient

Fixed length binary columns in user defined table types fail when constructed

Open
#413 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
F#
Stars
206
Forks
66
PR merge metrics
No merged PRs in 30d

Description

Issue Summary

When using a user defined table type with a fixed length binary column the wrong constructor for SqlMetaData is used resulting in the following exception.

System.ArgumentException: 'The dbType Binary is invalid for this constructor.'

This line looks like it's causing the issue, which incorrectly assumes if it is a fixed length that it can safely use the two parameter constructor:

https://github.com/fsprojects/FSharp.Data.SqlClient/blob/0bc5129586512316570da1f27e588287d7e8be35/src/SqlClient.DesignTime/DesignTime.fs#L544

To Reproduce
  1. Create a custom table type
CREATE TYPE [dbo].[CustomTableType] AS TABLE(
	[Value] [binary](16)
)
  1. Use the type in a query
type StaticProvider =
    SqlCommandProvider<"
        Declare @Updates as CustomTableType = @Inputs;
    " , staticConnectionString>

use cmd = new StaticProvider(context.connection, transaction = context.transaction)
cmd.AsyncExecute(
    data.inputs
    |> List.map(fun x ->
        StaticProvider.CustomTableType( // <--- Error in constructor
            Value = x.value
        )
    )
Error
System.ArgumentException: 'The dbType Binary is invalid for this constructor.'
Expected behavior

There should not be an error in this case.

What you can do
  • I am willing to contribute a PR with a unit test showcasing the issue
  • I am willing to test the bug fix before next release

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading src/SqlClient.DesignTime/DesignTime.fs around line 544 and reproduce the supplied custom table type using a binary(16) column. Add a regression unit test for constructing the generated table-type value, then verify that it completes without the reported SqlMetaData constructor exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
fsharp, sql
Domain
databases
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.