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

mysql: Fix GetInt() with negative NEWDECIMAL result #972

Merged
merged 2 commits into from
Jan 20, 2025

Conversation

dveeden
Copy link
Collaborator

@dveeden dveeden commented Jan 19, 2025

Example code:

package main

import (
	"github.com/go-mysql-org/go-mysql/client"
)

func main() {
	conn, _ := client.Connect("127.0.0.1:3307", "root", "", "test")
	r, _ := conn.Execute(`SELECT SUM(-1)`)
	v, err := r.GetInt(0, 0)
	if err != nil {
		panic(err)
	}
	println(v)
}

Without this PR:

$ go run main.go 
panic: strconv.ParseUint: parsing "-1": invalid syntax

goroutine 1 [running]:
main.main()
	/tmp/getint/main.go:12 +0xb1
exit status 2

With this PR:

-1

From Wireshark:
image

From MySQL Client:

mysql-8.4.3> SELECT SUM(-1);
Field   1:  `SUM(-1)`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       NEWDECIMAL
Collation:  binary (63)
Length:     24
Max_length: 2
Decimals:   0
Flags:      BINARY NUM 


+---------+
| SUM(-1) |
+---------+
|      -1 |
+---------+
1 row in set (0.00 sec)

@dveeden dveeden changed the title mysql: Fix GetInt() with negative text result mysql: Fix GetInt() with negative NEWDECIMAL result Jan 19, 2025
@lance6716 lance6716 merged commit 97aa985 into go-mysql-org:master Jan 20, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants