Skip to content

Issue with bigint unsigned Support for MySQL #352

Open
@korECM

Description

@korECM

Hi,

I've encountered an issue when working with the bob library. It appears that the conversion of uint64 to int64 in the following code is causing problems when handling MySQL's unsigned bigint type (defined as bigint unsigned null):

// aarondl/opt

func ToDriverValue(val any) (driver.Value, error) {
	refVal := reflect.ValueOf(val)
	if refVal.Type().Implements(globaldata.DriverValuerIntf) {
		valuer := refVal.Interface().(driver.Valuer)
		return valuer.Value()
	}

	// If it is of time.Time type, return it as is.
	if refVal.Type() == globaldata.TimeType {
		return val, nil
	}

	// If it implements encoding.TextMarshaler, use that.
	if refVal.Type().Implements(globaldata.EncodingTextMarshalerIntf) {
		marshaler := refVal.Interface().(encoding.TextMarshaler)
		return marshaler.MarshalText()
	}

	// If it implements encoding.BinaryMarshaler, use that.
	if refVal.Type().Implements(globaldata.EncodingBinaryMarshalerIntf) {
		marshaler := refVal.Interface().(encoding.BinaryMarshaler)
		return marshaler.MarshalBinary()
	}

	switch refVal.Kind() {
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		return refVal.Int(), nil
	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
		// Problem appears to originate from converting uint64 to int64.
		return int64(refVal.Uint()), nil
	case reflect.Float32, reflect.Float64:
		return refVal.Float(), nil
	case reflect.Bool:
		return refVal.Bool(), nil
	case reflect.Slice:
		if refVal.Type().Elem().Kind() == reflect.Uint8 {
			return refVal.Bytes(), nil
		}
	case reflect.String:
		return refVal.String(), nil
	}

	return val, nil
}

Could you confirm if this behavior is indeed a bug? Additionally, is there a temporary workaround available to resolve the issue with unsigned bigint support?

Thanks for your help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions