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

makeDecl for a nil value needs to use the original type #130

Open
shueybubbles opened this issue Jul 14, 2023 · 0 comments
Open

makeDecl for a nil value needs to use the original type #130

shueybubbles opened this issue Jul 14, 2023 · 0 comments
Labels
Always Encrypted Tasks related to implementation of AE

Comments

@shueybubbles
Copy link
Collaborator

This code path in makeParam is being hit because CheckNamedValue sends the sql.Nullable* type instances to convertInputParameter

func convertInputParameter(val interface{}) (interface{}, error) {
	switch v := val.(type) {
	case int, int16, int32, int64, int8:
		return val, nil
	case byte:
		return val, nil
	case VarChar:
		return val, nil
	case NVarCharMax:
		return val, nil
	case VarCharMax:
		return val, nil
	case NChar:
		return val, nil
	case DateTime1:
		return val, nil
	case DateTimeOffset:
		return val, nil
	case civil.Date:
		return val, nil
	case civil.DateTime:
		return val, nil
	case civil.Time:
		return val, nil
	// case *apd.Decimal:
	// 	return nil
	case float32:
		return val, nil
	default:
		return driver.DefaultParameterConverter.ConvertValue(v)
	}
}

The DefaultParameterConverter just returns nil so we lost the type information. If the value implements driver.Valuer it should be preserved when it has a nil value so makeParam can use it.

func (s *Stmt) makeParam(val driver.Value) (res param, err error) {
	if val == nil {
		res.ti.TypeId = typeNull
		res.buffer = nil
		res.ti.Size = 0
		return
	}
...
func makeDecl(ti typeInfo) string {
	switch ti.TypeId {
	case typeNull:
		// maybe we should use something else here
		// this is tested in TestNull
		return "nvarchar(1)"

makeParam should

@shueybubbles shueybubbles added this to the Always Encrypted P2 milestone Jul 14, 2023
@dlevy-msft dlevy-msft added the Always Encrypted Tasks related to implementation of AE label Aug 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Always Encrypted Tasks related to implementation of AE
Projects
None yet
Development

No branches or pull requests

2 participants