Skip to content

Commit

Permalink
Add conn session vars (pingcap#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
recall704 committed Apr 5, 2021
1 parent d1429a4 commit 7b80ecc
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions dumpling/v4/export/sql.go
Expand Up @@ -514,8 +514,20 @@ func isUnknownSystemVariableErr(err error) bool {
func resetDBWithSessionParams(tctx *tcontext.Context, db *sql.DB, dsn string, params map[string]interface{}) (*sql.DB, error) {
support := make(map[string]interface{})
for k, v := range params {
var pv interface{}
if str, ok := v.(string); ok {
if pvi, err := strconv.ParseInt(str, 10, 64); err == nil {
pv = pvi
} else if pvf, err := strconv.ParseFloat(str, 64); err == nil {
pv = pvf
} else {
pv = str
}
} else {
pv = v
}
s := fmt.Sprintf("SET SESSION %s = ?", k)
_, err := db.ExecContext(tctx, s, v)
_, err := db.ExecContext(tctx, s, pv)
if err != nil {
if isUnknownSystemVariableErr(err) {
tctx.L().Info("session variable is not supported by db", zap.String("variable", k), zap.Reflect("value", v))
Expand All @@ -524,7 +536,7 @@ func resetDBWithSessionParams(tctx *tcontext.Context, db *sql.DB, dsn string, pa
return nil, errors.Trace(err)
}

support[k] = v
support[k] = pv
}

for k, v := range support {
Expand Down

0 comments on commit 7b80ecc

Please sign in to comment.