Skip to content

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

Open
@shueybubbles

Description

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Always EncryptedTasks related to implementation of AE

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions