Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
lance6716 committed Sep 5, 2020
1 parent 83bacb7 commit 02df4e3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
9 changes: 5 additions & 4 deletions pkg/utils/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,16 +349,17 @@ func GetMariaDBUUID(db *sql.DB) (string, error) {
return fmt.Sprintf("%d%s%d", domainID, domainServerIDSeparator, serverID), nil
}

// GetParser gets a parser for sql.DB which maybe enabled `ANSI_QUOTES` sql_mode
// GetParser gets a parser for sql.DB which is suitable for session variable sql_mode
func GetParser(db *sql.DB) (*parser.Parser, error) {
sqlMode, err := GetGlobalVariable(db, "sql_mode")
c, err := db.Conn(context.Background())
if err != nil {
return nil, err
}
return GetParserFromSQLModeStr(sqlMode)
defer c.Close()
return GetParserForConn(c)
}

// GetParserForConn gets a parser for sql.Conn which maybe enabled `ANSI_QUOTES` sql_mode
// GetParserForConn gets a parser for sql.Conn which is suitable for session variable sql_mode
func GetParserForConn(conn *sql.Conn) (*parser.Parser, error) {
sqlMode, err := GetSessionVariable(conn, "sql_mode")
if err != nil {
Expand Down
8 changes: 1 addition & 7 deletions syncer/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package syncer

import (
"context"
"database/sql"
"strings"
"time"
Expand Down Expand Up @@ -93,12 +92,7 @@ func (conn *UpStreamConn) getServerUUID(flavor string) (string, error) {
}

func (conn *UpStreamConn) getParser() (*parser.Parser, error) {
c, err := conn.BaseDB.DB.Conn(context.Background())
if err != nil {
return nil, err
}
defer c.Close()
return utils.GetParserForConn(c)
return utils.GetParser(conn.BaseDB.DB)
}

func (conn *UpStreamConn) killConn(connID uint32) error {
Expand Down

0 comments on commit 02df4e3

Please sign in to comment.