-
Notifications
You must be signed in to change notification settings - Fork 65
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
*: support gbk charset #33
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,13 +26,13 @@ import ( | |
"sync" | ||
"time" | ||
|
||
"github.com/go-sql-driver/mysql" | ||
_ "github.com/go-sql-driver/mysql" | ||
"github.com/pingcap/errors" | ||
"github.com/pingcap/parser" | ||
"github.com/pingcap/parser/ast" | ||
"github.com/pingcap/parser/terror" | ||
_ "github.com/pingcap/parser/test_driver" | ||
"github.com/pingcap/tidb/parser" | ||
"github.com/pingcap/tidb/parser/ast" | ||
"github.com/pingcap/tidb/parser/charset" | ||
"github.com/pingcap/tidb/parser/terror" | ||
_ "github.com/pingcap/tidb/parser/test_driver" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
|
@@ -57,6 +57,18 @@ func init() { | |
flag.BoolVar(&record, "record", false, "Whether to record the test output to the result file.") | ||
flag.StringVar(¶ms, "params", "", "Additional params pass as DSN(e.g. session variable)") | ||
flag.BoolVar(&all, "all", false, "run all tests") | ||
|
||
c := &charset.Charset{ | ||
Name: "gbk", | ||
DefaultCollation: "gbk_bin", | ||
Collations: map[string]*charset.Collation{}, | ||
} | ||
charset.AddCharset(c) | ||
for _, coll := range charset.GetCollations() { | ||
if strings.EqualFold(coll.CharsetName, c.Name) { | ||
charset.AddCollation(coll) | ||
} | ||
} | ||
} | ||
|
||
const ( | ||
|
@@ -155,7 +167,7 @@ func isTiDB(db *sql.DB) bool { | |
} | ||
|
||
func (t *tester) addConnection(connName, hostName, userName, password, db string) { | ||
mdb, err := OpenDBWithRetry("mysql", userName+":"+password+"@tcp("+hostName+":"+port+")/"+db+"?strict=true&time_zone=%27Asia%2FShanghai%27"+params) | ||
mdb, err := OpenDBWithRetry("mysql", userName+":"+password+"@tcp("+hostName+":"+port+")/"+db+"?time_zone=%27Asia%2FShanghai%27"+params) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The strict mode is an option in the driver that changes warnings to errors. However in newer versions of the driver this has been removed. |
||
if err != nil { | ||
log.Fatalf("Open db err %v", err) | ||
} | ||
|
@@ -202,7 +214,7 @@ func (t *tester) disconnect(connName string) { | |
|
||
func (t *tester) preProcess() { | ||
dbName := "test" | ||
mdb, err := OpenDBWithRetry("mysql", user+":"+passwd+"@tcp("+host+":"+port+")/"+dbName+"?strict=true&time_zone=%27Asia%2FShanghai%27"+params) | ||
mdb, err := OpenDBWithRetry("mysql", user+":"+passwd+"@tcp("+host+":"+port+")/"+dbName+"?time_zone=%27Asia%2FShanghai%27"+params) | ||
t.conn = make(map[string]*Conn) | ||
if err != nil { | ||
log.Fatalf("Open db err %v", err) | ||
|
@@ -384,7 +396,7 @@ func (t *tester) concurrentExecute(querys []query, wg *sync.WaitGroup, errOccure | |
defer wg.Done() | ||
tt := newTester(t.name) | ||
dbName := "test" | ||
mdb, err := OpenDBWithRetry("mysql", user+":"+passwd+"@tcp("+host+":"+port+")/"+dbName+"?strict=true&time_zone=%27Asia%2FShanghai%27"+params) | ||
mdb, err := OpenDBWithRetry("mysql", user+":"+passwd+"@tcp("+host+":"+port+")/"+dbName+"?time_zone=%27Asia%2FShanghai%27"+params) | ||
if err != nil { | ||
log.Fatalf("Open db err %v", err) | ||
} | ||
|
@@ -575,7 +587,7 @@ func (t *tester) stmtExecute(query query, st ast.StmtNode) (err error) { | |
} | ||
default: | ||
if t.tx != nil { | ||
_, err = filterWarning(t.executeStmt(qText), t.enableWarning) | ||
err = t.executeStmt(qText) | ||
if err != nil { | ||
break | ||
} | ||
|
@@ -587,17 +599,16 @@ func (t *tester) stmtExecute(query query, st ast.StmtNode) (err error) { | |
break | ||
} | ||
|
||
var warn bool | ||
warn, err = filterWarning(t.executeStmt(qText), t.enableWarning) | ||
if err != nil && !warn { | ||
err = t.executeStmt(qText) | ||
if err != nil { | ||
t.rollback() | ||
break | ||
} else { | ||
warn, commitErr := filterWarning(t.commit(), t.enableWarning) | ||
commitErr := t.commit() | ||
if err == nil && commitErr != nil { | ||
err = commitErr | ||
} | ||
if commitErr != nil && !warn { | ||
if commitErr != nil{ | ||
t.rollback() | ||
break | ||
} | ||
|
@@ -654,21 +665,6 @@ func (t *tester) execute(query query) error { | |
return errors.Trace(err) | ||
} | ||
|
||
func filterWarning(err error, enableWarning bool) (isWarn bool, outErr error) { | ||
if err == nil { | ||
return false, err | ||
} | ||
causeErr := errors.Cause(err) | ||
_, isWarn = causeErr.(mysql.MySQLWarnings) | ||
// enableWarning is enabled by default | ||
if !enableWarning { | ||
if isWarn { | ||
return isWarn, nil | ||
} | ||
} | ||
return isWarn, err | ||
} | ||
|
||
func (t *tester) commit() error { | ||
err := t.tx.Commit() | ||
if err != nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GBK related issues are dealt with here. @dveeden