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

Can't pass null to a SP #15

Closed
isaacabraham opened this issue Apr 16, 2021 · 2 comments
Closed

Can't pass null to a SP #15

isaacabraham opened this issue Apr 16, 2021 · 2 comments

Comments

@isaacabraham
Copy link

I have an SP which expects a string as a parameter, but this parameter may be null:

let parameters = {| Foo = 123; OptionalString = Unchecked.defaultof<string> |}
let res = DbGen.Procedures.Schema.MySp.WithConnection(conn).WithParameters(parameters).Execute()

This goes pop:

Procedure or function 'MySp' expects parameter '@optionalString', which was not supplied.

I've tried e.g. null :> string and other things but it just gets ignored. If I supply a string, the SP correctly fires.

@cmeeren
Copy link
Owner

cmeeren commented Apr 16, 2021

See the readme for how nullability is handled.

In short, if your sproc parameter is defined as @optionalString = NULL, then it will be string option in F#, and you then use None to pass null. This is the only supported way of passing null to sprocs.

For scripts, it is possible to use Facil.yaml to explicitly specify whether parameters are nullable. (This is also generally necessary, since script parameter inference is limited). This is currently not possible for procedures. I realize now that this is fairly limiting; one does not always control the sproc definition, and it is not guaranteed that all nullable parameters are defined with NULL as the default value in the sproc parameter list.

I will implement the ability to override nulls for sproc parameters just like for script parameters.

@cmeeren
Copy link
Owner

cmeeren commented Apr 16, 2021

Releasing in v1.4.0 which is in the pipeline now.

@cmeeren cmeeren closed this as completed Apr 16, 2021
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

No branches or pull requests

2 participants