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

fix get db version bug #545

Merged
merged 2 commits into from
May 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions pkg/datasource/sql/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import (
"context"
"database/sql/driver"
"errors"
"github.com/go-sql-driver/mysql"
"io"
"reflect"
"sync"

"github.com/go-sql-driver/mysql"

"github.com/seata/seata-go/pkg/datasource/sql/types"
"github.com/seata/seata-go/pkg/util/log"
)
Expand Down Expand Up @@ -151,24 +151,28 @@ func (c *seataConnector) dbVersion(ctx context.Context, conn driver.Conn) (strin

dest := make([]driver.Value, 1)
var version string
for true {
if err = res.Next(dest); err != nil {
if err == io.EOF {
return version, nil
}
return "", err
}
if len(dest) != 1 {
return "", errors.New("get the mysql version is not column 1")
}

var isVersionOk bool
version, isVersionOk = dest[0].(string)
if !isVersionOk {
return "", errors.New("get the mysql version is not a string")
if err = res.Next(dest); err != nil {
if err == io.EOF {
return version, nil
}
return "", err
}
if len(dest) != 1 {
return "", errors.New("get the mysql version is not column 1")
}
return "", errors.New("get the mysql version is error")

switch reflect.TypeOf(dest[0]).Kind() {
case reflect.Slice, reflect.Array:
val := reflect.ValueOf(dest[0]).Bytes()
version = string(val)
case reflect.String:
version = reflect.ValueOf(dest[0]).String()
default:
return "", errors.New("get the mysql version is not a string")
}

return version, nil
}

// Driver returns the underlying Driver of the Connector,
Expand Down