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

Issue with bigint unsigned Support for MySQL #352

Open
korECM opened this issue Feb 6, 2025 · 1 comment
Open

Issue with bigint unsigned Support for MySQL #352

korECM opened this issue Feb 6, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@korECM
Copy link

korECM commented Feb 6, 2025

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!

@korECM
Copy link
Author

korECM commented Feb 6, 2025

I am aware that Go's driver does not support uint64, but the go-mysql-driver supports uint64. Is there any way in bob to handle this issue properly?

@stephenafamo stephenafamo added the enhancement New feature or request label Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants